mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Merge pull request #4699 from jaswilli/issue-4683
Finish tag post count UI. Misc tag related fixes
This commit is contained in:
commit
e90f10a6f1
8 changed files with 66 additions and 59 deletions
|
@ -1,7 +1,7 @@
|
||||||
var DeleteTagController = Ember.Controller.extend({
|
var DeleteTagController = Ember.ObjectController.extend({
|
||||||
inflection: function () {
|
postInflection: Ember.computed('post_count', function () {
|
||||||
return this.get('model').get('post_count') > 1 ? 'posts' : 'post';
|
return this.get('post_count') > 1 ? 'posts' : 'post';
|
||||||
}.property('model'),
|
}),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
confirmAccept: function () {
|
confirmAccept: function () {
|
||||||
|
|
|
@ -33,7 +33,7 @@ var PostTagsInputController = Ember.Controller.extend({
|
||||||
// queries hit a full store cache and we don't see empty or out-of-date
|
// queries hit a full store cache and we don't see empty or out-of-date
|
||||||
// suggestion lists
|
// suggestion lists
|
||||||
loadAllTags: function () {
|
loadAllTags: function () {
|
||||||
this.store.find('tag');
|
this.store.find('tag', {limit: 'all'});
|
||||||
},
|
},
|
||||||
|
|
||||||
addNewTag: function () {
|
addNewTag: function () {
|
||||||
|
@ -52,8 +52,13 @@ var PostTagsInputController = Ember.Controller.extend({
|
||||||
|
|
||||||
// add existing tag if we have a match
|
// add existing tag if we have a match
|
||||||
existingTags = this.store.all('tag').filter(function (tag) {
|
existingTags = this.store.all('tag').filter(function (tag) {
|
||||||
|
if (tag.get('isNew')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return tag.get('name').toLowerCase() === searchTerm;
|
return tag.get('name').toLowerCase() === searchTerm;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (existingTags.get('length')) {
|
if (existingTags.get('length')) {
|
||||||
this.send('addTag', existingTags.get('firstObject'));
|
this.send('addTag', existingTags.get('firstObject'));
|
||||||
} else {
|
} else {
|
||||||
|
@ -185,7 +190,7 @@ var PostTagsInputController = Ember.Controller.extend({
|
||||||
findMatchingTags: function (searchTerm) {
|
findMatchingTags: function (searchTerm) {
|
||||||
var matchingTags,
|
var matchingTags,
|
||||||
self = this,
|
self = this,
|
||||||
allTags = this.store.all('tag'),
|
allTags = this.store.all('tag').filterBy('isNew', false),
|
||||||
deDupe = {};
|
deDupe = {};
|
||||||
|
|
||||||
if (allTags.get('length') === 0) {
|
if (allTags.get('length') === 0) {
|
||||||
|
|
|
@ -92,7 +92,7 @@ var TagsController = Ember.ArrayController.extend(PaginationMixin, SettingsMenuM
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
newTag: function () {
|
newTag: function () {
|
||||||
this.set('activeTag', this.store.createRecord('tag'));
|
this.set('activeTag', this.store.createRecord('tag', {post_count: 0}));
|
||||||
this.send('openSettingsMenu');
|
this.send('openSettingsMenu');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -4,26 +4,9 @@ var PaginationControllerMixin = Ember.Mixin.create({
|
||||||
// set from PaginationRouteMixin
|
// set from PaginationRouteMixin
|
||||||
paginationSettings: null,
|
paginationSettings: null,
|
||||||
|
|
||||||
// holds the next page to load during infinite scroll
|
|
||||||
nextPage: null,
|
|
||||||
|
|
||||||
// indicates whether we're currently loading the next page
|
// indicates whether we're currently loading the next page
|
||||||
isLoading: null,
|
isLoading: null,
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {object} options: {
|
|
||||||
* modelType: <String> name of the model that will be paginated
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
init: function (options) {
|
|
||||||
this._super(options);
|
|
||||||
|
|
||||||
var metadata = this.store.metadataFor(options.modelType);
|
|
||||||
|
|
||||||
this.set('nextPage', metadata.pagination.next);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes an ajax response, concatenates any error messages, then generates an error notification.
|
* Takes an ajax response, concatenates any error messages, then generates an error notification.
|
||||||
* @param {jqXHR} response The jQuery ajax reponse object.
|
* @param {jqXHR} response The jQuery ajax reponse object.
|
||||||
|
@ -51,7 +34,8 @@ var PaginationControllerMixin = Ember.Mixin.create({
|
||||||
var self = this,
|
var self = this,
|
||||||
store = this.get('store'),
|
store = this.get('store'),
|
||||||
recordType = this.get('model').get('type'),
|
recordType = this.get('model').get('type'),
|
||||||
nextPage = this.get('nextPage'),
|
metadata = this.store.metadataFor(recordType),
|
||||||
|
nextPage = metadata.pagination && metadata.pagination.next,
|
||||||
paginationSettings = this.get('paginationSettings');
|
paginationSettings = this.get('paginationSettings');
|
||||||
|
|
||||||
if (nextPage) {
|
if (nextPage) {
|
||||||
|
@ -59,14 +43,16 @@ var PaginationControllerMixin = Ember.Mixin.create({
|
||||||
this.set('paginationSettings.page', nextPage);
|
this.set('paginationSettings.page', nextPage);
|
||||||
|
|
||||||
store.find(recordType, paginationSettings).then(function () {
|
store.find(recordType, paginationSettings).then(function () {
|
||||||
var metadata = store.metadataFor(recordType);
|
|
||||||
|
|
||||||
self.set('nextPage', metadata.pagination.next);
|
|
||||||
self.set('isLoading', false);
|
self.set('isLoading', false);
|
||||||
}, function (response) {
|
}, function (response) {
|
||||||
self.reportLoadError(response);
|
self.reportLoadError(response);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
resetPagination: function () {
|
||||||
|
this.set('paginationSettings.page', 1);
|
||||||
|
this.store.metaForType('tag', {pagination: undefined});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,16 @@ import AuthenticatedRoute from 'ghost/routes/authenticated';
|
||||||
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
|
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
|
||||||
import PaginationRouteMixin from 'ghost/mixins/pagination-route';
|
import PaginationRouteMixin from 'ghost/mixins/pagination-route';
|
||||||
|
|
||||||
var TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMixin, {
|
var TagsRoute,
|
||||||
|
paginationSettings;
|
||||||
|
|
||||||
|
paginationSettings = {
|
||||||
|
page: 1,
|
||||||
|
include: 'post_count',
|
||||||
|
limit: 15
|
||||||
|
};
|
||||||
|
|
||||||
|
TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMixin, {
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
willTransition: function () {
|
willTransition: function () {
|
||||||
|
@ -22,12 +31,16 @@ var TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMi
|
||||||
},
|
},
|
||||||
|
|
||||||
model: function () {
|
model: function () {
|
||||||
return this.store.find('tag', {include: 'post_count'});
|
this.store.unloadAll('tag');
|
||||||
|
|
||||||
|
return this.store.filter('tag', paginationSettings, function (tag) {
|
||||||
|
return !tag.get('isNew');
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController: function (controller, model) {
|
setupController: function (controller, model) {
|
||||||
this._super(controller, model);
|
this._super(controller, model);
|
||||||
this.setupPagination();
|
this.setupPagination(paginationSettings);
|
||||||
},
|
},
|
||||||
|
|
||||||
renderTemplate: function (controller, model) {
|
renderTemplate: function (controller, model) {
|
||||||
|
@ -37,6 +50,10 @@ var TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMi
|
||||||
outlet: 'settings-menu',
|
outlet: 'settings-menu',
|
||||||
view: 'settings/tags/settings-menu'
|
view: 'settings/tags/settings-menu'
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
deactivate: function () {
|
||||||
|
this.controller.send('resetPagination');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ var PostSerializer = ApplicationSerializer.extend(DS.EmbeddedRecordsMixin, {
|
||||||
|
|
||||||
serializeIntoHash: function (hash, type, record, options) {
|
serializeIntoHash: function (hash, type, record, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
options.includeId = true;
|
||||||
|
|
||||||
// We have a plural root in the API
|
// We have a plural root in the API
|
||||||
var root = Ember.String.pluralize(type.typeKey),
|
var root = Ember.String.pluralize(type.typeKey),
|
||||||
|
|
|
@ -1,21 +1,20 @@
|
||||||
import ApplicationSerializer from 'ghost/serializers/application';
|
import ApplicationSerializer from 'ghost/serializers/application';
|
||||||
|
|
||||||
var TagSerializer = ApplicationSerializer.extend(DS.EmbeddedRecordsMixin, {
|
var TagSerializer = ApplicationSerializer.extend({
|
||||||
|
serializeIntoHash: function (hash, type, record, options) {
|
||||||
serializeIntoHash: function (hash, type, record, options) {
|
options = options || {};
|
||||||
options = options || {};
|
options.includeId = true;
|
||||||
|
|
||||||
// We have a plural root in the API
|
var root = Ember.String.pluralize(type.typeKey),
|
||||||
var root = Ember.String.pluralize(type.typeKey),
|
data = this.serialize(record, options);
|
||||||
data = this.serialize(record, options);
|
|
||||||
|
// Properties that exist on the model but we don't want sent in the payload
|
||||||
// Properties that exist on the model but we don't want sent in the payload
|
|
||||||
|
delete data.uuid;
|
||||||
delete data.post_count;
|
delete data.post_count;
|
||||||
delete data.uuid;
|
|
||||||
|
hash[root] = [data];
|
||||||
hash[root] = [data];
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
export default TagSerializer;
|
||||||
export default TagSerializer;
|
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
{{#gh-modal-dialog action="closeModal" showClose=true type="action" style="wide,centered" animation="fade"
|
{{#gh-modal-dialog action="closeModal" showClose=true type="action" style="wide"
|
||||||
title="Are you sure you want to delete this tag?" confirm=confirm}}
|
title="Are you sure you want to delete this tag?" confirm=confirm}}
|
||||||
|
|
||||||
<p>You're about to delete "<strong>{{model.name}}</strong>".<br />
|
{{#if post_count}}
|
||||||
{{#if model.post_count}}
|
<strong>WARNING:</strong> <span class="red">This tag is attached to {{post_count}} {{postInflection}}.</span> You're about to delete "<strong>{{name}}</strong>". This is permanent! No backups, no restores, no magic undo button. We warned you, ok?
|
||||||
<span class="red">This tag will be removed from {{model.post_count}} {{inflection}}.</span>
|
{{else}}
|
||||||
|
<strong>WARNING:</strong> You're about to delete "<strong>{{name}}</strong>". This is permanent! No backups, no restores, no magic undo button. We warned you, ok?</p>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
This is permanent! No backups, no restores, no magic undo button. <br /> We warned you, ok?</p>
|
{{/gh-modal-dialog}}
|
||||||
|
|
||||||
{{/gh-modal-dialog}}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue