From e8ff43c6a7718e391369f721acfd9fcf7812f5b4 Mon Sep 17 00:00:00 2001 From: Xaver Maierhofer Date: Sat, 4 Feb 2017 16:14:24 +0100 Subject: [PATCH] [TASK] Href with working links --- lib/infobox/link.js | 4 ++-- lib/infobox/node.js | 4 ++-- lib/legend.js | 6 +++--- lib/linklist.js | 2 +- lib/main.js | 2 +- lib/nodelist.js | 11 +++++------ lib/router.js | 32 ++++++++++++++++++++------------ lib/sidebar.js | 2 +- lib/simplenodelist.js | 2 +- lib/utils/helper.js | 1 - 10 files changed, 36 insertions(+), 30 deletions(-) diff --git a/lib/infobox/link.js b/lib/infobox/link.js index a271fa7..9d10c1b 100644 --- a/lib/infobox/link.js +++ b/lib/infobox/link.js @@ -18,7 +18,7 @@ define(['helper'], function (helper) { var a1; if (!unknown) { a1 = document.createElement('a'); - a1.href = '#'; + a1.href = router.getUrl({ n: d.source.node_id }); a1.onclick = router.node(d.source.node); } else { a1 = document.createElement('span'); @@ -31,7 +31,7 @@ define(['helper'], function (helper) { h2.appendChild(arrow); var a2 = document.createElement('a'); - a2.href = '#'; + a2.href = router.getUrl({ n: d.target.node_id }); a2.onclick = router.node(d.target.node); a2.textContent = d.target.node.nodeinfo.hostname; h2.appendChild(a2); diff --git a/lib/infobox/node.js b/lib/infobox/node.js index 0bf03b0..55802a7 100644 --- a/lib/infobox/node.js +++ b/lib/infobox/node.js @@ -175,7 +175,7 @@ define(['chroma-js', 'moment', 'tablesort', 'helper'], return undefined; } - return au.enabled ? _.t('node.activated', {branch: au.branch}) : _.t('node.deactivated'); + return au.enabled ? _.t('node.activated', { branch: au.branch }) : _.t('node.deactivated'); } function showStatImg(o, d) { @@ -286,7 +286,7 @@ define(['chroma-js', 'moment', 'tablesort', 'helper'], var a1 = document.createElement('a'); a1.textContent = n.node.nodeinfo.hostname; a1.classList.add('online'); - a1.href = '#'; + a1.href = router.getUrl({ n: n.node.nodeinfo.node_id }); a1.onclick = router.node(n.node); td2.appendChild(a1); } else { diff --git a/lib/legend.js b/lib/legend.js index 22fa65d..d97b338 100644 --- a/lib/legend.js +++ b/lib/legend.js @@ -16,9 +16,9 @@ define(['helper'], function (helper) { return n.flags.gateway; }).map(helper.one)); - stats.textContent = _.t('sidebar.nodes', {total: totalNodes, online: totalOnlineNodes}) + ' ' + - _.t('sidebar.clients', {smart_count: totalClients}) + ' ' + - _.t('sidebar.gateway', {smart_count: totalGateways}); + stats.textContent = _.t('sidebar.nodes', { total: totalNodes, online: totalOnlineNodes }) + ' ' + + _.t('sidebar.clients', { smart_count: totalClients }) + ' ' + + _.t('sidebar.gateway', { smart_count: totalGateways }); timestamp.textContent = _.t('sidebar.lastUpdate') + ': ' + d.timestamp.format('DD.MM.Y HH:mm'); }; diff --git a/lib/linklist.js b/lib/linklist.js index 4548a4e..c1c2e9d 100644 --- a/lib/linklist.js +++ b/lib/linklist.js @@ -31,7 +31,7 @@ define(['sorttable', 'virtual-dom', 'helper'], function (SortTable, V, helper) { table.el.classList.add('link-list'); function renderRow(d) { - var td1Content = [V.h('a', { href: '#', onclick: router.link(d) }, linkName(d))]; + var td1Content = [V.h('a', { href: router.getUrl({ l: d.id }), onclick: router.link(d) }, linkName(d))]; var td1 = V.h('td', td1Content); var td2 = V.h('td', { style: { color: linkScale(d.tq).hex() } }, helper.showTq(d)); diff --git a/lib/main.js b/lib/main.js index d42e2b4..0324ade 100644 --- a/lib/main.js +++ b/lib/main.js @@ -177,7 +177,7 @@ define(['polyglot', 'moment', 'router', 'leaflet', 'gui', 'helper'], return false; }); - window._ = new Polyglot({locale: locale, allowMissing: true}); + window._ = new Polyglot({ locale: locale, allowMissing: true }); helper.getJSON('locale/' + _.locale() + '.json?' + config.cacheBreaker).then(setTranslation); var router = new Router(); diff --git a/lib/nodelist.js b/lib/nodelist.js index 613e120..2a141cd 100644 --- a/lib/nodelist.js +++ b/lib/nodelist.js @@ -33,23 +33,23 @@ define(['sorttable', 'virtual-dom', 'helper'], function (SortTable, V, helper) { return a.nodeinfo.hostname.localeCompare(b.nodeinfo.hostname); }, reverse: false - }, { + }, { name: 'node.uptime', sort: function (a, b) { return a.uptime - b.uptime; }, reverse: true - }, { + }, { name: 'node.links', sort: function (a, b) { return a.meshlinks - b.meshlinks; }, reverse: true - }, { + }, { name: 'node.clients', sort: function (a, b) { return ('clients' in a.statistics ? a.statistics.clients : -1) - - ('clients' in b.statistics ? b.statistics.clients : -1); + ('clients' in b.statistics ? b.statistics.clients : -1); }, reverse: true }]; @@ -63,9 +63,8 @@ define(['sorttable', 'virtual-dom', 'helper'], function (SortTable, V, helper) { td1Content.push(V.h('a', { className: aClass.join(' '), onclick: router.node(d), - href: '#' + href: router.getUrl({ n: d.nodeinfo.node_id }) }, d.nodeinfo.hostname)); - if (helper.hasLocation(d)) { td0Content.push(V.h('span', { className: 'icon ion-location' })); } diff --git a/lib/router.js b/lib/router.js index f6e58ff..5f8c9f7 100644 --- a/lib/router.js +++ b/lib/router.js @@ -11,25 +11,19 @@ define(['helper'], function (helper) { var running = false; function saveState() { - var e = []; + var e = '#!'; - if (currentView) { - e.push('v:' + currentView); - } + e += 'v:' + currentView; if (currentObject) { if ('node' in currentObject) { - e.push('n:' + encodeURIComponent(currentObject.node.nodeinfo.node_id)); - } - - if ('link' in currentObject) { - e.push('l:' + encodeURIComponent(currentObject.link.id)); + e += ';n:' + encodeURIComponent(currentObject.node.nodeinfo.node_id); + } else if ('link' in currentObject) { + e += ';l:' + encodeURIComponent(currentObject.link.id); } } - var s = '#!' + e.join(';'); - - window.history.pushState(s, undefined, s); + window.history.pushState(e, undefined, e); } function resetView(push) { @@ -129,6 +123,20 @@ define(['helper'], function (helper) { return targetSet; } + self.getUrl = function getUrl(data) { + var e = '#!'; + + if (data.n) { + e += 'n:' + encodeURIComponent(data.n); + } + + if (data.l) { + e += 'l:' + encodeURIComponent(data.l); + } + + return e; + }; + self.start = function start() { running = true; diff --git a/lib/sidebar.js b/lib/sidebar.js index 5fad7e5..6e93bef 100644 --- a/lib/sidebar.js +++ b/lib/sidebar.js @@ -24,7 +24,7 @@ define(function () { if (sidebar.classList.contains('hidden') || button.offsetHeight === 0) { return 0; } - return sidebar.offsetWidth; + return sidebar.offsetWidth; }; self.add = function add(d) { diff --git a/lib/simplenodelist.js b/lib/simplenodelist.js index 6ac17c8..81123c7 100644 --- a/lib/simplenodelist.js +++ b/lib/simplenodelist.js @@ -42,7 +42,7 @@ define(['moment', 'virtual-dom', 'helper'], function (moment, V, helper) { td1Content.push(V.h('a', { className: aClass.join(' '), onclick: router.node(d), - href: '#' + href: router.getUrl({ n: d.nodeinfo.node_id }) }, d.nodeinfo.hostname)); if (helper.hasLocation(d)) { diff --git a/lib/utils/helper.js b/lib/utils/helper.js index ed1aa34..b9fa5ed 100644 --- a/lib/utils/helper.js +++ b/lib/utils/helper.js @@ -132,7 +132,6 @@ define({ return ''; } - var tr = document.createElement('tr'); var th = document.createElement('th'); th.textContent = _.t(label);