Skip to content

Commit

Permalink
Made menu more modular, only showing what you want
Browse files Browse the repository at this point in the history
  • Loading branch information
Mstiekema committed Nov 4, 2021
1 parent 742d054 commit 65ab4fb
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion modules/dev_auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions modules/handle_state.js
Original file line number Diff line number Diff line change
@@ -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) } });
Expand Down
2 changes: 1 addition & 1 deletion modules/nfc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
7 changes: 7 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
@@ -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"]
11 changes: 8 additions & 3 deletions src/static/js/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -60,8 +68,5 @@ ipcRenderer.on('getUserInfo', (event, arg) => {
});


let query = querystring.parse(global.location.search)
let uuid = JSON.parse(query['?uuid']);

getUserInfo();
renderHomePage();
4 changes: 4 additions & 0 deletions src/views/base/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ body {
width: 100px;
}

.hidden {
display: none !important;
}

/* Default components */

main {
Expand Down
6 changes: 3 additions & 3 deletions src/views/base/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
class="item"
id="logo"
/>
<span class="item link" id="products">
<span class="item link hidden" id="products">
Products
</span>
<span class="item link" id="activities">
<span class="item link hidden" id="activities">
Activities
</span>
<span class="item link" id="funds">
<span class="item link hidden" id="funds">
Add funds
</span>
<span class="item" id="userFunds">
Expand Down

0 comments on commit 65ab4fb

Please sign in to comment.