mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 13:40:13 +01:00
feat: front-end date ranges support
This commit is contained in:
@@ -7,33 +7,64 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
import { getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||
import { getMyAccount, unhideElementById, hideElementById } from './generalUseHelpers.js';
|
||||
var isAscending = false;
|
||||
var optionsVisibility = false;
|
||||
function toggleListSortOrder(org_id) {
|
||||
isAscending = !isAscending;
|
||||
loadEvents(org_id);
|
||||
}
|
||||
function toggleOptionsVisibility() {
|
||||
optionsVisibility = !optionsVisibility;
|
||||
if (optionsVisibility) {
|
||||
unhideElementById(document, "fDate");
|
||||
unhideElementById(document, "tDate");
|
||||
unhideElementById(document, "flabel");
|
||||
unhideElementById(document, "tlabel");
|
||||
}
|
||||
else {
|
||||
hideElementById(document, "fDate");
|
||||
hideElementById(document, "tDate");
|
||||
hideElementById(document, "flabel");
|
||||
hideElementById(document, "tlabel");
|
||||
}
|
||||
}
|
||||
function getEvents(titleOrDescription, fDate, tDate) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var res;
|
||||
var searchbar = document.getElementById("searchbar");
|
||||
var eventDateFrom = document.getElementById('fDate').value;
|
||||
var eventDateTo = document.getElementById('tDate').value;
|
||||
if (titleOrDescription == null) {
|
||||
titleOrDescription = searchbar.value;
|
||||
//res = await fetch("/api/events" + (isAscending ? "?sort=asc" : ""));
|
||||
//if (!res.ok) throw new Error("Couldn't load events");
|
||||
}
|
||||
var payload = {
|
||||
titleOrDescription,
|
||||
fDate,
|
||||
tDate
|
||||
};
|
||||
res = yield fetch('/api/events/search' + (isAscending ? "?sort=asc" : ""), {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
if (!res.ok)
|
||||
throw new Error("Failed to get search results");
|
||||
if (optionsVisibility) {
|
||||
// Opcje widoczne
|
||||
var payload_visible = {
|
||||
titleOrDescription,
|
||||
eventDateFrom,
|
||||
eventDateTo
|
||||
};
|
||||
res = yield fetch('/api/events/search' + (isAscending ? "?sort=asc" : ""), {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload_visible)
|
||||
});
|
||||
if (!res.ok)
|
||||
throw new Error("Failed to get search results");
|
||||
}
|
||||
else {
|
||||
var payload_invisible = {
|
||||
titleOrDescription
|
||||
};
|
||||
res = yield fetch('/api/events/search' + (isAscending ? "?sort=asc" : ""), {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload_invisible)
|
||||
});
|
||||
if (!res.ok)
|
||||
throw new Error("Failed to get search results");
|
||||
}
|
||||
const events = yield res.json();
|
||||
return events;
|
||||
});
|
||||
@@ -117,6 +148,10 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
|
||||
if (listSortToggleButton) {
|
||||
listSortToggleButton.addEventListener("click", () => toggleListSortOrder(org_id));
|
||||
}
|
||||
const optionsToggleButton = document.getElementById("optionsbtn");
|
||||
if (optionsToggleButton) {
|
||||
optionsToggleButton.addEventListener("click", () => toggleOptionsVisibility());
|
||||
}
|
||||
// and for enter in search bar
|
||||
const searchBar = document.getElementById('searchbar');
|
||||
searchBar.addEventListener('keydown', (event) => {
|
||||
|
||||
Reference in New Issue
Block a user