Dateien nach "/" hochladen

This commit is contained in:
develcookingtest 2024-03-20 17:23:05 +00:00
parent 200d341a01
commit f8d9d9e36b
3 changed files with 475 additions and 0 deletions

87
selectedTime.json Normal file
View File

@ -0,0 +1,87 @@
[
{
"NameValue": {
"name": "da1"
},
"timeValue": {
"time": "08:06"
},
"daysValue": {
"Montag": false,
"Dienstag": false,
"Mittwoch": false,
"Donnerstag": false,
"Freitag": false,
"Samstag": false,
"Sonntag": false
}
},
{
"NameValue": {
"name": "da2"
},
"timeValue": {
"time": "08:06"
},
"daysValue": {
"Montag": false,
"Dienstag": false,
"Mittwoch": false,
"Donnerstag": true,
"Freitag": false,
"Samstag": false,
"Sonntag": false
}
},
{
"NameValue": {
"name": "daw"
},
"timeValue": {
"time": "08:06"
},
"daysValue": {
"Montag": false,
"Dienstag": false,
"Mittwoch": false,
"Donnerstag": true,
"Freitag": false,
"Samstag": false,
"Sonntag": false
}
},
{
"NameValue": {
"name": "daa"
},
"timeValue": {
"time": "08:06"
},
"daysValue": {
"Montag": false,
"Dienstag": false,
"Mittwoch": false,
"Donnerstag": true,
"Freitag": false,
"Samstag": false,
"Sonntag": false
}
},
{
"NameValue": {
"name": "daaa"
},
"timeValue": {
"time": "07:07"
},
"daysValue": {
"Montag": false,
"Dienstag": false,
"Mittwoch": false,
"Donnerstag": true,
"Freitag": true,
"Samstag": true,
"Sonntag": false
}
}
]

219
server.js Normal file
View File

@ -0,0 +1,219 @@
const http = require('http');
const fs = require('fs');
const path = require('path');
const PORT = process.env.PORT || 3000;
let savedData = {
name: null,
time: null,
days: null
};
/*
// Funktion zum Speichern der Auswahl
function saveSelection(NameValue, timeValue, daysValue) {
const data = {
NameValue,
timeValue,
daysValue
};
const jsonString = JSON.stringify(data, null, 4); // Hier wird ein Einzug von 4 Leerzeichen verwendet
const filePath = 'selectedTime.json';
fs.writeFile(filePath, jsonString, (err) => {
if (err) {
console.error('Fehler beim Speichern der Daten:', err);
} else {
console.log('Daten erfolgreich gespeichert.');
readSelectedTime();
}
});
}*/
// Funktion zum Speichern der Auswahl
function saveSelection(nameValue, timeValue, daysValue) {
readSelectedTimeclb((err, data) => {
if (err) {
console.error('Fehler beim Lesen der vorhandenen Daten:', err);
return;
}
// Überprüfen, ob ein Wecker mit dem gleichen Namen bereits existiert
const existingAlarm = data.find(alarm => alarm.NameValue.name === nameValue.name);
if (existingAlarm) {
console.log(`Ein Wecker mit dem Namen "${nameValue.name}" existiert bereits.`);
return;
}
// Wenn der Name noch nicht existiert, neuen Wecker hinzufügen
data.push({ NameValue: nameValue, timeValue: timeValue, daysValue: daysValue });
const jsonString = JSON.stringify(data, null, 4); // Hier wird ein Einzug von 4 Leerzeichen verwendet
const filePath = 'selectedTime.json';
fs.writeFile(filePath, jsonString, (err) => {
if (err) {
console.error('Fehler beim Speichern der Daten:', err);
} else {
console.log('Daten erfolgreich gespeichert.');
readSelectedTime(); // Aktualisierte Daten lesen und ausgeben
}
});
});
}
// Funktion zum Verarbeiten der gespeicherten Daten
function processSavedData() {
// Überprüfen, ob alle Daten vorhanden sind
if (savedData.name && savedData.time && savedData.days) {
// Aufrufen von saveSelection nur, wenn alle Daten vorhanden sind
saveSelection(savedData.name, savedData.time, savedData.days);
// Daten zurücksetzen, um für die nächste Anfrage bereit zu sein
savedData = {
name: null,
time: null,
days: null
};
} else {
// Nicht alle Daten sind verfügbar, daher warten wir auf weitere Anfragen
}
}
// Funktion zum Lesen der ausgewählten Zeit
function readSelectedTime() {
const filePath = 'selectedTime.json';
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Fehler beim Lesen der Datei:', err);
} else {
const parsedData = JSON.parse(data);
const formattedData = JSON.stringify(parsedData, null, 4); // Hier wird ein Einzug von 4 Leerzeichen verwendet
console.log('Inhalt von selectedTime.json:\n', formattedData);
}
});
}
// Funktion zum Lesen der ausgewählten Zeit
function readSelectedTimeclb(callback) {
const filePath = 'selectedTime.json';
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Fehler beim Lesen der Datei:', err);
callback(err, null);
} else {
let parsedData;
try {
parsedData = JSON.parse(data);
if (!Array.isArray(parsedData)) {
parsedData = []; // Wenn die Daten kein Array sind, initialisiere sie als leeres Array
}
} catch (parseError) {
console.error('Fehler beim Parsen der Daten:', parseError);
parsedData = []; // Bei einem Fehler beim Parsen initialisiere die Daten als leeres Array
}
callback(null, parsedData);
}
});
}
// Server erstellen
http.createServer((req, res) => {
if (req.method === 'POST' && req.url === '/savedays') {
let body = '';
req.on('data', chunk => {
body += chunk.toString();
});
req.on('end', () => {
const daysValue = JSON.parse(body);
savedData.days = daysValue; // Zwischengespeicherte Daten aktualisieren
processSavedData(); // Prozess starten
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Daten erfolgreich gespeichert.');
});
} else if (req.method === 'POST' && req.url === '/saveTime') {
let body = '';
req.on('data', chunk => {
body += chunk.toString();
});
req.on('end', () => {
const timeValue = JSON.parse(body);
savedData.time = timeValue; // Zwischengespeicherte Daten aktualisieren
processSavedData(); // Prozess starten
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Daten erfolgreich gespeichert.');
});
} else if (req.method === 'POST' && req.url === '/saveName') {
let body = '';
req.on('data', chunk => {
body += chunk.toString();
});
req.on('end', () => {
const nameValue = JSON.parse(body);
savedData.name = nameValue; // Zwischengespeicherte Daten aktualisieren
processSavedData(); // Prozess starten
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Daten erfolgreich gespeichert.');
});
} else if (req.method === 'GET' && req.url === '/selectedTime') {
readSelectedTimeclb((err, data) => {
if (err) {
res.writeHead(500, { 'Content-Type': 'text/plain' });
res.end('Internal Server Error');
} else {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(data));
}
});
} else {
let filePath = '.' + req.url;
if (filePath === './') {
filePath = './index.html';
}
const extname = String(path.extname(filePath)).toLowerCase();
const contentType = {
'.html': 'text/html',
'.js': 'text/javascript',
'.css': 'text/css',
'.json': 'application/json',
'.png': 'image/png',
'.jpg': 'image/jpg',
'.gif': 'image/gif',
'.wav': 'audio/wav',
'.mp4': 'video/mp4',
'.woff': 'application/font-woff',
'.ttf': 'application/font-ttf',
'.eot': 'application/vnd.ms-fontobject',
'.otf': 'application/font-otf',
'.svg': 'application/image/svg+xml'
}[extname] || 'application/octet-stream';
fs.readFile(filePath, (err, content) => {
if (err) {
if (err.code == 'ENOENT') {
res.writeHead(404);
res.end('File not found');
} else {
res.writeHead(500);
res.end('Sorry, check with the site admin for error: ' + err.code);
}
} else {
res.writeHead(200, { 'Content-Type': contentType });
res.end(content, 'utf-8');
}
});
}
}).listen(PORT);
console.log(`Server running at http://localhost:${PORT}/`);

169
time-pick.js Normal file
View File

@ -0,0 +1,169 @@
var TimePick = (function () {
'use strict';
var Constructor = function (element) {
var globalvar = {};
globalvar.set_hour = {};
globalvar.set_minute = {};
if(document.getElementById("TimePickStyleSheet") == null) {
MakeStyle();
}
var unique_id = RandomString(5);
if(document.getElementById("TimePickBackgroundOverlay") == null) {
let overlaydiv = document.createElement("div");
overlaydiv.id= "TimePickBackgroundOverlay";
document.body.insertBefore(overlaydiv, document.body.firstChild); // Hinzufügen am Anfang des body-Elements
overlaydiv.style.zIndex = "-1";
}
globalvar.elemets = document.querySelectorAll(element);
for (var i = 0; i < globalvar.elemets.length; i++) {
let timepickerbtn = globalvar.elemets[i];
let TIMESARRAY = {};
globalvar.elemets[i].setAttribute("TimePick", "input_" + unique_id + '_' + i);
timepickerbtn.insertAdjacentHTML("afterend", `<button class="TimePick_BTN"><svg class="TimePick_ICON" id="${unique_id + '_' + i}" height="20" width="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M22 12C22 17.52 17.52 22 12 22C6.48 22 2 17.52 2 12C2 6.48 6.48 2 12 2C17.52 2 22 6.48 22 12Z" stroke="#292D32" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M15.71 15.18L12.61 13.33C12.07 13.01 11.63 12.24 11.63 11.61V7.51001" stroke="#292D32" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></g></svg>
<div class="TimePick_POPUP" id="popup_${unique_id + '_' + i}">
<div class="hour">
<div class="adjustbtn uparrow" data='{"type": "hour", "action": "up", "id":"${unique_id + '_' + i}"}'><svg fill="#DDD" height="20px" width="20px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-30.7 -30.7 573.13 573.13" xml:space="preserve" stroke="#DDD" stroke-width="30"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <g> <g> <path d="M508.788,371.087L263.455,125.753c-4.16-4.16-10.88-4.16-15.04,0L2.975,371.087c-4.053,4.267-3.947,10.987,0.213,15.04 c4.16,3.947,10.667,3.947,14.827,0l237.867-237.76l237.76,237.76c4.267,4.053,10.987,3.947,15.04-0.213 C512.734,381.753,512.734,375.247,508.788,371.087z"></path> </g> </g> </g></svg>
</div>
<div id="label_hour_${unique_id + '_' + i}" class="label">00</div>
<div class="adjustbtn downarrow" data='{"type": "hour", "action": "down", "id":"${unique_id + '_' + i}"}'>
<svg fill="#DDD" height="20px" width="20px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-30.7 -30.7 573.13 573.13" xml:space="preserve" stroke="#DDD" stroke-width="30" transform="rotate(180)"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <g> <g> <path d="M508.788,371.087L263.455,125.753c-4.16-4.16-10.88-4.16-15.04,0L2.975,371.087c-4.053,4.267-3.947,10.987,0.213,15.04 c4.16,3.947,10.667,3.947,14.827,0l237.867-237.76l237.76,237.76c4.267,4.053,10.987,3.947,15.04-0.213 C512.734,381.753,512.734,375.247,508.788,371.087z"></path> </g> </g> </g></svg></div>
</div>
<div class="minute">
<div class="adjustbtn uparrow" data='{"type": "minute", "action": "up", "id":"${unique_id + '_' + i}"}'><svg fill="#DDD" height="20px" width="20px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-30.7 -30.7 573.13 573.13" xml:space="preserve" stroke="#DDD" stroke-width="30"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <g> <g> <path d="M508.788,371.087L263.455,125.753c-4.16-4.16-10.88-4.16-15.04,0L2.975,371.087c-4.053,4.267-3.947,10.987,0.213,15.04 c4.16,3.947,10.667,3.947,14.827,0l237.867-237.76l237.76,237.76c4.267,4.053,10.987,3.947,15.04-0.213 C512.734,381.753,512.734,375.247,508.788,371.087z"></path> </g> </g> </g></svg></div>
<div id="label_minute_${unique_id + '_' + i}" class="label">00</div>
<div class="adjustbtn downarrow" data='{"type": "minute", "action": "down", "id":"${unique_id + '_' + i}"}'><svg fill="#DDD" height="20px" width="20px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-30.7 -30.7 573.13 573.13" xml:space="preserve" stroke="#DDD" stroke-width="30" transform="rotate(180)"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <g> <g> <path d="M508.788,371.087L263.455,125.753c-4.16-4.16-10.88-4.16-15.04,0L2.975,371.087c-4.053,4.267-3.947,10.987,0.213,15.04 c4.16,3.947,10.667,3.947,14.827,0l237.867-237.76l237.76,237.76c4.267,4.053,10.987,3.947,15.04-0.213 C512.734,381.753,512.734,375.247,508.788,371.087z"></path> </g> </g> </g></svg></div>
</div>
</div>
<div class="ampm"></div>
</div>
</button>`);
if(globalvar.elemets[i].value){
let previustimestr = globalvar.elemets[i].value;
let previustimes = previustimestr.split(":");
let uniquecode = `${unique_id + '_' + i}`;
document.getElementById('label_hour_' + uniquecode).innerText = previustimes[0];
document.getElementById('label_minute_' + uniquecode).innerText = previustimes[1];
}
else {
globalvar.elemets[i].setAttribute("value", "00:00:00");
}
}
let timepickpopupbtn = document.getElementsByClassName("TimePick_ICON");
for(let i = 0; i < timepickpopupbtn.length; i++) {
timepickpopupbtn[i].onclick = function () {
let currID = "popup_" + timepickpopupbtn[i].id;
if(document.getElementById(currID).style.display == "flex"){
document.getElementById(currID).style.display = "none"
return;
}
document.getElementById(currID).style.display = "flex"
}
}
document.onclick = function(e){
if(e.target.id == 'TimePickBackgroundOverlay'){
let TimePick_POPUP = document.getElementsByClassName("TimePick_POPUP");
for(let i = 0; i < TimePick_POPUP.length; i++) {
TimePick_POPUP[i].style.display = "none";
}
}
};
let adjustbtn = document.getElementsByClassName("adjustbtn");
for(let i = 0; i < adjustbtn.length; i++) {
adjustbtn[i].onclick = function () {
let data = JSON.parse(adjustbtn[i].getAttribute("data"));
let curr_hour = document.getElementById('label_hour_' + data.id).innerText;
let curr_minute = document.getElementById('label_minute_' + data.id).innerText;
if (curr_hour != "00") {
globalvar.set_hour[data.id] = parseInt(curr_hour);
}
if (curr_minute != "00") {
globalvar.set_minute[data.id] = parseInt(curr_minute);
}
if(data.type == 'hour' && data.action == 'up'){
globalvar.set_hour[data.id] = (globalvar.set_hour[data.id]) ? (globalvar.set_hour[data.id] + 1) : 0 + 1;
globalvar.set_hour[data.id] = (globalvar.set_hour[data.id] == 24) ? 0 : globalvar.set_hour[data.id];
}
if(data.type == 'hour' && data.action == 'down'){
globalvar.set_hour[data.id] = (globalvar.set_hour[data.id]) ? (globalvar.set_hour[data.id] - 1) : -1;
globalvar.set_hour[data.id] = (globalvar.set_hour[data.id] == -1) ? 23 : globalvar.set_hour[data.id];
}
if(data.type == 'minute' && data.action == 'up'){
globalvar.set_minute[data.id] = (globalvar.set_minute[data.id]) ? (globalvar.set_minute[data.id] + 1) : 0 + 1;
globalvar.set_minute[data.id] = (globalvar.set_minute[data.id] == 60) ? 0 : globalvar.set_minute[data.id];
}
if(data.type == 'minute' && data.action == 'down'){
globalvar.set_minute[data.id] = (globalvar.set_minute[data.id]) ? (globalvar.set_minute[data.id] - 1) : -1;
globalvar.set_minute[data.id] = (globalvar.set_minute[data.id] == -1) ? 59 : globalvar.set_minute[data.id];
}
let hrview = (globalvar.set_hour[data.id] == undefined) ? '00' : (globalvar.set_hour[data.id] < 10) ? ("0" + globalvar.set_hour[data.id]) : globalvar.set_hour[data.id];
let mnview = (globalvar.set_minute[data.id] == undefined) ? '00' : (globalvar.set_minute[data.id] < 10) ? ("0" + globalvar.set_minute[data.id]) : globalvar.set_minute[data.id];
document.getElementById('label_hour_' + data.id).innerText = hrview;
document.getElementById('label_minute_' + data.id).innerText = mnview;
document.querySelectorAll('input[TimePick=input_' + data.id + ']')[0].value = hrview + ":" + mnview ;
}
}
//private function
function RandomString(length) {
const characters ='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
let result = '';
const charactersLength = characters.length;
for ( let i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
function MakeStyle(){
var styles = ".TimePick_POPUP{ position: absolute; height: 80px; width: 120px; background-color: #ffffff; border-radius: 3px; border: 1px solid #eeeeee; display: flex; justify-content: center; align-items: center; box-shadow: rgba(17, 17, 26, 0.05) 0px 4px 16px, rgba(17, 17, 26, 0.05) 0px 8px 32px; z-index:500; margin-left: 30px; margin-top: -32px; display: none;} svg:active{ fill: #0000; stroke: #0000;} .TimePick_BTN{ position: absolute; background-color: transparent; border: none; margin-left: -35px; margin-top: 7px; cursor: pointer;} .TimePick_ICON{ opacity: 0.5;} .TimePick_ICON:hover{ opacity: 1;} input{ padding: 10px; border-width: 1px; border-style: solid; border-color: lightgray; background-color: white;} #TimePickBackgroundOverlay{ background-color:transparent; position:fixed; top:0; left:0; right:0; bottom:0; display:block;} .label{ font-size: 20px;} .hour{ display: flex; flex-direction: column; width: 35px;} .minute{ display: flex; flex-direction: column; width: 35px;}";
var styleSheet = document.createElement("style");
styleSheet.type = "text/css";
styleSheet.id = "TimePickStyleSheet";
styleSheet.innerText = styles;
document.head.appendChild(styleSheet);
return;
}
return globalvar;
};
return Constructor;
})(
/**********
*************************************************************************
*********** JAVASCRIPT MODULE TIME PICKER DONE BY KATHEESKUMAR **********
*************************************************************************
***************************** Version: 1.0 ******************************
*************************************************************************
**********/
);