mirror of
https://gitlab1.ptb.de/aj2021/l-pa-so.git
synced 2024-02-04 23:49:43 +00:00
I made a feature and it is done D:
This commit is contained in:
parent
74df1a555e
commit
2ec71df24b
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.idea
|
||||
.idea/*
|
4
website/.gitignore
vendored
4
website/.gitignore
vendored
|
@ -4,8 +4,8 @@ node_modules
|
|||
/.svelte-kit
|
||||
/package
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
.env
|
||||
!.env
|
||||
vite.config.js.timestamp-*
|
||||
vite.config.ts.timestamp-*
|
||||
|
||||
|
|
15
website/src/lib/client/components/AnnouncementPopup.svelte
Normal file
15
website/src/lib/client/components/AnnouncementPopup.svelte
Normal file
|
@ -0,0 +1,15 @@
|
|||
<script>
|
||||
export let announcementJson ;
|
||||
export let announcementStyle;
|
||||
</script>
|
||||
|
||||
<div id="background" style={announcementStyle}>
|
||||
<div id="window">
|
||||
<div id="title">{announcementJson['title']}</div>
|
||||
<div id="time">{announcementJson['time']}</div>
|
||||
<div id="content">{announcementJson['content']}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
</style>
|
60
website/src/routes/+layout.svelte
Normal file
60
website/src/routes/+layout.svelte
Normal file
|
@ -0,0 +1,60 @@
|
|||
<script lang="js">
|
||||
import AnnouncementPopup from '$lib/client/components/AnnouncementPopup.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let announcement;
|
||||
let placeholder = {
|
||||
'title': 'None',
|
||||
'time': 'undefined',
|
||||
'content': 'None'
|
||||
}
|
||||
let intervalId;
|
||||
async function readSavedFile() {
|
||||
const response = await fetch('api/announcements');
|
||||
const savedAnnouncements = await response.json();
|
||||
console.log(savedAnnouncements)
|
||||
let date = new Date()
|
||||
let time = date.getHours() + ':' + date.getMinutes()
|
||||
console.log(time)
|
||||
for (let object of savedAnnouncements) {
|
||||
if (object['time'] === time) {
|
||||
announcement = object;
|
||||
}
|
||||
else {
|
||||
announcement = undefined
|
||||
}
|
||||
}
|
||||
console.log("Read saved file!")
|
||||
}
|
||||
|
||||
|
||||
function checkForSavedFile() {
|
||||
intervalId = setTimeout(
|
||||
() => {
|
||||
readSavedFile();
|
||||
checkForSavedFile();
|
||||
},
|
||||
announcement ? 3000000 : 10000
|
||||
);
|
||||
}
|
||||
|
||||
function cancelTimeout() {
|
||||
if (intervalId) {
|
||||
clearTimeout(intervalId);
|
||||
intervalId = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
intervalId = setInterval(readSavedFile, 10000);
|
||||
checkForSavedFile();
|
||||
return cancelTimeout();
|
||||
});
|
||||
</script>
|
||||
|
||||
<AnnouncementPopup
|
||||
announcementJson={announcement ? announcement: placeholder}
|
||||
announcementStyle={announcement ? 'display:flex' : 'display:none'}
|
||||
/>
|
||||
|
||||
<slot />
|
32
website/src/routes/Announcement/+page.server.js
Normal file
32
website/src/routes/Announcement/+page.server.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
import fs from 'fs';
|
||||
|
||||
import { SAVED_FOLDER_LOCATION } from '$env/static/private';
|
||||
|
||||
export const actions = {
|
||||
default: async ({ request }) => {
|
||||
const data = await request.formData();
|
||||
let upload = Object.fromEntries(data)
|
||||
|
||||
let fileData = []
|
||||
if (!fs.existsSync(SAVED_FOLDER_LOCATION))
|
||||
fs.mkdirSync(SAVED_FOLDER_LOCATION, { recursive: true });
|
||||
if (!fs.existsSync(SAVED_FOLDER_LOCATION + 'announcements.json')) {
|
||||
fileData.push(upload)
|
||||
fs.appendFile(SAVED_FOLDER_LOCATION + 'announcements.json', JSON.stringify(fileData),(err) => {
|
||||
if (err) throw err;
|
||||
}) }
|
||||
else {
|
||||
let temp = fs.readFileSync(SAVED_FOLDER_LOCATION + 'announcements.json')
|
||||
fileData.push(JSON.parse(temp))
|
||||
fileData.push(upload)
|
||||
fs.writeFile(SAVED_FOLDER_LOCATION + 'announcements.json', JSON.stringify(fileData), (err) => {
|
||||
if (err) throw err;
|
||||
})
|
||||
}
|
||||
throw redirect(302, '/')
|
||||
|
||||
|
||||
}
|
||||
};
|
13
website/src/routes/Announcement/+page.svelte
Normal file
13
website/src/routes/Announcement/+page.svelte
Normal file
|
@ -0,0 +1,13 @@
|
|||
<div id="ann-container">
|
||||
<form method="POST">
|
||||
<label for="ann-title"> Titel: </label>
|
||||
<input type="text" name="title" id="ann-title" />
|
||||
<label for="ann-time"> Uhrzeit: </label>
|
||||
<input type="time" name="time" id="ann-time" />
|
||||
<label for="ann-content"> Inhalt: </label>
|
||||
<input type="text" name="content" id="ann-content" />
|
||||
<label for="ann-reminder"> Wann erinnern? </label>
|
||||
<input type="text" name="reminder" id="ann-reminder" />
|
||||
<input type="submit">
|
||||
</form>
|
||||
</div>
|
15
website/src/routes/api/announcements/+server.js
Normal file
15
website/src/routes/api/announcements/+server.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import fs from 'fs';
|
||||
|
||||
import { SAVED_FOLDER_LOCATION } from '$env/static/private';
|
||||
|
||||
export async function GET() {
|
||||
if (!fs.existsSync(SAVED_FOLDER_LOCATION))
|
||||
fs.mkdirSync(SAVED_FOLDER_LOCATION, { recursive: true });
|
||||
|
||||
if (!fs.existsSync(SAVED_FOLDER_LOCATION + 'announcements.json'))
|
||||
return new Response({ status: 404 });
|
||||
|
||||
const announcementList = fs.readFileSync(SAVED_FOLDER_LOCATION + 'announcements.json');
|
||||
|
||||
return new Response(announcementList, { status: 200 });
|
||||
}
|
|
@ -6,7 +6,7 @@ export async function GET() {
|
|||
if (!fs.existsSync(TEMP_FOLDER_LOCATION)) fs.mkdirSync(TEMP_FOLDER_LOCATION, { recursive: true });
|
||||
|
||||
if (!fs.existsSync(TEMP_FOLDER_LOCATION + 'gameserverstatus.json'))
|
||||
return new Response({status: 404});
|
||||
return new Response({ status: 404 });
|
||||
|
||||
const serverList = fs.readFileSync(TEMP_FOLDER_LOCATION + 'gameserverstatus.json');
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user