0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Adds global feature manager

closes #4409
This commit is contained in:
Hannah Wolfe 2015-01-01 19:09:55 +00:00
parent cc6f698053
commit c0fc7c5bcd
6 changed files with 69 additions and 26 deletions

View file

@ -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;
})

View file

@ -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: {

View file

@ -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;

View file

@ -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');
}

View file

@ -49,25 +49,30 @@
<form>
<fieldset>
{{#unless tagsUIFlag}}
<div class="form-group for-checkbox">
<label for="labs-tagsUI">Tag Management</label>
<label class="checkbox" for="labs-tagsUI">
{{input id="labs-tagsUI" name="labs[tagsUI]" type="checkbox" checked=useTagsUI}}
<span class="input-toggle-component"></span>
<p>Enable the tag management interface (work in progress)</p>
<p>A settings screen which enables you to add, edit and delete tags</p>
<p>Enable the tag management interface</p>
</label>
<p>A settings screen which enables you to add, edit and delete tags (work in progress)</p>
</div>
{{/unless}}
{{#unless codeUIFlag}}
<div class="form-group for-checkbox">
<label for="labs-codeInjectionUI">Code Injection</label>
<label class="checkbox" for="labs-codeInjectionUI">
{{input id="labs-codeInjectionUI" name="labs[codeInjectionUI]" type="checkbox" checked=useCodeInjectionUI}}
<label class="check box" for="labs-codeInjectionUI">
{{input id="labs-codeInjectionUI" name="labs[codeInjectionUI]" type="checkbox"
checked=useCodeInjectionUI}}
<span class="input-toggle-component"></span>
<p>Enable the code injection interface (work in progress)</p>
<p>A settings screen which enables you to add code into your theme</p>
<p>Enable the code injection interface</p>
</label>
<p>A settings screen which enables you to add code into your theme (work in progress)</p>
</div>
{{/unless}}
</fieldset>
</form>

View file

@ -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;