Compare commits

..

5 Commits

Author SHA1 Message Date
schrom01 8a1a7d19b5 data Download Link 2023-02-14 23:49:23 +01:00
schrom01 c3fd986144 php functions to Store data 2023-02-14 23:47:03 +01:00
schrom01 930bd7de4b php functions to Store data 2023-02-14 23:20:53 +01:00
schrom01 a945fca764 php functions to Store data 2023-02-14 19:56:51 +01:00
schrom01 403099ebd6 refactoring 2023-02-14 12:42:31 +01:00
7 changed files with 2496 additions and 170 deletions

BIN
data/data.xlsx Normal file

Binary file not shown.

View File

@ -0,0 +1,55 @@
<?php
require $_SERVER['DOCUMENT_ROOT'] . '/spreadSheetReader/read_write_xlsx.php';
$fileName = $_SERVER['DOCUMENT_ROOT'] . '/data/data.xlsx';
function objectToArray($object, $fullJSON) {
return [$object -> id,
$object -> lastSave,
$fullJSON,
$object -> timeWatchM,
$object -> timeWatchW,
$object -> timeWatchD,
$object -> countWatchM,
$object -> countWatchW,
$object -> countWatchD];
}
function findRowIndex($id, $data) {
$rowCounter = -1;
foreach ($data as $row) {
$rowCounter ++;
if($row[0] == $id) {
return $rowCounter;
}
}
return $rowCounter + 1;
}
$entityBody = '{"lastSave": 0, "timeWatchM": 0, "timeWatchW": 0, "timeWatchD": 0, "countWatchM": 0, "countWatchW": 0, "countWatchD": 0, "id":"test","watches":[{"actions":[]},{"actions":[]},{"actions":[]}]}';
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
$entityBody = file_get_contents('php://input');
$entityBodyObject = json_decode($entityBody);
echo "POST Request received.<br>";
if(property_exists($entityBodyObject, "id")) {
$data = read_xls_file($fileName);
foreach ($data as $row) {
echo "new Row: <br>";
foreach ($row as $cell) {
echo $cell." ";
}
}
$rowIndex = findRowIndex($entityBodyObject->id, $data);
$data[$rowIndex] = objectToArray($entityBodyObject, $entityBody);
write_xlsxFile($fileName, $data);
echo "<br>Data saved.<br>";
}
}

View File

@ -1,140 +1,142 @@
<html> <html lang="de">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<link rel="stylesheet" href="css/custom.css"> <link rel="stylesheet" href="css/custom.css">
<link rel="stylesheet" href="css/bootstrap.css"> <link rel="stylesheet" href="css/bootstrap.css">
<title>Genderwatch-protocol</title>
</head>
<body> </head>
<section> <body>
<div class="container"> <section>
<h1>Genderwatch-protocol</h1> <div class="container">
<h2 style="margin-left: 10px;">Aktuelles Thema</h2> <h1>Genderwatch-protocol</h1>
<table class="table-bordered"> <a href="data/data.xlsx">Anonyme Daten herunterladen</a>
<tr> <h2 style="margin-left: 10px;">Aktuelles Thema</h2>
<td colspan="2"> <table class="table-bordered">
<input class="form-control" type="text" id="topicInput" placeholder="Thema hier eingeben"> <tr>
</td> <td colspan="2">
<td> <input class="form-control" type="text" id="topicInput" placeholder="Thema hier eingeben">
<button class="" onclick="closeTopic()"> </td>
Thema abschliessen <td>
</button> <button class="" onclick="closeTopic()">
</td> Thema abschliessen
</tr> </button>
<tr> </td>
<th> </tr>
M <tr>
</th> <th>
<th> M
W </th>
</th> <th>
<th> W
D </th>
</th> <th>
</tr> D
</th>
<tr> </tr>
<td id="time-0">
0 <tr>
</td> <td id="time-0">
<td id="time-1"> 0
0 </td>
</td> <td id="time-1">
<td id="time-2"> 0
0 </td>
</td> <td id="time-2">
</tr> 0
<tr> </td>
<td id="count-0"> </tr>
0 <tr>
</td> <td id="count-0">
<td id="count-1"> 0
0 </td>
</td> <td id="count-1">
<td id="count-2"> 0
0 </td>
</td> <td id="count-2">
</tr> 0
<tr> </td>
<td> </tr>
<button class="" onclick="start(0)">Beginnt zu Reden</button> <tr>
</td> <td>
<td> <button class="" onclick="start(0)">Beginnt zu Reden</button>
<button class="" onclick="start(1)">Beginnt zu Reden</button> </td>
</td> <td>
<td> <button class="" onclick="start(1)">Beginnt zu Reden</button>
<button class="" onclick="start(2)">Beginnt zu Reden</button> </td>
</td> <td>
</tr> <button class="" onclick="start(2)">Beginnt zu Reden</button>
<tr> </td>
<td colspan="3"> </tr>
<button class="" style="width: 98%;" onclick="stop()">Hört auf zu Reden, -> Stille</button> <tr>
</td> <td colspan="3">
</tr> <button class="" style="width: 98%;" onclick="stop()">Hört auf zu Reden, -> Stille</button>
<tr> </td>
<td colspan="3"> </tr>
<button class="" style="width: 98%;" onclick="resetButton()">Reset</button> <tr>
</td> <td colspan="3">
</tr> <button class="" style="width: 98%;" onclick="resetButton()">Reset</button>
</table> </td>
</tr>
</table>
</div>
<div class="container"> </div>
<div class="container">
<H2>Abgeschlossene Themen</H2>
<button class="" onclick="buttonDeleteAllClosedTopics()">alle Löschen</button>
<table class="table-bordered"> <H2>Abgeschlossene Themen</H2>
<thead> <button class="" onclick="buttonDeleteAllClosedTopics()">alle Löschen</button>
<tr> <table class="table-bordered">
<th style="min-width: 100px;"> <thead>
Thema <tr>
</th> <th style="min-width: 100px;">
<th style="min-width: 100px;"> Thema
M </th>
</th> <th style="min-width: 100px;">
<th style="min-width: 100px;"> M
W </th>
</th> <th style="min-width: 100px;">
<th style="min-width: 100px;"> W
D </th>
</th> <th style="min-width: 100px;">
</tr> D
</thead> </th>
<tbody id="closedTopicsTable"> </tr>
</thead>
</tbody> <tbody id="closedTopicsTable">
</tbody>
</table>
</div> </table>
</section>
</div>
</section>
<script src="js/functions.js"></script>
<script>
closedTopics = JSON.parse(localStorage.getItem("closedTopics")) <script src="js/functions.js"></script>
if(!closedTopics) { <script>
closedTopics = [] closedTopics = JSON.parse(localStorage.getItem("closedTopics"))
} if(!closedTopics) {
closedTopics = []
watches = JSON.parse(localStorage.getItem("watches")) }
if(!watches){
reset() actualTopic = JSON.parse(localStorage.getItem("actualTopic"))
} if(!actualTopic) {
initializeNewTopic()
document.getElementById("topicInput").value = localStorage.getItem("actualTopic") }
document.getElementById("topicInput").addEventListener('keyup', saveActualTopicToLocalStorage); document.getElementById("topicInput").value = actualTopic.name
refreshClosedTopics()
setInterval(() => { document.getElementById("topicInput").addEventListener('keyup', saveActualTopicName);
refreshWatch(0) refreshClosedTopics()
refreshWatch(1) setInterval(() => {
refreshWatch(2) refreshWatch(0)
}, 100); refreshWatch(1)
</script> refreshWatch(2)
</body> }, 100);
</script>
</body>
</html> </html>

View File

@ -1,6 +1,12 @@
function initializeNewTopic() {
actualTopic = {"name": "", "id": randomId()}
reset()
document.getElementById("topicInput").value = actualTopic.name
}
function reset() { function reset() {
actualTopic.watches = [{"actions": []}, {"actions": []}, {"actions": []}] actualTopic.watches = [{"actions": []}, {"actions": []}, {"actions": []}]
saveWatchesToLocalStorage() saveActualTopic()
} }
function resetButton() { function resetButton() {
@ -12,7 +18,7 @@ function resetButton() {
function buttonDeleteAllClosedTopics() { function buttonDeleteAllClosedTopics() {
if(confirm("Sollen alle abgeschlossenen Themen gelöscht werden?")) { if(confirm("Sollen alle abgeschlossenen Themen gelöscht werden?")) {
closedTopics = [] closedTopics = []
saveClosedTopicsToLocalStorage() saveClosedTopics()
refreshClosedTopics() refreshClosedTopics()
} }
} }
@ -24,8 +30,9 @@ function buttonDeleteClosedTopic(topicIndex) {
} }
function closeTopic() { function closeTopic() {
stop()
let defaultname = "Thema" let defaultname = "Thema"
let name = document.getElementById("topicInput").value let name = actualTopic.name
let nameLessCounter = 1 let nameLessCounter = 1
while(!name){ while(!name){
let foundName = false let foundName = false
@ -40,53 +47,50 @@ function closeTopic() {
name = defaultname + nameLessCounter name = defaultname + nameLessCounter
} }
} }
actualTopic.name = name
closedTopics.push({"name": name, "watches": watches}) closedTopics.push(actualTopic)
stop() saveClosedTopics()
reset()
document.getElementById("topicInput").value = ""
saveActualTopicToLocalStorage()
saveClosedTopicsToLocalStorage()
refreshClosedTopics() refreshClosedTopics()
initializeNewTopic()
} }
function deleteTopic(topicIndex) { function deleteTopic(topicIndex) {
closedTopics = closedTopics.slice(0, topicIndex).concat(closedTopics.slice(topicIndex+1)) closedTopics = closedTopics.slice(0, topicIndex).concat(closedTopics.slice(topicIndex+1))
saveClosedTopicsToLocalStorage() saveClosedTopics()
refreshClosedTopics() refreshClosedTopics()
} }
function reopenTopic(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() closeTopic()
} }
watches = closedTopics[topicIndex]["watches"] actualTopic = closedTopics[topicIndex]
document.getElementById("topicInput").value = closedTopics[topicIndex]["name"] document.getElementById("topicInput").value = actualTopic.name
deleteTopic(topicIndex) deleteTopic(topicIndex)
saveWatchesToLocalStorage() saveClosedTopics()
saveActualTopicToLocalStorage() saveActualTopic()
} }
function start(watchIndex) { function start(watchIndex) {
stop() stop()
watches[watchIndex].actions.push({"type": "start", "time": new Date().getTime()}) actualTopic.watches[watchIndex].actions.push({"type": "start", "time": new Date().getTime()})
saveWatchesToLocalStorage() saveActualTopic()
} }
function stop() { function stop() {
watches.forEach(watch => { actualTopic.watches.forEach(watch => {
if(watch["actions"]["length"] > 0) { 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()}) watch["actions"].push({"type": "stop", "time": new Date().getTime()})
} }
} }
}); });
saveWatchesToLocalStorage() saveActualTopic()
} }
function calcPercForWatch(watchIndex, topic) { function calcPercForWatch(watchIndex, topic) {
let sumAll = sumAllwatches(topic) let sumAll = sumAllwatches(topic)
if(sumAll == 0) { if(sumAll === 0) {
return 0 return 0
} }
return Math.round(sumForWatch(topic.watches[watchIndex]) / sumAllwatches(topic) * 100) return Math.round(sumForWatch(topic.watches[watchIndex]) / sumAllwatches(topic) * 100)
@ -112,7 +116,7 @@ function countForWatch(watch) {
function calcPercCountForWatch(watchindex, topic) { function calcPercCountForWatch(watchindex, topic) {
let sumAll = sumCountAllWatches(topic) let sumAll = sumCountAllWatches(topic)
if(sumAll == 0) { if(sumAll === 0) {
return 0 return 0
} }
return Math.round(countForWatch(topic.watches[watchindex]) / sumAll * 100) return Math.round(countForWatch(topic.watches[watchindex]) / sumAll * 100)
@ -132,14 +136,14 @@ function timeToISO(time){
function refreshWatch(watchIndex) { function refreshWatch(watchIndex) {
let timeCell = document.getElementById("time-" + watchIndex) let timeCell = document.getElementById("time-" + watchIndex)
timeCell.textContent = timeToISO(sumForWatch(watches[watchIndex])) timeCell.textContent = timeToISO(sumForWatch(actualTopic.watches[watchIndex]))
if(watches[watchIndex]["actions"].length != 0 && watches[watchIndex]["actions"].slice(-1)[0]["type"] == "start"){ if(actualTopic.watches[watchIndex]["actions"].length !== 0 && actualTopic.watches[watchIndex]["actions"].slice(-1)[0]["type"] === "start"){
timeCell.classList.add("active") timeCell.classList.add("active")
} else { } else {
timeCell.classList.remove("active") timeCell.classList.remove("active")
} }
let countCell = document.getElementById("count-" + watchIndex) let countCell = document.getElementById("count-" + watchIndex)
countCell.textContent = countForWatch(watches[watchIndex]) + " Wortmeldungen" countCell.textContent = countForWatch(actualTopic.watches[watchIndex]) + " Wortmeldungen"
} }
function refreshClosedTopics() { function refreshClosedTopics() {
@ -178,15 +182,20 @@ function refreshClosedTopics() {
} }
} }
function saveWatchesToLocalStorage() { function saveActualTopicName() {
localStorage.setItem("watches", JSON.stringify(watches)) actualTopic.name = document.getElementById("topicInput").value
saveActualTopic()
} }
function saveActualTopicToLocalStorage() {
localStorage.setItem("actualTopic", document.getElementById("topicInput").value)
function saveActualTopic() {
//save it to LocalStorage
localStorage.setItem("actualTopic", JSON.stringify(actualTopic))
} }
function saveClosedTopicsToLocalStorage() { function saveClosedTopics() {
//save it to LocalStorage
localStorage.setItem("closedTopics", JSON.stringify(closedTopics)) localStorage.setItem("closedTopics", JSON.stringify(closedTopics))
} }
@ -202,4 +211,10 @@ function elt (type, attrs, ...children) {
else node.appendChild(document.createTextNode(child)) else node.appendChild(document.createTextNode(child))
} }
return node return node
}
// random.ts
function randomId() {
const uint32 = window.crypto.getRandomValues(new Uint32Array(1))[0];
return uint32.toString(16);
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,19 @@
<?php
require $_SERVER['DOCUMENT_ROOT'] . '/spreadSheetReader/SimpleXLSX.php';
require $_SERVER['DOCUMENT_ROOT'] . '/spreadSheetReader/SimpleXLSXGen.php';
function read_xls_file($filename){
$fileContent = [];
if ($xlsx = SimpleXLSX::parse($filename)) {
$fileContent = ($xlsx->rows());
} else {
echo SimpleXLSX::parseError();
}
return $fileContent;
}
function write_xlsxFile($filename, $data) {
$xlsx = SimpleXLSXGen::fromArray($data);
$xlsx->saveAs($filename);
}