refactoring
This commit is contained in:
+25
-23
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user