This commit is contained in:
Martin Geno 2017-05-16 16:00:32 +02:00
parent 2e2142b155
commit d3fcd7f232
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
12 changed files with 74 additions and 51 deletions

View File

@ -1 +1,2 @@
document.title = config.title
/* global config */
document.title = config.title;

View File

@ -1,10 +1,12 @@
/* exported config */
var config = {
title: 'FreifunkManager - Breminale',
backend: 'ws://'+location.host+'/websocket',
map: {
view: {bound: [53.07093, 8.79464], zoom: 17},
maxZoom: 20,
tileLayer: '//tiles.bremen.freifunk.net/{z}/{x}/{y}.png',
tileLayer: 'https://tiles.bremen.freifunk.net/{z}/{x}/{y}.png',
/* heatmap settings
size: in meters (default: 30km)
opacity: in percent/100 (default: 1)
@ -13,15 +15,15 @@ var config = {
autoresize: resize heatmap when map size changes (default: false)
*/
heatmap: {
wifi24: {size: 230, opacity: 0.5, alphaRange: 1},
wifi5: {size: 230, opacity: 0.5, alphaRange: 1}
wifi24: {size: 230, opacity: 0.5, alphaRange: 1},
wifi5: {size: 230, opacity: 0.5, alphaRange: 1}
},
icon:{
warn:{wifi24:20,wifi5:20},
crit:{wifi24:30,wifi5:30}
warn:{wifi24:20,wifi5:20},
crit:{wifi24:30,wifi5:30}
},
geojson: {
url: '//events.ffhb.de/data/ground.geojson',
url: 'http://events.ffhb.de/data/ground.geojson',
pointToLayer: function (feature, latlng){
feature.properties.radius = 10;
return L.circleMarker(latlng, feature.properties);

View File

@ -1,3 +1,5 @@
/* exported domlin */
var domlib = {};
(function(){
domlib.newAt = function(at,eltype) {
@ -11,4 +13,4 @@ var domlib = {};
el.removeChild(el.firstChild);
}
};
})()
})();

View File

@ -1,3 +1,5 @@
/* exported gui,router */
/* globals socket,notify,domlib,guiList,guiMap,guiStats,guiNode */
var gui = {};
var router = new Navigo(null, true, '#');
@ -8,7 +10,7 @@ var router = new Navigo(null, true, '#');
var status = document.getElementsByClassName('status')[0];
if (status === undefined){
console.log("unable to render, render later");
setTimeout(render,100);
window.setTimeout(render,100);
return;
}
status.classList.remove('connecting','offline');
@ -24,7 +26,7 @@ var router = new Navigo(null, true, '#');
function setView(c){
currentView = c;
var main = document.querySelector('main')
var main = document.querySelector('main');
domlib.removeChildren(main);
currentView.bind(main);
currentView.render();
@ -61,12 +63,12 @@ var router = new Navigo(null, true, '#');
if (timeout){
console("skip rendering, because to often");
clearTimeout(timeout);
window.clearTimeout(timeout);
} else {
render();
}
timeout = setTimeout(reset, 100);
}
timeout = window.setTimeout(reset, 100);
};
window.onload = gui.render;
})();

View File

@ -1,3 +1,6 @@
/* exported guiList */
/* global domlib,store,router */
var guiList = {};
(function(){
@ -31,11 +34,11 @@ var guiList = {};
return a.statistics.clients.wifi24 - b.statistics.clients.wifi24;
case "ChanUtil":
var aMax = a.statistics.wireless.map(function(d){
return d.ChanUtil
return d.ChanUtil;
}).sort(sortNumber);
var bMax = b.statistics.wireless.map(function(d){
return d.ChanUtil
return d.ChanUtil;
}).sort(sortNumber);
if(!sortReverse){
@ -55,8 +58,7 @@ var guiList = {};
var startdate = new Date();
startdate.setMinutes(startdate.getMinutes() - 1);
if(new Date(node.lastseen) < startdate)
tr.classList.add('offline')
var td;
tr.classList.add('offline');
domlib.newAt(tr,'td').innerHTML = moment(node.lastseen).fromNow(true);
domlib.newAt(tr,'td').innerHTML = node.node_id;
@ -98,7 +100,7 @@ var guiList = {};
domlib.newAt(chanUtil,'span').innerHTML = chanUtil5.ChanUtil||'-';
var option = domlib.newAt(tr,'td');
edit = domlib.newAt(option,'div');
var edit = domlib.newAt(option,'div');
edit.classList.add('btn');
edit.innerHTML = 'Edit';
edit.addEventListener('click',function(){
@ -115,11 +117,11 @@ var guiList = {};
if(hostnameFilter && hostnameFilter.value != "")
nodes = nodes.filter(function(d){
return d.hostname.toLowerCase().indexOf(hostnameFilter.value) > -1;
})
});
if(nodeidFilter && nodeidFilter.value != "")
nodes = nodes.filter(function(d){
return d.node_id.indexOf(nodeidFilter.value) > -1;
})
});
nodes = nodes.sort(sort);

View File

@ -1,3 +1,6 @@
/* exported guiMap */
/* global config,store,domlib,socket */
var guiMap = {};
(function(){
@ -87,14 +90,14 @@ var guiMap = {};
return;
}
return [node.location.latitude,node.location.longitude,node.statistics.clients.wifi24 * 2 || 0];
})
});
clientLayer24.setData(clientData24);
var clientData5 = nodes.map(function(node){
if(node.location === undefined || node.location.latitude === undefined || node.location.longitude === undefined) {
return;
}
return [node.location.latitude,node.location.longitude,node.statistics.clients.wifi5 || 0];
})
});
clientLayer5.setData(clientData5);
}
@ -121,7 +124,7 @@ var guiMap = {};
maxZoom: config.map.maxZoom,
}).addTo(map);
layerControl = L.control.layers().addTo(map);
var layerControl = L.control.layers().addTo(map);
geoJsonLayer = L.geoJson.ajax(config.map.geojson.url, config.map.geojson);
@ -141,5 +144,5 @@ var guiMap = {};
});
update();
}
})()
};
})();

View File

@ -1,3 +1,5 @@
/* exported guiNode */
/* globals store, socket, domlib, config,notify */
var guiNode = {};
(function(){
@ -32,10 +34,10 @@ var guiNode = {};
var startdate = new Date();
startdate.setMinutes(startdate.getMinutes() - 1);
if(new Date(node.lastseen) < startdate){
ago.classList.add('offline')
ago.classList.add('offline');
ago.classList.remove('online');
}else{
ago.classList.remove('offline')
ago.classList.remove('offline');
ago.classList.add('online');
}
ago.innerHTML = moment(node.lastseen).fromNow() + ' ('+node.lastseen+')';
@ -51,7 +53,7 @@ var guiNode = {};
view.setNodeID = function (nodeID){
current_node_id = nodeID;
}
};
view.bind = function(el) {
container = el;
@ -69,7 +71,7 @@ var guiNode = {};
var title = domlib.newAt(el,'h1');
titleName = domlib.newAt(title,'span');
title.appendChild(document.createTextNode(" - "))
title.appendChild(document.createTextNode(" - "));
titleID = domlib.newAt(title,'i');
var lastseen = domlib.newAt(el,'p');
@ -86,10 +88,10 @@ var guiNode = {};
geoJsonLayer = L.geoJson.ajax(config.map.geojson.url, config.map.geojson).addTo(map);
marker = L.marker(config.map.view.bound,{draggable:true,opacity:0.5}).addTo(map);
marker.on('dragstart', function(e){
marker.on('dragstart', function(){
editing = true;
});
marker.on('dragend', function(e){
marker.on('dragend', function(){
editing = false;
var pos = marker.getLatLng();
updatePosition(pos.lat,pos.lng);
@ -109,7 +111,7 @@ var guiNode = {};
return;
}
btnGPS.innerHTML = 'Following position';
if (!!navigator.geolocation)
if (navigator.geolocation !== undefined)
editLocationGPS = navigator.geolocation.watchPosition(
function geo_success(position) {
btnGPS.innerHTML = "Stop following";
@ -123,7 +125,7 @@ var guiNode = {};
case error.TIMEOUT:
notify.send("error","Find Location timeout");
break;
};
}
},
{
enableHighAccuracy: true,
@ -131,10 +133,10 @@ var guiNode = {};
timeout: 27000
});
else
notify.send("error","Browser did not support Location")
notify.send("error","Browser did not support Location");
});
update();
}
})()
};
})();

View File

@ -1,3 +1,5 @@
/* exported guiSkel */
/* globals domlib */
var guiSkel = {};
(function(){
@ -22,5 +24,5 @@ var guiSkel = {};
el = domlib.newAt(container,'div');
update();
}
})()
};
})();

View File

@ -1,3 +1,5 @@
/* exported guiStats */
/* globals store, domlib */
var guiStats = {};
(function(){
@ -35,13 +37,13 @@ var guiStats = {};
var tr,title;
tr = domlib.newAt(table,'tr');
title = domlib.newAt(tr,'th')
title = domlib.newAt(tr,'th');
title.innerHTML = "Nodes";
title.setAttribute("colspan","2");
nodes = domlib.newAt(tr,'td');
tr = domlib.newAt(table,'tr');
title = domlib.newAt(tr,'th')
title = domlib.newAt(tr,'th');
title.innerHTML = "Clients";
title.setAttribute("colspan","2");
clients = domlib.newAt(tr,'td');
@ -58,5 +60,5 @@ var guiStats = {};
clientsWifi5 = domlib.newAt(tr,'td');
update();
}
})()
};
})();

View File

@ -1,12 +1,13 @@
var notify = {};
/* exported notify */
var notify = {};
(function(){
var container;
var messages = [];
if ("Notification" in window) {
Notification.requestPermission();
window.Notification.requestPermission();
}
function removeLast (){
@ -28,15 +29,15 @@ var notify = {};
});
}
setInterval(removeLast,15000);
window.setInterval(removeLast,15000);
notify.bind = function(el) {
container = el;
};
notify.send = function(type, text){
if("Notification" in window && Notification.permission === "granted") {
new Notification(text,{body:type,icon:'/img/logo.jpg'});
if("Notification" in window && window.Notification.permission === "granted") {
new window.Notification(text,{body:type,icon:'/img/logo.jpg'});
return;
}
if(messages.length > 10){
@ -47,4 +48,4 @@ var notify = {};
renderMsg(msg);
};
})()
})();

View File

@ -1,3 +1,5 @@
/* exported socket */
/*globals notify,gui,store,config*/
var socket = {readyState:0};
(function(){
@ -39,18 +41,18 @@ var socket = {readyState:0};
console.log("socket closed by server");
notify.send("warn","Es besteht ein Verbindungsproblem!");
gui.render();
setTimeout(connect, 5000);
window.setTimeout(connect, 5000);
}
function sendnode(node) {
var msg = {type:"to-update",node:node};
var string = JSON.stringify(msg);
socket.send(string)
socket.send(string);
notify.send("success","Node '"+node.node_id+"' mit neuen Werten wurde übermittelt.");
}
function connect() {
socket = new WebSocket(config.backend);
socket = new window.WebSocket(config.backend);
socket.onopen = onopen;
socket.onerror = onerror;
socket.onmessage = onmessage;

View File

@ -1,3 +1,5 @@
/* exported store */
var store = {
_list:{},
_toupdate:{},