2016-06-04 14:58:11 +02:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-07 00:21:26 +02:00
|
|
|
angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Constraints) {
|
2016-06-04 14:58:11 +02:00
|
|
|
function formatMoment(unix) {
|
|
|
|
return unix ? moment.unix(unix).fromNow() : 'N/A';
|
|
|
|
}
|
|
|
|
|
2016-06-07 00:21:26 +02:00
|
|
|
function nodeConstraint(field) {
|
|
|
|
var constraint = Constraints.node[field];
|
|
|
|
var result = {
|
|
|
|
required: !constraint.optional
|
|
|
|
};
|
|
|
|
if (constraint.type === 'string') {
|
|
|
|
result.pattern = constraint.regex;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-06-04 14:58:11 +02:00
|
|
|
var nga = NgAdminConfigurationProvider;
|
|
|
|
var admin = nga.application('Knotenverwaltung - Admin-Panel');
|
|
|
|
|
|
|
|
admin
|
|
|
|
.baseApiUrl('/internal/api/')
|
|
|
|
.debug(true);
|
|
|
|
|
2016-06-07 00:21:26 +02:00
|
|
|
function nodeClasses(node) {
|
|
|
|
if (!node) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var nodes = nga.entity('nodes').label('Nodes').identifier(nga.field('token'));
|
|
|
|
nodes
|
|
|
|
.listView()
|
|
|
|
.title('Nodes')
|
|
|
|
.actions([])
|
|
|
|
.batchActions([])
|
|
|
|
.exportFields([])
|
|
|
|
.fields([
|
|
|
|
nga.field('token').cssClasses(nodeClasses),
|
|
|
|
nga.field('hostname').cssClasses(nodeClasses),
|
|
|
|
nga.field('monitoring').cssClasses(nodeClasses).template(function (node) {
|
|
|
|
if (!node.values.monitoring) {
|
|
|
|
return '<span class="glyphicon glyphicon-remove monitoring-disabled" title="disabled"></span>';
|
|
|
|
}
|
|
|
|
return node.values.monitoringConfirmed
|
|
|
|
? '<span class="glyphicon glyphicon-ok monitoring-active" title="active"></span>'
|
|
|
|
: '<span class="glyphicon glyphicon-envelope monitoring-confirmation-pending" ' +
|
|
|
|
'title="confirmation pending"></span>';
|
|
|
|
})
|
|
|
|
])
|
|
|
|
.listActions([
|
|
|
|
'edit',
|
|
|
|
'delete'
|
|
|
|
])
|
|
|
|
;
|
|
|
|
|
|
|
|
nodes
|
|
|
|
.editionView()
|
|
|
|
.title('Edit node')
|
|
|
|
.actions(['list', 'delete'])
|
|
|
|
.addField(nga.field('token').editable(false))
|
|
|
|
.addField(nga.field('hostname').label('Name').validation(nodeConstraint('hostname')))
|
|
|
|
.addField(nga.field('key').label('Key').validation(nodeConstraint('key')))
|
|
|
|
.addField(nga.field('mac').label('MAC').validation(nodeConstraint('mac')))
|
|
|
|
.addField(nga.field('coords').label('GPS').validation(nodeConstraint('coords')))
|
|
|
|
.addField(nga.field('nickname').validation(nodeConstraint('nickname')))
|
|
|
|
.addField(nga.field('email').validation(nodeConstraint('email')))
|
|
|
|
.addField(nga.field('monitoring', 'boolean').validation(nodeConstraint('monitoring')))
|
|
|
|
.addField(nga.field('monitoringConfirmed').label('Monitoring confirmation').editable(false).map(
|
|
|
|
function (monitoringConfirmed, node) {
|
|
|
|
if (!node.monitoring) {
|
|
|
|
return 'N/A';
|
|
|
|
}
|
|
|
|
|
|
|
|
return monitoringConfirmed ? 'confirmed' : 'pending';
|
|
|
|
}
|
|
|
|
))
|
|
|
|
;
|
|
|
|
|
|
|
|
admin.addEntity(nodes);
|
|
|
|
|
2016-06-05 12:18:37 +02:00
|
|
|
function taskClasses(task) {
|
|
|
|
if (!task) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return task.values.enabled ? 'task-enabled' : 'task-disabled';
|
|
|
|
}
|
|
|
|
|
2016-06-04 14:58:11 +02:00
|
|
|
var tasks = nga.entity('tasks').label('Background-Jobs');
|
|
|
|
tasks
|
|
|
|
.listView()
|
|
|
|
.title('Background-Jobs')
|
|
|
|
.actions([])
|
|
|
|
.batchActions([])
|
|
|
|
.exportFields([])
|
|
|
|
.fields([
|
2016-06-05 12:18:37 +02:00
|
|
|
nga.field('id').cssClasses(taskClasses),
|
|
|
|
nga.field('name').cssClasses(taskClasses),
|
|
|
|
nga.field('schedule').cssClasses(taskClasses),
|
|
|
|
nga.field('state').cssClasses(taskClasses),
|
|
|
|
nga.field('runningSince').map(formatMoment).cssClasses(taskClasses),
|
|
|
|
nga.field('lastRunStarted').map(formatMoment).cssClasses(taskClasses)
|
2016-06-04 14:58:11 +02:00
|
|
|
])
|
|
|
|
.listActions(
|
2016-06-05 12:18:37 +02:00
|
|
|
'<fa-task-action-button action="run" task="entry" button="primary" label="run" size="sm"></fa-task-action-button> ' +
|
2016-06-05 22:58:46 +02:00
|
|
|
'<fa-task-action-button ng-if="!entry.values.enabled" button="success" action="enable" icon="off" task="entry" label="enable" size="sm"></fa-task-action-button> ' +
|
|
|
|
'<fa-task-action-button ng-if="entry.values.enabled" button="warning" action="disable" icon="off" task="entry" label="disable" size="sm"></fa-task-action-button>'
|
2016-06-07 00:21:26 +02:00
|
|
|
)
|
2016-06-04 14:58:11 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
admin.addEntity(tasks);
|
|
|
|
|
|
|
|
admin.menu(
|
|
|
|
nga.menu()
|
2016-06-07 00:21:26 +02:00
|
|
|
.addChild(nga
|
|
|
|
.menu(nodes)
|
|
|
|
.icon('<span class="glyphicon glyphicon-record"></span>')
|
|
|
|
)
|
2016-06-04 14:58:11 +02:00
|
|
|
.addChild(nga
|
|
|
|
.menu(tasks)
|
|
|
|
.icon('<span class="glyphicon glyphicon-cog"></span>')
|
|
|
|
)
|
|
|
|
.addChild(nga
|
|
|
|
.menu()
|
|
|
|
.template(
|
|
|
|
'<a href="/internal/logs" target="_blank">' +
|
|
|
|
'<span class="glyphicon glyphicon-list"></span> Logs' +
|
|
|
|
'</a>'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
nga.configure(admin);
|
2016-06-07 00:21:26 +02:00
|
|
|
});
|