-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5de547
commit 4292c44
Showing
5 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<script setup lang="ts"> | ||
import { CalendarView, CalendarViewHeader } from "vue-simple-calendar"; | ||
import { ref, watch } from "vue"; | ||
import type { ICalendarItem } from "vue-simple-calendar/dist/src/ICalendarItem"; | ||
import { useGlobalStore } from "@/stores/global"; | ||
import { useRoute } from "vue-router"; | ||
import type { components } from "@/api_types"; | ||
type CalendarResponse = components["schemas"]["CalendarResponse"]; | ||
import "/node_modules/vue-simple-calendar/dist/style.css"; | ||
import "/node_modules/vue-simple-calendar/dist/css/default.css"; | ||
import { useFetch } from "@/utils/fetch"; | ||
const global = useGlobalStore(); | ||
const showDate = ref(new Date()); | ||
const tumonlineCalendarUrl = ref("https://campus.tum.de/tumonline"); | ||
const lastmod = ref("xx.xx.xxxx xx:xx"); | ||
const events = ref<ICalendarItem[]>([]); | ||
const route = useRoute(); | ||
// called when the view is loaded | ||
update(); | ||
// called when the view navigates to another view, but not when its initially loaded | ||
watch(() => showDate.value, update); | ||
watch(() => route.params.id, update); | ||
function update() { | ||
// If we set the items like this, switching between months works without a problem | ||
const start = new Date(showDate.value); | ||
start.setDate(start.getDate() - 60); | ||
const end = new Date(showDate.value); | ||
end.setDate(end.getDate() + 60); | ||
const startString = start.toISOString().replace("Z", ""); | ||
const endString = end.toISOString().replace("Z", ""); | ||
console.table({ startString, endString }); | ||
useFetch<CalendarResponse>(`/api/calendar/${route.params.id}?start=${startString}&end=${endString}`, (d) => { | ||
console.log(d); | ||
tumonlineCalendarUrl.value = d.calendar_url; | ||
lastmod.value = d.lastmod; | ||
events.value = d.events.map((e) => ({ | ||
id: e.id, | ||
title: e.title, | ||
startDate: new Date(e.start), | ||
endDate: new Date(e.end), | ||
classes: e.classes, | ||
})); | ||
}); | ||
} | ||
function setShowDate(d) { | ||
showDate.value = d; | ||
} | ||
</script> | ||
<template> | ||
<div class="modal modal-lg active" id="calendar-modal"> | ||
<a @click="global.calendar.open = false" class="modal-overlay" aria-label="Close"></a> | ||
<div class="modal-container"> | ||
<div class="modal-header"> | ||
<a @click="global.calendar.open = false" class="btn btn-clear float-right" aria-label="Close"></a> | ||
<div class="modal-title h5">Calendar</div> | ||
</div> | ||
<div class="modal-body"> | ||
<div class="modal-body"> | ||
<CalendarView | ||
id="calendar-view" | ||
:items="global.calendar.events" | ||
:show-date="showDate" | ||
:startingDayOfWeek="1" | ||
class="theme-default" | ||
> | ||
<template #header="{ headerProps }"> | ||
<CalendarViewHeader :header-props="headerProps" @input="setShowDate" /> | ||
</template> | ||
</CalendarView> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
Events are updated daily, if in doubt, please check the | ||
<a v-bind:href="global.calendar.url || 'https://campus.tum.de'">official calendar on TUMonline</a>. <br /> | ||
Last update: {{ lastmod }} | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
<style lang="scss"> | ||
#calendar-modal { | ||
.modal-container { | ||
position: relative; | ||
top: 5em; | ||
height: auto; | ||
max-width: 100vw !important; | ||
max-height: 90vh !important; | ||
.modal-body { | ||
padding: 0; | ||
height: 50rem; | ||
#calendar-view { | ||
display: flex; | ||
flex-direction: column; | ||
flex-grow: 1; | ||
} | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters