more senisble default values, added layout persistance
This commit is contained in:
parent
160ef0dcda
commit
6076c05cfb
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
node_modules
|
node_modules
|
||||||
rename.sh
|
rename.sh
|
||||||
|
data-persistence.json
|
||||||
|
45
index.js
45
index.js
@ -16,13 +16,22 @@ app.use(
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let loadedData = {}
|
||||||
|
|
||||||
|
if(fs.existsSync("data-persistence.json")) {
|
||||||
|
const loadedDataRaw = fs.readFileSync("data-persistence.json", "utf8");
|
||||||
|
loadedData = JSON.parse(loadedDataRaw);
|
||||||
|
}else{
|
||||||
|
console.warn("Unable to load persistent data");
|
||||||
|
}
|
||||||
|
|
||||||
currentState = {
|
currentState = {
|
||||||
mode: "clock",
|
mode: "clock",
|
||||||
countdownGoal: new Date().getTime(),
|
countdownGoal: new Date().getTime(),
|
||||||
showMilliSeconds: true,
|
showMilliSeconds: true,
|
||||||
defaultFullScreen: true,
|
defaultFullScreen: true,
|
||||||
timeAmountInital: 0,
|
timeAmountInital: 0,
|
||||||
timerRunState: true,
|
timerRunState: false,
|
||||||
pauseMoment: 0,
|
pauseMoment: 0,
|
||||||
showTimeOnCountdown: true,
|
showTimeOnCountdown: true,
|
||||||
message: "",
|
message: "",
|
||||||
@ -36,8 +45,16 @@ currentState = {
|
|||||||
debug: false
|
debug: false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const dataToBeWritten = {};
|
||||||
|
|
||||||
|
currentState = Object.assign({}, currentState, loadedData);
|
||||||
|
|
||||||
|
console.log(currentState)
|
||||||
|
|
||||||
currentState.textColors = currentState.colorSegments
|
currentState.textColors = currentState.colorSegments
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
console.log("Preparing routes...");
|
console.log("Preparing routes...");
|
||||||
app.get("/", function (req, res) {
|
app.get("/", function (req, res) {
|
||||||
const data = fs.readFileSync("templates/newAdminPanel.html", "utf8");
|
const data = fs.readFileSync("templates/newAdminPanel.html", "utf8");
|
||||||
@ -67,6 +84,9 @@ app.get("/api/v1/set/mode", function (req, res) {
|
|||||||
|
|
||||||
app.get("/api/v1/set/layout/showMillis", function (req, res) {
|
app.get("/api/v1/set/layout/showMillis", function (req, res) {
|
||||||
currentState.showMilliSeconds = (req.query.show === 'true');
|
currentState.showMilliSeconds = (req.query.show === 'true');
|
||||||
|
if(req.query.persist === 'true'){
|
||||||
|
dataToBeWritten.showMilliSeconds = currentState.showMilliSeconds
|
||||||
|
}
|
||||||
res.json({ status: "ok" });
|
res.json({ status: "ok" });
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -103,17 +123,26 @@ app.get("/api/v1/ctrl/timer/restart", function (req, res) {
|
|||||||
|
|
||||||
app.get("/api/v1/set/layout/showTime", function (req, res) {
|
app.get("/api/v1/set/layout/showTime", function (req, res) {
|
||||||
currentState.showTimeOnCountdown = (req.query.show === 'true');
|
currentState.showTimeOnCountdown = (req.query.show === 'true');
|
||||||
|
if(req.query.persist === 'true'){
|
||||||
|
dataToBeWritten.showTimeOnCountdown = currentState.showTimeOnCountdown
|
||||||
|
}
|
||||||
res.json({ status: "ok" });
|
res.json({ status: "ok" });
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/api/v1/set/progressbar/show", function (req, res) {
|
app.get("/api/v1/set/progressbar/show", function (req, res) {
|
||||||
currentState.showProgressbar = (req.query.show === 'true');
|
currentState.showProgressbar = (req.query.show === 'true');
|
||||||
|
if(req.query.persist === 'true'){
|
||||||
|
dataToBeWritten.showProgressbar = currentState.showProgressbar
|
||||||
|
}
|
||||||
res.json({ status: "ok" });
|
res.json({ status: "ok" });
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/api/v1/set/progressbar/colors", function (req, res) {
|
app.get("/api/v1/set/progressbar/colors", function (req, res) {
|
||||||
try {
|
try {
|
||||||
currentState.colorSegments = JSON.parse(req.query.colors);
|
currentState.colorSegments = JSON.parse(req.query.colors);
|
||||||
|
if(req.query.persist === 'true'){
|
||||||
|
dataToBeWritten.colorSegments = currentState.colorSegments
|
||||||
|
}
|
||||||
res.json({ status: "ok" });
|
res.json({ status: "ok" });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.json({ status: "error", message: error });
|
res.json({ status: "error", message: error });
|
||||||
@ -127,6 +156,9 @@ app.get("/api/v1/set/text/colors", function (req, res) {
|
|||||||
} else {
|
} else {
|
||||||
currentState.textColors = JSON.parse(req.query.colors);
|
currentState.textColors = JSON.parse(req.query.colors);
|
||||||
}
|
}
|
||||||
|
if(req.query.persist === 'true'){
|
||||||
|
dataToBeWritten.textColors = currentState.textColors
|
||||||
|
}
|
||||||
res.json({ status: "ok" });
|
res.json({ status: "ok" });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.json({ status: "error", message: error });
|
res.json({ status: "error", message: error });
|
||||||
@ -135,6 +167,9 @@ app.get("/api/v1/set/text/colors", function (req, res) {
|
|||||||
|
|
||||||
app.get("/api/v1/set/text/enableColoring", function (req, res) {
|
app.get("/api/v1/set/text/enableColoring", function (req, res) {
|
||||||
currentState.enableColoredText = (req.query.enable === 'true');
|
currentState.enableColoredText = (req.query.enable === 'true');
|
||||||
|
if(req.query.persist === 'true'){
|
||||||
|
dataToBeWritten.enableColoredText = currentState.enableColoredText
|
||||||
|
}
|
||||||
res.json({ status: "ok" });
|
res.json({ status: "ok" });
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -154,6 +189,14 @@ app.get("/api/v1/ctrl/message/hide", function (req, res) {
|
|||||||
currentState.showMessage = false
|
currentState.showMessage = false
|
||||||
res.json({ status: "ok" });
|
res.json({ status: "ok" });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get("/api/v1/storage/commit", function (req, res) {
|
||||||
|
const tempString = JSON.stringify(dataToBeWritten);
|
||||||
|
fs.writeFileSync("data-persistence.json", tempString);
|
||||||
|
res.json({ status: "ok" });
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
console.log("Starting server...");
|
console.log("Starting server...");
|
||||||
const port = 8005
|
const port = 8005
|
||||||
app.listen(port);
|
app.listen(port);
|
||||||
|
@ -567,6 +567,42 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
$("#saveLayout").click(function (event) {
|
||||||
|
$("#saveLayout")[0].innerHTML = '<div class="spinner-border-sm spinner-border"></div>'
|
||||||
|
|
||||||
|
// Collect all data, build all paths3
|
||||||
|
const allPathes = [];
|
||||||
|
|
||||||
|
const showTimeB = $("#showTime")[0].checked
|
||||||
|
const showMillisB = $("#showMillis")[0].checked
|
||||||
|
const progBarShowB = $("#progBarShow")[0].checked
|
||||||
|
const textColorsB = $("#textColors")[0].checked
|
||||||
|
|
||||||
|
allPathes.push("/api/v1/set/layout/showTime?persist=true&show=" + showTimeB)
|
||||||
|
allPathes.push("/api/v1/set/layout/showMillis?persist=true&show=" + showMillisB)
|
||||||
|
allPathes.push("/api/v1/set/progressbar/show?persist=true&show=" + progBarShowB)
|
||||||
|
allPathes.push("/api/v1/set/text/enableColoring?persist=true&enable=" + textColorsB)
|
||||||
|
|
||||||
|
for (pI in allPathes) {
|
||||||
|
const path = allPathes[pI];
|
||||||
|
console.warn(path)
|
||||||
|
saveOption(path, function (event) {
|
||||||
|
console.debug(event)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
saveOption("/api/v1/storage/commit", function (event) {
|
||||||
|
console.debug(event)
|
||||||
|
setTimeout(function () {
|
||||||
|
$("#saveLayout")[0].innerHTML = 'Save as startup settings (Layout only)'
|
||||||
|
}, 500)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
function msToTime(s, data) {
|
function msToTime(s, data) {
|
||||||
var ms = s % 1000;
|
var ms = s % 1000;
|
||||||
s = (s - ms) / 1000;
|
s = (s - ms) / 1000;
|
||||||
|
Loading…
Reference in New Issue
Block a user