From c151be05de9baf3cb6ef4c4d26dd80239a9b1a61 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Mon, 23 Nov 2015 19:56:50 +0000 Subject: [PATCH] Update client for tag.post_count -> tag.count.posts rename refs #6105 - adds `raw` ember-data transform to handle standard JSON `count` attribute - update mirage factory to return correct `count.posts` format - rename all uses of `post_count` to `count.posts` --- ghost/admin/app/controllers/modals/delete-tag.js | 14 ++++++++------ ghost/admin/app/mirage/factories/tag.js | 8 ++++++-- ghost/admin/app/models/tag.js | 2 +- ghost/admin/app/routes/settings/tags.js | 2 +- ghost/admin/app/serializers/tag.js | 2 +- ghost/admin/app/templates/modals/delete-tag.hbs | 4 ++-- ghost/admin/app/templates/settings/tags.hbs | 2 +- ghost/admin/app/transforms/raw.js | 13 +++++++++++++ 8 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 ghost/admin/app/transforms/raw.js diff --git a/ghost/admin/app/controllers/modals/delete-tag.js b/ghost/admin/app/controllers/modals/delete-tag.js index 39cd15454a..8ef0b694c1 100644 --- a/ghost/admin/app/controllers/modals/delete-tag.js +++ b/ghost/admin/app/controllers/modals/delete-tag.js @@ -1,16 +1,18 @@ import Ember from 'ember'; -export default Ember.Controller.extend({ - notifications: Ember.inject.service(), - application: Ember.inject.controller(), +const {Controller, computed, inject} = Ember; - postInflection: Ember.computed('model.post_count', function () { - return this.get('model.post_count') > 1 ? 'posts' : 'post'; +export default Controller.extend({ + application: inject.controller(), + notifications: inject.service(), + + postInflection: computed('model.count.posts', function () { + return this.get('model.count.posts') > 1 ? 'posts' : 'post'; }), actions: { confirmAccept: function () { - var tag = this.get('model'); + let tag = this.get('model'); this.send('closeMenus'); diff --git a/ghost/admin/app/mirage/factories/tag.js b/ghost/admin/app/mirage/factories/tag.js index 04065c100f..7a17d574bb 100644 --- a/ghost/admin/app/mirage/factories/tag.js +++ b/ghost/admin/app/mirage/factories/tag.js @@ -11,9 +11,13 @@ export default Mirage.Factory.extend({ meta_title(i) { return `Meta Title for tag ${i}`; }, name(i) { return `Tag ${i}`; }, parent() { return null; }, - post_count() { return 1; }, slug(i) { return `tag-${i}`; }, updated_at() { return '2015-10-19T16:25:07.756Z'; }, updated_by() { return 1; }, - uuid(i) { return `tag-${i}`; } + uuid(i) { return `tag-${i}`; }, + count() { + return { + posts: 1 + }; + }, }); diff --git a/ghost/admin/app/models/tag.js b/ghost/admin/app/models/tag.js index 3e95ef6841..cac81306b9 100644 --- a/ghost/admin/app/models/tag.js +++ b/ghost/admin/app/models/tag.js @@ -17,5 +17,5 @@ export default DS.Model.extend(ValidationEngine, { updated_at: DS.attr('moment-date'), created_by: DS.attr(), updated_by: DS.attr(), - post_count: DS.attr('number') + count: DS.attr('raw') }); diff --git a/ghost/admin/app/routes/settings/tags.js b/ghost/admin/app/routes/settings/tags.js index a83bbb3b49..63e60a88e0 100644 --- a/ghost/admin/app/routes/settings/tags.js +++ b/ghost/admin/app/routes/settings/tags.js @@ -9,7 +9,7 @@ export default AuthenticatedRoute.extend(CurrentUserSettings, PaginationRoute, S paginationModel: 'tag', paginationSettings: { - include: 'post_count', + include: 'count.posts', limit: 15 }, diff --git a/ghost/admin/app/serializers/tag.js b/ghost/admin/app/serializers/tag.js index 31d1dd3348..c2e6f078a2 100644 --- a/ghost/admin/app/serializers/tag.js +++ b/ghost/admin/app/serializers/tag.js @@ -12,7 +12,7 @@ export default ApplicationSerializer.extend({ // Properties that exist on the model but we don't want sent in the payload delete data.uuid; - delete data.post_count; + delete data.count; hash[root] = [data]; } diff --git a/ghost/admin/app/templates/modals/delete-tag.hbs b/ghost/admin/app/templates/modals/delete-tag.hbs index a00448c5a8..d9c90af43e 100644 --- a/ghost/admin/app/templates/modals/delete-tag.hbs +++ b/ghost/admin/app/templates/modals/delete-tag.hbs @@ -1,8 +1,8 @@ {{#gh-modal-dialog action="closeModal" showClose=true type="action" style="wide" title="Are you sure you want to delete this tag?" confirm=confirm}} - {{#if model.post_count}} - WARNING: This tag is attached to {{model.post_count}} {{postInflection}}. You're about to delete "{{model.name}}". This is permanent! No backups, no restores, no magic undo button. We warned you, ok? + {{#if model.count.posts}} + WARNING: This tag is attached to {{model.count.posts}} {{postInflection}}. You're about to delete "{{model.name}}". This is permanent! No backups, no restores, no magic undo button. We warned you, ok? {{else}} WARNING: You're about to delete "{{model.name}}". This is permanent! No backups, no restores, no magic undo button. We warned you, ok? {{/if}} diff --git a/ghost/admin/app/templates/settings/tags.hbs b/ghost/admin/app/templates/settings/tags.hbs index 14e4f4c8fb..44b1d51fd2 100644 --- a/ghost/admin/app/templates/settings/tags.hbs +++ b/ghost/admin/app/templates/settings/tags.hbs @@ -20,7 +20,7 @@ {{tag.name}} /{{tag.slug}}

{{tag.description}}

- {{tag.post_count}} + {{tag.count.posts}} {{/link-to}} {{/each}} diff --git a/ghost/admin/app/transforms/raw.js b/ghost/admin/app/transforms/raw.js new file mode 100644 index 0000000000..5ae6f6c5c9 --- /dev/null +++ b/ghost/admin/app/transforms/raw.js @@ -0,0 +1,13 @@ +import DS from 'ember-data'; + +const {Transform} = DS; + +export default Transform.extend({ + deserialize: function (serialized) { + return serialized; + }, + + serialize: function (deserialized) { + return deserialized; + } +});