'use strict'; angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, RestangularProvider, Constraints) { RestangularProvider.addFullRequestInterceptor(function(element, operation, what, url, headers, params) { if (operation === 'getList') { if (params._filters) { // flatten filter query params for (var filter in params._filters) { params[filter] = params._filters[filter]; } delete params._filters; } } return { params: params }; }); 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'); admin .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') .perPage(30) .sortDir('ASC') .sortField('hostname') .actions([]) .batchActions([]) .exportFields([]) .fields([ nga.field('hostname').cssClasses(nodeClasses), nga.field('nickname').cssClasses(nodeClasses), nga.field('email').cssClasses(nodeClasses), nga.field('token').cssClasses(nodeClasses), nga.field('mac').cssClasses(nodeClasses), nga.field('key').label('VPN').cssClasses(nodeClasses).template(function (node) { return node.values.key ? '' : ''; }), nga.field('coords').label('GPS').cssClasses(nodeClasses).template(function (node) { return node.values.coords ? '' : ''; }), nga.field('monitoringState').cssClasses(nodeClasses).template(function (node) { switch (node.values.monitoringState) { case 'active': return ''; case 'pending': return ''; default: return ''; } }) ]) .filters([ nga.field('q') .label('') .pinned(true) .template( '
' + '' + '
'), ]) .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; } return task.values.enabled ? 'task-enabled' : 'task-disabled'; } var tasks = nga.entity('tasks').label('Background-Jobs'); tasks .listView() .title('Background-Jobs') .perPage(30) .sortDir('ASC') .sortField('id') .actions([]) .batchActions([]) .exportFields([]) .fields([ 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) ]) .filters([ nga.field('q') .label('') .pinned(true) .template( '
' + '' + '
'), ]) .listActions( ' ' + ' ' + '' ) ; admin.addEntity(tasks); admin.menu( nga.menu() .addChild(nga .menu(nodes) .icon('') ) .addChild(nga .menu(tasks) .icon('') ) .addChild(nga .menu() .template( '' + ' Logs' + '' ) ) ); nga.configure(admin); });