mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 13:54:35 +03:00
c3b49b45cf
no issue - adds `settings` service that acts as a proxy to the singular settings model with methods to fetch and reload, also prevents accidentally loading only some settings types which has caused problems in the past - updates app boot, signin, and signup processes to fetch settings ensuring that any part of the app can grab settings synchronously if needed - removes `timeZone` service, it's no longer needed as we can grab `settings.activeTimezone` directly - replaces all store queries for the settings model with appropriate `settings` methods - refactors `apps/*` routes/controllers, they had become a little convoluted with the way they were dealing with settings and the new service helped to clean that up
65 lines
1.8 KiB
JavaScript
65 lines
1.8 KiB
JavaScript
import Ember from 'ember';
|
|
import Service from 'ember-service';
|
|
import injectService from 'ember-service/inject';
|
|
import RSVP from 'rsvp';
|
|
import ValidationEngine from 'ghost-admin/mixins/validation-engine';
|
|
|
|
// ember-cli-shims doesn't export _ProxyMixin
|
|
const {_ProxyMixin} = Ember;
|
|
|
|
export default Service.extend(_ProxyMixin, ValidationEngine, {
|
|
store: injectService(),
|
|
|
|
// will be set to the single Settings model, it's a reference so any later
|
|
// changes to the settings object in the store will be reflected
|
|
content: null,
|
|
|
|
validationType: 'setting',
|
|
_loadingPromise: null,
|
|
|
|
// the settings API endpoint is a little weird as it's singular and we have
|
|
// to pass in all types - if we ever fetch settings without all types then
|
|
// save we have problems with the missing settings being removed or reset
|
|
_loadSettings() {
|
|
if (!this._loadingPromise) {
|
|
this._loadingPromise = this.get('store')
|
|
.queryRecord('setting', {type: 'blog,theme,private'})
|
|
.then((settings) => {
|
|
this._loadingPromise = null;
|
|
return settings;
|
|
});
|
|
}
|
|
|
|
return this._loadingPromise;
|
|
},
|
|
|
|
fetch() {
|
|
if (!this.get('content')) {
|
|
return this.reload();
|
|
} else {
|
|
return RSVP.resolve(this);
|
|
}
|
|
},
|
|
|
|
reload() {
|
|
return this._loadSettings().then((settings) => {
|
|
this.set('content', settings);
|
|
return this;
|
|
});
|
|
},
|
|
|
|
save() {
|
|
let settings = this.get('content');
|
|
|
|
if (!settings) {
|
|
return false;
|
|
}
|
|
|
|
return settings.save();
|
|
},
|
|
|
|
rollbackAttributes() {
|
|
return this.get('content').rollbackAttributes();
|
|
}
|
|
});
|