From cc6f698053f1da7a0da32cfcf4474b3ee914e89d Mon Sep 17 00:00:00 2001 From: Paul Adam Davis Date: Sun, 14 Dec 2014 17:56:04 +0000 Subject: [PATCH 1/2] Start of labs issue #4409 --- core/client/controllers/settings/labs.js | 43 +++++++++++++++++++++++- core/client/models/setting.js | 3 +- core/client/templates/settings/labs.hbs | 27 +++++++++++++++ core/server/data/default-settings.json | 3 ++ 4 files changed, 74 insertions(+), 2 deletions(-) diff --git a/core/client/controllers/settings/labs.js b/core/client/controllers/settings/labs.js index 8287e3b754..07b3c8e6d1 100644 --- a/core/client/controllers/settings/labs.js +++ b/core/client/controllers/settings/labs.js @@ -1,7 +1,48 @@ -var LabsController = Ember.Controller.extend(Ember.Evented, { +var LabsController = Ember.ObjectController.extend(Ember.Evented, { uploadButtonText: 'Import', importErrors: '', + saveLabs: function (optionName, optionValue) { + var labsConfig = this.get('labs'), + labsJSON = (this.get('labs')) ? JSON.parse(labsConfig) : {}; + + // Set new value in the JSON object + labsJSON[optionName] = optionValue; + + this.set('labs', JSON.stringify(labsJSON)); + + this.get('model').save().catch(function (errors) { + self.showErrors(errors); + self.get('model').rollback(); + }); + }, + + useTagsUI: Ember.computed('tagsUI', function (key, value) { + // setter + if (arguments.length > 1) { + this.saveLabs('tagsUI', value); + } + + // getter + var labsConfig = (this.get('labs')) ? JSON.parse(this.get('labs')) : false; + + + return (labsConfig.tagsUI) ? labsConfig.tagsUI : false; + }), + + useCodeInjectionUI: Ember.computed('codeInjectionUI', function (key, value) { + // setter + if (arguments.length > 1) { + this.saveLabs('codeInjectionUI', value); + } + + // getter + var labsConfig = (this.get('labs')) ? JSON.parse(this.get('labs')) : false; + + + return (labsConfig.codeInjectionUI) ? labsConfig.codeInjectionUI : false; + }), + actions: { onUpload: function (file) { var self = this, diff --git a/core/client/models/setting.js b/core/client/models/setting.js index 025a664051..a44f3e4d74 100644 --- a/core/client/models/setting.js +++ b/core/client/models/setting.js @@ -16,7 +16,8 @@ var Setting = DS.Model.extend(NProgressSaveMixin, ValidationEngine, { activeTheme: DS.attr('string'), availableThemes: DS.attr(), ghost_head: DS.attr('string'), - ghost_foot: DS.attr('string') + ghost_foot: DS.attr('string'), + labs: DS.attr('string') }); export default Setting; diff --git a/core/client/templates/settings/labs.hbs b/core/client/templates/settings/labs.hbs index 1ee042a8b6..e0cc43e11d 100644 --- a/core/client/templates/settings/labs.hbs +++ b/core/client/templates/settings/labs.hbs @@ -44,4 +44,31 @@ + +
+ +
+
+
+ + +
+ +
+ + +
+
+
+ diff --git a/core/server/data/default-settings.json b/core/server/data/default-settings.json index 65c076b9c3..8818fc7b0b 100644 --- a/core/server/data/default-settings.json +++ b/core/server/data/default-settings.json @@ -67,6 +67,9 @@ }, "ghost_foot": { "defaultValue" : "" + }, + "labs": { + "defaultValue": "{}" } }, "theme": { From c0fc7c5bcd0c27c70a27be3eb36243f436a27681 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Thu, 1 Jan 2015 19:09:55 +0000 Subject: [PATCH 2/2] Adds global feature manager closes #4409 --- core/client/controllers/settings.js | 11 ++++------- core/client/controllers/settings/labs.js | 24 ++++++++++++------------ core/client/initializers/feature.js | 17 +++++++++++++++++ core/client/routes/settings/tags.js | 2 +- core/client/templates/settings/labs.hbs | 17 +++++++++++------ core/client/utils/feature.js | 24 ++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 26 deletions(-) create mode 100644 core/client/initializers/feature.js create mode 100644 core/client/utils/feature.js diff --git a/core/client/controllers/settings.js b/core/client/controllers/settings.js index 5ea159700d..df07e47fd7 100644 --- a/core/client/controllers/settings.js +++ b/core/client/controllers/settings.js @@ -5,18 +5,15 @@ var SettingsController = Ember.Controller.extend({ showUsers: Ember.computed('session.user.name', function () { return this.get('session.user.isAuthor') ? false : true; }), - showTags: Ember.computed('session.user.name', 'config.tagsUI', function () { - return this.get('session.user.isAuthor') || !this.get('config.tagsUI') ? false : true; + showTags: Ember.computed('session.user.name', 'feature.tagsUI', function () { + return this.get('session.user.isAuthor') || !this.get('feature.tagsUI') ? false : true; }), - - showCodeInjection: Ember.computed('session.user.name', 'config.codeInjectionUI', function () { - return this.get('session.user.isAuthor') || this.get('session.user.isEditor') || !this.get('config.codeInjectionUI') ? false : true; + showCodeInjection: Ember.computed('session.user.name', 'feature.codeInjectionUI', function () { + return this.get('session.user.isAuthor') || this.get('session.user.isEditor') || !this.get('feature.codeInjectionUI') ? false : true; }), - showLabs: Ember.computed('session.user.name', function () { return this.get('session.user.isAuthor') || this.get('session.user.isEditor') ? false : true; }), - showAbout: Ember.computed('session.user.name', function () { return this.get('session.user.isAuthor') ? false : true; }) diff --git a/core/client/controllers/settings/labs.js b/core/client/controllers/settings/labs.js index 07b3c8e6d1..c111d765ba 100644 --- a/core/client/controllers/settings/labs.js +++ b/core/client/controllers/settings/labs.js @@ -1,15 +1,18 @@ -var LabsController = Ember.ObjectController.extend(Ember.Evented, { +var LabsController = Ember.Controller.extend(Ember.Evented, { uploadButtonText: 'Import', importErrors: '', + labsJSON: Ember.computed('model.labs', function () { + return JSON.parse(this.get('model.labs') || {}); + }), saveLabs: function (optionName, optionValue) { - var labsConfig = this.get('labs'), - labsJSON = (this.get('labs')) ? JSON.parse(labsConfig) : {}; + var self = this, + labsJSON = this.get('labsJSON'); // Set new value in the JSON object labsJSON[optionName] = optionValue; - this.set('labs', JSON.stringify(labsJSON)); + this.set('model.labs', JSON.stringify(labsJSON)); this.get('model').save().catch(function (errors) { self.showErrors(errors); @@ -17,6 +20,9 @@ var LabsController = Ember.ObjectController.extend(Ember.Evented, { }); }, + tagsUIFlag: Ember.computed.alias('config.tagsUI'), + codeUIFlag: Ember.computed.alias('config.codeInjectionUI'), + useTagsUI: Ember.computed('tagsUI', function (key, value) { // setter if (arguments.length > 1) { @@ -24,10 +30,7 @@ var LabsController = Ember.ObjectController.extend(Ember.Evented, { } // getter - var labsConfig = (this.get('labs')) ? JSON.parse(this.get('labs')) : false; - - - return (labsConfig.tagsUI) ? labsConfig.tagsUI : false; + return this.get('feature.tagsUI') || false; }), useCodeInjectionUI: Ember.computed('codeInjectionUI', function (key, value) { @@ -37,10 +40,7 @@ var LabsController = Ember.ObjectController.extend(Ember.Evented, { } // getter - var labsConfig = (this.get('labs')) ? JSON.parse(this.get('labs')) : false; - - - return (labsConfig.codeInjectionUI) ? labsConfig.codeInjectionUI : false; + return this.get('feature.codeInjectionUI') || false; }), actions: { diff --git a/core/client/initializers/feature.js b/core/client/initializers/feature.js new file mode 100644 index 0000000000..52ff88e15e --- /dev/null +++ b/core/client/initializers/feature.js @@ -0,0 +1,17 @@ +import Feature from 'ghost/utils/feature'; + +var injectFeatureInitializer = { + name: 'injectFeature', + after: ['config', 'store'], + + initialize: function (container, application) { + application.register('feature:main', Feature); + application.inject('feature:main', 'store', 'store:main'); + application.inject('feature:main', 'config', 'ghost:config'); + + application.inject('controller', 'feature', 'feature:main'); + application.inject('route', 'feature', 'feature:main'); + } +}; + +export default injectFeatureInitializer; diff --git a/core/client/routes/settings/tags.js b/core/client/routes/settings/tags.js index 3bc3470585..e7e7469419 100644 --- a/core/client/routes/settings/tags.js +++ b/core/client/routes/settings/tags.js @@ -13,7 +13,7 @@ var TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMi titleToken: 'Tags', beforeModel: function () { - if (!this.get('config.tagsUI')) { + if (!this.get('feature.tagsUI')) { return this.transitionTo('settings.general'); } diff --git a/core/client/templates/settings/labs.hbs b/core/client/templates/settings/labs.hbs index e0cc43e11d..6af0e7f49f 100644 --- a/core/client/templates/settings/labs.hbs +++ b/core/client/templates/settings/labs.hbs @@ -49,25 +49,30 @@
+ {{#unless tagsUIFlag}}
+

A settings screen which enables you to add, edit and delete tags (work in progress)

+ {{/unless}} + {{#unless codeUIFlag}}
-
+ {{/unless}}
diff --git a/core/client/utils/feature.js b/core/client/utils/feature.js new file mode 100644 index 0000000000..185cbd9f39 --- /dev/null +++ b/core/client/utils/feature.js @@ -0,0 +1,24 @@ +var Feature; + +Feature = Ember.Object.extend({ + init: function () { + var self = this; + this.store.find('setting').then(function (settings) { + self.set('setting', settings.get('firstObject')); + }); + }, + labs: Ember.computed('setting', 'setting.labs', function () { + if (this.setting) { + return JSON.parse(this.get('setting.labs') || {}); + } + return {}; + }), + tagsUI: Ember.computed('config.tagsUI', 'labs.tagsUI', function () { + return this.config.tagsUI || this.get('labs.tagsUI'); + }), + codeInjectionUI: Ember.computed('config.codeInjectionUI', 'labs.codeInjectionUI', function () { + return this.config.codeInjectionUI || this.get('labs.codeInjectionUI'); + }) +}); + +export default Feature;