Split recent events and calendar into separate pages.

Closes: #140
This commit is contained in:
Edward Betts 2024-06-19 22:15:32 +01:00
parent fcf935271c
commit d91eab02ad
3 changed files with 54 additions and 65 deletions

View file

@ -9,67 +9,6 @@
<script async src="{{ url_for("static", filename="es-module-shims/es-module-shims.js") }}"></script> <script async src="{{ url_for("static", filename="es-module-shims/es-module-shims.js") }}"></script>
<script type='importmap'>
{
"imports": {
"@fullcalendar/core": "https://cdn.skypack.dev/@fullcalendar/core@6.1.9",
"@fullcalendar/daygrid": "https://cdn.skypack.dev/@fullcalendar/daygrid@6.1.9",
"@fullcalendar/timegrid": "https://cdn.skypack.dev/@fullcalendar/timegrid@6.1.9",
"@fullcalendar/list": "https://cdn.skypack.dev/@fullcalendar/list@6.1.9",
"@fullcalendar/core/locales/en-gb": "https://cdn.skypack.dev/@fullcalendar/core@6.1.9/locales/en-gb"
}
}
</script>
<script type='module'>
import { Calendar } from '@fullcalendar/core'
import dayGridPlugin from '@fullcalendar/daygrid'
import timeGridPlugin from '@fullcalendar/timegrid'
import listPlugin from '@fullcalendar/list'
import gbLocale from '@fullcalendar/core/locales/en-gb';
// Function to save the current view to local storage
function saveView(view) {
localStorage.setItem('fullCalendarDefaultView', view);
}
// Function to get the saved view from local storage
function getSavedView() {
return localStorage.getItem('fullCalendarDefaultView') || 'dayGridMonth';
}
document.addEventListener('DOMContentLoaded', function() {
const calendarEl = document.getElementById('calendar')
const calendar = new Calendar(calendarEl, {
locale: gbLocale,
plugins: [dayGridPlugin, timeGridPlugin, listPlugin ],
themeSystem: 'bootstrap5',
firstDay: 1,
initialView: getSavedView(),
viewDidMount: function(info) {
saveView(info.view.type);
},
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
},
nowIndicator: true,
weekNumbers: true,
eventTimeFormat: {
hour: '2-digit',
minute: '2-digit',
hour12: false,
},
events: {{ fullcalendar_events | tojson(indent=2) }},
eventDidMount: function(info) {
info.el.title = info.event.title;
},
})
calendar.render()
})
</script>
</head> </head>
{% set event_labels = { {% set event_labels = {
@ -140,8 +79,6 @@
<p>{{ market }}</p> <p>{{ market }}</p>
{% endfor %} {% endfor %}
<div class="mb-3" id="calendar"></div>
<h3>Agenda</h3> <h3>Agenda</h3>
<div> <div>
@ -151,7 +88,7 @@
| <a href="{{ url_for(request.endpoint, markets="hide") }}">Hide all</a> | <a href="{{ url_for(request.endpoint, markets="hide") }}">Hide all</a>
</div> </div>
{% for event in events if event.as_date >= two_weeks_ago %} {% for event in events if start_event_list <= event.as_date <= end_event_list %}
{% if loop.first or event.date.year != loop.previtem.date.year or event.date.month != loop.previtem.date.month %} {% if loop.first or event.date.year != loop.previtem.date.year or event.date.month != loop.previtem.date.month %}
<div class="row mt-2"> <div class="row mt-2">
<div class="col"> <div class="col">

View file

@ -2,6 +2,8 @@
{% set pages = [ {% set pages = [
{"endpoint": "index", "label": "Home" }, {"endpoint": "index", "label": "Home" },
{"endpoint": "recent", "label": "Recent" },
{"endpoint": "calendar_page", "label": "Calendar" },
{"endpoint": "trip_future_list", "label": "Future trips" }, {"endpoint": "trip_future_list", "label": "Future trips" },
{"endpoint": "trip_past_list", "label": "Past trips" }, {"endpoint": "trip_past_list", "label": "Past trips" },
{"endpoint": "conference_list", "label": "Conferences" }, {"endpoint": "conference_list", "label": "Conferences" },

View file

@ -81,10 +81,60 @@ async def index() -> str:
agenda.data.hide_markets_while_away(events, data["accommodation_events"]) agenda.data.hide_markets_while_away(events, data["accommodation_events"])
return flask.render_template( return flask.render_template(
"index.html", "event_list.html",
today=now.date(), today=now.date(),
events=events, events=events,
fullcalendar_events=calendar.build_events(events), fullcalendar_events=calendar.build_events(events),
start_event_list=date.today() - timedelta(days=1),
end_event_list=date.today() + timedelta(days=365 * 2),
**data,
)
@app.route("/calendar")
async def calendar_page() -> str:
"""Index page."""
now = datetime.now()
data = await agenda.data.get_data(now, app.config)
events = data.pop("events")
markets_arg = flask.request.args.get("markets")
if markets_arg == "hide":
events = [e for e in events if e.name != "market"]
if markets_arg != "show":
agenda.data.hide_markets_while_away(events, data["accommodation_events"])
return flask.render_template(
"calendar.html",
today=now.date(),
events=events,
fullcalendar_events=calendar.build_events(events),
**data,
)
@app.route("/recent")
async def recent() -> str:
"""Index page."""
now = datetime.now()
data = await agenda.data.get_data(now, app.config)
events = data.pop("events")
markets_arg = flask.request.args.get("markets")
if markets_arg == "hide":
events = [e for e in events if e.name != "market"]
if markets_arg != "show":
agenda.data.hide_markets_while_away(events, data["accommodation_events"])
return flask.render_template(
"event_list.html",
today=now.date(),
events=events,
fullcalendar_events=calendar.build_events(events),
start_event_list=date.today() - timedelta(days=14),
end_event_list=date.today(),
**data, **data,
) )