mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-05 18:34:39 +03:00
Rework Labs feature toggling
Refs #4750 - Make "Feature" a Controller with promise support. - Use via 'needs' instead of injecting from an initializer because we need authenticated access to the API. - Check whether feature is enabled when entering Code Injection route.
This commit is contained in:
parent
7c7dbb911c
commit
e6fd1b89c0
37
core/client/controllers/feature.js
Normal file
37
core/client/controllers/feature.js
Normal file
@ -0,0 +1,37 @@
|
||||
var FeatureController = Ember.Controller.extend(Ember.PromiseProxyMixin, {
|
||||
init: function () {
|
||||
var promise;
|
||||
|
||||
promise = this.store.find('setting', {type: 'blog,theme'}).then(function (settings) {
|
||||
return settings.get('firstObject');
|
||||
});
|
||||
|
||||
this.set('promise', promise);
|
||||
},
|
||||
|
||||
setting: Ember.computed.alias('content'),
|
||||
|
||||
labs: Ember.computed('isSettled', 'setting.labs', function () {
|
||||
var value = {};
|
||||
|
||||
if (this.get('isFulfilled')) {
|
||||
try {
|
||||
value = JSON.parse(this.get('setting.labs') || {});
|
||||
} catch (err) {
|
||||
value = {};
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}),
|
||||
|
||||
tagsUI: Ember.computed('config.tagsUI', 'labs.tagsUI', function () {
|
||||
return this.get('config.tagsUI') || this.get('labs.tagsUI');
|
||||
}),
|
||||
|
||||
codeInjectionUI: Ember.computed('config.codeInjectionUI', 'labs.codeInjectionUI', function () {
|
||||
return this.get('config.codeInjectionUI') || this.get('labs.codeInjectionUI');
|
||||
})
|
||||
});
|
||||
|
||||
export default FeatureController;
|
@ -1,15 +1,17 @@
|
||||
var SettingsController = Ember.Controller.extend({
|
||||
needs: ['feature'],
|
||||
|
||||
showGeneral: Ember.computed('session.user.name', function () {
|
||||
return this.get('session.user.isAuthor') || this.get('session.user.isEditor') ? false : true;
|
||||
}),
|
||||
showUsers: Ember.computed('session.user.name', function () {
|
||||
return this.get('session.user.isAuthor') ? false : true;
|
||||
}),
|
||||
showTags: Ember.computed('session.user.name', 'feature.tagsUI', function () {
|
||||
return this.get('session.user.isAuthor') || !this.get('feature.tagsUI') ? false : true;
|
||||
showTags: Ember.computed('session.user.name', 'controllers.feature.tagsUI', function () {
|
||||
return this.get('session.user.isAuthor') || !this.get('controllers.feature.tagsUI') ? 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;
|
||||
showCodeInjection: Ember.computed('session.user.name', 'controllers.feature.codeInjectionUI', function () {
|
||||
return this.get('session.user.isAuthor') || this.get('session.user.isEditor') || !this.get('controllers.feature.codeInjectionUI') ? false : true;
|
||||
}),
|
||||
showLabs: Ember.computed('session.user.name', function () {
|
||||
return this.get('session.user.isAuthor') || this.get('session.user.isEditor') ? false : true;
|
||||
|
@ -1,4 +1,6 @@
|
||||
var LabsController = Ember.Controller.extend(Ember.Evented, {
|
||||
needs: ['feature'],
|
||||
|
||||
uploadButtonText: 'Import',
|
||||
importErrors: '',
|
||||
labsJSON: Ember.computed('model.labs', function () {
|
||||
@ -23,24 +25,24 @@ var LabsController = Ember.Controller.extend(Ember.Evented, {
|
||||
tagsUIFlag: Ember.computed.alias('config.tagsUI'),
|
||||
codeUIFlag: Ember.computed.alias('config.codeInjectionUI'),
|
||||
|
||||
useTagsUI: Ember.computed('tagsUI', function (key, value) {
|
||||
useTagsUI: Ember.computed('controllers.feature.tagsUI', function (key, value) {
|
||||
// setter
|
||||
if (arguments.length > 1) {
|
||||
this.saveLabs('tagsUI', value);
|
||||
}
|
||||
|
||||
// getter
|
||||
return this.get('feature.tagsUI') || false;
|
||||
return this.get('controllers.feature.tagsUI') || false;
|
||||
}),
|
||||
|
||||
useCodeInjectionUI: Ember.computed('codeInjectionUI', function (key, value) {
|
||||
useCodeInjectionUI: Ember.computed('controllers.feature.tagsUI', function (key, value) {
|
||||
// setter
|
||||
if (arguments.length > 1) {
|
||||
this.saveLabs('codeInjectionUI', value);
|
||||
}
|
||||
|
||||
// getter
|
||||
return this.get('feature.codeInjectionUI') || false;
|
||||
return this.get('controllers.feature.codeInjectionUI') || false;
|
||||
}),
|
||||
|
||||
actions: {
|
||||
|
@ -1,17 +0,0 @@
|
||||
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;
|
@ -7,9 +7,24 @@ var SettingsCodeInjectionRoute = AuthenticatedRoute.extend(styleBody, loadingInd
|
||||
classNames: ['settings-view-code'],
|
||||
|
||||
beforeModel: function () {
|
||||
var feature = this.controllerFor('feature'),
|
||||
self = this;
|
||||
|
||||
if (!feature) {
|
||||
this.generateController('feature');
|
||||
feature = this.controllerFor('feature');
|
||||
}
|
||||
|
||||
return this.currentUser()
|
||||
.then(this.transitionAuthor())
|
||||
.then(this.transitionEditor());
|
||||
.then(this.transitionEditor())
|
||||
.then(function () {
|
||||
return feature.then(function () {
|
||||
if (!feature.get('codeInjectionUI')) {
|
||||
return self.transitionTo('settings.general');
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
model: function () {
|
||||
|
@ -12,7 +12,6 @@ paginationSettings = {
|
||||
};
|
||||
|
||||
TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMixin, {
|
||||
|
||||
actions: {
|
||||
willTransition: function () {
|
||||
this.send('closeSettingsMenu');
|
||||
@ -22,12 +21,23 @@ TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMixin,
|
||||
titleToken: 'Tags',
|
||||
|
||||
beforeModel: function () {
|
||||
if (!this.get('feature.tagsUI')) {
|
||||
return this.transitionTo('settings.general');
|
||||
var feature = this.controllerFor('feature'),
|
||||
self = this;
|
||||
|
||||
if (!feature) {
|
||||
this.generateController('feature');
|
||||
feature = this.controllerFor('feature');
|
||||
}
|
||||
|
||||
return this.currentUser()
|
||||
.then(this.transitionAuthor());
|
||||
.then(this.transitionAuthor())
|
||||
.then(function () {
|
||||
return feature.then(function () {
|
||||
if (!feature.get('tagsUI')) {
|
||||
return self.transitionTo('settings.general');
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
model: function () {
|
||||
|
@ -1,24 +0,0 @@
|
||||
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;
|
Loading…
Reference in New Issue
Block a user