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,3 @@
|
||||
"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) {
|
||||
@@ -8,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
console.log("TypeScript działa!");
|
||||
import { getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||
function createEvent() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// Pobieranie danych z formularza
|
||||
@@ -49,6 +48,17 @@ function createEvent() {
|
||||
}
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
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();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
"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) {
|
||||
@@ -8,21 +7,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
import { getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||
var isAscending = false;
|
||||
function toggleListSortOrder() {
|
||||
isAscending = !isAscending;
|
||||
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() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const container = document.getElementById("eventList");
|
||||
if (!container)
|
||||
return;
|
||||
try {
|
||||
const res = yield fetch("/api/events" + (isAscending ? "?sort=asc" : ""));
|
||||
if (!res.ok)
|
||||
throw new Error("Błąd pobierania wydarzeń");
|
||||
const events = yield res.json();
|
||||
var events = yield getEvents();
|
||||
if (events.length === 0) {
|
||||
container.innerHTML = "<p class='text-muted'>Brak wydarzeń do wyświetlenia.</p>";
|
||||
return;
|
||||
@@ -48,6 +54,18 @@ function loadEvents() {
|
||||
});
|
||||
}
|
||||
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();
|
||||
// listen for clicks
|
||||
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;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user