mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 15:12:58 +03:00
675a1221fa
refs #6039 - add `jquery-deparam` ember testing dependency for use in mirage config - setup necessary mirage fixtures & endpoints for successful testing of setup flow's happy-path - add happy-path acceptance test for setup flow
60 lines
1.4 KiB
JavaScript
60 lines
1.4 KiB
JavaScript
import Ember from 'ember';
|
|
import {request as ajax} from 'ic-ajax';
|
|
|
|
var DownloadCountPoller = Ember.Object.extend({
|
|
url: null,
|
|
count: '',
|
|
runId: null,
|
|
|
|
init: function () {
|
|
this.downloadCounter();
|
|
this.poll();
|
|
},
|
|
|
|
poll: function () {
|
|
var interval = Ember.testing ? 20 : 2000,
|
|
runId;
|
|
|
|
runId = Ember.run.later(this, function () {
|
|
this.downloadCounter();
|
|
if (!Ember.testing) {
|
|
this.poll();
|
|
}
|
|
}, interval);
|
|
|
|
this.set('runId', runId);
|
|
},
|
|
|
|
downloadCounter: function () {
|
|
var self = this;
|
|
|
|
ajax(this.get('url')).then(function (data) {
|
|
var count = data.count.toString(),
|
|
pattern = /(-?\d+)(\d{3})/;
|
|
|
|
while (pattern.test(count)) {
|
|
count = count.replace(pattern, '$1,$2');
|
|
}
|
|
|
|
self.set('count', count);
|
|
}).catch(function () {
|
|
self.set('count', '');
|
|
});
|
|
}
|
|
});
|
|
|
|
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);
|
|
}
|
|
}
|
|
});
|