mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03: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
f11a81067a
commit
c614a652cb
3
core/client/adapters/app.js
Normal file
3
core/client/adapters/app.js
Normal file
@ -0,0 +1,3 @@
|
||||
var AppAdapter = DS.FixtureAdapter.extend({});
|
||||
|
||||
export default AppAdapter;
|
54
core/client/controllers/settings/app.js
Normal file
54
core/client/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
core/client/fixtures/apps.js
Normal file
68
core/client/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 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;
|
||||
|
13
core/client/models/app.js
Normal file
13
core/client/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
core/client/routes/settings/apps.js
Normal file
9
core/client/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>
|
||||
|
||||
<section class="content fade-in">
|
||||
<ul class="js-apps">
|
||||
{{#each availableApps}}
|
||||
<li>
|
||||
{{#if package}}{{package.name}} - {{package.version}}{{else}}{{name}} - package.json missing :({{/if}}
|
||||
<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>
|
||||
</li>
|
||||
<table class="js-apps">
|
||||
<thead>
|
||||
<th>App name</th>
|
||||
<th>Status</th>
|
||||
</thead>
|
||||
<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}}
|
||||
</ul>
|
||||
</section>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
Loading…
Reference in New Issue
Block a user