Add deck switch and settings access on index
This commit is contained in:
parent
26a9b5c3b7
commit
cccfacfa02
8 changed files with 79 additions and 19 deletions
|
@ -1,14 +1,15 @@
|
||||||
const socket = io();
|
const socket = io();
|
||||||
|
const deckSelect = document.getElementById("deck-select");
|
||||||
const deck = document.getElementById("deck");
|
const deck = document.getElementById("deck");
|
||||||
|
|
||||||
socket.on("connected", () => {
|
socket.on("connected", () => {
|
||||||
console.log("Connected !");
|
console.log("Connected !");
|
||||||
socket.emit("getDeck");
|
socket.emit("getDeck");
|
||||||
|
socket.emit("getDecks");
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("getDeck", d => {
|
socket.on("getDeck", d => {
|
||||||
let data = d.data, name = d.name;
|
let data = d.data, name = d.name;
|
||||||
console.log(name);
|
|
||||||
deck.innerHTML = "";
|
deck.innerHTML = "";
|
||||||
|
|
||||||
for (let x = 0; x < data.x; x++) {
|
for (let x = 0; x < data.x; x++) {
|
||||||
|
@ -27,6 +28,13 @@ socket.on("getDeck", d => {
|
||||||
setSlot(name, col, x, y);
|
setSlot(name, col, x, y);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on("getDecks", data => {
|
||||||
|
deckSelect.innerHTML = "";
|
||||||
|
for (const deck of data)
|
||||||
|
deckSelect.insertAdjacentHTML("beforeend", `<option name="${deck}">${deck}</option>`);
|
||||||
|
M.FormSelect.init(deckSelect);
|
||||||
|
});
|
||||||
|
|
||||||
socket.on("trigger", data => {
|
socket.on("trigger", data => {
|
||||||
if (data.error)
|
if (data.error)
|
||||||
alert(data.error)
|
alert(data.error)
|
||||||
|
@ -37,21 +45,33 @@ socket.on("setSlot", data => {
|
||||||
setSlot(data.name, data.data, ...data.position)
|
setSlot(data.name, data.data, ...data.position)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
deckSelect.addEventListener("change", ev => {
|
||||||
|
ev.stopPropagation();
|
||||||
|
socket.emit("getDeck", deckSelect.value);
|
||||||
|
});
|
||||||
|
|
||||||
function setSlot(name, data, x, y) {
|
function setSlot(name, data, x, y) {
|
||||||
let e = document.getElementById(`r${x}c${y}`);
|
let e = document.getElementById(`r${x}c${y}`);
|
||||||
if (e && data) {
|
|
||||||
if (data.image)
|
|
||||||
e.insertAdjacentHTML("beforeend", `<img src="${data.image}" alt="${data.text}">`);
|
|
||||||
else if (data.text)
|
|
||||||
e.insertAdjacentHTML("beforeend", `<p>${data.text}</p>`);
|
|
||||||
|
|
||||||
e.addEventListener("click", ev => {
|
if (e) {
|
||||||
ev.stopPropagation();
|
|
||||||
socket.emit("trigger", [name, x, y]);
|
|
||||||
})
|
|
||||||
} else if (e) {
|
|
||||||
let d = document.createElement("div");
|
let d = document.createElement("div");
|
||||||
d.id = e.id;
|
d.id = e.id;
|
||||||
e.replaceWith(d);
|
e.replaceWith(d);
|
||||||
|
e = d;
|
||||||
|
if (data) {
|
||||||
|
if (data.image)
|
||||||
|
e.insertAdjacentHTML("beforeend", `<img src="${data.image}" alt="${data.text}">`);
|
||||||
|
else if (data.text)
|
||||||
|
e.insertAdjacentHTML("beforeend", `<p>${data.text}</p>`);
|
||||||
|
|
||||||
|
e.addEventListener("click", ev => {
|
||||||
|
ev.stopPropagation();
|
||||||
|
socket.emit("trigger", [name, x, y]);
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
M.AutoInit();
|
||||||
|
});
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const socket = io();
|
const socket = io();
|
||||||
|
const deckSelect = document.getElementById("deck-select");
|
||||||
const deck = document.getElementById("deck");
|
const deck = document.getElementById("deck");
|
||||||
const modal = document.getElementById("modal");
|
const modal = document.getElementById("modal");
|
||||||
const type = document.getElementById("type");
|
const type = document.getElementById("type");
|
||||||
|
@ -11,6 +12,7 @@ let modalInstance, types, slot;
|
||||||
socket.on("connected", () => {
|
socket.on("connected", () => {
|
||||||
console.log("Connected !");
|
console.log("Connected !");
|
||||||
socket.emit("getDeck");
|
socket.emit("getDeck");
|
||||||
|
socket.emit("getDecks");
|
||||||
socket.emit("getType");
|
socket.emit("getType");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -45,6 +47,13 @@ socket.on("getDeck", d => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on("getDecks", data => {
|
||||||
|
deckSelect.innerHTML = "";
|
||||||
|
for (const deck of data)
|
||||||
|
deckSelect.insertAdjacentHTML("beforeend", `<option name="${deck}">${deck}</option>`);
|
||||||
|
M.FormSelect.init(deckSelect);
|
||||||
|
});
|
||||||
|
|
||||||
socket.on("getSlot", data => {
|
socket.on("getSlot", data => {
|
||||||
slot = data;
|
slot = data;
|
||||||
customs.innerHTML = "";
|
customs.innerHTML = "";
|
||||||
|
@ -75,16 +84,22 @@ socket.on("setSlot", data => {
|
||||||
else {
|
else {
|
||||||
modalInstance.close();
|
modalInstance.close();
|
||||||
let e = document.getElementById(`r${data.position[0]}c${data.position[1]}`);
|
let e = document.getElementById(`r${data.position[0]}c${data.position[1]}`);
|
||||||
if (e && data.data) {
|
if (e) {
|
||||||
if (data.data.image)
|
|
||||||
e.insertAdjacentHTML("beforeend", `<img src="${data.data.image}" alt="${data.data.text}">`);
|
|
||||||
else if (data.data.text)
|
|
||||||
e.insertAdjacentHTML("beforeend", `<p>${data.data.text}</p>`);
|
|
||||||
} else if (e)
|
|
||||||
e.innerHTML = "";
|
e.innerHTML = "";
|
||||||
|
if (data.data)
|
||||||
|
if (data.data.image)
|
||||||
|
e.insertAdjacentHTML("beforeend", `<img src="${data.data.image}" alt="${data.data.text}">`);
|
||||||
|
else if (data.data.text)
|
||||||
|
e.insertAdjacentHTML("beforeend", `<p>${data.data.text}</p>`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
deckSelect.addEventListener("change", ev => {
|
||||||
|
ev.stopPropagation();
|
||||||
|
socket.emit("getDeck", deckSelect.value);
|
||||||
|
});
|
||||||
|
|
||||||
document.getElementById("save").addEventListener("click", ev => {
|
document.getElementById("save").addEventListener("click", ev => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
|
||||||
|
|
8
sockets/getDecks.js
Normal file
8
sockets/getDecks.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
const db = require("../db.json");
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = socket => {
|
||||||
|
return () => {
|
||||||
|
socket.emit("getDecks", Object.keys(db.decks));
|
||||||
|
}
|
||||||
|
};
|
|
@ -1,5 +1,6 @@
|
||||||
module.exports = socket => {
|
module.exports = socket => {
|
||||||
socket.on("getDeck", require("./getDeck")(socket));
|
socket.on("getDeck", require("./getDeck")(socket));
|
||||||
|
socket.on("getDecks", require("./getDecks")(socket));
|
||||||
socket.on("getSlot", require("./getSlot")(socket));
|
socket.on("getSlot", require("./getSlot")(socket));
|
||||||
socket.on("getType", require("./getType")(socket));
|
socket.on("getType", require("./getType")(socket));
|
||||||
socket.on("setSlot", require("./setSlot")(socket));
|
socket.on("setSlot", require("./setSlot")(socket));
|
||||||
|
|
|
@ -4,4 +4,20 @@ block content
|
||||||
h1.center OpenDeck
|
h1.center OpenDeck
|
||||||
.container#deck
|
.container#deck
|
||||||
|
|
||||||
|
.fixed-action-btn
|
||||||
|
a(href="#modal").btn-floating.btn-large.green.modal-trigger
|
||||||
|
i.large.material-icons toc
|
||||||
|
ul
|
||||||
|
li
|
||||||
|
a(href="/settings").btn-floating.red
|
||||||
|
i.material-icons settings
|
||||||
|
|
||||||
|
#modal.modal
|
||||||
|
.modal-content
|
||||||
|
.input-field
|
||||||
|
select#deck-select
|
||||||
|
label Deck
|
||||||
|
.modal-footer
|
||||||
|
a#save.modal-close.waves-effect.waves-grey.btn-flat(href="#!") Close
|
||||||
|
|
||||||
script(src="/javascripts/index.js")
|
script(src="/javascripts/index.js")
|
||||||
|
|
|
@ -3,6 +3,7 @@ html
|
||||||
head
|
head
|
||||||
title= "OpenDeck" + (title ? " - " + title: "")
|
title= "OpenDeck" + (title ? " - " + title: "")
|
||||||
link(rel="stylesheet", href="/stylesheets/style.css")
|
link(rel="stylesheet", href="/stylesheets/style.css")
|
||||||
|
link(rel="stylesheet", href="https://fonts.googleapis.com/icon?family=Material+Icons")
|
||||||
script(src="/javascripts/materialize.js")
|
script(src="/javascripts/materialize.js")
|
||||||
script(src="/socket.io/socket.io.js")
|
script(src="/socket.io/socket.io.js")
|
||||||
body
|
body
|
||||||
|
|
|
@ -3,7 +3,6 @@ extends ./settings
|
||||||
block settings
|
block settings
|
||||||
.input-field
|
.input-field
|
||||||
select#deck-select
|
select#deck-select
|
||||||
option(value="default" selected) Default
|
|
||||||
label Deck
|
label Deck
|
||||||
|
|
||||||
.container#deck
|
.container#deck
|
||||||
|
|
|
@ -6,5 +6,5 @@ block content
|
||||||
a.brand-logo.right(href="/") OpenDeck
|
a.brand-logo.right(href="/") OpenDeck
|
||||||
ul#nav-mobile.left.hide-on-med-and-down
|
ul#nav-mobile.left.hide-on-med-and-down
|
||||||
li
|
li
|
||||||
a(href="sass.html") Decks
|
a(href="/settings") Decks
|
||||||
block settings
|
block settings
|
||||||
|
|
Loading…
Reference in a new issue