Basic node management in admin panel.
This commit is contained in:
parent
6cab6371d1
commit
d5c69fa78f
10 changed files with 180 additions and 38 deletions
admin/js
4
admin/js/app.js
Normal file
4
admin/js/app.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('ffffng', []);
|
||||
angular.module('ffffngAdmin', ['ng-admin', 'ffffng']);
|
|
@ -1,12 +1,21 @@
|
|||
'use strict';
|
||||
|
||||
var myApp = angular.module('ffffngAdmin', ['ng-admin']);
|
||||
|
||||
myApp.config(['NgAdminConfigurationProvider', function(NgAdminConfigurationProvider) {
|
||||
angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Constraints) {
|
||||
function formatMoment(unix) {
|
||||
return unix ? moment.unix(unix).fromNow() : 'N/A';
|
||||
}
|
||||
|
||||
function nodeConstraint(field) {
|
||||
var constraint = Constraints.node[field];
|
||||
var result = {
|
||||
required: !constraint.optional
|
||||
};
|
||||
if (constraint.type === 'string') {
|
||||
result.pattern = constraint.regex;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
var nga = NgAdminConfigurationProvider;
|
||||
var admin = nga.application('Knotenverwaltung - Admin-Panel');
|
||||
|
||||
|
@ -14,6 +23,64 @@ myApp.config(['NgAdminConfigurationProvider', function(NgAdminConfigurationProvi
|
|||
.baseApiUrl('/internal/api/')
|
||||
.debug(true);
|
||||
|
||||
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);
|
||||
|
||||
function taskClasses(task) {
|
||||
if (!task) {
|
||||
return;
|
||||
|
@ -40,13 +107,17 @@ myApp.config(['NgAdminConfigurationProvider', function(NgAdminConfigurationProvi
|
|||
'<fa-task-action-button action="run" task="entry" button="primary" label="run" size="sm"></fa-task-action-button> ' +
|
||||
'<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>'
|
||||
)
|
||||
)
|
||||
;
|
||||
|
||||
admin.addEntity(tasks);
|
||||
|
||||
admin.menu(
|
||||
nga.menu()
|
||||
.addChild(nga
|
||||
.menu(nodes)
|
||||
.icon('<span class="glyphicon glyphicon-record"></span>')
|
||||
)
|
||||
.addChild(nga
|
||||
.menu(tasks)
|
||||
.icon('<span class="glyphicon glyphicon-cog"></span>')
|
||||
|
@ -62,4 +133,4 @@ myApp.config(['NgAdminConfigurationProvider', function(NgAdminConfigurationProvi
|
|||
);
|
||||
|
||||
nga.configure(admin);
|
||||
}]);
|
||||
});
|
||||
|
|
1
admin/js/validation
Symbolic link
1
admin/js/validation
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../shared/validation
|
Loading…
Add table
Add a link
Reference in a new issue