From 17d455cebae0f8e8d6ae8f2dc46a20e016ddad27 Mon Sep 17 00:00:00 2001 From: Peter Szel Date: Wed, 28 May 2014 08:57:55 +0200 Subject: [PATCH] Ported settings/apps logic to Ember. Closes #2423 - Created the apps route to fetch apps from server - Created controller for a single app - Modified the template of the apps page to use this controller - Created the Apps model - Created AppAdapter to use the FixtureAdapter for Ember Data --- ghost/admin/adapters/app.js | 3 ++ ghost/admin/controllers/settings/app.js | 54 ++++++++++++++++++++ ghost/admin/fixtures/apps.js | 68 +++++++++++++++++++++++++ ghost/admin/fixtures/init.js | 9 ++++ ghost/admin/models/app.js | 13 +++++ ghost/admin/routes/settings/apps.js | 9 ++++ ghost/admin/templates/settings/apps.hbs | 28 +++++++--- 7 files changed, 176 insertions(+), 8 deletions(-) create mode 100644 ghost/admin/adapters/app.js create mode 100644 ghost/admin/controllers/settings/app.js create mode 100644 ghost/admin/fixtures/apps.js create mode 100644 ghost/admin/models/app.js create mode 100644 ghost/admin/routes/settings/apps.js diff --git a/ghost/admin/adapters/app.js b/ghost/admin/adapters/app.js new file mode 100644 index 0000000000..6dadeb3e98 --- /dev/null +++ b/ghost/admin/adapters/app.js @@ -0,0 +1,3 @@ +var AppAdapter = DS.FixtureAdapter.extend({}); + +export default AppAdapter; \ No newline at end of file diff --git a/ghost/admin/controllers/settings/app.js b/ghost/admin/controllers/settings/app.js new file mode 100644 index 0000000000..19c92d706c --- /dev/null +++ b/ghost/admin/controllers/settings/app.js @@ -0,0 +1,54 @@ +/*global alert */ + +var AppStates = { + active: 'active', + working: 'working', + inactive: 'inactive' +}; + +var SettingsAppController = Ember.ObjectController.extend({ + appState: AppStates.active, + buttonText: '', + setAppState: function () { + this.set('appState', this.get('active') ? AppStates.active : AppStates.inactive); + }.on('init'), + buttonTextSetter: function () { + switch (this.get('appState')) { + case AppStates.active: + this.set('buttonText', 'Deactivate'); + break; + case AppStates.inactive: + this.set('buttonText', 'Activate'); + break; + case AppStates.working: + this.set('buttonText', 'Working'); + break; + } + }.observes('appState').on('init'), + activeClass: function () { + return this.appState === AppStates.active ? true : false; + }.property('appState'), + inactiveClass: function () { + return this.appState === AppStates.inactive ? true : false; + }.property('appState'), + actions: { + toggleApp: function (app) { + var self = this; + this.set('appState', AppStates.working); + + app.set('active', !app.get('active')); + + app.save().then(function () { + self.setAppState(); + }) + .then(function () { + alert('@TODO: Success'); + }) + .catch(function () { + alert('@TODO: Failure'); + }); + } + } +}); + +export default SettingsAppController; diff --git a/ghost/admin/fixtures/apps.js b/ghost/admin/fixtures/apps.js new file mode 100644 index 0000000000..508ac3e81e --- /dev/null +++ b/ghost/admin/fixtures/apps.js @@ -0,0 +1,68 @@ +var apps = [ + { + 'id': 1, + 'name': 'testApp', + 'package': { + 'name': 'testApp', + 'version': '2.0.1', + 'description': 'An example application showing how to filter jquery from ghost foot', + 'author': 'Ghost Foundation', + 'homepage': 'http://ghost.org', + 'repository': { + 'type': 'git', + 'url': 'git://github.com/TryGhost/Example-Apps' + }, + 'licenses': [ + { + 'type': 'MIT', + 'url': 'https://raw.github.com/TryGhost/Example-Apps/master/LICENSE' + } + ], + 'main': 'index.js', + 'engines': { + 'node': '0.10.*' + }, + 'engineStrict': true, + 'dependencies': { + 'ghost-app': '~0.0.2', + 'lodash': '~2.4.1' + }, + 'devDependencies': {} + }, + 'active': true + }, + { + 'id': 2, + 'name': 'testApp2', + 'package': { + 'name': 'testApp2', + 'version': '0.1.1', + 'description': 'An example application showing how to filter jquery from ghost foot', + 'author': 'Ghost Foundation', + 'homepage': 'http://ghost.org', + 'repository': { + 'type': 'git', + 'url': 'git://github.com/TryGhost/Example-Apps' + }, + 'licenses': [ + { + 'type': 'MIT', + 'url': 'https://raw.github.com/TryGhost/Example-Apps/master/LICENSE' + } + ], + 'main': 'index.js', + 'engines': { + 'node': '0.10.*' + }, + 'engineStrict': true, + 'dependencies': { + 'ghost-app': '~0.0.2', + 'lodash': '~2.4.1' + }, + 'devDependencies': {} + }, + 'active': false + }, +]; + +export default apps; \ No newline at end of file diff --git a/ghost/admin/fixtures/init.js b/ghost/admin/fixtures/init.js index e645e5eaf4..7cf349b26f 100644 --- a/ghost/admin/fixtures/init.js +++ b/ghost/admin/fixtures/init.js @@ -1,6 +1,7 @@ import postFixtures from 'ghost/fixtures/posts'; import userFixtures from 'ghost/fixtures/users'; import settingsFixtures from 'ghost/fixtures/settings'; +import appFixtures from 'ghost/fixtures/apps'; var response = function (responseBody, status) { status = status || 200; @@ -35,6 +36,10 @@ var settings = function (status) { return response(settingsFixtures, status); }; +var apps = function (status) { + return response(appFixtures, status); +}; + var defineFixtures = function (status) { ic.ajax.defineFixture('/ghost/api/v0.1/posts', posts(status)); ic.ajax.defineFixture('/ghost/api/v0.1/posts/1', post(1, status)); @@ -54,6 +59,10 @@ var defineFixtures = function (status) { msg: 'Password changed successfully' })); ic.ajax.defineFixture('/ghost/api/v0.1/settings/?type=blog,theme,app', settings(status)); + ic.ajax.defineFixture('/ghost/api/v0.1/apps', apps(status)); + ic.ajax.defineFixture('/ghost/api/v0.1/apps/1', response({ + response: 'success' + })); }; export default defineFixtures; diff --git a/ghost/admin/models/app.js b/ghost/admin/models/app.js new file mode 100644 index 0000000000..7672ab350d --- /dev/null +++ b/ghost/admin/models/app.js @@ -0,0 +1,13 @@ +import appFixtures from 'ghost/fixtures/apps'; + +var App = DS.Model.extend({ + name: DS.attr('string'), + package: DS.attr(), + active: DS.attr('boolean') +}); + +App.reopenClass({ + FIXTURES: appFixtures +}); + +export default App; diff --git a/ghost/admin/routes/settings/apps.js b/ghost/admin/routes/settings/apps.js new file mode 100644 index 0000000000..8c3672718b --- /dev/null +++ b/ghost/admin/routes/settings/apps.js @@ -0,0 +1,9 @@ +import AuthenticatedRoute from 'ghost/routes/authenticated'; + +var AppsRoute = AuthenticatedRoute.extend({ + model: function () { + return this.store.find('app'); + } +}); + +export default AppsRoute; diff --git a/ghost/admin/templates/settings/apps.hbs b/ghost/admin/templates/settings/apps.hbs index 11f0425889..cccd8df798 100644 --- a/ghost/admin/templates/settings/apps.hbs +++ b/ghost/admin/templates/settings/apps.hbs @@ -4,12 +4,24 @@
-