From def2e8e146492595db379b5e1ac451b09e2cb779 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Wed, 27 May 2015 15:10:47 -0500 Subject: [PATCH] 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. --- .../app/components/gh-activating-list-item.js | 9 +-- ghost/admin/app/controllers/setup/one.js | 27 --------- ghost/admin/app/controllers/setup/two.js | 16 ++--- ghost/admin/app/controllers/signup.js | 4 +- ghost/admin/app/router.js | 2 +- ghost/admin/app/routes/setup/one.js | 60 +++++++++++++------ ghost/admin/app/routes/setup/three.js | 7 --- ghost/admin/app/routes/setup/two.js | 7 --- ghost/admin/app/templates/setup.hbs | 6 +- ghost/admin/app/templates/setup/one.hbs | 2 +- 10 files changed, 62 insertions(+), 78 deletions(-) delete mode 100644 ghost/admin/app/controllers/setup/one.js delete mode 100644 ghost/admin/app/routes/setup/three.js delete mode 100644 ghost/admin/app/routes/setup/two.js diff --git a/ghost/admin/app/components/gh-activating-list-item.js b/ghost/admin/app/components/gh-activating-list-item.js index 4796918f8e..5a409f5ba5 100644 --- a/ghost/admin/app/components/gh-activating-list-item.js +++ b/ghost/admin/app/components/gh-activating-list-item.js @@ -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; diff --git a/ghost/admin/app/controllers/setup/one.js b/ghost/admin/app/controllers/setup/one.js deleted file mode 100644 index e6e0ce52a2..0000000000 --- a/ghost/admin/app/controllers/setup/one.js +++ /dev/null @@ -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; diff --git a/ghost/admin/app/controllers/setup/two.js b/ghost/admin/app/controllers/setup/two.js index a886e6adc7..cf61173325 100644 --- a/ghost/admin/app/controllers/setup/two.js +++ b/ghost/admin/app/controllers/setup/two.js @@ -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; diff --git a/ghost/admin/app/controllers/signup.js b/ghost/admin/app/controllers/signup.js index ed29e2fb0e..64f9b8f56f 100644 --- a/ghost/admin/app/controllers/signup.js +++ b/ghost/admin/app/controllers/signup.js @@ -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); }); diff --git a/ghost/admin/app/router.js b/ghost/admin/app/router.js index 066de50e08..552fedff98 100644 --- a/ghost/admin/app/router.js +++ b/ghost/admin/app/router.js @@ -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'); diff --git a/ghost/admin/app/routes/setup/one.js b/ghost/admin/app/routes/setup/one.js index a741ebc1c6..73c4628be7 100644 --- a/ghost/admin/app/routes/setup/one.js +++ b/ghost/admin/app/routes/setup/one.js @@ -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); + } + } +}); diff --git a/ghost/admin/app/routes/setup/three.js b/ghost/admin/app/routes/setup/three.js deleted file mode 100644 index 26281ebffc..0000000000 --- a/ghost/admin/app/routes/setup/three.js +++ /dev/null @@ -1,7 +0,0 @@ -import Ember from 'ember'; - -var SetupTwoRoute = Ember.Route.extend({ - titleToken: 'Setup' -}); - -export default SetupTwoRoute; diff --git a/ghost/admin/app/routes/setup/two.js b/ghost/admin/app/routes/setup/two.js deleted file mode 100644 index 26281ebffc..0000000000 --- a/ghost/admin/app/routes/setup/two.js +++ /dev/null @@ -1,7 +0,0 @@ -import Ember from 'ember'; - -var SetupTwoRoute = Ember.Route.extend({ - titleToken: 'Setup' -}); - -export default SetupTwoRoute; diff --git a/ghost/admin/app/templates/setup.hbs b/ghost/admin/app/templates/setup.hbs index 3c5da62b5f..b7ed9f381e 100644 --- a/ghost/admin/app/templates/setup.hbs +++ b/ghost/admin/app/templates/setup.hbs @@ -5,15 +5,15 @@ {{!-- TODO: this should only appear on screens 2 & 3 --}} Back
    - {{#gh-activating-list-item route="setup.one" linkClass="step"}} + {{#gh-activating-list-item route="setup.one" linkClasses="step"}} 1 {{/gh-activating-list-item}}
  1. - {{#gh-activating-list-item route="setup.two" linkClass="step"}} + {{#gh-activating-list-item route="setup.two" linkClasses="step"}} 2 {{/gh-activating-list-item}}
  2. - {{#gh-activating-list-item route="setup.three" linkClass="step"}} + {{#gh-activating-list-item route="setup.three" linkClasses="step"}} 3 {{/gh-activating-list-item}}
diff --git a/ghost/admin/app/templates/setup/one.hbs b/ghost/admin/app/templates/setup/one.hbs index b4d3a67d85..9f19354453 100644 --- a/ghost/admin/app/templates/setup/one.hbs +++ b/ghost/admin/app/templates/setup/one.hbs @@ -1,7 +1,7 @@

Welcome to Ghost!

-

So far there have been {{count}} Ghost blogs made by people all over the world. Today we’re making yours.

+

So far there have been {{model.count}} Ghost blogs made by people all over the world. Today we’re making yours.

Ghost screenshot