2015-11-24 08:36:36 +01:00
|
|
|
(function() {
|
|
|
|
// Get application context
|
|
|
|
var app = Sammy.apps['#main'];
|
|
|
|
var store = app.store;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Services
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// All services status
|
|
|
|
app.get('#/services', function (c) {
|
|
|
|
c.api('/services', function(data) { // ?
|
2017-07-24 17:03:39 +02:00
|
|
|
var data2 = {
|
|
|
|
services: []
|
|
|
|
};
|
2015-11-24 08:36:36 +01:00
|
|
|
$.each(data, function(k, v) {
|
|
|
|
v.name = k;
|
|
|
|
// Handlebars want booleans
|
|
|
|
v.is_loaded = (v.loaded=='enabled') ? true : false;
|
|
|
|
v.is_running = (v.status=='running') ? true : false;
|
|
|
|
// Translate status and loaded state
|
|
|
|
v.status = y18n.t(v.status);
|
|
|
|
v.loaded = y18n.t(v.loaded);
|
|
|
|
data2.services.push(v);
|
|
|
|
});
|
2018-05-17 06:38:02 +02:00
|
|
|
|
|
|
|
data2.services.sort(function (a, b) {
|
|
|
|
if (a.name > b.name) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (a.name < b.name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
2015-11-24 08:36:36 +01:00
|
|
|
c.view('service/service_list', data2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Status & actions for a service
|
|
|
|
app.get('#/services/:service', function (c) {
|
|
|
|
c.api('/services/'+ c.params['service'], function(data) { // ?
|
2017-07-24 17:03:39 +02:00
|
|
|
var data2 = {
|
|
|
|
service: data
|
|
|
|
};
|
2015-11-24 08:36:36 +01:00
|
|
|
data2.service.name = c.params['service'];
|
|
|
|
// Handlebars want booleans
|
|
|
|
data2.service.is_loaded = (data.loaded=='enabled') ? true : false;
|
2018-06-12 01:40:18 +02:00
|
|
|
data2.service.is_running = (data.active=='active') ? true : false;
|
2015-11-24 08:36:36 +01:00
|
|
|
// Translate status and loaded state
|
2018-06-12 01:40:18 +02:00
|
|
|
data2.service.active = y18n.t(data.active);
|
2015-11-24 08:36:36 +01:00
|
|
|
data2.service.loaded = y18n.t(data.loaded);
|
|
|
|
store.clear('slide');
|
|
|
|
c.view('service/service_info', data2);
|
|
|
|
}, 'GET');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Service log
|
|
|
|
app.get('#/services/:service/log', function (c) {
|
2017-07-24 17:03:39 +02:00
|
|
|
var params = {
|
|
|
|
number: 50
|
|
|
|
};
|
2015-11-24 08:36:36 +01:00
|
|
|
c.api('/services/'+ c.params['service'] +'/log', function(data) { // ?
|
|
|
|
data2 = { 'logs': [], 'name': c.params['service'] };
|
|
|
|
$.each(data, function(k, v) {
|
|
|
|
data2.logs.push({filename: k, filecontent: v.join('\n')});
|
|
|
|
});
|
|
|
|
|
|
|
|
c.view('service/service_log', data2);
|
|
|
|
}, 'GET', params);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Enable/Disable & Start/Stop service
|
|
|
|
app.get('#/services/:service/:action', function (c) {
|
|
|
|
c.confirm(
|
|
|
|
"Service",
|
2017-04-03 15:53:42 +02:00
|
|
|
// confirm_service_start, confirm_service_stop, confirm_service_enable and confirm_service_disable
|
|
|
|
y18n.t('confirm_service_' + c.params['action'].toLowerCase(), [c.params['service']]),
|
2015-11-24 08:36:36 +01:00
|
|
|
function(){
|
2017-07-24 17:03:39 +02:00
|
|
|
var method = null,
|
|
|
|
endurl = c.params['service'];
|
2015-11-24 08:36:36 +01:00
|
|
|
|
|
|
|
switch (c.params['action']) {
|
|
|
|
case 'start':
|
|
|
|
method = 'PUT';
|
|
|
|
break;
|
|
|
|
case 'stop':
|
|
|
|
method = 'DELETE';
|
|
|
|
break;
|
|
|
|
case 'enable':
|
|
|
|
method = 'PUT';
|
|
|
|
endurl += '/enable';
|
|
|
|
break;
|
|
|
|
case 'disable':
|
|
|
|
method = 'DELETE';
|
|
|
|
endurl += '/enable';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
c.flash('fail', y18n.t('unknown_action', [c.params['action']]));
|
|
|
|
store.clear('slide');
|
|
|
|
c.redirect('#/services/'+ c.params['service']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (method && endurl) {
|
|
|
|
c.api('/services/'+ endurl, function(data) {
|
|
|
|
store.clear('slide');
|
|
|
|
c.redirect('#/services/'+ c.params['service']);
|
|
|
|
}, method);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
store.clear('slide');
|
|
|
|
c.redirect('#/services/'+ c.params['service']);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function(){
|
|
|
|
store.clear('slide');
|
|
|
|
c.redirect('#/services/'+ c.params['service']);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-05-17 05:08:41 +02:00
|
|
|
})();
|