mirror of
https://github.com/lucaspalomodevelop/Party.git
synced 2026-03-13 00:07:21 +00:00
anfang vom planer
This commit is contained in:
parent
83699a92c2
commit
2d83151405
@ -3,6 +3,7 @@ from flask_socketio import SocketIO, send, emit, join_room, leave_room
|
||||
from http import HTTPStatus
|
||||
from mate import generate_kiste, MateKiste
|
||||
from chat import Chat
|
||||
from planer import Planer
|
||||
import bson.json_util as json_util
|
||||
|
||||
|
||||
@ -85,6 +86,24 @@ def handle_chat_get_message(data):
|
||||
data = { 'messages': json_util.dumps(messages) }
|
||||
return { 'data': data }
|
||||
|
||||
@app.route('/api/planer', methods=['GET'])
|
||||
def api_planer():
|
||||
events = Planer.getNextEvents(10, 0)
|
||||
resp = jsonify(succ=True, events=json_util.dumps(events))
|
||||
resp.status_code = 200
|
||||
return resp
|
||||
|
||||
@socketio.on('planer-event')
|
||||
def handle_chat_event(data):
|
||||
Planer.insertNewEvent(data['name'], data['zeit'])
|
||||
emit('planer-event', data, broadcast=True)
|
||||
|
||||
@socketio.on('planer-get-events')
|
||||
def handle_planer_get_events(data):
|
||||
events = Planer.getNextEvents(data['count'], data['skip'])
|
||||
data = { 'evemts': json_util.dumps(events)}
|
||||
return { 'data': data}
|
||||
|
||||
@socketio.on('mate-status')
|
||||
def handle_mate_status():
|
||||
status = MateKiste.getStatus()
|
||||
|
||||
61
party/planer.py
Normal file
61
party/planer.py
Normal file
@ -0,0 +1,61 @@
|
||||
from pymongo import MongoClient
|
||||
from datetime import datetime
|
||||
|
||||
class Planer:
|
||||
CONNECTION_STRING = None
|
||||
client = None
|
||||
collection = None
|
||||
initialized = False
|
||||
|
||||
@classmethod
|
||||
def init(self):
|
||||
self.CONNECTION_STRING = "mongodb://localhost:27017/"
|
||||
self.client = MongoClient(self.CONNECTION_STRING)
|
||||
self.collection = self.client['partyyy']['planer']
|
||||
self.initialized = True
|
||||
|
||||
@classmethod
|
||||
def getNewEvent(self):
|
||||
print("huhu")
|
||||
|
||||
@classmethod
|
||||
def insertNewEvent(self, name: str, time: str):
|
||||
if not self.initialized:
|
||||
self.init()
|
||||
|
||||
event = self.convertToEvent(name, time)
|
||||
self.collection.insert_one(event)
|
||||
print('Inserted event:', event)
|
||||
|
||||
@classmethod
|
||||
def deleteEvent(self):
|
||||
print("huhu")
|
||||
|
||||
@classmethod
|
||||
def getAllEvents(self) -> list[dict]:
|
||||
if not self.initialized:
|
||||
self.init()
|
||||
|
||||
events = self.collection.find().sort('time', 1)
|
||||
return list(events)
|
||||
|
||||
@classmethod
|
||||
def getNextEvents(self, count: int, skip: int) -> list[dict]:
|
||||
if not self.initialized:
|
||||
self.init()
|
||||
|
||||
events = list(self.collection.find()
|
||||
.skip(skip)
|
||||
.limit(count)
|
||||
.sort('time', 1))
|
||||
|
||||
return events
|
||||
|
||||
@classmethod
|
||||
def convertToEvent(self, name: str, time: str) -> dict:
|
||||
event = {
|
||||
'name': name,
|
||||
'time': str(datetime.strptime(time, '%Y-%m-%d %H:%M:%S'))
|
||||
}
|
||||
|
||||
return event
|
||||
@ -457,3 +457,34 @@ margin-right: auto;
|
||||
font-size: 10px;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
|
||||
/* CSS für die Bearbeitungsbuttons beim planer */
|
||||
.button-wrapper {
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
.button-wrapper img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: transparent;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.button-wrapper:first-child {
|
||||
margin-right: 5%;
|
||||
}
|
||||
|
||||
.button-wrapper:last-child {
|
||||
margin-left: 5%;
|
||||
}
|
||||
|
||||
|
||||
BIN
party/static/icons/edit.png
Normal file
BIN
party/static/icons/edit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.2 KiB |
BIN
party/static/icons/x.png
Normal file
BIN
party/static/icons/x.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
68
party/static/js/planer.js
Normal file
68
party/static/js/planer.js
Normal file
@ -0,0 +1,68 @@
|
||||
function updateEventsTable() {
|
||||
fetch('/api/planer')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const events = JSON.parse(data.events);
|
||||
const tableBody = document.querySelector('#events tbody');
|
||||
|
||||
// macht platz
|
||||
while (tableBody.firstChild) {
|
||||
tableBody.removeChild(tableBody.firstChild);
|
||||
}
|
||||
|
||||
// macht die tabelle voll
|
||||
events.forEach(event => {
|
||||
const row = document.createElement('tr');
|
||||
const nameCell = document.createElement('td');
|
||||
const timeCell = document.createElement('td');
|
||||
const statusCell = document.createElement('td');
|
||||
const manageCell = document.createElement('td');
|
||||
|
||||
nameCell.textContent = event.name;
|
||||
timeCell.textContent = event.time;
|
||||
statusCell.textContent = 'Wird wohl noch kommen';
|
||||
|
||||
// Buttons zum bearbeiten eines events. Die bearbeitung muss aber noch gebaut werden
|
||||
const editButton = document.createElement('button');
|
||||
const deleteButton = document.createElement('button');
|
||||
|
||||
editButton.classList.add('button-wrapper');
|
||||
deleteButton.classList.add('button-wrapper');
|
||||
|
||||
editButton.innerHTML = '<img src="/static/icons/edit.png" alt="Edit">';
|
||||
deleteButton.innerHTML = '<img src="/static/icons/x.png" alt="Delete">';
|
||||
|
||||
|
||||
manageCell.appendChild(editButton);
|
||||
manageCell.appendChild(deleteButton);
|
||||
|
||||
row.appendChild(nameCell);
|
||||
row.appendChild(timeCell);
|
||||
row.appendChild(statusCell);
|
||||
row.appendChild(manageCell);
|
||||
|
||||
tableBody.appendChild(row);
|
||||
});
|
||||
})
|
||||
.catch(error => console.error('Error fetching events:', error));
|
||||
}
|
||||
|
||||
|
||||
|
||||
socket.on('planer-event', (data) => {
|
||||
updateEventsTable();
|
||||
});
|
||||
|
||||
|
||||
socket.on('planer-get-events', (data) => {
|
||||
|
||||
});
|
||||
|
||||
|
||||
function addNewEvent(name, time) {
|
||||
socket.emit('planer-event', { name, zeit: time });
|
||||
}
|
||||
|
||||
|
||||
|
||||
updateEventsTable();
|
||||
@ -125,6 +125,7 @@
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.7.1/socket.io.js"></script>
|
||||
<script src="/static/js/session.js"></script>
|
||||
<script src="/static/js/chat.js"></script>
|
||||
<script src="/static/js/planer.js"></script>
|
||||
<script src="/static/js/mate.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user