Hide scheduled work groups
This commit is contained in:
parent
99bfacbaf0
commit
b473221f92
3 changed files with 51 additions and 1 deletions
|
@ -1,7 +1,10 @@
|
||||||
package de.kif.frontend.views.calendar
|
package de.kif.frontend.views.calendar
|
||||||
|
|
||||||
import de.kif.common.Search
|
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.launch
|
||||||
|
import de.kif.frontend.repository.ScheduleRepository
|
||||||
import de.kif.frontend.repository.WorkGroupRepository
|
import de.kif.frontend.repository.WorkGroupRepository
|
||||||
import de.westermann.kobserve.list.filterObservable
|
import de.westermann.kobserve.list.filterObservable
|
||||||
import de.westermann.kobserve.list.observableListOf
|
import de.westermann.kobserve.list.observableListOf
|
||||||
|
@ -31,9 +34,12 @@ class CalendarEdit(
|
||||||
view.querySelector(".calendar-edit-list") as HTMLElement
|
view.querySelector(".calendar-edit-list") as HTMLElement
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private var showAll = false
|
||||||
|
|
||||||
private var loaded = false
|
private var loaded = false
|
||||||
|
|
||||||
val workGroupList = observableListOf<CalendarWorkGroup>()
|
val workGroupList = observableListOf<CalendarWorkGroup>()
|
||||||
|
|
||||||
private val sortedList = workGroupList.sortObservable(compareBy {
|
private val sortedList = workGroupList.sortObservable(compareBy {
|
||||||
it.workGroup.name
|
it.workGroup.name
|
||||||
}).filterObservable(search.valueProperty) { entry, search ->
|
}).filterObservable(search.valueProperty) { entry, search ->
|
||||||
|
@ -41,13 +47,19 @@ class CalendarEdit(
|
||||||
Search.match(search, s)
|
Search.match(search, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var scheduled: Map<WorkGroup, List<Schedule>> = emptyMap()
|
||||||
|
|
||||||
private fun load() {
|
private fun load() {
|
||||||
if (loaded) return
|
if (loaded) return
|
||||||
loaded = true
|
loaded = true
|
||||||
|
|
||||||
launch {
|
launch {
|
||||||
|
scheduled = ScheduleRepository.all().groupBy { it.workGroup }
|
||||||
|
|
||||||
for (workGroup in WorkGroupRepository.all()) {
|
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)
|
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 {
|
init {
|
||||||
load(workGroup)
|
load(workGroup)
|
||||||
|
|
||||||
|
|
|
@ -142,6 +142,10 @@
|
||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.scheduled {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
@include no-select()
|
@include no-select()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue