mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 05:30:13 +01:00
fix: front-end improvements
makes some fields visible and other hidden depending on the result of some API calls, e.g. visitor is logged in -> show "Log out" button
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
console.log("TypeScript działa!");
|
import { getEvent, getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||||
|
|
||||||
async function createEvent() {
|
async function createEvent() {
|
||||||
// Pobieranie danych z formularza
|
// Pobieranie danych z formularza
|
||||||
@@ -44,6 +44,18 @@ async function createEvent() {
|
|||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
const saveBtn = document.getElementById("saveBtn");
|
const saveBtn = document.getElementById("saveBtn");
|
||||||
|
|
||||||
|
var user = await getMyAccount();
|
||||||
|
if (user) {
|
||||||
|
if (user.isOrganisation) {
|
||||||
|
unhideElementById(document, "mainContainer");
|
||||||
|
}
|
||||||
|
unhideElementById(document, "logout-btn");
|
||||||
|
} else {
|
||||||
|
unhideElementById(document, "joinnow-btn");
|
||||||
|
unhideElementById(document, "signin-btn");
|
||||||
|
}
|
||||||
|
|
||||||
if (saveBtn) {
|
if (saveBtn) {
|
||||||
saveBtn.addEventListener("click", (e) => {
|
saveBtn.addEventListener("click", (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
@@ -1,19 +1,26 @@
|
|||||||
var isAscending: boolean = false;
|
import { getEvent, getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||||
|
|
||||||
|
var isAscending: boolean = false;
|
||||||
|
|
||||||
function toggleListSortOrder() {
|
function toggleListSortOrder() {
|
||||||
isAscending = !isAscending;
|
isAscending = !isAscending;
|
||||||
loadEvents();
|
loadEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getEvents() {
|
||||||
|
const res = await fetch("/api/events" + (isAscending ? "?sort=asc" : ""));
|
||||||
|
if (!res.ok) throw new Error("Błąd pobierania wydarzeń");
|
||||||
|
|
||||||
|
const events = await res.json();
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
async function loadEvents() {
|
async function loadEvents() {
|
||||||
const container = document.getElementById("eventList");
|
const container = document.getElementById("eventList");
|
||||||
if (!container) return;
|
if (!container) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/events" + (isAscending ? "?sort=asc" : ""));
|
var events = await getEvents();
|
||||||
if (!res.ok) throw new Error("Błąd pobierania wydarzeń");
|
|
||||||
|
|
||||||
const events = await res.json();
|
|
||||||
|
|
||||||
if (events.length === 0) {
|
if (events.length === 0) {
|
||||||
container.innerHTML = "<p class='text-muted'>Brak wydarzeń do wyświetlenia.</p>";
|
container.innerHTML = "<p class='text-muted'>Brak wydarzeń do wyświetlenia.</p>";
|
||||||
@@ -41,6 +48,20 @@ async function loadEvents() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", async () => {
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
|
|
||||||
|
var user = await getMyAccount();
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
if (user.isOrganisation) {
|
||||||
|
unhideElementById(document, "mainContainer");
|
||||||
|
unhideElementById(document, "addnewevent-btn");
|
||||||
|
}
|
||||||
|
unhideElementById(document, "logout-btn");
|
||||||
|
} else {
|
||||||
|
unhideElementById(document, "joinnow-btn");
|
||||||
|
unhideElementById(document, "signin-btn");
|
||||||
|
}
|
||||||
|
|
||||||
loadEvents();
|
loadEvents();
|
||||||
// listen for clicks
|
// listen for clicks
|
||||||
const listSortToggleButton = document.getElementById("list-sort-btn");
|
const listSortToggleButton = document.getElementById("list-sort-btn");
|
||||||
|
|||||||
99
WebApp/ts/eventModify.ts
Normal file
99
WebApp/ts/eventModify.ts
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
import { getEvent, getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||||
|
|
||||||
|
const queryString = window.location.search;
|
||||||
|
const urlParams = new URLSearchParams(queryString);
|
||||||
|
const eventId = urlParams.get('event');
|
||||||
|
|
||||||
|
async function modifyEvent()
|
||||||
|
{
|
||||||
|
// Pobieranie danych z formularza
|
||||||
|
const title = (document.getElementById('title') as HTMLInputElement).value;
|
||||||
|
const location = (document.getElementById('location') as HTMLInputElement).value;
|
||||||
|
const description = (document.getElementById('description') as HTMLTextAreaElement).value;
|
||||||
|
const eventDateRaw = (document.getElementById('eventDate') as HTMLInputElement).value;
|
||||||
|
|
||||||
|
// Walidacja prostych pól
|
||||||
|
if (!title || !location || !eventDateRaw)
|
||||||
|
{
|
||||||
|
alert("Należy uzupełnić wszystkie pola!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const eventDate = new Date(eventDateRaw).toISOString();
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
title,
|
||||||
|
location,
|
||||||
|
description,
|
||||||
|
eventDate,
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const response = await fetch('/api/events/' + eventId, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(payload)
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok)
|
||||||
|
{
|
||||||
|
const errorText = await response.text();
|
||||||
|
throw new Error(errorText);
|
||||||
|
}
|
||||||
|
|
||||||
|
alert("Wydarzenie zmodyfikowane!");
|
||||||
|
window.location.href = "/"; // Przekierowanie do strony głównej
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Błąd podczas modyfikowania:", error);
|
||||||
|
alert("Nie udało się zmodyfikować wydarzenia: " + error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
|
var container = document.getElementById("mainContainer");
|
||||||
|
const saveBtn = document.getElementById("saveBtn");
|
||||||
|
var user = await getMyAccount();
|
||||||
|
if (user) {
|
||||||
|
if (user.isOrganisation) {
|
||||||
|
unhideElementById(document, "mainContainer");
|
||||||
|
}
|
||||||
|
unhideElementById(document, "logout-btn");
|
||||||
|
} else {
|
||||||
|
unhideElementById(document, "joinnow-btn");
|
||||||
|
unhideElementById(document, "signin-btn");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (saveBtn)
|
||||||
|
{
|
||||||
|
saveBtn.addEventListener("click", (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
createEvent();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (eventId !== null && container !== null) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
const titleInput = document.getElementById( 'title') as HTMLInputElement;
|
||||||
|
const locationInput = document.getElementById( 'location') as HTMLInputElement;
|
||||||
|
const descriptionInput = document.getElementById('description') as HTMLInputElement;
|
||||||
|
const dateInput = document.getElementById( 'eventDate') as HTMLInputElement;
|
||||||
|
var ev = await getEvent(eventId);
|
||||||
|
|
||||||
|
if (ev === null) {
|
||||||
|
container.innerHTML = "<p class='text-muted'>Brak wydarzeń do wyświetlenia.</p>";
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
titleInput.value = ev.title || '';
|
||||||
|
locationInput.value = ev.location || '';
|
||||||
|
descriptionInput.value = ev.description || '';
|
||||||
|
dateInput.value = ev.eventDate.slice(0, 16) || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
container.innerHTML = `<p class="text-danger">` + err + `</p>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
42
WebApp/ts/generalUseHelpers.ts
Normal file
42
WebApp/ts/generalUseHelpers.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
interface EventData {
|
||||||
|
title: string;
|
||||||
|
location: string;
|
||||||
|
description: string;
|
||||||
|
eventDate: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MyAccount {
|
||||||
|
userId: number;
|
||||||
|
email: string;
|
||||||
|
firstName: string;
|
||||||
|
lastName: string;
|
||||||
|
createdAt: string;
|
||||||
|
isOrganisation: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function unhideElementById(document: Document, e: string) {
|
||||||
|
var element = document.getElementById(e);
|
||||||
|
if (element) {
|
||||||
|
element.classList.remove('hidden-before-load');
|
||||||
|
console.log(element.classList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getEvent(id: string): Promise<EventData> {
|
||||||
|
const res = await fetch("/api/events/" + id);
|
||||||
|
if (!res.ok) {
|
||||||
|
throw Error("To wydarzenie nie istnieje");
|
||||||
|
}
|
||||||
|
const events = await res.json();
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getMyAccount(): Promise<MyAccount> {
|
||||||
|
const res = await fetch("/api/auth/my_account");
|
||||||
|
if (!res.ok) {
|
||||||
|
throw Error("U¿ytkownik niezalogowany!");
|
||||||
|
}
|
||||||
|
const data = await res.json();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<html lang="pl">
|
<html lang="pl">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Nowe wydarzenie</title>
|
<title>New event</title>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="/css/style.css" />
|
<link rel="stylesheet" href="/css/style.css" />
|
||||||
@@ -48,12 +48,13 @@
|
|||||||
<div class="topnav d-flex justify-content-between align-items-center shadow">
|
<div class="topnav d-flex justify-content-between align-items-center shadow">
|
||||||
<a href="index.html" class="eventsText m-0 logo text-decoration-none">Lend a Hand</a>
|
<a href="index.html" class="eventsText m-0 logo text-decoration-none">Lend a Hand</a>
|
||||||
<div>
|
<div>
|
||||||
<button class="button-join">Join now</button>
|
<button class="button-join hidden-before-load" id="joinnow-btn">Join now</button>
|
||||||
<button class="button-sign">Sign In</button>
|
<button class="button-sign hidden-before-load" id="signin-btn">Sign In</button>
|
||||||
|
<button class="button-sign hidden-before-load" id="logout-btn">Log out</button>
|
||||||
<svg class="position-relative" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#2898BD"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z" /></svg>
|
<svg class="position-relative" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#2898BD"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z" /></svg>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="main">
|
<div class="main hidden-before-load">
|
||||||
<h1 class="mb-4">Create a new event</h1>
|
<h1 class="mb-4">Create a new event</h1>
|
||||||
|
|
||||||
<div class="form-group mb-2">
|
<div class="form-group mb-2">
|
||||||
@@ -78,6 +79,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="module" src="/js/eventCreate.js"></script>
|
<script type="module" src="/js/eventCreate.js"></script>
|
||||||
|
<script type="module" src="/js/generalUseHelpers.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,11 @@
|
|||||||
font-size: 36px;
|
font-size: 36px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hidden-before-load {
|
||||||
|
display: none !important;
|
||||||
|
visibility: hidden !important;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: 'Segoe UI', sans-serif;
|
font-family: 'Segoe UI', sans-serif;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,11 @@ html {
|
|||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hidden-before-load {
|
||||||
|
display: none !important;
|
||||||
|
visibility: hidden !important;
|
||||||
|
}
|
||||||
|
|
||||||
@media (min-width: 768px) {
|
@media (min-width: 768px) {
|
||||||
html {
|
html {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
body {
|
body {
|
||||||
color: #2898BD;
|
color: #2898BD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hidden-before-load {
|
||||||
|
display: none !important;
|
||||||
|
visibility: hidden !important;
|
||||||
|
}
|
||||||
|
|
||||||
.input-field {
|
.input-field {
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
|
|||||||
@@ -46,8 +46,9 @@
|
|||||||
<div class="topnav d-flex justify-content-between align-items-center shadow">
|
<div class="topnav d-flex justify-content-between align-items-center shadow">
|
||||||
<a href="index.html" class="eventsText m-0 logo text-decoration-none">Lend a Hand</a>
|
<a href="index.html" class="eventsText m-0 logo text-decoration-none">Lend a Hand</a>
|
||||||
<div>
|
<div>
|
||||||
<button class="button-join">Join now</button>
|
<button class="button-join hidden-before-load" id="joinnow-btn">Join now</button>
|
||||||
<button class="button-sign">Sign In</button>
|
<button class="button-sign hidden-before-load" id="signin-btn">Sign In</button>
|
||||||
|
<button class="button-sign hidden-before-load" id="logout-btn">Log out</button>
|
||||||
<svg class="position-relative" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#2898BD"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z" /></svg>
|
<svg class="position-relative" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#2898BD"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z" /></svg>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -86,9 +87,10 @@
|
|||||||
|
|
||||||
<script type="module" src="/js/eventList.js"></script>
|
<script type="module" src="/js/eventList.js"></script>
|
||||||
<script type="module" src="/js/eventDelete.js"></script>
|
<script type="module" src="/js/eventDelete.js"></script>
|
||||||
|
<script type="module" src="/js/generalUseHelpers.js"></script>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<a href="/create.html" class="button-add mt-xl-auto rounded-5 align-content-center center-text">
|
<a href="/create.html" class="button-add mt-xl-auto rounded-5 align-content-center center-text hidden-before-load" id="addnewevent-btn">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#FFFFFF"><path d="M440-440H200v-80h240v-240h80v240h240v80H520v240h-80v-240Z" /></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#FFFFFF"><path d="M440-440H200v-80h240v-240h80v240h240v80H520v240h-80v-240Z" /></svg>
|
||||||
</a>
|
</a>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
"use strict";
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
@@ -8,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
console.log("TypeScript działa!");
|
import { getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||||
function createEvent() {
|
function createEvent() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// Pobieranie danych z formularza
|
// Pobieranie danych z formularza
|
||||||
@@ -49,6 +48,17 @@ function createEvent() {
|
|||||||
}
|
}
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
const saveBtn = document.getElementById("saveBtn");
|
const saveBtn = document.getElementById("saveBtn");
|
||||||
|
var user = yield getMyAccount();
|
||||||
|
if (user) {
|
||||||
|
if (user.isOrganisation) {
|
||||||
|
unhideElementById(document, "mainContainer");
|
||||||
|
}
|
||||||
|
unhideElementById(document, "logout-btn");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
unhideElementById(document, "joinnow-btn");
|
||||||
|
unhideElementById(document, "signin-btn");
|
||||||
|
}
|
||||||
if (saveBtn) {
|
if (saveBtn) {
|
||||||
saveBtn.addEventListener("click", (e) => {
|
saveBtn.addEventListener("click", (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
"use strict";
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
@@ -8,21 +7,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
import { getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||||
var isAscending = false;
|
var isAscending = false;
|
||||||
function toggleListSortOrder() {
|
function toggleListSortOrder() {
|
||||||
isAscending = !isAscending;
|
isAscending = !isAscending;
|
||||||
loadEvents();
|
loadEvents();
|
||||||
}
|
}
|
||||||
|
function getEvents() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const res = yield fetch("/api/events" + (isAscending ? "?sort=asc" : ""));
|
||||||
|
if (!res.ok)
|
||||||
|
throw new Error("Błąd pobierania wydarzeń");
|
||||||
|
const events = yield res.json();
|
||||||
|
return events;
|
||||||
|
});
|
||||||
|
}
|
||||||
function loadEvents() {
|
function loadEvents() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const container = document.getElementById("eventList");
|
const container = document.getElementById("eventList");
|
||||||
if (!container)
|
if (!container)
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
const res = yield fetch("/api/events" + (isAscending ? "?sort=asc" : ""));
|
var events = yield getEvents();
|
||||||
if (!res.ok)
|
|
||||||
throw new Error("Błąd pobierania wydarzeń");
|
|
||||||
const events = yield res.json();
|
|
||||||
if (events.length === 0) {
|
if (events.length === 0) {
|
||||||
container.innerHTML = "<p class='text-muted'>Brak wydarzeń do wyświetlenia.</p>";
|
container.innerHTML = "<p class='text-muted'>Brak wydarzeń do wyświetlenia.</p>";
|
||||||
return;
|
return;
|
||||||
@@ -48,6 +54,18 @@ function loadEvents() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, void 0, function* () {
|
document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
var user = yield getMyAccount();
|
||||||
|
if (user) {
|
||||||
|
if (user.isOrganisation) {
|
||||||
|
unhideElementById(document, "mainContainer");
|
||||||
|
unhideElementById(document, "addnewevent-btn");
|
||||||
|
}
|
||||||
|
unhideElementById(document, "logout-btn");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
unhideElementById(document, "joinnow-btn");
|
||||||
|
unhideElementById(document, "signin-btn");
|
||||||
|
}
|
||||||
loadEvents();
|
loadEvents();
|
||||||
// listen for clicks
|
// listen for clicks
|
||||||
const listSortToggleButton = document.getElementById("list-sort-btn");
|
const listSortToggleButton = document.getElementById("list-sort-btn");
|
||||||
|
|||||||
95
WebApp/wwwroot/js/eventModify.js
Normal file
95
WebApp/wwwroot/js/eventModify.js
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
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());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
import { getEvent, getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||||
|
const queryString = window.location.search;
|
||||||
|
const urlParams = new URLSearchParams(queryString);
|
||||||
|
const eventId = urlParams.get('event');
|
||||||
|
function modifyEvent() {
|
||||||
|
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;
|
||||||
|
// Walidacja prostych pól
|
||||||
|
if (!title || !location || !eventDateRaw) {
|
||||||
|
alert("Należy uzupełnić wszystkie pola!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const eventDate = new Date(eventDateRaw).toISOString();
|
||||||
|
const payload = {
|
||||||
|
title,
|
||||||
|
location,
|
||||||
|
description,
|
||||||
|
eventDate,
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const response = yield fetch('/api/events/' + eventId, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(payload)
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorText = yield response.text();
|
||||||
|
throw new Error(errorText);
|
||||||
|
}
|
||||||
|
alert("Wydarzenie zmodyfikowane!");
|
||||||
|
window.location.href = "/"; // Przekierowanie do strony głównej
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error("Błąd podczas modyfikowania:", error);
|
||||||
|
alert("Nie udało się zmodyfikować wydarzenia: " + error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
var container = document.getElementById("mainContainer");
|
||||||
|
const saveBtn = document.getElementById("saveBtn");
|
||||||
|
var user = yield getMyAccount();
|
||||||
|
if (user) {
|
||||||
|
if (user.isOrganisation) {
|
||||||
|
unhideElementById(document, "mainContainer");
|
||||||
|
}
|
||||||
|
unhideElementById(document, "logout-btn");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
unhideElementById(document, "joinnow-btn");
|
||||||
|
unhideElementById(document, "signin-btn");
|
||||||
|
}
|
||||||
|
if (saveBtn) {
|
||||||
|
saveBtn.addEventListener("click", (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
createEvent();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (eventId !== null && container !== null) {
|
||||||
|
try {
|
||||||
|
const titleInput = document.getElementById('title');
|
||||||
|
const locationInput = document.getElementById('location');
|
||||||
|
const descriptionInput = document.getElementById('description');
|
||||||
|
const dateInput = document.getElementById('eventDate');
|
||||||
|
var ev = yield getEvent(eventId);
|
||||||
|
if (ev === null) {
|
||||||
|
container.innerHTML = "<p class='text-muted'>Brak wydarzeń do wyświetlenia.</p>";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
titleInput.value = ev.title || '';
|
||||||
|
locationInput.value = ev.location || '';
|
||||||
|
descriptionInput.value = ev.description || '';
|
||||||
|
dateInput.value = ev.eventDate.slice(0, 16) || '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
container.innerHTML = `<p class="text-danger">` + err + `</p>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
38
WebApp/wwwroot/js/generalUseHelpers.js
Normal file
38
WebApp/wwwroot/js/generalUseHelpers.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
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());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
export function unhideElementById(document, e) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
var element = document.getElementById(e);
|
||||||
|
if (element) {
|
||||||
|
element.classList.remove('hidden-before-load');
|
||||||
|
console.log(element.classList);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export function getEvent(id) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const res = yield fetch("/api/events/" + id);
|
||||||
|
if (!res.ok) {
|
||||||
|
throw Error("To wydarzenie nie istnieje");
|
||||||
|
}
|
||||||
|
const events = yield res.json();
|
||||||
|
return events;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export function getMyAccount() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const res = yield fetch("/api/auth/my_account");
|
||||||
|
if (!res.ok) {
|
||||||
|
throw Error("Użytkownik niezalogowany!");
|
||||||
|
}
|
||||||
|
const data = yield res.json();
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
}
|
||||||
88
WebApp/wwwroot/modify.html
Normal file
88
WebApp/wwwroot/modify.html
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="pl">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Modify existing event</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="/css/style.css" />
|
||||||
|
<link rel="stylesheet" href="/css/panel.css" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<body class="bg-light">
|
||||||
|
<div class="">
|
||||||
|
<!-- Sidebar -->
|
||||||
|
<div class="sidebar">
|
||||||
|
<div class="text-center mb-4">
|
||||||
|
</div>
|
||||||
|
<nav class="sidebar d-flex flex-column align-items-center pt-3">
|
||||||
|
<div class="icon-box my-2">
|
||||||
|
<a href="index.html" class="nav-link text-info mb-3">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M240-200h120v-240h240v240h120v-360L480-740 240-560v360Zm-80 80v-480l320-240 320 240v480H520v-240h-80v240H160Zm320-350Z" /></svg>
|
||||||
|
<br /><h8 class="iconText">Home</h8>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="icon-box my-2">
|
||||||
|
<a href="#" class="nav-link text-info mb-3">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M880-80 720-240H320q-33 0-56.5-23.5T240-320v-40h440q33 0 56.5-23.5T760-440v-280h40q33 0 56.5 23.5T880-640v560ZM160-473l47-47h393v-280H160v327ZM80-280v-520q0-33 23.5-56.5T160-880h440q33 0 56.5 23.5T680-800v280q0 33-23.5 56.5T600-440H240L80-280Zm80-240v-280 280Z" /></svg>
|
||||||
|
<br /><h8 class="iconText">Chats</h8>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="icon-box my-2">
|
||||||
|
<a href="#" class="nav-link text-info mb-3">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M580-240q-42 0-71-29t-29-71q0-42 29-71t71-29q42 0 71 29t29 71q0 42-29 71t-71 29ZM200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Zm0-480h560v-80H200v80Zm0 0v-80 80Z" /></svg>
|
||||||
|
<br /><h8 class="iconText">Calendar</h8>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="icon-box mt-auto mb-4">
|
||||||
|
<a href="#" class="nav-link text-info mb-3">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="m370-80-16-128q-13-5-24.5-12T307-235l-119 50L78-375l103-78q-1-7-1-13.5v-27q0-6.5 1-13.5L78-585l110-190 119 50q11-8 23-15t24-12l16-128h220l16 128q13 5 24.5 12t22.5 15l119-50 110 190-103 78q1 7 1 13.5v27q0 6.5-2 13.5l103 78-110 190-118-50q-11 8-23 15t-24 12L590-80H370Zm70-80h79l14-106q31-8 57.5-23.5T639-327l99 41 39-68-86-65q5-14 7-29.5t2-31.5q0-16-2-31.5t-7-29.5l86-65-39-68-99 42q-22-23-48.5-38.5T533-694l-13-106h-79l-14 106q-31 8-57.5 23.5T321-633l-99-41-39 68 86 64q-5 15-7 30t-2 32q0 16 2 31t7 30l-86 65 39 68 99-42q22 23 48.5 38.5T427-266l13 106Zm42-180q58 0 99-41t41-99q0-58-41-99t-99-41q-59 0-99.5 41T342-480q0 58 40.5 99t99.5 41Zm-2-140Z" /></svg>
|
||||||
|
<br /><h8 class="iconText">Settings</h8>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
<!-- Top Nav -->
|
||||||
|
<div class="topnav d-flex justify-content-between align-items-center shadow">
|
||||||
|
<a href="index.html" class="eventsText m-0 logo text-decoration-none">Lend a Hand</a>
|
||||||
|
<div>
|
||||||
|
<button class="button-join hidden-before-load" id="joinnow-btn">Join now</button>
|
||||||
|
<button class="button-sign hidden-before-load" id="signin-btn">Sign In</button>
|
||||||
|
<button class="button-sign hidden-before-load" id="logout-btn">Log out</button>
|
||||||
|
<svg class="position-relative" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#2898BD"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z" /></svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="main hidden-before-load" id="mainContainer">
|
||||||
|
<h1 class="mb-4">Modify an existing event</h1>
|
||||||
|
|
||||||
|
<div class="form-group mb-2">
|
||||||
|
<label for="title">Tytuł</label>
|
||||||
|
<input id="title" class="form-control input-field" />
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-2">
|
||||||
|
<label for="location">Lokalizacja</label>
|
||||||
|
<input id="location" class="form-control input-field" />
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-2">
|
||||||
|
<label for="description">Opis</label>
|
||||||
|
<textarea id="description" class="form-control input-field"></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-2">
|
||||||
|
<label for="eventDate">Data</label>
|
||||||
|
<input id="eventDate" type="datetime-local" class="form-control input-field" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button id="saveBtn" class="button"><span>Update</span><span>⮞</span></button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="module" src="/js/eventModify.js"></script>
|
||||||
|
<script type="module" src="/js/generalUseHelpers.js"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
"strict": true,
|
"strict": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"outDir": "WebApp/wwwroot/js",
|
"outDir": "WebApp/wwwroot/js",
|
||||||
"lib": [ "es2015", "dom" ]
|
"lib": [ "es2017", "dom" ]
|
||||||
},
|
},
|
||||||
"include": [ "WebApp/ts/**/*" ],
|
"include": [ "WebApp/ts/**/*" ],
|
||||||
"compileOnSave": true
|
"compileOnSave": true
|
||||||
|
|||||||
Reference in New Issue
Block a user