Ghost/ghost/admin/app/services/config.js
Kevin Ansfield c3b49b45cf 🎨 synchronous settings service
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
2017-03-20 07:43:49 -05:00

44 lines
1.3 KiB
JavaScript

import Ember from 'ember';
import Service from 'ember-service';
import computed from 'ember-computed';
import injectService from 'ember-service/inject';
import {isBlank} from 'ember-utils';
// ember-cli-shims doesn't export _ProxyMixin
const {_ProxyMixin} = Ember;
export default Service.extend(_ProxyMixin, {
ajax: injectService(),
ghostPaths: injectService(),
content: {},
fetch() {
let configUrl = this.get('ghostPaths.url').api('configuration');
return this.get('ajax').request(configUrl).then((config) => {
// normalize blogUrl to non-trailing-slash
let [{blogUrl}] = config.configuration;
config.configuration[0].blogUrl = blogUrl.replace(/\/$/, '');
this.set('content', config.configuration[0]);
});
},
availableTimezones: computed(function () {
let timezonesUrl = this.get('ghostPaths.url').api('configuration', 'timezones');
return this.get('ajax').request(timezonesUrl).then((configTimezones) => {
let [timezonesObj] = configTimezones.configuration;
timezonesObj = timezonesObj.timezones;
return timezonesObj;
});
}),
ghostOAuth: computed('ghostAuthId', function () {
return !isBlank(this.get('ghostAuthId'));
})
});