Skip to content
Snippets Groups Projects
Commit 7eca340e authored by permcu's avatar permcu
Browse files

Reformat

parent c48942a4
No related branches found
No related tags found
1 merge request!464Resolve "Allow using time slot numbers in long term absences dialog (instead of datetimes)"
...@@ -34,15 +34,15 @@ ...@@ -34,15 +34,15 @@
/> />
</div> </div>
</v-col> </v-col>
<v-col cols="12" :sm="2" v-if="startPeriods" align-self="end"> <v-col cols="12" :sm="2" v-if="startPeriods" align-self="end">
<v-select <v-select
:label="$t('lesrooster.slot.period')" :label="$t('lesrooster.slot.period')"
:items="startPeriods" :items="startPeriods"
item-text="period" item-text="period"
:value="startSlot" :value="startSlot"
@input="handleStartSlot" @input="handleStartSlot"
return-object return-object
/> />
</v-col> </v-col>
<v-col cols="12" :sm="endPeriods ? 4 : 6" class="pr-0"> <v-col cols="12" :sm="endPeriods ? 4 : 6" class="pr-0">
<div aria-required="true"> <div aria-required="true">
...@@ -55,14 +55,14 @@ ...@@ -55,14 +55,14 @@
</div> </div>
</v-col> </v-col>
<v-col cols="12" :sm="2" v-if="endPeriods" align-self="end"> <v-col cols="12" :sm="2" v-if="endPeriods" align-self="end">
<v-select <v-select
:label="$t('lesrooster.slot.period')" :label="$t('lesrooster.slot.period')"
:items="endPeriods" :items="endPeriods"
item-text="period" item-text="period"
:value="endSlot" :value="endSlot"
@input="handleEndSlot" @input="handleEndSlot"
return-object return-object
/> />
</v-col> </v-col>
</v-row> </v-row>
<v-row> <v-row>
...@@ -89,10 +89,7 @@ ...@@ -89,10 +89,7 @@
<script> <script>
import AbsenceReasonGroupSelect from "aleksis.apps.kolego/components/AbsenceReasonGroupSelect.vue"; import AbsenceReasonGroupSelect from "aleksis.apps.kolego/components/AbsenceReasonGroupSelect.vue";
import DateTimeField from "aleksis.core/components/generic/forms/DateTimeField.vue"; import DateTimeField from "aleksis.core/components/generic/forms/DateTimeField.vue";
import { import { periodsByDay, persons } from "./absenceCreation.graphql";
periodsByDay,
persons,
} from "./absenceCreation.graphql";
import formRulesMixin from "aleksis.core/mixins/formRulesMixin.js"; import formRulesMixin from "aleksis.core/mixins/formRulesMixin.js";
import { DateTime } from "luxon"; import { DateTime } from "luxon";
...@@ -188,20 +185,24 @@ export default { ...@@ -188,20 +185,24 @@ export default {
getPeriodsForWeekday(weekday) { getPeriodsForWeekday(weekday) {
// Adapt from python conventions // Adapt from python conventions
const pythonWeekday = weekday - 1; const pythonWeekday = weekday - 1;
return this.periodsByDay.find((period) => period.weekday === pythonWeekday).periods; return this.periodsByDay.find(
(period) => period.weekday === pythonWeekday,
).periods;
}, },
handleStartDate(date) { handleStartDate(date) {
console.log("handleStartDate", date); console.log("handleStartDate", date);
this.start = DateTime.fromISO(date); this.start = DateTime.fromISO(date);
if (this.periodsByDay.length > 0) { if (this.periodsByDay.length > 0) {
// Select periods for day // Select periods for day
this.startPeriods = this.getPeriodsForWeekday(this.start.weekday); this.startPeriods = this.getPeriodsForWeekday(this.start.weekday);
// Sync PeriodSelect // Sync PeriodSelect
const startTime = this.start.toFormat("HH:mm:ss") const startTime = this.start.toFormat("HH:mm:ss");
console.log("syncing to ", startTime) console.log("syncing to ", startTime);
this.startSlot = this.startPeriods.find((period) => period.timeStart === startTime) this.startSlot = this.startPeriods.find(
console.log("startSlot ", this.startSlot) (period) => period.timeStart === startTime,
);
console.log("startSlot ", this.startSlot);
} }
}, },
handleEndDate(date) { handleEndDate(date) {
...@@ -211,13 +212,15 @@ export default { ...@@ -211,13 +212,15 @@ export default {
// Select periods for day // Select periods for day
this.endPeriods = this.getPeriodsForWeekday(this.end.weekday); this.endPeriods = this.getPeriodsForWeekday(this.end.weekday);
// Sync PeriodSelect // Sync PeriodSelect
const endTime = this.end.toFormat("HH:mm:ss") const endTime = this.end.toFormat("HH:mm:ss");
this.endSlot = this.endPeriods.find((period) => period.endTime === endTime) this.endSlot = this.endPeriods.find(
(period) => period.endTime === endTime,
);
} }
}, },
handleStartSlot(slot) { handleStartSlot(slot) {
// Sync TimeSelect // Sync TimeSelect
const startTime = DateTime.fromISO(slot.timeStart) const startTime = DateTime.fromISO(slot.timeStart);
this.start = this.start.set({ this.start = this.start.set({
hour: startTime.hour, hour: startTime.hour,
minute: startTime.minute, minute: startTime.minute,
...@@ -226,7 +229,7 @@ export default { ...@@ -226,7 +229,7 @@ export default {
}, },
handleEndSlot(slot) { handleEndSlot(slot) {
// Sync TimeSelect // Sync TimeSelect
const endTime = DateTime.fromISO(slot.timeEnd) const endTime = DateTime.fromISO(slot.timeEnd);
this.end = this.end.set({ this.end = this.end.set({
hour: endTime.hour, hour: endTime.hour,
minute: endTime.minute, minute: endTime.minute,
......
from datetime import datetime
from collections import defaultdict from collections import defaultdict
from datetime import datetime
from django.db.models import BooleanField, ExpressionWrapper, Q
from django.apps import apps from django.apps import apps
from django.db.models import BooleanField, ExpressionWrapper, Q
import graphene import graphene
import graphene_django_optimizer import graphene_django_optimizer
...@@ -366,7 +366,11 @@ class Query(graphene.ObjectType): ...@@ -366,7 +366,11 @@ class Query(graphene.ObjectType):
if apps.is_installed("aleksis.apps.lesrooster"): if apps.is_installed("aleksis.apps.lesrooster"):
Slot = apps.get_model("lesrooster", "Slot") Slot = apps.get_model("lesrooster", "Slot")
ValidityRange = apps.get_model("lesrooster", "ValidityRange") ValidityRange = apps.get_model("lesrooster", "ValidityRange")
slots = Slot.objects.filter(time_grid__validity_range=ValidityRange.current).order_by("weekday").values("weekday", "period", "time_start", "time_end") slots = (
Slot.objects.filter(time_grid__validity_range=ValidityRange.current)
.order_by("weekday")
.values("weekday", "period", "time_start", "time_end")
)
# Key by weekday # Key by weekday
by_weekday = defaultdict(list) by_weekday = defaultdict(list)
for slot in slots: for slot in slots:
...@@ -376,12 +380,15 @@ class Query(graphene.ObjectType): ...@@ -376,12 +380,15 @@ class Query(graphene.ObjectType):
# Nest and sort periods # Nest and sort periods
periods = [] periods = []
for weekday, slots in by_weekday.items(): for weekday, slots in by_weekday.items():
periods.append({"weekday": weekday, "periods": sorted(slots, key=lambda slot: slot["period"])}) periods.append(
{"weekday": weekday, "periods": sorted(slots, key=lambda slot: slot["period"])}
)
return periods return periods
else: else:
return [] return []
class Mutation(graphene.ObjectType): class Mutation(graphene.ObjectType):
create_or_update_documentations = DocumentationBatchCreateOrUpdateMutation.Field() create_or_update_documentations = DocumentationBatchCreateOrUpdateMutation.Field()
touch_documentation = TouchDocumentationMutation.Field() touch_documentation = TouchDocumentationMutation.Field()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment