From 55918a40fe8f9190e3b3cca6d83f41a21ea0b4b9 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Tue, 3 Dec 2019 13:08:48 +0100 Subject: [PATCH] Frontend: Fix tests & code clean-up Signed-off-by: Michael Mayer --- frontend/.eslintrc.js | 1 + frontend/src/common/api.js | 7 +++++-- frontend/src/common/config.js | 3 +-- frontend/src/common/log.js | 2 +- frontend/src/common/notify.js | 10 +++++----- frontend/src/common/session.js | 2 +- frontend/src/common/websocket.js | 12 ++++++------ frontend/src/model/settings.js | 2 +- 8 files changed, 21 insertions(+), 18 deletions(-) diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.js index 13a0459a0..596cfa08d 100644 --- a/frontend/.eslintrc.js +++ b/frontend/.eslintrc.js @@ -18,5 +18,6 @@ module.exports = { semi: ['error', 'always'], 'no-unused-vars': ['warn'], 'no-console': 0, + 'no-prototype-builtins': 0, }, }; diff --git a/frontend/src/common/api.js b/frontend/src/common/api.js index 1cc52fdf6..57dac613c 100644 --- a/frontend/src/common/api.js +++ b/frontend/src/common/api.js @@ -2,12 +2,15 @@ import "@babel/polyfill/noConflict"; import Axios from "axios"; import Notify from "common/notify"; +const testConfig = {"jsHash": "test", "version": "test"}; +const config = window.clientConfig ? window.clientConfig : testConfig; + const Api = Axios.create({ baseURL: "/api/v1", headers: {common: { "X-Session-Token": window.localStorage.getItem("session_token"), - "X-Client-Hash": window.clientConfig.jsHash, - "X-Client-Version": window.clientConfig.version, + "X-Client-Hash": config.jsHash, + "X-Client-Version": config.version, }}, }); diff --git a/frontend/src/common/config.js b/frontend/src/common/config.js index 4dc2c988d..2ce585c50 100644 --- a/frontend/src/common/config.js +++ b/frontend/src/common/config.js @@ -1,7 +1,6 @@ import Event from "pubsub-js"; import themes from "../resources/themes.json"; import translations from "../resources/translations.json"; -import Vue from "vue"; class Config { /** @@ -15,7 +14,7 @@ class Config { this.translations = translations; this.values = values; - this.subscriptionId = Event.subscribe('config.updated', (ev, data) => this.setValues(data)); + this.subscriptionId = Event.subscribe("config.updated", (ev, data) => this.setValues(data)); if(this.hasValue("settings")) { this.setTheme(this.getValue("settings").theme); diff --git a/frontend/src/common/log.js b/frontend/src/common/log.js index 0c971c926..c8dd5c45a 100644 --- a/frontend/src/common/log.js +++ b/frontend/src/common/log.js @@ -5,7 +5,7 @@ class Log { this.logs = []; this.logId = 0; - Event.subscribe('log', this.onLog.bind(this)); + Event.subscribe("log", this.onLog.bind(this)); } onLog(ev, data) { diff --git a/frontend/src/common/notify.js b/frontend/src/common/notify.js index a72353183..c75ada9b7 100644 --- a/frontend/src/common/notify.js +++ b/frontend/src/common/notify.js @@ -24,19 +24,19 @@ const Notify = { Event.publish("ajax.end"); }, blockUI: function() { - const el = document.getElementById('p-busy-overlay'); + const el = document.getElementById("p-busy-overlay"); if(el) { - el.style.display = 'block'; + el.style.display = "block"; } }, unblockUI: function() { - const el = document.getElementById('p-busy-overlay'); + const el = document.getElementById("p-busy-overlay"); if(el) { - el.style.display = 'none'; + el.style.display = "none"; } - } + }, }; export default Notify; diff --git a/frontend/src/common/session.js b/frontend/src/common/session.js index f70a0da08..60d20fbb9 100644 --- a/frontend/src/common/session.js +++ b/frontend/src/common/session.js @@ -24,7 +24,7 @@ export default class Session { this.auth = true; } - Event.subscribe('session.logout', this.onLogout.bind(this)); + Event.subscribe("session.logout", this.onLogout.bind(this)); } useSessionStorage() { diff --git a/frontend/src/common/websocket.js b/frontend/src/common/websocket.js index 7be48e15a..15b5b87f4 100644 --- a/frontend/src/common/websocket.js +++ b/frontend/src/common/websocket.js @@ -4,7 +4,7 @@ import randomString from "crypto-random-string"; export const token = randomString({length: 16}); const host = window.location.host; -const prot = ('https:' === document.location.protocol ? 'wss://' : 'ws://'); +const prot = ("https:" === document.location.protocol ? "wss://" : "ws://"); const url = prot + host + "/api/v1/ws"; const clientInfo = { "token": token, @@ -15,17 +15,17 @@ const clientInfo = { const Socket = new Sockette(url, { timeout: 5e3, onopen: e => { - console.log('websocket: connected', e); + console.log("websocket: connected", e); Socket.send(JSON.stringify(clientInfo)); }, onmessage: e => { const m = JSON.parse(e.data); Event.publish(m.event, m.data); }, - onreconnect: e => console.log('websocket: reconnecting', e), - onmaximum: e => console.warn('websocket: hit max reconnect limit', e), - onclose: e => console.log('websocket: closed', e), - onerror: e => console.log('websocket: error', e) + onreconnect: e => console.log("websocket: reconnecting", e), + onmaximum: e => console.warn("websocket: hit max reconnect limit", e), + onclose: e => console.log("websocket: closed", e), + onerror: e => console.log("websocket: error", e), }); export default Socket; diff --git a/frontend/src/model/settings.js b/frontend/src/model/settings.js index 6fd5bda41..234a0d706 100644 --- a/frontend/src/model/settings.js +++ b/frontend/src/model/settings.js @@ -5,7 +5,7 @@ class Settings { this.__originalValues = {}; if (!values) { - throw "can't create settings with empty values" + throw "can't create settings with empty values"; } this.setValues(values);