From 26268d76677518a130db4b7028f7945609af240c Mon Sep 17 00:00:00 2001 From: Matt Enlow Date: Wed, 19 Nov 2014 17:27:45 -0700 Subject: [PATCH] Tags management api hookup Ref #4248 - Added tags settings menu - Added basic new, edit, delete, and save actions - Show actionable edit buttons dynamically based on tag state - Infinite scroll - Closing the tag settings menu rollbacks your changes - Removed not-yet-implementable code --- ghost/admin/controllers/settings/tags.js | 50 ++++++++++++ ghost/admin/mixins/pagination-controller.js | 2 +- ghost/admin/routes/application.js | 7 +- ghost/admin/routes/settings/tags.js | 17 +++- ghost/admin/templates/-publish-bar.hbs | 2 +- ghost/admin/templates/settings/tags.hbs | 77 ++----------------- .../templates/settings/tags/settings-menu.hbs | 34 ++++++++ ghost/admin/views/settings/tags.js | 3 +- .../views/settings/tags/settings-menu.js | 9 +++ 9 files changed, 123 insertions(+), 78 deletions(-) create mode 100644 ghost/admin/controllers/settings/tags.js create mode 100644 ghost/admin/templates/settings/tags/settings-menu.hbs create mode 100644 ghost/admin/views/settings/tags/settings-menu.js diff --git a/ghost/admin/controllers/settings/tags.js b/ghost/admin/controllers/settings/tags.js new file mode 100644 index 0000000000..210453c6c6 --- /dev/null +++ b/ghost/admin/controllers/settings/tags.js @@ -0,0 +1,50 @@ +import PaginationMixin from 'ghost/mixins/pagination-controller'; + +var TagsController = Ember.ArrayController.extend(PaginationMixin, { + tags: Ember.computed.alias('model'), + activeTag: null, + init: function (options) { + options = options || {}; + options.modelType = 'tag'; + this._super(options); + }, + actions: { + // Clear any unsaved changes until autosave is implemented + closeTagEditor: function () { + this.get('activeTag').rollback(); + this.send('closeSettingsMenu'); + }, + newTag: function () { + this.set('activeTag', this.store.createRecord('tag')); + this.send('openSettingsMenu'); + }, + editTag: function (tag) { + this.set('activeTag', tag); + this.send('openSettingsMenu'); + }, + deleteTag: function (tag) { + var name = tag.get('name'), + self = this; + + this.send('closeSettingsMenu'); + + tag.destroyRecord().then(function () { + self.notifications.showSuccess('Deleted ' + name); + }).catch(function (error) { + self.notifications.showAPIError(error); + }); + }, + saveTag: function (tag) { + var name = tag.get('name'), + self = this; + + tag.save().then(function () { + self.notifications.showSuccess('Saved ' + name); + }).catch(function (error) { + self.notifications.showAPIError(error); + }); + } + } +}); + +export default TagsController; diff --git a/ghost/admin/mixins/pagination-controller.js b/ghost/admin/mixins/pagination-controller.js index 40c812e10d..b4f910cb2e 100644 --- a/ghost/admin/mixins/pagination-controller.js +++ b/ghost/admin/mixins/pagination-controller.js @@ -17,7 +17,7 @@ var PaginationControllerMixin = Ember.Mixin.create({ * } */ init: function (options) { - this._super(); + this._super(options); var metadata = this.store.metadataFor(options.modelType); diff --git a/ghost/admin/routes/application.js b/ghost/admin/routes/application.js index fd1ec7203a..c6b8c353a9 100644 --- a/ghost/admin/routes/application.js +++ b/ghost/admin/routes/application.js @@ -31,12 +31,15 @@ var ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, Shor this.toggleProperty('controller.showGlobalMobileNav'); }, - toggleSettingsMenu: function () { - this.toggleProperty('controller.showSettingsMenu'); + openSettingsMenu: function () { + this.set('controller.showSettingsMenu', true); }, closeSettingsMenu: function () { this.set('controller.showSettingsMenu', false); }, + toggleSettingsMenu: function () { + this.toggleProperty('controller.showSettingsMenu'); + }, closePopups: function () { this.get('dropdown').closeDropdowns(); diff --git a/ghost/admin/routes/settings/tags.js b/ghost/admin/routes/settings/tags.js index 17e6dc5fa6..b59aa2bdef 100644 --- a/ghost/admin/routes/settings/tags.js +++ b/ghost/admin/routes/settings/tags.js @@ -1,7 +1,8 @@ import AuthenticatedRoute from 'ghost/routes/authenticated'; import CurrentUserSettings from 'ghost/mixins/current-user-settings'; +import PaginationRouteMixin from 'ghost/mixins/pagination-route'; -var TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, { +var TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMixin, { beforeModel: function () { if (!this.get('config.tagsUI')) { @@ -14,6 +15,20 @@ var TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, { model: function () { return this.store.find('tag'); + }, + + setupController: function (controller, model) { + this._super(controller, model); + this.setupPagination(); + }, + + renderTemplate: function (controller, model) { + this._super(controller, model); + this.render('settings/tags/settings-menu', { + into: 'application', + outlet: 'settings-menu', + view: 'settings/tags/settings-menu' + }); } }); diff --git a/ghost/admin/templates/-publish-bar.hbs b/ghost/admin/templates/-publish-bar.hbs index 79a0407a92..10c6ce0209 100644 --- a/ghost/admin/templates/-publish-bar.hbs +++ b/ghost/admin/templates/-publish-bar.hbs @@ -3,7 +3,7 @@ {{render 'post-tags-input'}}
- + {{view "editor-save-button" id="entry-actions" classNameBindings="isNew:unsaved"}}
diff --git a/ghost/admin/templates/settings/tags.hbs b/ghost/admin/templates/settings/tags.hbs index 1d9e179074..1161e4896a 100644 --- a/ghost/admin/templates/settings/tags.hbs +++ b/ghost/admin/templates/settings/tags.hbs @@ -2,84 +2,17 @@ Back

Tags

- - - - - +
- {{#each}} + {{#each tag in tags}}
- {{name}} - /{{slug}} -

{{description}}

+ + /{{tag.slug}} +

{{tag.description}}

N/A
{{/each}}
-{{!-- This is the example markup -
- -
- News - /news -

The latest news, reviews and information from around the world

- 20 - -
- General - /news/general -

My go-to category when I’m not really sure what else to file news

- 7 -
-
- -
- Image - Private -

All posts with the “image” post format

- 12 -
- -
- Kittens - /kittens -

My sordid past and wrongdoings

- 9 - -
- A Short History of Nearly Everything - /kittens/a-short-history - 4 - -
- In Parts - /kittens/a-short-history/in-parts -

Lorem ipsum kittens innit

- 2 -
-
-
- -
- Video - Private -

All posts containing a YouTube video link

- 6 -
- -
- The End - /the-end -

The final frontier

- 1 -
- -
---}} \ No newline at end of file diff --git a/ghost/admin/templates/settings/tags/settings-menu.hbs b/ghost/admin/templates/settings/tags/settings-menu.hbs new file mode 100644 index 0000000000..011abca425 --- /dev/null +++ b/ghost/admin/templates/settings/tags/settings-menu.hbs @@ -0,0 +1,34 @@ +
+
+
+
+

Tag Settings

+ +
+
+
+
+ + {{input type="text" value=activeTag.name}} +
+ +
+ {{!--@TODO show full url preview, not just slug--}} + {{input type="text" value=activeTag.slug}} +
+ +
+ + {{textarea value=activeTag.description}} +
+ + {{#unless activeTag.isNew}} + + {{/unless}} + +
+
+
+
diff --git a/ghost/admin/views/settings/tags.js b/ghost/admin/views/settings/tags.js index 359d32c56e..e29b40eded 100644 --- a/ghost/admin/views/settings/tags.js +++ b/ghost/admin/views/settings/tags.js @@ -1,5 +1,6 @@ import BaseView from 'ghost/views/settings/content-base'; +import PaginationScrollMixin from 'ghost/mixins/pagination-view-infinite-scroll'; -var SettingsTagsView = BaseView.extend(); +var SettingsTagsView = BaseView.extend(PaginationScrollMixin); export default SettingsTagsView; diff --git a/ghost/admin/views/settings/tags/settings-menu.js b/ghost/admin/views/settings/tags/settings-menu.js new file mode 100644 index 0000000000..a655914635 --- /dev/null +++ b/ghost/admin/views/settings/tags/settings-menu.js @@ -0,0 +1,9 @@ +var TagsSettingsMenuView = Ember.View.extend({ + saveText: Ember.computed('controller.model.isNew', function () { + return this.get('controller.model.isNew') ? + 'Add Tag' : + 'Save Tag'; + }) +}); + +export default TagsSettingsMenuView;