refactoring

This commit is contained in:
schrom01 2023-02-14 12:42:31 +01:00
parent 5e0793c7fc
commit 403099ebd6
2 changed files with 32 additions and 28 deletions

View File

@ -1,8 +1,9 @@
<html>
<html lang="de">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/custom.css">
<link rel="stylesheet" href="css/bootstrap.css">
<title>Genderwatch-protocol</title>
</head>
<body>
@ -122,13 +123,14 @@
closedTopics = []
}
watches = JSON.parse(localStorage.getItem("watches"))
if(!watches){
actualTopic = JSON.parse(localStorage.getItem("actualTopic"))
if(!actualTopic) {
actualTopic = {}
reset()
}
document.getElementById("topicInput").value = actualTopic.name
document.getElementById("topicInput").value = localStorage.getItem("actualTopic")
document.getElementById("topicInput").addEventListener('keyup', saveActualTopicToLocalStorage);
document.getElementById("topicInput").addEventListener('keyup', saveActualTopicName);
refreshClosedTopics()
setInterval(() => {
refreshWatch(0)

View File

@ -1,6 +1,6 @@
function reset() {
actualTopic.watches = [{"actions": []}, {"actions": []}, {"actions": []}]
saveWatchesToLocalStorage()
saveActualTopicToLocalStorage()
}
function resetButton() {
@ -24,8 +24,9 @@ function buttonDeleteClosedTopic(topicIndex) {
}
function closeTopic() {
stop()
let defaultname = "Thema"
let name = document.getElementById("topicInput").value
let name = actualTopic.name
let nameLessCounter = 1
while(!name){
let foundName = false
@ -40,11 +41,11 @@ function closeTopic() {
name = defaultname + nameLessCounter
}
}
closedTopics.push({"name": name, "watches": watches})
stop()
actualTopic.name = name
closedTopics.push(actualTopic)
actualTopic = {"name": ""}
reset()
document.getElementById("topicInput").value = ""
document.getElementById("topicInput").value = actualTopic.name
saveActualTopicToLocalStorage()
saveClosedTopicsToLocalStorage()
refreshClosedTopics()
@ -57,36 +58,36 @@ function deleteTopic(topicIndex) {
}
function reopenTopic(topicIndex) {
if(watches[0]["actions"]["length"] > 0 || watches[1]["actions"]["length"] > 0 ||watches[2]["actions"]["length"] > 0 || document.getElementById("topicInput").value != "") {
if(actualTopic.watches[0]["actions"]["length"] > 0 || actualTopic.watches[1]["actions"]["length"] > 0 ||actualTopic.watches[2]["actions"]["length"] > 0 || actualTopic.name !== "") {
closeTopic()
}
watches = closedTopics[topicIndex]["watches"]
document.getElementById("topicInput").value = closedTopics[topicIndex]["name"]
actualTopic = closedTopics[topicIndex]
document.getElementById("topicInput").value = actualTopic.name
deleteTopic(topicIndex)
saveWatchesToLocalStorage()
saveClosedTopicsToLocalStorage()
saveActualTopicToLocalStorage()
}
function start(watchIndex) {
stop()
watches[watchIndex].actions.push({"type": "start", "time": new Date().getTime()})
saveWatchesToLocalStorage()
actualTopic.watches[watchIndex].actions.push({"type": "start", "time": new Date().getTime()})
saveActualTopicToLocalStorage()
}
function stop() {
watches.forEach(watch => {
actualTopic.watches.forEach(watch => {
if(watch["actions"]["length"] > 0) {
if(watch["actions"]["length"] % 2 == 1){
if(watch["actions"]["length"] % 2 === 1){
watch["actions"].push({"type": "stop", "time": new Date().getTime()})
}
}
});
saveWatchesToLocalStorage()
saveActualTopicToLocalStorage()
}
function calcPercForWatch(watchIndex, topic) {
let sumAll = sumAllwatches(topic)
if(sumAll == 0) {
if(sumAll === 0) {
return 0
}
return Math.round(sumForWatch(topic.watches[watchIndex]) / sumAllwatches(topic) * 100)
@ -112,7 +113,7 @@ function countForWatch(watch) {
function calcPercCountForWatch(watchindex, topic) {
let sumAll = sumCountAllWatches(topic)
if(sumAll == 0) {
if(sumAll === 0) {
return 0
}
return Math.round(countForWatch(topic.watches[watchindex]) / sumAll * 100)
@ -132,14 +133,14 @@ function timeToISO(time){
function refreshWatch(watchIndex) {
let timeCell = document.getElementById("time-" + watchIndex)
timeCell.textContent = timeToISO(sumForWatch(watches[watchIndex]))
if(watches[watchIndex]["actions"].length != 0 && watches[watchIndex]["actions"].slice(-1)[0]["type"] == "start"){
timeCell.textContent = timeToISO(sumForWatch(actualTopic.watches[watchIndex]))
if(actualTopic.watches[watchIndex]["actions"].length !== 0 && actualTopic.watches[watchIndex]["actions"].slice(-1)[0]["type"] === "start"){
timeCell.classList.add("active")
} else {
timeCell.classList.remove("active")
}
let countCell = document.getElementById("count-" + watchIndex)
countCell.textContent = countForWatch(watches[watchIndex]) + " Wortmeldungen"
countCell.textContent = countForWatch(actualTopic.watches[watchIndex]) + " Wortmeldungen"
}
function refreshClosedTopics() {
@ -178,12 +179,13 @@ function refreshClosedTopics() {
}
}
function saveWatchesToLocalStorage() {
localStorage.setItem("watches", JSON.stringify(watches))
function saveActualTopicName() {
actualTopic.name = document.getElementById("topicInput").value
saveActualTopicToLocalStorage()
}
function saveActualTopicToLocalStorage() {
localStorage.setItem("actualTopic", document.getElementById("topicInput").value)
localStorage.setItem("actualTopic", JSON.stringify(actualTopic))
}
function saveClosedTopicsToLocalStorage() {