Change things
This commit is contained in:
parent
d124e2a26f
commit
a458d8c684
|
@ -34,6 +34,7 @@ class PushServiceClient {
|
|||
clearInterval(id)
|
||||
intervalId = null
|
||||
|
||||
println("reload")
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
|
|
|
@ -120,6 +120,16 @@ class Calendar(calendar: HTMLElement) : View(calendar) {
|
|||
event?.stopPropagation()
|
||||
}
|
||||
|
||||
private var visibleRooms: Set<Long> = emptySet()
|
||||
|
||||
fun isRoomHidden(roomId: Long): Boolean {
|
||||
return hideEmpty && roomId !in visibleRooms
|
||||
}
|
||||
|
||||
fun updateVisibility() {
|
||||
visibleRooms = body.calendarCells.asSequence().filter { it.isNotEmpty() }.map { it.roomId }.toSet()
|
||||
}
|
||||
|
||||
init {
|
||||
scroll += calendarTable
|
||||
|
||||
|
|
|
@ -36,6 +36,12 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
|
|||
var maxTime = 0
|
||||
var minTime = 0
|
||||
|
||||
fun updateVisibility() {
|
||||
for (c in children) {
|
||||
c.updateVisibility()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun updateRows(startTime: Int? = null, length: Int = 0) {
|
||||
if (calendarEntries.isEmpty() && startTime == null && !editable) {
|
||||
for (row in iterator().asSequence().toList()) {
|
||||
|
@ -99,6 +105,8 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
|
|||
while (max > last().time + 15) {
|
||||
append(CalendarRow.create(this, last().time + 15))
|
||||
}
|
||||
|
||||
calendar.updateVisibility()
|
||||
}
|
||||
|
||||
fun update(scroll: ScrollBehavior) {
|
||||
|
@ -173,8 +181,11 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
|
|||
updateRows(schedule.time, schedule.workGroup.length)
|
||||
|
||||
calendarEntries += CalendarEntry.create(this, schedule)
|
||||
|
||||
calendar.updateVisibility()
|
||||
}
|
||||
}
|
||||
|
||||
ScheduleRepository.onUpdate {
|
||||
launch {
|
||||
val schedule = ScheduleRepository.get(it) ?: throw NoSuchElementException()
|
||||
|
|
|
@ -8,11 +8,17 @@ import org.w3c.dom.HTMLDivElement
|
|||
import org.w3c.dom.HTMLElement
|
||||
import org.w3c.dom.set
|
||||
|
||||
class CalendarCell(row: CalendarRow, view: HTMLElement) : ViewCollection<CalendarEntry>(view) {
|
||||
class CalendarCell(val row: CalendarRow, view: HTMLElement) : ViewCollection<CalendarEntry>(view) {
|
||||
val day = row.day
|
||||
val time = row.time
|
||||
|
||||
val roomId = dataset["room"]?.toLongOrNull() ?: 0
|
||||
var hiddenString by dataset.property("hidden")
|
||||
var hidden: Boolean
|
||||
get() = hiddenString?.toBoolean() ?: false
|
||||
set(value) {
|
||||
hiddenString = value.toString()
|
||||
}
|
||||
|
||||
private lateinit var room: Room
|
||||
|
||||
|
@ -25,6 +31,10 @@ class CalendarCell(row: CalendarRow, view: HTMLElement) : ViewCollection<Calenda
|
|||
return room
|
||||
}
|
||||
|
||||
fun updateVisibility() {
|
||||
hidden = row.calendar.calendar.isRoomHidden(roomId)
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun create(row: CalendarRow, roomId: Long): CalendarCell {
|
||||
val view = createHtmlView<HTMLDivElement>()
|
||||
|
|
|
@ -13,6 +13,12 @@ class CalendarRow(val calendar: CalendarBody, view: HTMLElement) : ViewCollectio
|
|||
|
||||
val time = dataset["time"]?.toIntOrNull() ?: 0
|
||||
|
||||
fun updateVisibility() {
|
||||
for (c in children) {
|
||||
c.updateVisibility()
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
wrapContent {
|
||||
CalendarCell(this, it)
|
||||
|
@ -20,6 +26,7 @@ class CalendarRow(val calendar: CalendarBody, view: HTMLElement) : ViewCollectio
|
|||
|
||||
RoomRepository.onCreate {
|
||||
+CalendarCell.create(this, it)
|
||||
calendar.calendar.updateVisibility()
|
||||
}
|
||||
RoomRepository.onDelete { id ->
|
||||
find { it.roomId == id }?.let(this@CalendarRow::remove)
|
||||
|
|
|
@ -169,7 +169,7 @@
|
|||
background-color: var(--table-header-color) !important;
|
||||
}
|
||||
|
||||
.calendar-cell[data-empty = "true"] {
|
||||
.calendar-cell[data-hidden = "true"] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
|
|
@ -152,7 +152,7 @@ fun DIV.renderCalendar(
|
|||
div("calendar-cell") {
|
||||
attributes["data-room"] = room.id.toString()
|
||||
attributes["data-blocked"] = blocked.toString()
|
||||
attributes["data-empty"] = (hideEmptyRooms && room !in schedules).toString()
|
||||
attributes["data-hidden"] = (hideEmptyRooms && room !in schedules).toString()
|
||||
|
||||
title = room.name + " - " + timeString
|
||||
|
||||
|
|
Loading…
Reference in a new issue