change code style to ffrgb/meshviewer fork

This commit is contained in:
Milan Pässler 2017-03-17 03:14:57 +01:00 committed by Milan Paessler
commit eb4c7a04b0
42 changed files with 3505 additions and 3154 deletions

View file

@ -1,48 +1,49 @@
define(function () {
function showStatImg(o, d) {
var subst = {}
subst["{SOURCE}"] = d.source.node_id
subst["{SOURCE_NAME}"] = d.source.node.nodeinfo.hostname ? d.source.node.nodeinfo.hostname : "unknown"
subst["{TARGET}"] = d.target.node_id
subst["{TARGET_NAME}"] = d.target.node.nodeinfo.hostname ? d.target.node.nodeinfo.hostname : "unknown"
return showStat(o, subst)
var subst = {};
subst["{SOURCE}"] = d.source.node_id;
subst["{SOURCE_NAME}"] = d.source.node.nodeinfo.hostname ? d.source.node.nodeinfo.hostname : "unknown";
subst["{TARGET}"] = d.target.node_id;
subst["{TARGET_NAME}"] = d.target.node.nodeinfo.hostname ? d.target.node.nodeinfo.hostname : "unknown";
return showStat(o, subst);
}
return function (config, el, router, d) {
var unknown = !(d.source.node)
var h2 = document.createElement("h2")
var a1 = document.createElement("a")
var unknown = !(d.source.node);
var h2 = document.createElement("h2");
var a1 = document.createElement("a");
if (!unknown) {
a1.href = "#"
a1.onclick = router.node(d.source.node)
a1.href = "#";
a1.onclick = router.node(d.source.node);
}
a1.textContent = unknown ? d.source.id : d.source.node.nodeinfo.hostname
h2.appendChild(a1)
h2.appendChild(document.createTextNode(" → "))
var a2 = document.createElement("a")
a2.href = "#"
a2.onclick = router.node(d.target.node)
a2.textContent = d.target.node.nodeinfo.hostname
h2.appendChild(a2)
el.appendChild(h2)
a1.textContent = unknown ? d.source.id : d.source.node.nodeinfo.hostname;
h2.appendChild(a1);
h2.appendChild(document.createTextNode(" → "));
var a2 = document.createElement("a");
a2.href = "#";
a2.onclick = router.node(d.target.node);
a2.textContent = d.target.node.nodeinfo.hostname;
h2.appendChild(a2);
el.appendChild(h2);
var attributes = document.createElement("table")
attributes.classList.add("attributes")
var attributes = document.createElement("table");
attributes.classList.add("attributes");
attributeEntry(attributes, "TQ", showTq(d))
attributeEntry(attributes, "Entfernung", showDistance(d))
attributeEntry(attributes, "Typ", d.type)
var hw1 = unknown ? null : dictGet(d.source.node.nodeinfo, ["hardware", "model"])
var hw2 = dictGet(d.target.node.nodeinfo, ["hardware", "model"])
attributeEntry(attributes, "Hardware", (hw1 != null ? hw1 : "unbekannt") + " " + (hw2 != null ? hw2 : "unbekannt"))
el.appendChild(attributes)
attributeEntry(attributes, "TQ", showTq(d));
attributeEntry(attributes, "Entfernung", showDistance(d));
attributeEntry(attributes, "Typ", d.type);
var hw1 = unknown ? null : dictGet(d.source.node.nodeinfo, ["hardware", "model"]);
var hw2 = dictGet(d.target.node.nodeinfo, ["hardware", "model"]);
attributeEntry(attributes, "Hardware", (hw1 != null ? hw1 : "unbekannt") + " " + (hw2 != null ? hw2 : "unbekannt"));
el.appendChild(attributes);
if (config.linkInfos)
config.linkInfos.forEach( function (linkInfo) {
var h4 = document.createElement("h4")
h4.textContent = linkInfo.name
el.appendChild(h4)
el.appendChild(showStatImg(linkInfo, d))
})
}
})
if (config.linkInfos) {
config.linkInfos.forEach(function (linkInfo) {
var h4 = document.createElement("h4");
h4.textContent = linkInfo.name;
el.appendChild(h4);
el.appendChild(showStatImg(linkInfo, d));
});
}
};
});

View file

@ -1,100 +1,103 @@
define(function () {
return function (config, el, router, d) {
var sidebarTitle = document.createElement("h2")
sidebarTitle.textContent = "Location: " + d.toString()
el.appendChild(sidebarTitle)
var sidebarTitle = document.createElement("h2");
sidebarTitle.textContent = "Location: " + d.toString();
el.appendChild(sidebarTitle);
getJSON("https://nominatim.openstreetmap.org/reverse?format=json&lat=" + d.lat + "&lon=" + d.lng + "&zoom=18&addressdetails=0")
.then(function(result) {
if(result.display_name)
sidebarTitle.textContent = result.display_name
})
.then(function (result) {
if (result.display_name) {
sidebarTitle.textContent = result.display_name;
}
});
var editLat = document.createElement("input")
editLat.type = "text"
editLat.value = d.lat.toFixed(9)
el.appendChild(createBox("lat", "Breitengrad", editLat))
var editLat = document.createElement("input");
editLat.type = "text";
editLat.value = d.lat.toFixed(9);
el.appendChild(createBox("lat", "Breitengrad", editLat));
var editLng = document.createElement("input")
editLng.type = "text"
editLng.value = d.lng.toFixed(9)
el.appendChild(createBox("lng", "Längengrad", editLng))
var editLng = document.createElement("input");
editLng.type = "text";
editLng.value = d.lng.toFixed(9);
el.appendChild(createBox("lng", "Längengrad", editLng));
var editUci = document.createElement("textarea")
var editUci = document.createElement("textarea");
editUci.value =
"uci set gluon-node-info.@location[0]='location'; " +
"uci set gluon-node-info.@location[0].share_location='1';" +
"uci set gluon-node-info.@location[0].latitude='" + d.lat.toFixed(9) + "';" +
"uci set gluon-node-info.@location[0].longitude='" + d.lng.toFixed(9) + "';" +
"uci commit gluon-node-info"
"uci commit gluon-node-info";
el.appendChild(createBox("uci", "Befehl", editUci, false))
el.appendChild(createBox("uci", "Befehl", editUci, false));
var linkPlain = document.createElement("a")
linkPlain.textContent = "plain"
linkPlain.onclick = function() {
switch2plain()
return false
}
linkPlain.href = "#"
var linkPlain = document.createElement("a");
linkPlain.textContent = "plain";
linkPlain.onclick = function () {
switch2plain();
return false;
};
linkPlain.href = "#";
var linkUci = document.createElement("a")
linkUci.textContent = "uci"
linkUci.onclick = function() {
switch2uci()
return false
}
linkUci.href = "#"
var linkUci = document.createElement("a");
linkUci.textContent = "uci";
linkUci.onclick = function () {
switch2uci();
return false;
};
linkUci.href = "#";
var hintText = document.createElement("p")
hintText.appendChild(document.createTextNode("Du kannst zwischen "))
hintText.appendChild(linkPlain)
hintText.appendChild(document.createTextNode(" und "))
hintText.appendChild(linkUci)
hintText.appendChild(document.createTextNode(" wechseln."))
el.appendChild(hintText)
var hintText = document.createElement("p");
hintText.appendChild(document.createTextNode("Du kannst zwischen "));
hintText.appendChild(linkPlain);
hintText.appendChild(document.createTextNode(" und "));
hintText.appendChild(linkUci);
hintText.appendChild(document.createTextNode(" wechseln."));
el.appendChild(hintText);
function createBox(name, title, inputElem, isVisible) {
var visible = typeof isVisible !== "undefined" ? isVisible : true
var box = document.createElement("div")
var heading = document.createElement("h3")
heading.textContent = title
box.appendChild(heading)
var btn = document.createElement("button")
btn.className = "ion-ios-copy"
btn.title = "Kopieren"
btn.onclick = function() { copy2clip(inputElem.id) }
inputElem.id = "location-" + name
inputElem.readOnly = true
var line = document.createElement("p")
line.appendChild(inputElem)
line.appendChild(btn)
box.appendChild(line)
box.id = "box-" + name
box.style.display = visible ? "block" : "none"
return box
var visible = typeof isVisible !== "undefined" ? isVisible : true;
var box = document.createElement("div");
var heading = document.createElement("h3");
heading.textContent = title;
box.appendChild(heading);
var btn = document.createElement("button");
btn.className = "ion-ios-copy";
btn.title = "Kopieren";
btn.onclick = function () {
copy2clip(inputElem.id);
};
inputElem.id = "location-" + name;
inputElem.readOnly = true;
var line = document.createElement("p");
line.appendChild(inputElem);
line.appendChild(btn);
box.appendChild(line);
box.id = "box-" + name;
box.style.display = visible ? "block" : "none";
return box;
}
function copy2clip(id) {
var copyField = document.querySelector("#" + id)
copyField.select()
var copyField = document.querySelector("#" + id);
copyField.select();
try {
document.execCommand("copy")
document.execCommand("copy");
} catch (err) {
console.log(err)
console.log(err);
}
}
function switch2plain() {
document.getElementById("box-uci").style.display = "none"
document.getElementById("box-lat").style.display = "block"
document.getElementById("box-lng").style.display = "block"
document.getElementById("box-uci").style.display = "none";
document.getElementById("box-lat").style.display = "block";
document.getElementById("box-lng").style.display = "block";
}
function switch2uci() {
document.getElementById("box-uci").style.display = "block"
document.getElementById("box-lat").style.display = "none"
document.getElementById("box-lng").style.display = "none"
document.getElementById("box-uci").style.display = "block";
document.getElementById("box-lat").style.display = "none";
document.getElementById("box-lng").style.display = "none";
}
}
})
};
});

View file

@ -1,51 +1,51 @@
define(["infobox/link", "infobox/node", "infobox/location"], function (Link, Node, Location) {
return function (config, sidebar, router) {
var self = this
var el
var self = this;
var el;
function destroy() {
if (el && el.parentNode) {
el.parentNode.removeChild(el)
el = undefined
sidebar.reveal()
el.parentNode.removeChild(el);
el = undefined;
sidebar.reveal();
}
}
function create() {
destroy()
sidebar.ensureVisible()
sidebar.hide()
destroy();
sidebar.ensureVisible();
sidebar.hide();
el = document.createElement("div")
sidebar.container.insertBefore(el, sidebar.container.firstChild)
el = document.createElement("div");
sidebar.container.insertBefore(el, sidebar.container.firstChild);
el.scrollIntoView(false)
el.classList.add("infobox")
el.destroy = destroy
el.scrollIntoView(false);
el.classList.add("infobox");
el.destroy = destroy;
var closeButton = document.createElement("button")
closeButton.classList.add("close")
closeButton.onclick = router.reset
el.appendChild(closeButton)
var closeButton = document.createElement("button");
closeButton.classList.add("close");
closeButton.onclick = router.reset;
el.appendChild(closeButton);
}
self.resetView = destroy
self.resetView = destroy;
self.gotoNode = function (d) {
create()
new Node(config, el, router, d)
}
create();
new Node(config, el, router, d);
};
self.gotoLink = function (d) {
create()
new Link(config, el, router, d)
}
create();
new Link(config, el, router, d);
};
self.gotoLocation = function (d) {
create()
new Location(config, el, router, d)
}
create();
new Location(config, el, router, d);
};
return self
}
})
return self;
};
});

File diff suppressed because it is too large Load diff