diff --git a/ghost/admin/app/adapters/theme.js b/ghost/admin/app/adapters/theme.js new file mode 100644 index 0000000000..92025e6998 --- /dev/null +++ b/ghost/admin/app/adapters/theme.js @@ -0,0 +1,13 @@ +import ApplicationAdapter from './application'; + +export default ApplicationAdapter.extend({ + + activate(model) { + let url = `${this.buildURL('theme', model.get('id'))}activate/`; + + return this.ajax(url, 'PUT', {data: {}}).then((data) => { + return this.store.pushPayload(data); + }); + } + +}); diff --git a/ghost/admin/app/components/gh-theme-table.js b/ghost/admin/app/components/gh-theme-table.js index c2f4cb68be..6ffae061ed 100644 --- a/ghost/admin/app/components/gh-theme-table.js +++ b/ghost/admin/app/components/gh-theme-table.js @@ -5,19 +5,18 @@ import get from 'ember-metal/get'; export default Component.extend({ themes: null, - activeTheme: null, - sortedThemes: computed('themes.[]', 'activeTheme', function () { - let activeTheme = get(this, 'activeTheme'); + sortedThemes: computed('themes.@each.active', function () { let themes = get(this, 'themes').map((t) => { let theme = {}; let themePackage = get(t, 'package'); + theme.model = t; theme.name = get(t, 'name'); theme.label = themePackage ? `${themePackage.name}` : theme.name; theme.version = themePackage ? `${themePackage.version}` : '1.0'; theme.package = themePackage; - theme.active = theme.name === activeTheme; + theme.active = get(t, 'active'); theme.isDeletable = !theme.active; return theme; diff --git a/ghost/admin/app/components/modals/upload-theme.js b/ghost/admin/app/components/modals/upload-theme.js index 56431a888c..037a758932 100644 --- a/ghost/admin/app/components/modals/upload-theme.js +++ b/ghost/admin/app/components/modals/upload-theme.js @@ -21,6 +21,7 @@ export default ModalComponent.extend({ displayOverwriteWarning: false, eventBus: injectService(), + store: injectService(), hideUploader: or('theme', 'displayOverwriteWarning'), @@ -29,9 +30,10 @@ export default ModalComponent.extend({ }), themeName: computed('theme.{name,package.name}', function () { - let t = this.get('theme'); + let themePackage = this.get('theme.package'); + let name = this.get('theme.name'); - return t.package ? `${t.package.name} - ${t.package.version}` : t.name; + return themePackage ? `${themePackage.name} - ${themePackage.version}` : name; }), currentThemeNames: mapBy('model.themes', 'name'), @@ -43,13 +45,12 @@ export default ModalComponent.extend({ canActivateTheme: computed('theme', function () { let theme = this.get('theme'); - // TODO: do we still get theme.active back or do we need to check settings.activeTheme? - return theme && !theme.active; + return theme && !theme.get('active'); }), actions: { validateTheme(file) { - let themeName = file.name.replace(/\.zip$/, '').replace(/[^\w@.]/gi, '-'); + let themeName = file.name.replace(/\.zip$/, '').replace(/[^\w@.]/gi, '-').toLowerCase(); let currentThemeNames = this.get('currentThemeNames'); @@ -94,16 +95,18 @@ export default ModalComponent.extend({ }, uploadSuccess(response) { - let [theme] = response.themes; + this.get('store').pushPayload(response); + + let theme = this.get('store').peekRecord('theme', response.themes[0].name); this.set('theme', theme); if (get(theme, 'warnings.length') > 0) { - this.set('validationWarnings', theme.warnings); + this.set('validationWarnings', get(theme, 'warnings')); } // invoke the passed in confirm action - invokeAction(this, 'model.uploadSuccess', this.get('theme')); + invokeAction(this, 'model.uploadSuccess', theme); }, uploadFailed(error) { diff --git a/ghost/admin/app/controllers/settings/design.js b/ghost/admin/app/controllers/settings/design.js index afc53c30c2..d6653e8a91 100644 --- a/ghost/admin/app/controllers/settings/design.js +++ b/ghost/admin/app/controllers/settings/design.js @@ -109,9 +109,8 @@ export default Controller.extend(SettingsSaveMixin, { navItem.set('url', url); }, - setTheme(theme) { - this.set('model.activeTheme', theme.name); - this.send('save'); + activateTheme(theme) { + return theme.activate(); }, downloadTheme(theme) { diff --git a/ghost/admin/app/models/setting.js b/ghost/admin/app/models/setting.js index 0214e3b362..39771646fd 100644 --- a/ghost/admin/app/models/setting.js +++ b/ghost/admin/app/models/setting.js @@ -15,7 +15,6 @@ export default Model.extend(ValidationEngine, { postsPerPage: attr('number'), forceI18n: attr('boolean'), permalinks: attr('string'), - activeTheme: attr('string'), activeTimezone: attr('string', {defaultValue: 'Etc/UTC'}), ghost_head: attr('string'), ghost_foot: attr('string'), diff --git a/ghost/admin/app/models/theme.js b/ghost/admin/app/models/theme.js index ded4933b45..c68e382d5f 100644 --- a/ghost/admin/app/models/theme.js +++ b/ghost/admin/app/models/theme.js @@ -3,5 +3,12 @@ import attr from 'ember-data/attr'; export default Model.extend({ name: attr('string'), - package: attr('raw') + package: attr('raw'), + active: attr('boolean'), + warnings: attr('raw'), + + activate() { + let adapter = this.store.adapterFor(this.constructor.modelName); + return adapter.activate(this); + } }); diff --git a/ghost/admin/app/routes/settings/design.js b/ghost/admin/app/routes/settings/design.js index 376572fc7f..1dacdb23af 100644 --- a/ghost/admin/app/routes/settings/design.js +++ b/ghost/admin/app/routes/settings/design.js @@ -49,12 +49,8 @@ export default AuthenticatedRoute.extend(styleBody, CurrentUserSettings, { return this._super(...arguments); }, - reloadThemes() { - return this.get('store').findAll('theme'); - }, - activateTheme(theme) { - return this.get('controller').send('setTheme', theme); + return this.get('controller').send('activateTheme', theme); } } }); diff --git a/ghost/admin/app/templates/components/gh-theme-table.hbs b/ghost/admin/app/templates/components/gh-theme-table.hbs index 83a5faff24..20cc353418 100644 --- a/ghost/admin/app/templates/components/gh-theme-table.hbs +++ b/ghost/admin/app/templates/components/gh-theme-table.hbs @@ -22,7 +22,7 @@ {{#if theme.active}} Active {{else}} - + Activate {{/if}} diff --git a/ghost/admin/app/templates/settings/design.hbs b/ghost/admin/app/templates/settings/design.hbs index 1ff151d16a..699809d3ed 100644 --- a/ghost/admin/app/templates/settings/design.hbs +++ b/ghost/admin/app/templates/settings/design.hbs @@ -23,8 +23,7 @@
{{asset}}
helper',
+ details: 'The listed files should be included using the {{asset}}
helper. For more information, please see the asset helper documentation.
{{asset}}
helper',
- details: 'The listed files should be included using the {{asset}}
helper. For more information, please see the asset helper documentation.