mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 05:30:13 +01:00
Calendar
Calendar that show all events that we joined
This commit is contained in:
39
WebApp/ts/calendar.ts
Normal file
39
WebApp/ts/calendar.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
async function getRegisteredEvents(): Promise<any[]> {
|
||||
const res = await fetch("/api/events/registered");
|
||||
if (!res.ok) throw new Error("Couldn't load joined events");
|
||||
|
||||
const data = await res.json();
|
||||
return data.map((ev: any) => ({
|
||||
title: ev.title,
|
||||
start: ev.eventDate,
|
||||
url: `/view.html?event=${ev.eventId}`
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
const calendarEl = document.getElementById("calendar") as HTMLElement;
|
||||
if (!calendarEl) return;
|
||||
|
||||
const events = await getRegisteredEvents();
|
||||
|
||||
const calendar = new (window as any).FullCalendar.Calendar(calendarEl, {
|
||||
initialView: 'dayGridMonth',
|
||||
headerToolbar: {
|
||||
left: 'prev,next today',
|
||||
center: 'title',
|
||||
right: 'dayGridMonth,timeGridWeek,listWeek'
|
||||
},
|
||||
themeSystem: 'bootstrap5',
|
||||
events: events,
|
||||
eventClick: function (info: any) {
|
||||
if (info.event.url) {
|
||||
window.location.href = info.event.url;
|
||||
info.jsEvent.preventDefault();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
calendar.render();
|
||||
});
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
console.log("TypeScript działa!");
|
||||
function createEvent() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// Pobieranie danych z formularza
|
||||
const title = document.getElementById('title').value;
|
||||
const location = document.getElementById('location').value;
|
||||
const description = document.getElementById('description').value;
|
||||
const eventDateRaw = document.getElementById('eventDate').value;
|
||||
const organisationIdRaw = document.getElementById('organisationId').value;
|
||||
// Walidacja prostych pól
|
||||
if (!title || !location || !eventDateRaw || !organisationIdRaw) {
|
||||
alert("Uzupełnij wszystkie wymagane pola!");
|
||||
return;
|
||||
}
|
||||
const eventDate = new Date(eventDateRaw).toISOString();
|
||||
const organisationId = parseInt(organisationIdRaw);
|
||||
const payload = {
|
||||
title,
|
||||
location,
|
||||
description,
|
||||
eventDate,
|
||||
organisationId
|
||||
};
|
||||
try {
|
||||
const response = yield fetch('/api/events', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
if (!response.ok) {
|
||||
const errorText = yield response.text();
|
||||
throw new Error(errorText);
|
||||
}
|
||||
alert("Wydarzenie zostało utworzone!");
|
||||
window.location.href = "/"; // Przekierowanie do strony głównej
|
||||
}
|
||||
catch (error) {
|
||||
console.error("Błąd podczas tworzenia:", error);
|
||||
alert("Nie udało się utworzyć wydarzenia: " + error);
|
||||
}
|
||||
});
|
||||
}
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const saveBtn = document.getElementById("saveBtn");
|
||||
if (saveBtn) {
|
||||
saveBtn.addEventListener("click", (e) => {
|
||||
e.preventDefault();
|
||||
createEvent();
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user