From 65ab4fbee71c74bad0e423a860498d7f11987a2a Mon Sep 17 00:00:00 2001 From: Mstiekema Date: Tue, 2 Nov 2021 12:41:54 +0100 Subject: [PATCH] Made menu more modular, only showing what you want --- modules/dev_auth.js | 2 +- modules/handle_state.js | 4 ++-- modules/nfc.js | 2 +- sample.env | 7 +++++++ src/static/js/menu.js | 11 ++++++++--- src/views/base/base.css | 4 ++++ src/views/base/base.html | 6 +++--- 7 files changed, 26 insertions(+), 10 deletions(-) diff --git a/modules/dev_auth.js b/modules/dev_auth.js index 9e5155e..e7a8e39 100644 --- a/modules/dev_auth.js +++ b/modules/dev_auth.js @@ -3,7 +3,7 @@ const { CardOn, ClearBasket } = require('./handle_state'); module.exports.HandleAuthDev = async (win) => { globalShortcut.register('Ctrl+1', () => { - CardOn(win, process.env.TEST_UUID); + CardOn(win, process.env.TEST_UUID, process.env.MODULES); }); globalShortcut.register('Ctrl+2', () => { diff --git a/modules/handle_state.js b/modules/handle_state.js index 945da27..15783c6 100644 --- a/modules/handle_state.js +++ b/modules/handle_state.js @@ -1,10 +1,10 @@ const { Request } = require('./api'); -module.exports.CardOn = async (win, uuid) => { +module.exports.CardOn = async (win, uuid, modules) => { await Request('GET', `api/checkout/card?uuid=${uuid}`, null, (err, data, statusCode) => { if (statusCode == 200) { // Load the dashboard - win.loadFile(`src/views/base/base.html`, { query: { "uuid": JSON.stringify(uuid) } }); + win.loadFile(`src/views/base/base.html`, { query: { "uuid": JSON.stringify(uuid), "modules": modules } }); } else if (statusCode == 404) { // Show register page if card not found win.loadFile(`src/views/register/register.html`, { query: { "uuid": JSON.stringify(uuid) } }); diff --git a/modules/nfc.js b/modules/nfc.js index 3d2a38d..4e2fc93 100644 --- a/modules/nfc.js +++ b/modules/nfc.js @@ -24,7 +24,7 @@ module.exports.HandleAuthNFC = async (win) => { if (err) throw err }); - CardOn(win, uuid); + CardOn(win, uuid, process.env.MODULES); }); reader.on('card.off', card => { diff --git a/sample.env b/sample.env index cf3a9c9..ae39941 100644 --- a/sample.env +++ b/sample.env @@ -1,10 +1,17 @@ # Define whether the API is secure or not (http: or https:) PROTOCOl=http: + # Hostname of where Koala is hosted HOST=koala.rails.local + # Port on which the API is hosted PORT=3000 + # Token which is defined by Koala TOKEN=token + # UUID which is used purely for development purposes TEST_UUID=123abc + +# You can select what modules you want to enable. The options are "products", "activities" and "funds" +MODULES=["products", "activities", "funds"] diff --git a/src/static/js/menu.js b/src/static/js/menu.js index e9152f5..07c18ab 100644 --- a/src/static/js/menu.js +++ b/src/static/js/menu.js @@ -6,6 +6,10 @@ const path = require('path'); const fs = require('fs'); let url = "products"; +const query = querystring.parse(global.location.search) +const modules = JSON.parse(query['modules']); +const uuid = JSON.parse(query['?uuid']); + renderHTML = page => { page = path.join(__dirname, page); const file = fs.readFileSync(page); @@ -29,6 +33,10 @@ getUserInfo = () => { } document.querySelectorAll('.link').forEach((element) => { + if (modules.indexOf(element.id) != -1) { + element.classList.remove("hidden") + } + element.addEventListener('click', function (e) { url = element.id; @@ -60,8 +68,5 @@ ipcRenderer.on('getUserInfo', (event, arg) => { }); -let query = querystring.parse(global.location.search) -let uuid = JSON.parse(query['?uuid']); - getUserInfo(); renderHomePage(); diff --git a/src/views/base/base.css b/src/views/base/base.css index 3bb1602..f255b55 100644 --- a/src/views/base/base.css +++ b/src/views/base/base.css @@ -33,6 +33,10 @@ body { width: 100px; } +.hidden { + display: none !important; +} + /* Default components */ main { diff --git a/src/views/base/base.html b/src/views/base/base.html index e4e413c..466d704 100644 --- a/src/views/base/base.html +++ b/src/views/base/base.html @@ -20,13 +20,13 @@ class="item" id="logo" /> - + - + - +