Files
ember-panda/addon/routes/project/show/operate.js
T
2023-11-28 14:30:02 -05:00

62 lines
1.9 KiB
JavaScript

// Generated by CoffeeScript 2.7.0
import Ember from 'ember';
import config from 'ember-get-config';
//import Route from '@ember/route'
//import { inject as service } from '@ember/service'
export default Ember.Route.extend({
poll: Ember.inject.service(),
session: Ember.inject.service(),
model: function() {
return this.modelFor('project.show');
},
afterModel: function(model, transition) {
var ref;
if ((ref = this.controllerFor('application').get('currentRouteName')) !== 'loading' && ref !== 'project.show.operate') {
return model.reload();
}
},
actions: {
didTransition: function() {
var base_url, endpoint, model_name, pollFunction, pollId, request, session;
model_name = 'panda/setting';
base_url = this.store.adapterFor(model_name).buildURL(model_name);
endpoint = `${base_url}/operation_running/get_value`;
request = {
url: endpoint,
success: (operation_running) => {
if (operation_running) {
return this.set('router.globals.operation_running', moment(operation_running));
} else {
return this.set('router.globals.operation_running', '');
}
}
};
session = this.get('session');
if (Ember.get(session, 'isAuthenticated')) {
session.authorize('authorizer:devise', function(key, authorization) {
request.crossDomain = true;
return request.headers = {
[`${key}`]: authorization
};
});
}
pollFunction = () => {
return Ember.$.ajax(request);
};
pollFunction();
return pollId = this.get('poll').addPoll({
interval: 30 * 1000,
callback: pollFunction,
label: 'project-running'
});
},
//@get('poll').startPoll(pollId)
//@get('poll').startPollByLabel('project-running')
willTransition: function() {
return this.get('poll').stopPollByLabel('project-running');
}
}
});