Fix up new setup code

No issue
- Prevent download count ajax request from running forever, even after setup is complete.
- Remove unneeded setup routes and controllers.
- Refactor to use ES6-imported ajax.
- Refactor to use injected services.
This commit is contained in:
Jason Williams 2015-05-27 15:10:47 -05:00
parent 3f93963c51
commit 67a2eaec2d
10 changed files with 62 additions and 78 deletions

View File

@ -1,15 +1,12 @@
import Ember from 'ember';
var ActivatingListItem = Ember.Component.extend({
export default Ember.Component.extend({
tagName: 'li',
classNameBindings: ['active'],
active: false,
linkClasses: Ember.computed('linkClass', function () {
return this.get('linkClass');
}),
linkClasses: null,
unfocusLink: function () {
this.$('a').blur();
}.on('click')
});
export default ActivatingListItem;

View File

@ -1,27 +0,0 @@
import Ember from 'ember';
import ajax from 'ghost/utils/ajax';
var SetupOneController = Ember.Controller.extend({
count: 'many, many',
downloadCounter: function () {
var self = this,
interval = 3000;
Ember.run.later(this, function () {
ajax({
url: self.get('ghostPaths.count'),
type: 'GET'
}).then(function (data) {
self.set('count', data.count.toLocaleString());
}).catch(function () {
self.set('count', 'many, many');
});
this.downloadCounter();
}, interval);
}.on('init')
});
export default SetupOneController;

View File

@ -1,9 +1,9 @@
/* global md5 */
import Ember from 'ember';
import ajax from 'ghost/utils/ajax';
import {request as ajax} from 'ic-ajax';
import ValidationEngine from 'ghost/mixins/validation-engine';
var SetupTwoController = Ember.Controller.extend(ValidationEngine, {
export default Ember.Controller.extend(ValidationEngine, {
size: 90,
blogTitle: null,
name: null,
@ -12,6 +12,9 @@ var SetupTwoController = Ember.Controller.extend(ValidationEngine, {
image: null,
submitting: false,
ghostPaths: Ember.inject.service('ghost-paths'),
notifications: Ember.inject.service(),
gravatarUrl: Ember.computed('email', function () {
var email = this.get('email'),
size = this.get('size');
@ -33,9 +36,10 @@ var SetupTwoController = Ember.Controller.extend(ValidationEngine, {
actions: {
setup: function () {
var self = this,
notifications = this.get('notifications'),
data = self.getProperties('blogTitle', 'name', 'email', 'password');
self.notifications.closePassive();
notifications.closePassive();
this.toggleProperty('submitting');
this.validate({format: false}).then(function () {
@ -57,14 +61,12 @@ var SetupTwoController = Ember.Controller.extend(ValidationEngine, {
});
}).catch(function (resp) {
self.toggleProperty('submitting');
self.notifications.showAPIError(resp);
notifications.showAPIError(resp);
});
}).catch(function (errors) {
self.toggleProperty('submitting');
self.notifications.showErrors(errors);
notifications.showErrors(errors);
});
}
}
});
export default SetupTwoController;

View File

@ -39,11 +39,11 @@ export default Ember.Controller.extend(ValidationEngine, {
identification: self.get('model.email'),
password: self.get('model.password')
});
}, function (resp) {
}).catch(function (resp) {
self.toggleProperty('submitting');
notifications.showAPIError(resp);
});
}, function (errors) {
}).catch(function (errors) {
self.toggleProperty('submitting');
notifications.showErrors(errors);
});

View File

@ -19,7 +19,7 @@ var Router = Ember.Router.extend({
documentTitle();
Router.map(function () {
this.resource('setup', function () {
this.route('setup', function () {
this.route('one');
this.route('two');
this.route('three');

View File

@ -1,24 +1,50 @@
import Ember from 'ember';
import ajax from 'ghost/utils/ajax';
import {request as ajax} from 'ic-ajax';
var SetupOneRoute = Ember.Route.extend({
titleToken: 'Setup',
beforeModel: function () {
var self = this,
ctrl = this.controllerFor('setup.one');
var DownloadCountPoller = Ember.Object.extend({
url: null,
count: 'many, many',
runId: null,
if (!ctrl) {
this.generateController('setup.one');
ctrl = this.controllerFor('setup.one');
}
init: function () {
this.downloadCounter();
this.poll();
},
return ajax({
url: self.get('ghostPaths.count'),
type: 'GET'
}).then(function (data) {
ctrl.set('count', data.count.toLocaleString());
}).catch(function () { /* Do nothing */ });
poll: function () {
var interval = 3000,
runId;
runId = Ember.run.later(this, function () {
this.downloadCounter();
this.poll();
}, interval);
this.set('runId', runId);
},
downloadCounter: function () {
var self = this;
ajax(this.get('url')).then(function (data) {
self.set('count', data.count.toLocaleString());
}).catch(function () {
self.set('count', 'many, many');
});
}
});
export default SetupOneRoute;
export default Ember.Route.extend({
ghostPaths: Ember.inject.service('ghost-paths'),
model: function () {
return DownloadCountPoller.create({url: this.get('ghostPaths.count')});
},
resetController: function (controller, isExiting) {
if (isExiting) {
Ember.run.cancel(controller.get('model.runId'));
controller.set('model', null);
}
}
});

View File

@ -1,7 +0,0 @@
import Ember from 'ember';
var SetupTwoRoute = Ember.Route.extend({
titleToken: 'Setup'
});
export default SetupTwoRoute;

View File

@ -1,7 +0,0 @@
import Ember from 'ember';
var SetupTwoRoute = Ember.Route.extend({
titleToken: 'Setup'
});
export default SetupTwoRoute;

View File

@ -5,15 +5,15 @@
{{!-- TODO: this should only appear on screens 2 & 3 --}}
<a class="gh-flow-back" href="#"><i class="icon-arrow-left"></i> Back</a>
<ol>
{{#gh-activating-list-item route="setup.one" linkClass="step"}}
{{#gh-activating-list-item route="setup.one" linkClasses="step"}}
<i class="icon-check"></i><span class="num">1</span>
{{/gh-activating-list-item}}
<li class="divider"></li>
{{#gh-activating-list-item route="setup.two" linkClass="step"}}
{{#gh-activating-list-item route="setup.two" linkClasses="step"}}
<i class="icon-check"></i><span class="num">2</span>
{{/gh-activating-list-item}}
<li class="divider"></li>
{{#gh-activating-list-item route="setup.three" linkClass="step"}}
{{#gh-activating-list-item route="setup.three" linkClasses="step"}}
<i class="icon-check"></i><span class="num">3</span>
{{/gh-activating-list-item}}
</ol>

View File

@ -1,7 +1,7 @@
<section class="gh-flow-content">
<header>
<h1>Welcome to <strong>Ghost</strong>!</h1>
<p>So far there have been <em>{{count}}</em> Ghost blogs made by people all over the world. Today were making yours.</p>
<p>So far there have been <em>{{model.count}}</em> Ghost blogs made by people all over the world. Today were making yours.</p>
</header>
<img class="gh-flow-screenshot" src="{{gh-path 'admin' 'img/install-welcome.png'}}" alt="Ghost screenshot" />