0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00
ghost/core/client/app/routes/setup/one.js
Kevin Ansfield 3d6856614f Use es6 across client and add ember-suave to enforce rules
no issue
- add ember-suave dependency
- upgrade grunt-jscs dependency
- add a new .jscsrc for the client's tests directory that extends from client's base .jscsrc
- separate client tests in Gruntfile jscs task so they pick up the test's .jscsrc
- standardize es6 usage across client
2015-11-30 10:41:01 +00:00

57 lines
1.3 KiB
JavaScript

import Ember from 'ember';
import {request as ajax} from 'ic-ajax';
const {Route, inject, run} = Ember;
let DownloadCountPoller = Ember.Object.extend({
url: null,
count: '',
runId: null,
init() {
this.downloadCounter();
this.poll();
},
poll() {
let interval = Ember.testing ? 20 : 2000;
let runId = run.later(this, function () {
this.downloadCounter();
if (!Ember.testing) {
this.poll();
}
}, interval);
this.set('runId', runId);
},
downloadCounter() {
ajax(this.get('url')).then((data) => {
let pattern = /(-?\d+)(\d{3})/;
let count = data.count.toString();
while (pattern.test(count)) {
count = count.replace(pattern, '$1,$2');
}
this.set('count', count);
}).catch(() => {
this.set('count', '');
});
}
});
export default Route.extend({
ghostPaths: inject.service('ghost-paths'),
model() {
return DownloadCountPoller.create({url: this.get('ghostPaths.count')});
},
resetController(controller, isExiting) {
if (isExiting) {
run.cancel(controller.get('model.runId'));
controller.set('model', null);
}
}
});