2023-02-14 19:56:51 +01:00
|
|
|
function initializeNewTopic() {
|
|
|
|
actualTopic = {"name": "", "id": randomId()}
|
|
|
|
reset()
|
|
|
|
document.getElementById("topicInput").value = actualTopic.name
|
|
|
|
}
|
|
|
|
|
2023-02-09 21:23:22 +01:00
|
|
|
function reset() {
|
2023-02-14 12:13:53 +01:00
|
|
|
actualTopic.watches = [{"actions": []}, {"actions": []}, {"actions": []}]
|
2023-02-14 19:56:51 +01:00
|
|
|
saveActualTopic()
|
2023-02-09 21:23:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function resetButton() {
|
|
|
|
if(confirm("Soll die Zähler zurückgesetzt werden?")){
|
|
|
|
reset()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buttonDeleteAllClosedTopics() {
|
|
|
|
if(confirm("Sollen alle abgeschlossenen Themen gelöscht werden?")) {
|
|
|
|
closedTopics = []
|
2023-02-14 19:56:51 +01:00
|
|
|
saveClosedTopics()
|
2023-02-09 21:23:22 +01:00
|
|
|
refreshClosedTopics()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buttonDeleteClosedTopic(topicIndex) {
|
|
|
|
if(confirm('Soll das Thema "' + closedTopics[topicIndex]["name"] + '" gelöscht werden?')) {
|
|
|
|
deleteTopic(topicIndex)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeTopic() {
|
2023-02-14 12:42:31 +01:00
|
|
|
stop()
|
2023-02-09 21:23:22 +01:00
|
|
|
let defaultname = "Thema"
|
2023-02-14 12:42:31 +01:00
|
|
|
let name = actualTopic.name
|
2023-02-09 21:23:22 +01:00
|
|
|
let nameLessCounter = 1
|
|
|
|
while(!name){
|
|
|
|
let foundName = false
|
|
|
|
closedTopics.forEach(topic => {
|
|
|
|
if(topic.name === defaultname + nameLessCounter){
|
|
|
|
foundName = true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if(foundName) {
|
|
|
|
nameLessCounter++
|
|
|
|
} else {
|
|
|
|
name = defaultname + nameLessCounter
|
|
|
|
}
|
|
|
|
}
|
2023-02-14 12:42:31 +01:00
|
|
|
actualTopic.name = name
|
|
|
|
closedTopics.push(actualTopic)
|
2023-02-14 19:56:51 +01:00
|
|
|
saveClosedTopics()
|
2023-02-09 21:23:22 +01:00
|
|
|
refreshClosedTopics()
|
2023-02-14 19:56:51 +01:00
|
|
|
initializeNewTopic()
|
2023-02-09 21:23:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteTopic(topicIndex) {
|
|
|
|
closedTopics = closedTopics.slice(0, topicIndex).concat(closedTopics.slice(topicIndex+1))
|
2023-02-14 19:56:51 +01:00
|
|
|
saveClosedTopics()
|
2023-02-09 21:23:22 +01:00
|
|
|
refreshClosedTopics()
|
|
|
|
}
|
|
|
|
|
|
|
|
function reopenTopic(topicIndex) {
|
2023-02-14 12:42:31 +01:00
|
|
|
if(actualTopic.watches[0]["actions"]["length"] > 0 || actualTopic.watches[1]["actions"]["length"] > 0 ||actualTopic.watches[2]["actions"]["length"] > 0 || actualTopic.name !== "") {
|
2023-02-09 21:23:22 +01:00
|
|
|
closeTopic()
|
|
|
|
}
|
2023-02-14 12:42:31 +01:00
|
|
|
actualTopic = closedTopics[topicIndex]
|
|
|
|
document.getElementById("topicInput").value = actualTopic.name
|
2023-02-09 21:23:22 +01:00
|
|
|
deleteTopic(topicIndex)
|
2023-02-14 19:56:51 +01:00
|
|
|
saveClosedTopics()
|
|
|
|
saveActualTopic()
|
2023-02-09 21:23:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function start(watchIndex) {
|
|
|
|
stop()
|
2023-02-14 12:42:31 +01:00
|
|
|
actualTopic.watches[watchIndex].actions.push({"type": "start", "time": new Date().getTime()})
|
2023-02-14 19:56:51 +01:00
|
|
|
saveActualTopic()
|
2023-02-09 21:23:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function stop() {
|
2023-02-14 12:42:31 +01:00
|
|
|
actualTopic.watches.forEach(watch => {
|
2023-02-09 21:23:22 +01:00
|
|
|
if(watch["actions"]["length"] > 0) {
|
2023-02-14 12:42:31 +01:00
|
|
|
if(watch["actions"]["length"] % 2 === 1){
|
2023-02-09 21:23:22 +01:00
|
|
|
watch["actions"].push({"type": "stop", "time": new Date().getTime()})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2023-02-14 19:56:51 +01:00
|
|
|
saveActualTopic()
|
2023-02-09 21:23:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function calcPercForWatch(watchIndex, topic) {
|
|
|
|
let sumAll = sumAllwatches(topic)
|
2023-02-14 12:42:31 +01:00
|
|
|
if(sumAll === 0) {
|
2023-02-09 21:23:22 +01:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return Math.round(sumForWatch(topic.watches[watchIndex]) / sumAllwatches(topic) * 100)
|
|
|
|
}
|
|
|
|
function sumForWatch(watch) {
|
|
|
|
let summe = 0
|
|
|
|
let i = 0
|
|
|
|
while( i < watch["actions"]["length"]){
|
|
|
|
let start = watch.actions[i].time
|
|
|
|
let stop = new Date().getTime()
|
|
|
|
if(i+1 < watch["actions"]["length"]) {
|
|
|
|
stop = watch["actions"][i+1].time
|
|
|
|
}
|
|
|
|
summe += (stop - start)
|
|
|
|
i += 2
|
|
|
|
}
|
|
|
|
return summe
|
|
|
|
}
|
|
|
|
|
2023-02-14 12:13:53 +01:00
|
|
|
function countForWatch(watch) {
|
|
|
|
return watch["actions"].length / 2
|
|
|
|
}
|
|
|
|
|
|
|
|
function calcPercCountForWatch(watchindex, topic) {
|
|
|
|
let sumAll = sumCountAllWatches(topic)
|
2023-02-14 12:42:31 +01:00
|
|
|
if(sumAll === 0) {
|
2023-02-14 12:13:53 +01:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return Math.round(countForWatch(topic.watches[watchindex]) / sumAll * 100)
|
|
|
|
}
|
|
|
|
|
|
|
|
function sumCountAllWatches(topic){
|
|
|
|
return countForWatch(topic.watches[0]) + countForWatch(topic.watches[1]) + countForWatch(topic.watches[2])
|
|
|
|
}
|
|
|
|
|
2023-02-09 21:23:22 +01:00
|
|
|
function sumAllwatches(topic) {
|
|
|
|
return sumForWatch(topic.watches[0]) + sumForWatch(topic.watches[1]) + sumForWatch(topic.watches[2])
|
|
|
|
}
|
|
|
|
|
|
|
|
function timeToISO(time){
|
|
|
|
return new Date(time).toISOString().slice(11, 19)
|
|
|
|
}
|
|
|
|
|
|
|
|
function refreshWatch(watchIndex) {
|
2023-02-14 12:13:53 +01:00
|
|
|
let timeCell = document.getElementById("time-" + watchIndex)
|
2023-02-14 12:42:31 +01:00
|
|
|
timeCell.textContent = timeToISO(sumForWatch(actualTopic.watches[watchIndex]))
|
|
|
|
if(actualTopic.watches[watchIndex]["actions"].length !== 0 && actualTopic.watches[watchIndex]["actions"].slice(-1)[0]["type"] === "start"){
|
2023-02-16 12:44:01 +01:00
|
|
|
timeCell.classList.add("activeWatch")
|
2023-02-09 21:23:22 +01:00
|
|
|
} else {
|
2023-02-16 12:44:01 +01:00
|
|
|
timeCell.classList.remove("activeWatch")
|
2023-02-09 21:23:22 +01:00
|
|
|
}
|
2023-02-14 12:13:53 +01:00
|
|
|
let countCell = document.getElementById("count-" + watchIndex)
|
2023-02-14 12:42:31 +01:00
|
|
|
countCell.textContent = countForWatch(actualTopic.watches[watchIndex]) + " Wortmeldungen"
|
2023-02-09 21:23:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function refreshClosedTopics() {
|
|
|
|
let table = document.getElementById("closedTopicsTable")
|
|
|
|
table.innerHTML = ""
|
|
|
|
for(let i = closedTopics.length - 1; i >= 0; i--) {
|
|
|
|
let topic = closedTopics[i]
|
|
|
|
let topicColumn = elt("td")
|
|
|
|
topicColumn.textContent = topic.name
|
|
|
|
|
|
|
|
let time0 = elt("div")
|
|
|
|
time0.textContent = timeToISO(sumForWatch(topic.watches[0])) + " (" + calcPercForWatch(0, topic) + "%)"
|
|
|
|
let count0 = elt("div")
|
2023-02-14 12:13:53 +01:00
|
|
|
count0.textContent = countForWatch(topic.watches[0]) + " Wortmeldungen (" + calcPercCountForWatch(0, topic) + "%)"
|
2023-02-09 21:23:22 +01:00
|
|
|
let time0Column = elt("td", {}, time0, count0)
|
|
|
|
|
|
|
|
let time1 = elt("div")
|
|
|
|
time1.textContent = timeToISO(sumForWatch(topic.watches[1])) + " (" + calcPercForWatch(1, topic) + "%)"
|
|
|
|
let count1 = elt("div")
|
2023-02-14 12:13:53 +01:00
|
|
|
count1.textContent = ((topic.watches[1]["actions"].length) / 2) + " Wortmeldungen (" + calcPercCountForWatch(1, topic) + "%)"
|
2023-02-09 21:23:22 +01:00
|
|
|
let time1Column = elt("td", {}, time1, count1)
|
|
|
|
|
|
|
|
let time2 = elt("div")
|
|
|
|
time2.textContent = timeToISO(sumForWatch(topic.watches[2])) + " (" + calcPercForWatch(2, topic) + "%)"
|
|
|
|
let count2 = elt("div")
|
2023-02-14 12:13:53 +01:00
|
|
|
count2.textContent = ((topic.watches[2]["actions"].length) / 2) + " Wortmeldungen (" + calcPercCountForWatch(2, topic) + "%)"
|
2023-02-09 21:23:22 +01:00
|
|
|
let time2Column = elt("td", {}, time2, count2)
|
|
|
|
|
|
|
|
let reopenButton = elt("button", {"onclick": "reopenTopic(" + i + ")"})
|
|
|
|
reopenButton.textContent = "wieder öffnen"
|
|
|
|
let reopenButtonColumn = elt("td", {}, reopenButton)
|
|
|
|
let deleteButton = elt("button", {"onclick": "buttonDeleteClosedTopic(" + i + ")"})
|
|
|
|
deleteButton.textContent = "löschen"
|
|
|
|
let deleteButtonColumn = elt("td", {}, deleteButton)
|
|
|
|
table.appendChild(elt("tr", {}, topicColumn, time0Column, time1Column, time2Column, reopenButtonColumn, deleteButtonColumn))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-14 12:42:31 +01:00
|
|
|
function saveActualTopicName() {
|
|
|
|
actualTopic.name = document.getElementById("topicInput").value
|
2023-02-14 19:56:51 +01:00
|
|
|
saveActualTopic()
|
2023-02-09 21:23:22 +01:00
|
|
|
}
|
|
|
|
|
2023-02-14 19:56:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
function saveActualTopic() {
|
|
|
|
//save it to LocalStorage
|
2023-02-14 12:42:31 +01:00
|
|
|
localStorage.setItem("actualTopic", JSON.stringify(actualTopic))
|
2023-02-15 00:06:36 +01:00
|
|
|
|
|
|
|
//save it to Server
|
|
|
|
fetch(document.URL + "dataCollector/dataCollector.php", {
|
|
|
|
method: 'POST',
|
|
|
|
headers: { 'Content-type': 'application/json' },
|
|
|
|
body: JSON.stringify({
|
|
|
|
"lastSave": new Date().getTime(),
|
|
|
|
"timeWatchM": sumForWatch(actualTopic.watches[0]),
|
|
|
|
"timeWatchW": sumForWatch(actualTopic.watches[1]),
|
|
|
|
"timeWatchD": sumForWatch(actualTopic.watches[2]),
|
|
|
|
"countWatchM": countForWatch(actualTopic.watches[0]),
|
|
|
|
"countWatchW": countForWatch(actualTopic.watches[1]),
|
|
|
|
"countWatchD": countForWatch(actualTopic.watches[2]),
|
|
|
|
"id": actualTopic.id,
|
|
|
|
"watches": actualTopic.watches
|
|
|
|
})
|
|
|
|
});
|
2023-02-09 21:23:22 +01:00
|
|
|
}
|
|
|
|
|
2023-02-14 19:56:51 +01:00
|
|
|
function saveClosedTopics() {
|
2023-02-09 21:23:22 +01:00
|
|
|
localStorage.setItem("closedTopics", JSON.stringify(closedTopics))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper function for DOM manipulation
|
|
|
|
//
|
|
|
|
function elt (type, attrs, ...children) {
|
|
|
|
let node = document.createElement(type)
|
|
|
|
for (a in attrs) {
|
|
|
|
node.setAttribute(a, attrs[a])
|
|
|
|
}
|
|
|
|
for (let child of children) {
|
|
|
|
if (typeof child != "string") node.appendChild(child)
|
|
|
|
else node.appendChild(document.createTextNode(child))
|
|
|
|
}
|
|
|
|
return node
|
2023-02-14 19:56:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// random.ts
|
|
|
|
function randomId() {
|
|
|
|
const uint32 = window.crypto.getRandomValues(new Uint32Array(1))[0];
|
|
|
|
return uint32.toString(16);
|
2023-02-09 21:23:22 +01:00
|
|
|
}
|