meshviewer/lib/gui.js

132 lines
3.9 KiB
JavaScript
Raw Permalink Normal View History

2017-03-09 23:53:23 +00:00
define(['d3-interpolate', 'map', 'sidebar', 'tabs', 'container', 'legend',
'linklist', 'nodelist', 'simplenodelist', 'infobox/main',
'proportions', 'forcegraph', 'title', 'about', 'datadistributor',
2017-02-01 21:13:06 +00:00
'filters/filtergui', 'filters/hostname'],
2017-03-09 23:53:23 +00:00
function (d3Interpolate, Map, Sidebar, Tabs, Container, Legend, Linklist,
Nodelist, SimpleNodelist, Infobox, Proportions, ForceGraph,
2017-02-01 21:13:06 +00:00
Title, About, DataDistributor, FilterGUI, HostnameFilter) {
'use strict';
2016-05-27 21:59:01 +00:00
return function (config, router, language) {
var self = this;
var content;
var contentDiv;
2017-03-09 23:53:23 +00:00
var linkScale = d3Interpolate.interpolate('#F02311', '#04C714');
var sidebar;
var buttons = document.createElement('div');
buttons.classList.add('buttons');
var fanout = new DataDistributor();
var fanoutUnfiltered = new DataDistributor();
fanoutUnfiltered.add(fanout);
function removeContent() {
if (!content) {
return;
}
router.removeTarget(content);
fanout.remove(content);
content.destroy();
content = null;
}
function addContent(K) {
removeContent();
content = new K(config, linkScale, sidebar.getWidth, router, buttons);
content.render(contentDiv);
fanout.add(content);
router.addTarget(content);
}
function mkView(K) {
return function () {
addContent(K);
};
}
var loader = document.getElementsByClassName('loader')[0];
loader.classList.add('hide');
2016-06-01 20:56:26 +00:00
contentDiv = document.createElement('div');
contentDiv.classList.add('content');
document.body.appendChild(contentDiv);
sidebar = new Sidebar(document.body);
contentDiv.appendChild(buttons);
var buttonToggle = document.createElement('button');
buttonToggle.classList.add('ion-eye', 'shadow');
2017-02-02 00:31:57 +00:00
buttonToggle.setAttribute('data-tooltip', _.t('button.switchView'));
buttonToggle.onclick = function onclick() {
2017-03-05 11:29:21 +00:00
var data;
if (content.constructor === Map) {
2017-03-05 11:29:21 +00:00
data = { view: 'graph', lat: undefined, lng: undefined, zoom: undefined };
} else {
2017-03-05 11:29:21 +00:00
data = { view: 'map' };
}
2017-03-05 11:29:21 +00:00
router.fullUrl(data, false, true);
};
2015-04-01 01:55:45 +00:00
buttons.appendChild(buttonToggle);
var title = new Title(config);
var header = new Container('header');
var infobox = new Infobox(config, sidebar, router);
var tabs = new Tabs();
var overview = new Container();
var legend = new Legend(config, language);
2017-01-28 14:33:13 +00:00
var newnodeslist = new SimpleNodelist('new', 'firstseen', router, _.t('node.new'));
var lostnodeslist = new SimpleNodelist('lost', 'lastseen', router, _.t('node.missing'));
var nodelist = new Nodelist(router);
var linklist = new Linklist(linkScale, router);
var statistics = new Proportions(config, fanout);
var about = new About();
2015-04-01 01:55:45 +00:00
2017-01-26 22:52:34 +00:00
fanoutUnfiltered.add(legend);
fanoutUnfiltered.add(newnodeslist);
fanoutUnfiltered.add(lostnodeslist);
fanout.add(nodelist);
fanout.add(linklist);
fanout.add(statistics);
2015-07-07 22:36:57 +00:00
sidebar.add(header);
header.add(legend);
2015-07-11 22:11:18 +00:00
overview.add(newnodeslist);
overview.add(lostnodeslist);
2015-04-01 01:55:45 +00:00
var filterGUI = new FilterGUI(fanout);
fanout.watchFilters(filterGUI);
header.add(filterGUI);
2015-04-01 01:55:45 +00:00
2017-02-01 21:13:06 +00:00
var hostnameFilter = new HostnameFilter();
fanout.addFilter(hostnameFilter);
sidebar.add(tabs);
2017-01-28 14:33:13 +00:00
tabs.add('sidebar.actual', overview);
tabs.add('node.nodes', nodelist);
tabs.add('node.links', linklist);
tabs.add('sidebar.stats', statistics);
tabs.add('sidebar.about', about);
2015-04-01 01:55:45 +00:00
router.addTarget(title);
router.addTarget(infobox);
2015-07-06 22:06:38 +00:00
2017-03-05 11:29:21 +00:00
router.addView('map', mkView(Map));
router.addView('graph', mkView(ForceGraph));
self.setData = fanoutUnfiltered.setData;
return self;
};
});