2016-06-23 17:31:39 +02:00
|
|
|
var internal = {
|
|
|
|
config:{},
|
|
|
|
nodes:{},
|
2016-06-24 03:17:12 +02:00
|
|
|
aliases:{},
|
|
|
|
lastload:0
|
2016-06-23 17:31:39 +02:00
|
|
|
}
|
|
|
|
//var toast = document.querySelector('#toast');
|
|
|
|
var container = document.getElementById("container")
|
|
|
|
var menuNodes = document.getElementById("menu_nodes")
|
|
|
|
var menuAliases = document.getElementById("menu_aliases")
|
|
|
|
|
|
|
|
|
2016-06-24 03:17:12 +02:00
|
|
|
|
|
|
|
function updateBange(){
|
|
|
|
if(internal.nodes && Object.keys(internal.nodes))
|
|
|
|
menuNodes.setAttribute("data-badge",Object.keys(internal.nodes).length)
|
|
|
|
if(internal.aliases && Object.keys(internal.aliases))
|
|
|
|
menuAliases.setAttribute("data-badge",Object.keys(internal.aliases).length)
|
|
|
|
}
|
|
|
|
|
2016-06-23 17:31:39 +02:00
|
|
|
function refreshData(){
|
2016-06-24 03:17:12 +02:00
|
|
|
console.log("load new files")
|
2016-06-23 17:31:39 +02:00
|
|
|
send('GET',internal.config.api+"/aliases").then(function(data){
|
|
|
|
internal.aliases = data
|
2016-06-24 03:17:12 +02:00
|
|
|
updateBange()
|
|
|
|
localStorage.setItem("aliases",JSON.stringify(internal.aliases))
|
2016-06-23 17:31:39 +02:00
|
|
|
})
|
2016-06-24 03:17:12 +02:00
|
|
|
return send('GET',internal.config.api+"/nodes").then(function(data){
|
2016-06-23 17:31:39 +02:00
|
|
|
Object.keys(data).map(function(key){
|
2016-06-24 03:17:12 +02:00
|
|
|
if(internal.nodes[key]== undefined){
|
|
|
|
notify(key,data[key])
|
2016-06-23 17:31:39 +02:00
|
|
|
}
|
|
|
|
internal.nodes[key] = data[key]
|
|
|
|
})
|
2016-06-24 03:17:12 +02:00
|
|
|
updateBange()
|
|
|
|
internal.lastload = new Date()
|
|
|
|
localStorage.setItem("nodes",JSON.stringify(internal.nodes))
|
|
|
|
route()
|
2016-06-23 17:31:39 +02:00
|
|
|
})
|
|
|
|
}
|