Hide scheduled work groups
This commit is contained in:
parent
99bfacbaf0
commit
b473221f92
|
@ -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<CalendarWorkGroup>()
|
||||
|
||||
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<WorkGroup, List<Schedule>> = 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)
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -142,6 +142,10 @@
|
|||
opacity: 0.6;
|
||||
}
|
||||
|
||||
&.scheduled {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@include no-select()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue