[TASK] Define complete subst

This commit is contained in:
Xaver Maierhofer 2017-11-06 18:54:50 +01:00 committed by Xaver Maierhofer
parent d0b6031d5f
commit 18a2a17d97
4 changed files with 22 additions and 18 deletions

View File

@ -3,13 +3,14 @@ define(['helper', 'snabbdom'], function (helper, V) {
V = V.default; V = V.default;
function showStatImg(o, d, time) { function showStatImg(o, d, time) {
var subst = {}; var subst = {
subst['{SOURCE_ID}'] = d.source.node_id; '{SOURCE_ID}': d.source.node_id,
subst['{SOURCE_NAME}'] = d.source.hostname.replace(/[^a-z0-9\-]/ig, '_'); '{SOURCE_NAME}': d.source.hostname.replace(/[^a-z0-9\-]/ig, '_'),
subst['{TARGET_ID}'] = d.target.node_id; '{TARGET_ID}': d.target.node_id,
subst['{TARGET_NAME}'] = d.target.hostname.replace(/[^a-z0-9\-]/ig, '_'); '{TARGET_NAME}': d.target.hostname.replace(/[^a-z0-9\-]/ig, '_'),
subst['{TIME}'] = time; '{TIME}': time,
subst['{LOCALE}'] = _.locale(); '{LOCALE}': _.locale()
};
return helper.showStat(V, o, subst); return helper.showStat(V, o, subst);
} }

View File

@ -4,11 +4,12 @@ define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper', 'utils/no
V = V.default; V = V.default;
function showStatImg(o, d) { function showStatImg(o, d) {
var subst = {}; var subst = {
subst['{NODE_ID}'] = d.node_id; '{NODE_ID}': d.node_id,
subst['{NODE_NAME}'] = d.hostname.replace(/[^a-z0-9\-]/ig, '_'); '{NODE_NAME}': d.hostname.replace(/[^a-z0-9\-]/ig, '_'),
subst['{TIME}'] = d.lastseen.format('DDMMYYYYHmmss'); '{TIME}': d.lastseen.format('DDMMYYYYHmmss'),
subst['{LOCALE}'] = _.locale(); '{LOCALE}': _.locale()
};
return helper.showStat(V, o, subst); return helper.showStat(V, o, subst);
} }
@ -138,7 +139,6 @@ define(['sorttable', 'snabbdom', 'd3-interpolate', 'moment', 'helper', 'utils/no
} }
}); });
children.push(V.h('tr', [ children.push(V.h('tr', [
V.h('th', _.t('node.gateway')), V.h('th', _.t('node.gateway')),
showGateway(d) showGateway(d)

View File

@ -6,6 +6,7 @@ define(['d3-interpolate', 'snabbdom', 'filters/genericnode', 'helper'],
return function (filterManager) { return function (filterManager) {
var self = this; var self = this;
var scale = d3Interpolate.interpolate(config.forceGraph.tqFrom, config.forceGraph.tqTo); var scale = d3Interpolate.interpolate(config.forceGraph.tqFrom, config.forceGraph.tqTo);
var time;
var statusTable; var statusTable;
var fwTable; var fwTable;
@ -78,6 +79,7 @@ define(['d3-interpolate', 'snabbdom', 'filters/genericnode', 'helper'],
self.setData = function setData(data) { self.setData = function setData(data) {
var onlineNodes = data.nodes.online; var onlineNodes = data.nodes.online;
var nodes = onlineNodes.concat(data.nodes.lost); var nodes = onlineNodes.concat(data.nodes.lost);
time = data.timestamp;
function hostnameOfNodeID(nodeid) { function hostnameOfNodeID(nodeid) {
var gateway = data.nodeDict[nodeid]; var gateway = data.nodeDict[nodeid];
@ -163,9 +165,13 @@ define(['d3-interpolate', 'snabbdom', 'filters/genericnode', 'helper'],
var images = document.createElement('div'); var images = document.createElement('div');
el.appendChild(images); el.appendChild(images);
var img = []; var img = [];
var subst = {
'{TIME}': time,
'{LOCALE}': _.locale()
};
config.globalInfos.forEach(function (globalInfo) { config.globalInfos.forEach(function (globalInfo) {
img.push(V.h('h2', globalInfo.name)); img.push(V.h('h2', globalInfo.name));
img.push(helper.showStat(V, globalInfo)); img.push(helper.showStat(V, globalInfo, subst));
}); });
V.patch(images, V.h('div', img)); V.patch(images, V.h('div', img));
} }

View File

@ -117,10 +117,7 @@ define({
} }
}, },
showStat: function showStat(V, o, subst) { showStat: function showStat(V, o, subst) {
var content; var content = V.h('img', { attrs: { src: require('helper').listReplace(o.image, subst) } });
subst = typeof subst !== 'undefined' ? subst : {};
content = V.h('img', { attrs: { src: require('helper').listReplace(o.image, subst) } });
if (o.href) { if (o.href) {
return V.h('p', V.h('a', { return V.h('p', V.h('a', {