mirror of
https://github.com/ae-utbm/sith.git
synced 2025-01-08 16:11:17 +00:00
Add support for event location and more detail link
This commit is contained in:
parent
f32ebe6a41
commit
8406cbe7ad
@ -3,6 +3,7 @@ from datetime import timedelta
|
|||||||
import urllib3
|
import urllib3
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
from django.urls import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from ics import Calendar, Event
|
from ics import Calendar, Event
|
||||||
from ninja_extra import ControllerBase, api_controller, route
|
from ninja_extra import ControllerBase, api_controller, route
|
||||||
@ -38,12 +39,14 @@ class CalendarController(ControllerBase):
|
|||||||
calendar = Calendar()
|
calendar = Calendar()
|
||||||
for news_date in NewsDate.objects.filter(
|
for news_date in NewsDate.objects.filter(
|
||||||
news__is_moderated=True,
|
news__is_moderated=True,
|
||||||
start_date__lte=timezone.now() + timedelta(days=30),
|
end_date__gte=timezone.now()
|
||||||
|
- (timedelta(days=30) * 60), # Roughly get the last 6 months
|
||||||
).prefetch_related("news"):
|
).prefetch_related("news"):
|
||||||
event = Event(
|
event = Event(
|
||||||
name=news_date.news.title,
|
name=news_date.news.title,
|
||||||
begin=news_date.start_date,
|
begin=news_date.start_date,
|
||||||
end=news_date.end_date,
|
end=news_date.end_date,
|
||||||
|
url=reverse("com:news_detail", kwargs={"news_id": news_date.news.id}),
|
||||||
)
|
)
|
||||||
calendar.events.add(event)
|
calendar.events.add(event)
|
||||||
|
|
||||||
|
@ -61,18 +61,24 @@ export class IcsCalendar extends inheritHtmlElement("div") {
|
|||||||
oldPopup.remove();
|
oldPopup.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
const makePopupTitle = (event: EventImpl) => {
|
const makePopupInfo = (info: HTMLElement, iconClass: string) => {
|
||||||
const row = document.createElement("div");
|
const row = document.createElement("div");
|
||||||
const icon = document.createElement("i");
|
const icon = document.createElement("i");
|
||||||
const infoRow = document.createElement("div");
|
|
||||||
const title = document.createElement("h4");
|
|
||||||
const time = document.createElement("span");
|
|
||||||
row.setAttribute("class", "event-details-row");
|
row.setAttribute("class", "event-details-row");
|
||||||
|
|
||||||
icon.setAttribute(
|
icon.setAttribute("class", `event-detail-row-icon fa-xl ${iconClass}`);
|
||||||
"class",
|
|
||||||
"fa-solid fa-calendar-days fa-xl event-detail-row-icon",
|
row.appendChild(icon);
|
||||||
);
|
row.appendChild(info);
|
||||||
|
|
||||||
|
return row;
|
||||||
|
};
|
||||||
|
|
||||||
|
const makePopupTitle = (event: EventImpl) => {
|
||||||
|
const row = document.createElement("div");
|
||||||
|
const title = document.createElement("h4");
|
||||||
|
const time = document.createElement("span");
|
||||||
|
|
||||||
title.setAttribute("class", "event-details-row-content");
|
title.setAttribute("class", "event-details-row-content");
|
||||||
title.textContent = event.title;
|
title.textContent = event.title;
|
||||||
@ -80,13 +86,33 @@ export class IcsCalendar extends inheritHtmlElement("div") {
|
|||||||
time.setAttribute("class", "event-details-row-content");
|
time.setAttribute("class", "event-details-row-content");
|
||||||
time.textContent = `${this.formatDate(event.start)} - ${this.formatDate(event.end)}`;
|
time.textContent = `${this.formatDate(event.start)} - ${this.formatDate(event.end)}`;
|
||||||
|
|
||||||
infoRow.appendChild(title);
|
row.appendChild(title);
|
||||||
infoRow.appendChild(time);
|
row.appendChild(time);
|
||||||
|
return makePopupInfo(
|
||||||
|
row,
|
||||||
|
"fa-solid fa-calendar-days fa-xl event-detail-row-icon",
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
row.appendChild(icon);
|
const makePopupLocation = (event: EventImpl) => {
|
||||||
row.appendChild(infoRow);
|
if (event.extendedProps.location === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const info = document.createElement("div");
|
||||||
|
info.innerText = event.extendedProps.location;
|
||||||
|
|
||||||
return row;
|
return makePopupInfo(info, "fa-solid fa-location-dot");
|
||||||
|
};
|
||||||
|
|
||||||
|
const makePopupUrl = (event: EventImpl) => {
|
||||||
|
if (event.url === "") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const url = document.createElement("a");
|
||||||
|
url.href = event.url;
|
||||||
|
url.textContent = gettext("More info");
|
||||||
|
|
||||||
|
return makePopupInfo(url, "fa-solid fa-link");
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create new popup
|
// Create new popup
|
||||||
@ -98,6 +124,16 @@ export class IcsCalendar extends inheritHtmlElement("div") {
|
|||||||
|
|
||||||
popupContainer.appendChild(makePopupTitle(event.event));
|
popupContainer.appendChild(makePopupTitle(event.event));
|
||||||
|
|
||||||
|
const location = makePopupLocation(event.event);
|
||||||
|
if (location !== null) {
|
||||||
|
popupContainer.appendChild(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = makePopupUrl(event.event);
|
||||||
|
if (url !== null) {
|
||||||
|
popupContainer.appendChild(url);
|
||||||
|
}
|
||||||
|
|
||||||
popup.appendChild(popupContainer);
|
popup.appendChild(popupContainer);
|
||||||
|
|
||||||
// We can't just add the element relative to the one we want to appear under
|
// We can't just add the element relative to the one we want to appear under
|
||||||
@ -143,6 +179,8 @@ export class IcsCalendar extends inheritHtmlElement("div") {
|
|||||||
eventClick: (event) => {
|
eventClick: (event) => {
|
||||||
// Avoid our popup to be deleted because we clicked outside of it
|
// Avoid our popup to be deleted because we clicked outside of it
|
||||||
event.jsEvent.stopPropagation();
|
event.jsEvent.stopPropagation();
|
||||||
|
// Don't auto-follow events URLs
|
||||||
|
event.jsEvent.preventDefault();
|
||||||
this.createEventDetailPopup(event);
|
this.createEventDetailPopup(event);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -39,6 +39,7 @@ ics-calendar {
|
|||||||
border-radius: var(--event-details-border-radius);
|
border-radius: var(--event-details-border-radius);
|
||||||
background-color: var(--event-details-background-color);
|
background-color: var(--event-details-background-color);
|
||||||
box-shadow: var(--event-details-box-shadow);
|
box-shadow: var(--event-details-box-shadow);
|
||||||
|
gap: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.event-detail-row-icon {
|
.event-detail-row-icon {
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2024-12-23 02:38+0100\n"
|
"POT-Creation-Date: 2024-12-31 16:26+0100\n"
|
||||||
"PO-Revision-Date: 2024-09-17 11:54+0200\n"
|
"PO-Revision-Date: 2024-09-17 11:54+0200\n"
|
||||||
"Last-Translator: Sli <antoine@bartuccio.fr>\n"
|
"Last-Translator: Sli <antoine@bartuccio.fr>\n"
|
||||||
"Language-Team: AE info <ae.info@utbm.fr>\n"
|
"Language-Team: AE info <ae.info@utbm.fr>\n"
|
||||||
@ -17,6 +17,10 @@ msgstr ""
|
|||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||||
|
|
||||||
|
#: com/static/bundled/com/components/ics-calendar-index.ts:113
|
||||||
|
msgid "More info"
|
||||||
|
msgstr "Plus d'informations"
|
||||||
|
|
||||||
#: core/static/bundled/core/components/ajax-select-base.ts:68
|
#: core/static/bundled/core/components/ajax-select-base.ts:68
|
||||||
msgid "Remove"
|
msgid "Remove"
|
||||||
msgstr "Retirer"
|
msgstr "Retirer"
|
||||||
|
Loading…
Reference in New Issue
Block a user