From a2d69adacff11a7c71bc3ae748766d02cb161d06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20B=C3=A4lter?= Date: Wed, 13 Jun 2018 09:54:18 +0200 Subject: [PATCH] eslint all js --- .eslintrc.js | 15 ++++ .jshintignore | 1 + static/channels.html | 18 ++--- static/connection.html | 171 ++++++++++++++++++++++++++++++++++++++++ static/connections.html | 34 +++++--- static/exchanges.html | 20 ++--- static/index.html | 16 ++-- static/js/auth.js | 94 +++++++++++----------- static/js/http.js | 85 ++++++++++---------- static/js/overview.js | 58 +++++++------- static/js/table.js | 166 +++++++++++++++++++------------------- static/js/users.js | 30 +++---- static/js/vhosts.js | 30 +++---- static/login.html | 23 +++--- static/queues.html | 64 +++++++-------- static/user.html | 92 ++++++++++----------- static/users.html | 36 ++++----- static/vhost.html | 70 ++++++++-------- static/vhosts.html | 26 +++--- 19 files changed, 630 insertions(+), 419 deletions(-) create mode 100644 .eslintrc.js create mode 100644 .jshintignore create mode 100644 static/connection.html diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000000..3a2d445c9b --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,15 @@ +module.exports = { + "extends": "standard", + "plugins": [ + "html" + ], + "settings": { + "html/indent": "+2" + }, + "globals": { + "avalanchemq": true + }, + "rules": { + "indent": ["error", 2] + } +}; diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 0000000000..798c60da1f --- /dev/null +++ b/.jshintignore @@ -0,0 +1 @@ +*/** diff --git a/static/channels.html b/static/channels.html index 7c42dfc2ec..facb63c308 100644 --- a/static/channels.html +++ b/static/channels.html @@ -52,17 +52,17 @@

diff --git a/static/connection.html b/static/connection.html new file mode 100644 index 0000000000..c910117e19 --- /dev/null +++ b/static/connection.html @@ -0,0 +1,171 @@ + + + + Connection | AvalancheMQ + + + + +
+
+

+ AvalancheMQ + +

+
+ 👤:  + + +
+
+ +

+ Connection: + +

+ + + + + + + + + + + + + + + + + + + +
UsernameState
Connected atHeartbeat
AuthenticationChannel max
+
+

+ Channels + +

+ + + + + + + + + + + + + +
NameVirtual HostUsernameModeConsumersPrefetch limitUnacked messages
+

Client properties

+ + + + + + + + + + + + + + + + + + + + + +
Capabilities
Product
Platform
Version
Information
+
+
+ Close connection + + +
+
+
+ + + + + + + diff --git a/static/connections.html b/static/connections.html index b942d5b619..4371f39a65 100644 --- a/static/connections.html +++ b/static/connections.html @@ -35,11 +35,16 @@

- + - - + + + + + + + @@ -50,13 +55,22 @@

diff --git a/static/exchanges.html b/static/exchanges.html index 121a64b5e9..6aa217298f 100644 --- a/static/exchanges.html +++ b/static/exchanges.html @@ -49,16 +49,16 @@

diff --git a/static/index.html b/static/index.html index eef8347387..0d48dc4732 100644 --- a/static/index.html +++ b/static/index.html @@ -62,14 +62,14 @@

Overview

diff --git a/static/js/auth.js b/static/js/auth.js index 14c24f4dc1..e59a57ab2e 100644 --- a/static/js/auth.js +++ b/static/js/auth.js @@ -1,86 +1,86 @@ (function () { - window.avalanchemq = window.avalanchemq || {}; + window.avalanchemq = window.avalanchemq || {} - function setUsername() { - document.querySelector("#username").innerText = getCookieValue("username"); + function setUsername () { + document.querySelector('#username').innerText = getCookieValue('username') } - function header() { + function header () { if (getCookieValue('auth')) { - return "Basic " + decodeURIComponent(getCookieValue('auth')); + return 'Basic ' + decodeURIComponent(getCookieValue('auth')) } else { - return null; + return null } } - function signOut() { - clearCookieValue('auth'); - clearCookieValue('username'); - window.location.assign("/login"); + function signOut () { + clearCookieValue('auth') + clearCookieValue('username') + window.location.assign('/login') } - function setAuth(userInfo) { - clearCookieValue('auth'); - clearCookieValue('username'); + function setAuth (userInfo) { + clearCookieValue('auth') + clearCookieValue('username') - var b64 = window.btoa(userInfo); - storeCookie({ 'auth': encodeURIComponent(b64) }); - storeCookie({ 'username': userInfo.split(':')[0] }); + var b64 = window.btoa(userInfo) + storeCookie({ 'auth': encodeURIComponent(b64) }) + storeCookie({ 'username': userInfo.split(':')[0] }) } - function storeCookie(dict) { - var date = new Date(); - date.setHours(date.getHours() + 8); - Object.assign(dict, parseCookie()); - storeCookieWithExpiration(dict, date); + function storeCookie (dict) { + var date = new Date() + date.setHours(date.getHours() + 8) + Object.assign(dict, parseCookie()) + storeCookieWithExpiration(dict, date) } - function storeCookieWithExpiration(dict, expiration_date) { - var enc = []; + function storeCookieWithExpiration (dict, expirationDate) { + var enc = [] for (var k in dict) { - enc.push(k + ':' + escape(dict[k])); + enc.push(k + ':' + escape(dict[k])) } - document.cookie = 'm=' + enc.join('|') + '; expires=' + expiration_date.toUTCString(); + document.cookie = 'm=' + enc.join('|') + '; expires=' + expirationDate.toUTCString() } - function clearCookieValue(k) { - var d = parseCookie(); - delete d[k]; - var date = new Date(); - date.setHours(date.getHours() + 8); - storeCookieWithExpiration(d, date); + function clearCookieValue (k) { + var d = parseCookie() + delete d[k] + var date = new Date() + date.setHours(date.getHours() + 8) + storeCookieWithExpiration(d, date) } - function getCookieValue(k) { - return parseCookie()[k]; + function getCookieValue (k) { + return parseCookie()[k] } - function parseCookie() { - var c = getCookie('m'); - var items = c.length === 0 ? [] : c.split('|'); + function parseCookie () { + var c = getCookie('m') + var items = c.length === 0 ? [] : c.split('|') - var dict = {}; + var dict = {} for (var i in items) { - var kv = items[i].split(':'); - dict[kv[0]] = unescape(kv[1]); + var kv = items[i].split(':') + dict[kv[0]] = unescape(kv[1]) } - return dict; + return dict } - function getCookie(key) { - var cookies = document.cookie.split(';'); + function getCookie (key) { + var cookies = document.cookie.split(';') for (var i in cookies) { - var kv = cookies[i].trim().split('='); + var kv = cookies[i].trim().split('=') if (kv[0] === key) { - return kv[1]; + return kv[1] } } - return ''; + return '' } Object.assign(window.avalanchemq, { auth: { header, setAuth, storeCookie, signOut, setUsername } - }); -}) (); + }) +})() diff --git a/static/js/http.js b/static/js/http.js index 48eed2f4df..6c472960d2 100644 --- a/static/js/http.js +++ b/static/js/http.js @@ -1,78 +1,79 @@ (function () { - window.avalanchemq = window.avalanchemq || {}; - let avalanchemq = window.avalanchemq; + window.avalanchemq = window.avalanchemq || {} + let avalanchemq = window.avalanchemq - function testLoggedIn() { - var hash = location.hash; - if (hash.startsWith("#/login")) { - var arr = hash.split("/"); - avalanchemq.auth.setAuth(arr[2] + ":" + arr[3]); - location.hash = ""; - window.location.assign("/"); + function testLoggedIn () { + const hash = location.hash + if (hash.startsWith('#/login')) { + const arr = hash.split('/') + avalanchemq.auth.setAuth(arr[2] + ':' + arr[3]) + location.hash = '' + window.location.assign('/') } - if (location.pathname !== "/login") { - request("GET", "/api/whoami").then(function () { - avalanchemq.auth.setUsername(); + if (location.pathname !== '/login') { + request('GET', '/api/whoami').then(function () { + avalanchemq.auth.setUsername() }).catch(function () { // not logged in - }); - request("GET", "/api/overview").then(function (response) { + }) + request('GET', '/api/overview').then(function (response) { try { - localStorage.setItem("/api/overview", JSON.stringify(response)); + localStorage.setItem('/api/overview', JSON.stringify(response)) } catch (e) { - console.error("Saving localStorage", e); + console.error('Saving localStorage', e) } - }); + }) } } - function redirectToLogin() { - window.location.assign("/login"); + function redirectToLogin () { + window.location.assign('/login') } - function request(method, path, body) { - let headers = new Headers(); - if (!avalanchemq.auth && window.location.pathname !== "/login") { - redirectToLogin(); + function request (method, path, options = {}) { + const body = options.body + const headers = options.headers || new Headers() + if (!avalanchemq.auth && window.location.pathname !== '/login') { + redirectToLogin() } - var hdr = avalanchemq.auth.header(); - headers.append('Authorization', hdr); - let opts = { + const hdr = avalanchemq.auth.header() + headers.append('Authorization', hdr) + const opts = { method: method, headers: headers, - credentials: "include", - mode: "cors", - redirect: "follow" - }; + credentials: 'include', + mode: 'cors', + redirect: 'follow' + } if (body instanceof FormData) { - headers.delete('Content-Type'); // browser will set to multipart with boundary - opts.body = body; + headers.delete('Content-Type') // browser will set to multipart with boundary + opts.body = body } else if (body) { - headers.append('Content-Type', 'application/json'); - opts.body = JSON.stringify(body); + headers.append('Content-Type', 'application/json') + opts.body = JSON.stringify(body) } return fetch(path, opts) .then(function (response) { if (response.status === 401) { - redirectToLogin(); + redirectToLogin() } else if (!(response.status >= 200 && response.status < 400)) { // not ok } - return response; + return response }) .then(function (response) { return response.json().catch(function (e) { // not json - return e; - }); - }); + return e + }) + }) } - testLoggedIn(); + testLoggedIn() Object.assign(window.avalanchemq, { http: { request, redirectToLogin } - }); -}) (); + }) +})() diff --git a/static/js/overview.js b/static/js/overview.js index 9ea7925441..02e51b3d95 100644 --- a/static/js/overview.js +++ b/static/js/overview.js @@ -1,54 +1,54 @@ (function () { - window.avalanchemq = window.avalanchemq || {}; - let avalanchemq = window.avalanchemq; + window.avalanchemq = window.avalanchemq || {} + let avalanchemq = window.avalanchemq - let url = "/api/overview"; - let raw = localStorage.getItem(url); - let updateTimer = null; + let url = '/api/overview' + let raw = localStorage.getItem(url) + let updateTimer = null if (raw) { try { - let data = JSON.parse(raw); + let data = JSON.parse(raw) if (data) { - render(data); + render(data) } - } catch(e) { - localStorage.removeItem(url); - console.log("Error parsing data from localStorage"); - console.error(e); + } catch (e) { + localStorage.removeItem(url) + console.log('Error parsing data from localStorage') + console.error(e) } } - function update() { - avalanchemq.http.request("GET", url).then(function (response) { + function update () { + avalanchemq.http.request('GET', url).then(function (response) { try { - localStorage.setItem("/api/overview", JSON.stringify(response)); + localStorage.setItem('/api/overview', JSON.stringify(response)) } catch (e) { - console.error("Saving localStorage", e); + console.error('Saving localStorage', e) } - render(response); - }); + render(response) + }) } - function render(data) { - document.querySelector("#version").innerText = data.avalanchemq_version; - let table = document.querySelector("#overview"); + function render (data) { + document.querySelector('#version').innerText = data.avalanchemq_version + let table = document.querySelector('#overview') if (table) { Object.keys(data.object_totals).forEach(function (key) { - table.querySelector("." + key).innerText = data.object_totals[key]; - }); + table.querySelector('.' + key).innerText = data.object_totals[key] + }) } } - function start() { - update(); - updateTimer = setInterval(update, 5000); + function start () { + update() + updateTimer = setInterval(update, 5000) } - function stop() { + function stop () { if (updateTimer) { - clearInterval(updateTimer); + clearInterval(updateTimer) } } @@ -56,5 +56,5 @@ overview: { update, start, stop, render } - }); -}) (); + }) +})() diff --git a/static/js/table.js b/static/js/table.js index 57a27633a0..2a5896c2cb 100644 --- a/static/js/table.js +++ b/static/js/table.js @@ -1,150 +1,158 @@ (function () { - window.avalanchemq = window.avalanchemq || {}; - let avalanchemq = window.avalanchemq; + window.avalanchemq = window.avalanchemq || {} + let avalanchemq = window.avalanchemq - function renderTable(id, url, keyColumns, interval, renderRow) { - let sortKey = ""; - let reverseOrder = false; - let raw = localStorage.getItem(url); - let updateTimer = null; + function renderTable (id, url, keyColumns, interval, renderRow) { + let sortKey = '' + let reverseOrder = false + let raw = localStorage.getItem(url) + let updateTimer = null - makeHeadersSortable(); + makeHeadersSortable() if (raw) { - updateTable(raw); + updateTable(raw) } - fetchAndUpdate(); + fetchAndUpdate() if (interval) { - updateTimer = setInterval(fetchAndUpdate, interval); + updateTimer = setInterval(fetchAndUpdate, interval) } - function makeHeadersSortable() { - document.querySelectorAll("#" + id + " th[data-sort-key]").forEach(function (cell) { - cell.addEventListener("click", function (e) { + function makeHeadersSortable () { + document.querySelectorAll('#' + id + ' th[data-sort-key]').forEach(function (cell) { + cell.addEventListener('click', function (e) { // let column = e.target.cellIndex; // let newSortColumn = e.target.textContent.toLowerCase(); - let newSortKey = e.target.getAttribute("data-sort-key"); - if (newSortKey === newSortKey) { - reverseOrder = !reverseOrder; + let newSortKey = e.target.getAttribute('data-sort-key') + if (newSortKey === sortKey) { + reverseOrder = !reverseOrder } else { - sortKey = newSortKey; - reverseOrder = false; + sortKey = newSortKey + reverseOrder = false } - clearInterval(updateTimer); - let t = document.getElementById(id).tBodies[0]; - clearRows(t); - let raw = localStorage.getItem(url); - updateTable(raw); - }); - }); + clearInterval(updateTimer) + let t = document.getElementById(id).tBodies[0] + clearRows(t) + let raw = localStorage.getItem(url) + updateTable(raw) + }) + }) } - function clearRows(t) { + function clearRows (t) { while (t.rows.length) { - t.deleteRow(-1); + t.deleteRow(-1) } } - function fetchAndUpdate() { - let tableError = document.getElementById(id + "-error"); - return avalanchemq.http.request("GET", url).then(function (response) { - tableError.textContent = ""; + function fetchAndUpdate () { + let tableError = document.getElementById(id + '-error') + return avalanchemq.http.request('GET', url).then(function (response) { + tableError.textContent = '' try { - localStorage.setItem(url, JSON.stringify(response)); + localStorage.setItem(url, JSON.stringify(response)) } catch (e) { - console.error("Saving localStorage", e); + console.error('Saving localStorage', e) } - updateTable(response); + updateTable(response) }).catch(function (e) { - tableError.textContent = "Error fetching data"; - console.error(e.message); - }); + tableError.textContent = 'Error fetching data' + console.error(e.message) + }) } - function updateTable(raw) { - let data = raw; + function updateTable (raw) { + let data = raw if (raw instanceof String) { - data = JSON.parse(raw); + data = JSON.parse(raw) } if (!Array.isArray(data)) { - return; + return } - data.sort(byColumn); - document.getElementById(id + "-count").textContent = data.length; - let t = document.getElementById(id).tBodies[0]; + data.sort(byColumn) + document.getElementById(id + '-count').textContent = data.length + let t = document.getElementById(id).tBodies[0] for (let i = 0; i < data.length; i++) { - let item = data[i]; - let foundIndex = findIndex(t.rows, i, item); + let item = data[i] + let foundIndex = findIndex(t.rows, i, item) if (foundIndex !== -1) { - let d = foundIndex - i; + let d = foundIndex - i while (d--) { - t.deleteRow(i); + t.deleteRow(i) } - renderRow(t.rows[i], item); + renderRow(t.rows[i], item) } else { - let tr = t.insertRow(i); - setKeyAttributes(tr, item); - renderRow(tr, item); + let tr = t.insertRow(i) + setKeyAttributes(tr, item) + renderRow(tr, item) } } - let rowsToDelete = t.rows.length - data.length; - while (0 < rowsToDelete--) { - t.deleteRow(t.rows.length - 1); + let rowsToDelete = t.rows.length - data.length + while (rowsToDelete-- > 0) { + t.deleteRow(t.rows.length - 1) } } - function byColumn(a, b) { - let sortColumns = sortKey === "" ? keyColumns : [sortKey].concat(keyColumns); + function byColumn (a, b) { + let sortColumns = sortKey === '' ? keyColumns : [sortKey].concat(keyColumns) for (let i = 0; i < sortColumns.length; i++) { if (a[sortColumns[i]] > b[sortColumns[i]]) { - return 1 * (reverseOrder ? -1 : 1); + return 1 * (reverseOrder ? -1 : 1) } if (a[sortColumns[i]] < b[sortColumns[i]]) { - return -1 * (reverseOrder ? -1 : 1); + return -1 * (reverseOrder ? -1 : 1) } } - return 0; + return 0 } - function findIndex(rows, start, item) { + function findIndex (rows, start, item) { for (let i = start; i < rows.length; i++) { for (let k = 0; k < keyColumns.length; k++) { - if (rows[i].getAttribute("data-" + keyColumns[k]) !== item[keyColumns[k]]) { - break; + if (rows[i].getAttribute('data-' + keyColumns[k]) !== item[keyColumns[k]]) { + break } else if (k === keyColumns.length - 1) { - return i; + return i } } } - return -1; + return -1 } - function setKeyAttributes(tr, item) { + function setKeyAttributes (tr, item) { keyColumns.forEach(function (key) { - tr.setAttribute("data-" + key, item[key]); - }); + tr.setAttribute('data-' + key, item[key]) + }) } } - function renderCell(tr, column, value) { - let cell = tr.cells[column] || tr.insertCell(-1); + function renderCell (tr, column, value) { + let cell = tr.cells[column] || tr.insertCell(-1) if (value instanceof Element) { if (!value.isEqualNode(cell.firstChild)) { while (cell.lastChild) { - cell.removeChild(cell.lastChild); + cell.removeChild(cell.lastChild) } - cell.appendChild(value); + cell.appendChild(value) } } else { - let text = value === undefined ? "" : value.toString(); + let text = value === undefined ? '' : value.toString() if (cell.textContent !== text) { - cell.textContent = text; + cell.textContent = text } } - return cell; + return cell + } + + function renderHtmlCell (tr, column, innerHTML) { + let cell = tr.cells[column] || tr.insertCell(-1) + if (cell.innerHTML !== innerHTML) { + cell.innerHTML = innerHTML + } + return cell } Object.assign(window.avalanchemq, { - table: { renderCell, renderTable } - }); -}) (); + table: { renderCell, renderTable, renderHtmlCell } + }) +})() diff --git a/static/js/users.js b/static/js/users.js index 43557d4aec..e581aef021 100644 --- a/static/js/users.js +++ b/static/js/users.js @@ -1,29 +1,29 @@ (function () { - window.avalanchemq = window.avalanchemq || {}; - let avalanchemq = window.avalanchemq; + window.avalanchemq = window.avalanchemq || {} + let avalanchemq = window.avalanchemq - function fetch(cb) { - let url = "/api/users"; - let raw = localStorage.getItem(url); + function fetch (cb) { + let url = '/api/users' + let raw = localStorage.getItem(url) if (raw) { - var users = JSON.parse(raw); - cb(users); + var users = JSON.parse(raw) + cb(users) } - avalanchemq.http.request("GET", url).then(function (users) { + avalanchemq.http.request('GET', url).then(function (users) { try { - localStorage.setItem("/api/users", JSON.stringify(users)); + localStorage.setItem('/api/users', JSON.stringify(users)) } catch (e) { - console.error("Saving localStorage", e); + console.error('Saving localStorage', e) } - cb(users); + cb(users) }).catch(function (e) { - console.error(e.message); - }); + console.error(e.message) + }) } Object.assign(window.avalanchemq, { users: { fetch } - }); -})(); + }) +})() diff --git a/static/js/vhosts.js b/static/js/vhosts.js index 2dcc972d0c..d43f86945f 100644 --- a/static/js/vhosts.js +++ b/static/js/vhosts.js @@ -1,29 +1,29 @@ (function () { - window.avalanchemq = window.avalanchemq || {}; - let avalanchemq = window.avalanchemq; + window.avalanchemq = window.avalanchemq || {} + let avalanchemq = window.avalanchemq - function fetch(cb) { - let url = "/api/vhosts"; - let raw = localStorage.getItem(url); + function fetch (cb) { + let url = '/api/vhosts' + let raw = localStorage.getItem(url) if (raw) { - var vhosts = JSON.parse(raw); - cb(vhosts); + var vhosts = JSON.parse(raw) + cb(vhosts) } - avalanchemq.http.request("GET", url).then(function (vhosts) { + avalanchemq.http.request('GET', url).then(function (vhosts) { try { - localStorage.setItem("/api/vhosts", JSON.stringify(vhosts)); + localStorage.setItem('/api/vhosts', JSON.stringify(vhosts)) } catch (e) { - console.error("Saving localStorage", e); + console.error('Saving localStorage', e) } - cb(vhosts); + cb(vhosts) }).catch(function (e) { - console.error(e.message); - }); + console.error(e.message) + }) } Object.assign(window.avalanchemq, { vhosts: { fetch } - }); -})(); + }) +})() diff --git a/static/login.html b/static/login.html index 36e21290a6..86189c1b4d 100644 --- a/static/login.html +++ b/static/login.html @@ -34,19 +34,18 @@

localhost

diff --git a/static/queues.html b/static/queues.html index 1cfd9268e5..c689892835 100644 --- a/static/queues.html +++ b/static/queues.html @@ -75,45 +75,47 @@

diff --git a/static/user.html b/static/user.html index 8cdbfb78bf..3fdd911182 100644 --- a/static/user.html +++ b/static/user.html @@ -110,29 +110,29 @@

diff --git a/static/users.html b/static/users.html index c08aa6821f..72d57d6f7b 100644 --- a/static/users.html +++ b/static/users.html @@ -70,37 +70,37 @@

diff --git a/static/vhost.html b/static/vhost.html index 41e17c66ca..eb8fc2e1e7 100644 --- a/static/vhost.html +++ b/static/vhost.html @@ -100,30 +100,30 @@

diff --git a/static/vhosts.html b/static/vhosts.html index d09a16e942..cd06179cdf 100644 --- a/static/vhosts.html +++ b/static/vhosts.html @@ -64,16 +64,16 @@

VHostVirtual host NameUsernameTLSUsernameStateTLS ChannelsChannel maxAuth mechanismClientConnected at