mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-07 11:30:55 +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({
|
var SettingsController = Ember.Controller.extend({
|
||||||
|
needs: ['feature'],
|
||||||
|
|
||||||
showGeneral: Ember.computed('session.user.name', function () {
|
showGeneral: Ember.computed('session.user.name', function () {
|
||||||
return this.get('session.user.isAuthor') || this.get('session.user.isEditor') ? false : true;
|
return this.get('session.user.isAuthor') || this.get('session.user.isEditor') ? false : true;
|
||||||
}),
|
}),
|
||||||
showUsers: Ember.computed('session.user.name', function () {
|
showUsers: Ember.computed('session.user.name', function () {
|
||||||
return this.get('session.user.isAuthor') ? false : true;
|
return this.get('session.user.isAuthor') ? false : true;
|
||||||
}),
|
}),
|
||||||
showTags: Ember.computed('session.user.name', 'feature.tagsUI', function () {
|
showTags: Ember.computed('session.user.name', 'controllers.feature.tagsUI', function () {
|
||||||
return this.get('session.user.isAuthor') || !this.get('feature.tagsUI') ? false : true;
|
return this.get('session.user.isAuthor') || !this.get('controllers.feature.tagsUI') ? false : true;
|
||||||
}),
|
}),
|
||||||
showCodeInjection: Ember.computed('session.user.name', 'feature.codeInjectionUI', function () {
|
showCodeInjection: Ember.computed('session.user.name', 'controllers.feature.codeInjectionUI', function () {
|
||||||
return this.get('session.user.isAuthor') || this.get('session.user.isEditor') || !this.get('feature.codeInjectionUI') ? false : true;
|
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 () {
|
showLabs: Ember.computed('session.user.name', function () {
|
||||||
return this.get('session.user.isAuthor') || this.get('session.user.isEditor') ? false : true;
|
return this.get('session.user.isAuthor') || this.get('session.user.isEditor') ? false : true;
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
var LabsController = Ember.Controller.extend(Ember.Evented, {
|
var LabsController = Ember.Controller.extend(Ember.Evented, {
|
||||||
|
needs: ['feature'],
|
||||||
|
|
||||||
uploadButtonText: 'Import',
|
uploadButtonText: 'Import',
|
||||||
importErrors: '',
|
importErrors: '',
|
||||||
labsJSON: Ember.computed('model.labs', function () {
|
labsJSON: Ember.computed('model.labs', function () {
|
||||||
@ -23,24 +25,24 @@ var LabsController = Ember.Controller.extend(Ember.Evented, {
|
|||||||
tagsUIFlag: Ember.computed.alias('config.tagsUI'),
|
tagsUIFlag: Ember.computed.alias('config.tagsUI'),
|
||||||
codeUIFlag: Ember.computed.alias('config.codeInjectionUI'),
|
codeUIFlag: Ember.computed.alias('config.codeInjectionUI'),
|
||||||
|
|
||||||
useTagsUI: Ember.computed('tagsUI', function (key, value) {
|
useTagsUI: Ember.computed('controllers.feature.tagsUI', function (key, value) {
|
||||||
// setter
|
// setter
|
||||||
if (arguments.length > 1) {
|
if (arguments.length > 1) {
|
||||||
this.saveLabs('tagsUI', value);
|
this.saveLabs('tagsUI', value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// getter
|
// 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
|
// setter
|
||||||
if (arguments.length > 1) {
|
if (arguments.length > 1) {
|
||||||
this.saveLabs('codeInjectionUI', value);
|
this.saveLabs('codeInjectionUI', value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// getter
|
// getter
|
||||||
return this.get('feature.codeInjectionUI') || false;
|
return this.get('controllers.feature.codeInjectionUI') || false;
|
||||||
}),
|
}),
|
||||||
|
|
||||||
actions: {
|
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'],
|
classNames: ['settings-view-code'],
|
||||||
|
|
||||||
beforeModel: function () {
|
beforeModel: function () {
|
||||||
|
var feature = this.controllerFor('feature'),
|
||||||
|
self = this;
|
||||||
|
|
||||||
|
if (!feature) {
|
||||||
|
this.generateController('feature');
|
||||||
|
feature = this.controllerFor('feature');
|
||||||
|
}
|
||||||
|
|
||||||
return this.currentUser()
|
return this.currentUser()
|
||||||
.then(this.transitionAuthor())
|
.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 () {
|
model: function () {
|
||||||
|
@ -12,7 +12,6 @@ paginationSettings = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMixin, {
|
TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMixin, {
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
willTransition: function () {
|
willTransition: function () {
|
||||||
this.send('closeSettingsMenu');
|
this.send('closeSettingsMenu');
|
||||||
@ -22,12 +21,23 @@ TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMixin,
|
|||||||
titleToken: 'Tags',
|
titleToken: 'Tags',
|
||||||
|
|
||||||
beforeModel: function () {
|
beforeModel: function () {
|
||||||
if (!this.get('feature.tagsUI')) {
|
var feature = this.controllerFor('feature'),
|
||||||
return this.transitionTo('settings.general');
|
self = this;
|
||||||
|
|
||||||
|
if (!feature) {
|
||||||
|
this.generateController('feature');
|
||||||
|
feature = this.controllerFor('feature');
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.currentUser()
|
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 () {
|
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