mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
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
This commit is contained in:
parent
2bd3a77fa7
commit
17d455ceba
7 changed files with 176 additions and 8 deletions
3
ghost/admin/adapters/app.js
Normal file
3
ghost/admin/adapters/app.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
var AppAdapter = DS.FixtureAdapter.extend({});
|
||||||
|
|
||||||
|
export default AppAdapter;
|
54
ghost/admin/controllers/settings/app.js
Normal file
54
ghost/admin/controllers/settings/app.js
Normal file
|
@ -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;
|
68
ghost/admin/fixtures/apps.js
Normal file
68
ghost/admin/fixtures/apps.js
Normal file
|
@ -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;
|
|
@ -1,6 +1,7 @@
|
||||||
import postFixtures from 'ghost/fixtures/posts';
|
import postFixtures from 'ghost/fixtures/posts';
|
||||||
import userFixtures from 'ghost/fixtures/users';
|
import userFixtures from 'ghost/fixtures/users';
|
||||||
import settingsFixtures from 'ghost/fixtures/settings';
|
import settingsFixtures from 'ghost/fixtures/settings';
|
||||||
|
import appFixtures from 'ghost/fixtures/apps';
|
||||||
|
|
||||||
var response = function (responseBody, status) {
|
var response = function (responseBody, status) {
|
||||||
status = status || 200;
|
status = status || 200;
|
||||||
|
@ -35,6 +36,10 @@ var settings = function (status) {
|
||||||
return response(settingsFixtures, status);
|
return response(settingsFixtures, status);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var apps = function (status) {
|
||||||
|
return response(appFixtures, status);
|
||||||
|
};
|
||||||
|
|
||||||
var defineFixtures = function (status) {
|
var defineFixtures = function (status) {
|
||||||
ic.ajax.defineFixture('/ghost/api/v0.1/posts', posts(status));
|
ic.ajax.defineFixture('/ghost/api/v0.1/posts', posts(status));
|
||||||
ic.ajax.defineFixture('/ghost/api/v0.1/posts/1', post(1, 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'
|
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/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;
|
export default defineFixtures;
|
||||||
|
|
13
ghost/admin/models/app.js
Normal file
13
ghost/admin/models/app.js
Normal file
|
@ -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;
|
9
ghost/admin/routes/settings/apps.js
Normal file
9
ghost/admin/routes/settings/apps.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import AuthenticatedRoute from 'ghost/routes/authenticated';
|
||||||
|
|
||||||
|
var AppsRoute = AuthenticatedRoute.extend({
|
||||||
|
model: function () {
|
||||||
|
return this.store.find('app');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default AppsRoute;
|
|
@ -4,12 +4,24 @@
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<section class="content fade-in">
|
<section class="content fade-in">
|
||||||
<ul class="js-apps">
|
<table class="js-apps">
|
||||||
{{#each availableApps}}
|
<thead>
|
||||||
<li>
|
<th>App name</th>
|
||||||
{{#if package}}{{package.name}} - {{package.version}}{{else}}{{name}} - package.json missing :({{/if}}
|
<th>Status</th>
|
||||||
<button data-app="{{name}}" class="{{#if active}}button-delete js-button-deactivate js-button-active">Deactivate{{else}}button-add js-button-activate">Activate{{/if}}</button>
|
</thead>
|
||||||
</li>
|
<tbody>
|
||||||
|
{{#each itemController="settings/app"}}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
{{#if package}}{{package.name}} - {{package.version}}{{else}}{{name}} - package.json missing :({{/if}}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button {{action toggleApp this}} {{bind-attr class=":js-button-active activeClass:button-delete inactiveClass:button-add activeClass:js-button-deactivate"}}>
|
||||||
|
{{buttonText}}
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ul>
|
</tbody>
|
||||||
|
</table>
|
||||||
</section>
|
</section>
|
Loading…
Add table
Reference in a new issue