diff --git a/src/jsMain/kotlin/de/kif/frontend/views/calendar/CalendarEdit.kt b/src/jsMain/kotlin/de/kif/frontend/views/calendar/CalendarEdit.kt index 025ec3a..aaaed7a 100644 --- a/src/jsMain/kotlin/de/kif/frontend/views/calendar/CalendarEdit.kt +++ b/src/jsMain/kotlin/de/kif/frontend/views/calendar/CalendarEdit.kt @@ -1,7 +1,10 @@ package de.kif.frontend.views.calendar import de.kif.common.Search +import de.kif.common.model.Schedule +import de.kif.common.model.WorkGroup import de.kif.frontend.launch +import de.kif.frontend.repository.ScheduleRepository import de.kif.frontend.repository.WorkGroupRepository import de.westermann.kobserve.list.filterObservable import de.westermann.kobserve.list.observableListOf @@ -31,9 +34,12 @@ class CalendarEdit( view.querySelector(".calendar-edit-list") as HTMLElement ) + private var showAll = false + private var loaded = false val workGroupList = observableListOf() + private val sortedList = workGroupList.sortObservable(compareBy { it.workGroup.name }).filterObservable(search.valueProperty) { entry, search -> @@ -41,13 +47,19 @@ class CalendarEdit( Search.match(search, s) } + var scheduled: Map> = emptyMap() + private fun load() { if (loaded) return loaded = true launch { + scheduled = ScheduleRepository.all().groupBy { it.workGroup } + for (workGroup in WorkGroupRepository.all()) { - workGroupList += CalendarWorkGroup(calendar, this, workGroup) + workGroupList += CalendarWorkGroup(calendar, this, workGroup).also { + it.isScheduled = workGroup in scheduled + } } } } @@ -77,6 +89,27 @@ class CalendarEdit( } } + ScheduleRepository.onCreate { id -> + launch { + val schedule = ScheduleRepository.get(id) ?: return@launch + + val schedules = scheduled[schedule.workGroup] ?: emptyList() + scheduled += schedule.workGroup to schedules + schedule + + + workGroupList.firstOrNull { it.workGroup.id == schedule.workGroup.id }?.isScheduled = true + } + } + + ScheduleRepository.onDelete { id -> + val schedule = scheduled.values.flatten().firstOrNull { it.id == id } ?: return@onDelete + + val schedules = scheduled[schedule.workGroup] ?: emptyList() + scheduled += schedule.workGroup to schedules - schedule + + workGroupList.firstOrNull { it.workGroup.id == schedule.workGroup.id }?.isScheduled = true + } + listView.listFactory(sortedList) } } \ No newline at end of file diff --git a/src/jsMain/kotlin/de/kif/frontend/views/calendar/CalendarWorkGroup.kt b/src/jsMain/kotlin/de/kif/frontend/views/calendar/CalendarWorkGroup.kt index 443f8d1..39c5564 100644 --- a/src/jsMain/kotlin/de/kif/frontend/views/calendar/CalendarWorkGroup.kt +++ b/src/jsMain/kotlin/de/kif/frontend/views/calendar/CalendarWorkGroup.kt @@ -30,6 +30,19 @@ class CalendarWorkGroup( } } + fun remove() { + html.remove() + } + + var isScheduled: Boolean by classList.property("scheduled") + + fun update() { + launch { + val wk = WorkGroupRepository.get(workGroup.id ?: return@launch) ?: return@launch + load(wk) + } + } + init { load(workGroup) diff --git a/src/jsMain/resources/style/components/_calendar.scss b/src/jsMain/resources/style/components/_calendar.scss index a6bdca0..09b1830 100644 --- a/src/jsMain/resources/style/components/_calendar.scss +++ b/src/jsMain/resources/style/components/_calendar.scss @@ -142,6 +142,10 @@ opacity: 0.6; } + &.scheduled { + display: none; + } + @include no-select() }