diff --git a/aleksis/apps/alsijil/frontend/components/Coursebook.vue b/aleksis/apps/alsijil/frontend/components/Coursebook.vue index 422a9c1be102031d837646dd98763716cf4ab38f..2a2988867f4e04a146f481e014b890f933618781 100644 --- a/aleksis/apps/alsijil/frontend/components/Coursebook.vue +++ b/aleksis/apps/alsijil/frontend/components/Coursebook.vue @@ -19,6 +19,13 @@ hide-details :loading="selectLoading" @input="changeSelection" + @click:clear="changeSelection" + /> + <v-switch + :loading="selectLoading" + :label="$t('alsijil.coursebook.filter.own')" + :input-value="filterType === 'my'" + @change="changeSelection({ filterType: $event ? 'my' : 'all', type: objType, id: objId })" /> </template> <template #default="{ items }"> @@ -98,15 +105,19 @@ export default { props: { // Either as props OR route params // TODO: Remove default? + filterType: { + type: String, + required: true, + }, objId: { type: [Number, String], required: false, - default: 0, + default: null, }, objType: { type: String, required: false, - default: "group", + default: null, }, // Next two in ISODate dateStart: { @@ -141,8 +152,9 @@ export default { gqlQueryArgs() { return { // Assure courseId is a number - objId: Number(this.objId), - objType: this.objType.toUpperCase(), + own: this.filterType === "all" ? false : true, + objId: this.objId ? Number(this.objId) : null, + objType: this.objType?.toUpperCase(), dateStart: this.dateStart, dateEnd: this.dateEnd, }; @@ -163,8 +175,9 @@ export default { methods: { changeSelection(selection) { this.$router.push({ - name: "alsijil.coursebook_by_obj_id_and_date", + name: "alsijil.coursebook_by_type_and_date", params: { + filterType: selection.filterType ? selection.filterType : this.filterType, objType: selection.type, objId: selection.id, dateStart: this.dateStart, diff --git a/aleksis/apps/alsijil/frontend/components/coursebook.graphql b/aleksis/apps/alsijil/frontend/components/coursebook.graphql index ab7a3a901feaf6aa694a7d67ceedf8ba03f0411a..a8067e79a9b8bdc765b70a2beb4f1f9ea4cb24fb 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook.graphql +++ b/aleksis/apps/alsijil/frontend/components/coursebook.graphql @@ -17,12 +17,14 @@ query coursesOfTeacher { } query documentationsForCoursebook( - $objId: ID! - $objType: String! + $own: Boolean! + $objId: ID + $objType: String $dateStart: Date! $dateEnd: Date! ) { items: documentationsForCoursebook( + own: $own objId: $objId objType: $objType dateStart: $dateStart diff --git a/aleksis/apps/alsijil/frontend/index.js b/aleksis/apps/alsijil/frontend/index.js index 60d897e952f3b0dd924bba01d03ef968d024a2d2..eb09dd25feb32f56e5d91af5bb5a99e7efc5e2d5 100644 --- a/aleksis/apps/alsijil/frontend/index.js +++ b/aleksis/apps/alsijil/frontend/index.js @@ -387,21 +387,19 @@ export default { }, }, { - path: "coursebook/:objType(group|course|teacher)/:objId(\\d+)/", + path: "coursebook/", component: () => import("./components/Coursebook.vue"), redirect: (to) => { - console.log("redirect to", to); return { - name: "alsijil.coursebook_by_obj_id_and_date", + name: "alsijil.coursebook_by_type_and_date", params: { - objType: to.params.objType, - objId: to.params.objId, dateStart: DateTime.now().toISODate(), dateEnd: DateTime.now().plus({ weeks: 1 }).toISODate(), + filterType: "my", }, }; }, - name: "alsijil.coursebook_by_obj_id", + name: "alsijil.coursebook", props: true, meta: { inMenu: true, @@ -413,9 +411,9 @@ export default { }, children: [ { - path: ":dateStart(\\d\\d\\d\\d-\\d\\d-\\d\\d)/:dateEnd(\\d\\d\\d\\d-\\d\\d-\\d\\d)/", + path: ":dateStart(\\d\\d\\d\\d-\\d\\d-\\d\\d)/:dateEnd(\\d\\d\\d\\d-\\d\\d-\\d\\d)/:filterType(my|all)/:objType(group|course|teacher)?/:objId(\\d+)?/", component: () => import("./components/Coursebook.vue"), - name: "alsijil.coursebook_by_obj_id_and_date", + name: "alsijil.coursebook_by_type_and_date", meta: { titleKey: "alsijil.coursebook.menu_title", toolbarTitle: "alsijil.coursebook.menu_title", diff --git a/aleksis/apps/alsijil/frontend/messages/de.json b/aleksis/apps/alsijil/frontend/messages/de.json index 0d6f76832a125b8957f40f2ba0b31f36b42b5578..a9dbb6b4060f746f9383f3694b1af14a364cfdf1 100644 --- a/aleksis/apps/alsijil/frontend/messages/de.json +++ b/aleksis/apps/alsijil/frontend/messages/de.json @@ -47,6 +47,9 @@ "value": "Gruppennotiz: {groupNote}", "empty": "Keine Gruppennotiz" } + }, + "filter": { + "own": "Nur eigene Stunden anzeigen" } } } diff --git a/aleksis/apps/alsijil/frontend/messages/en.json b/aleksis/apps/alsijil/frontend/messages/en.json index 2537974f97c1726325303ac0d88743fdef996d36..b009570d78f2257901a5d2e7aaa0e3f94b840891 100644 --- a/aleksis/apps/alsijil/frontend/messages/en.json +++ b/aleksis/apps/alsijil/frontend/messages/en.json @@ -47,6 +47,9 @@ "value": "Group note: {groupNote}", "empty": "No group note" } + }, + "filter": { + "own": "Only show own lessons" } } } diff --git a/aleksis/apps/alsijil/models.py b/aleksis/apps/alsijil/models.py index 8e80f165ab56f188c9f2c1525f9c2c4a1a4a2957..803efbfb8227c8f66597049f099c82b52411cb18 100644 --- a/aleksis/apps/alsijil/models.py +++ b/aleksis/apps/alsijil/models.py @@ -518,11 +518,12 @@ class Documentation(CalendarEvent): @classmethod def get_for_coursebook( cls, - obj_type: str, - obj_id: str, + own: bool, date_start: datetime, date_end: datetime, request: HttpRequest, + obj_type: Optional[str], + obj_id: Optional[str], ) -> list: """Get all the documentations for an object and a time frame. @@ -530,15 +531,21 @@ class Documentation(CalendarEvent): """ # 1. Find all LessonEvents for all Lessons of this Course in this date range + event_params = { + "own": own, + "not_amended": True, + } + if obj_type is not None and obj_id is not None: + event_params.update({ + "type": obj_type, + "id": obj_id, + }) + events = LessonEvent.get_single_events( date_start, date_end, request, - { - "type": obj_type, - "id": obj_id, - "not_amended": True, - }, + event_params, with_reference_object=True, ) # (1.5 filter them by permissions) diff --git a/aleksis/apps/alsijil/schema/__init__.py b/aleksis/apps/alsijil/schema/__init__.py index b74c77e13bdb02b2391d9cb2dbffdffed9142d4b..1cfc2ca6526dc921a6d349c39c950fc0fc0cc664 100644 --- a/aleksis/apps/alsijil/schema/__init__.py +++ b/aleksis/apps/alsijil/schema/__init__.py @@ -26,8 +26,9 @@ class Query(graphene.ObjectType): ) documentations_for_coursebook = FilterOrderList( DocumentationType, - obj_type=graphene.String(required=True), - obj_id=graphene.ID(required=True), + own=graphene.Boolean(required=True), + obj_type=graphene.String(required=False), + obj_id=graphene.ID(required=False), date_start=graphene.Date(required=True), date_end=graphene.Date(required=True), ) @@ -39,7 +40,7 @@ class Query(graphene.ObjectType): return documentations def resolve_documentations_for_coursebook( - root, info, obj_type, obj_id, date_start, date_end, **kwargs + root, info, own, date_start, date_end, obj_type=None, obj_id=None, **kwargs ): datetime_start = datetime.combine(date_start, datetime.min.time()) datetime_end = datetime.combine(date_end, datetime.max.time()) @@ -67,7 +68,7 @@ class Query(graphene.ObjectType): raise PermissionDenied() return Documentation.get_for_coursebook( - obj_type, obj_id, datetime_start, datetime_end, info.context + own, datetime_start, datetime_end, info.context, obj_type, obj_id )