Add field "site" in admin panel.

This commit is contained in:
baldo 2017-08-13 17:22:34 +02:00
parent a9c6ddc03b
commit 88dab5743f
4 changed files with 24 additions and 4 deletions

View file

@ -112,6 +112,7 @@ angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Rest
? '<i class="fa fa-lock vpn-key-set" aria-hidden="true" title="VPN key set"></i>' ? '<i class="fa fa-lock vpn-key-set" aria-hidden="true" title="VPN key set"></i>'
: '<i class="fa fa-times vpn-key-unset" aria-hidden="true" title="no VPN key"></i>'; : '<i class="fa fa-times vpn-key-unset" aria-hidden="true" title="no VPN key"></i>';
}), }),
nga.field('site').map(nullable).cssClasses(nodeClasses),
nga.field('coords').label('GPS').cssClasses(nodeClasses).template(function (node) { nga.field('coords').label('GPS').cssClasses(nodeClasses).template(function (node) {
return node.values.coords return node.values.coords
? '<i class="fa fa-map-marker coords-set" aria-hidden="true" title="coordinates set"></i>' ? '<i class="fa fa-map-marker coords-set" aria-hidden="true" title="coordinates set"></i>'
@ -238,6 +239,7 @@ angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Rest
nga.field('id').cssClasses(monitoringStateClasses), nga.field('id').cssClasses(monitoringStateClasses),
nga.field('hostname').cssClasses(monitoringStateClasses), nga.field('hostname').cssClasses(monitoringStateClasses),
nga.field('mac').cssClasses(monitoringStateClasses), nga.field('mac').cssClasses(monitoringStateClasses),
nga.field('site').map(nullable).cssClasses(monitoringStateClasses),
nga.field('monitoring_state').cssClasses(monitoringStateClasses).template(function (monitoringState) { nga.field('monitoring_state').cssClasses(monitoringStateClasses).template(function (monitoringState) {
switch (monitoringState.values.monitoring_state) { switch (monitoringState.values.monitoring_state) {
case 'active': case 'active':

View file

@ -0,0 +1 @@
ALTER TABLE node_state ADD COLUMN site VARCHAR(32);

View file

@ -127,6 +127,7 @@ angular.module('ffffng').factory('NodeResource', function (
var nodeState = nodeStateByMac[node.mac]; var nodeState = nodeStateByMac[node.mac];
if (nodeState) { if (nodeState) {
return deepExtend({}, node, { return deepExtend({}, node, {
site: nodeState.site,
onlineState: nodeState.state onlineState: nodeState.state
}); });
} }

View file

@ -44,11 +44,12 @@ angular.module('ffffng')
return Database.run( return Database.run(
'INSERT INTO node_state ' + 'INSERT INTO node_state ' +
'(hostname, mac, monitoring_state, state, last_seen, import_timestamp, last_status_mail_sent, last_status_mail_type) ' + '(hostname, mac, site, monitoring_state, state, last_seen, import_timestamp, last_status_mail_sent, last_status_mail_type) ' +
'VALUES (?, ?, ?, ?, ?, ?, ?, ?)', 'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
[ [
node.hostname, node.hostname,
node.mac, node.mac,
node.site,
node.monitoringState, node.monitoringState,
nodeData.state, nodeData.state,
nodeData.lastSeen.unix(), nodeData.lastSeen.unix(),
@ -80,10 +81,18 @@ angular.module('ffffng')
return Database.run( return Database.run(
'UPDATE node_state ' + 'UPDATE node_state ' +
'SET hostname = ?, monitoring_state = ?, state = ?, last_seen = ?, import_timestamp = ?, modified_at = ?' + 'SET ' +
'hostname = ?, ' +
'site = ?, ' +
'monitoring_state = ?, ' +
'state = ?, ' +
'last_seen = ?, ' +
'import_timestamp = ?, ' +
'modified_at = ? ' +
'WHERE id = ? AND mac = ?', 'WHERE id = ? AND mac = ?',
[ [
node.hostname, node.hostname,
node.site,
node.monitoringState, node.monitoringState,
nodeData.state, nodeData.state,
nodeData.lastSeen.unix(), nodeData.lastSeen.unix(),
@ -201,11 +210,17 @@ angular.module('ffffng')
); );
} }
var site = null;
if (_.isPlainObject(nodeData.nodeinfo.system) && _.isString(nodeData.nodeinfo.system.site_code)) {
site = nodeData.nodeinfo.system.site_code;
}
return { return {
mac: mac, mac: mac,
importTimestamp: data.importTimestamp, importTimestamp: data.importTimestamp,
state: isOnline ? 'ONLINE' : 'OFFLINE', state: isOnline ? 'ONLINE' : 'OFFLINE',
lastSeen: lastSeen lastSeen: lastSeen,
site: site
}; };
})); }));
} }
@ -533,6 +548,7 @@ angular.module('ffffng')
'id', 'id',
'hostname', 'hostname',
'mac', 'mac',
'site',
'monitoring_state', 'monitoring_state',
'state', 'state',
'last_seen', 'last_seen',