Change things

This commit is contained in:
Lars Westermann 2019-06-15 14:50:56 +02:00
parent d124e2a26f
commit a458d8c684
Signed by: lars.westermann
GPG key ID: 9D417FA5BB9D5E1D
7 changed files with 42 additions and 3 deletions

View file

@ -34,6 +34,7 @@ class PushServiceClient {
clearInterval(id) clearInterval(id)
intervalId = null intervalId = null
println("reload")
window.location.reload() window.location.reload()
} }

View file

@ -120,6 +120,16 @@ class Calendar(calendar: HTMLElement) : View(calendar) {
event?.stopPropagation() 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 { init {
scroll += calendarTable scroll += calendarTable

View file

@ -36,6 +36,12 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
var maxTime = 0 var maxTime = 0
var minTime = 0 var minTime = 0
fun updateVisibility() {
for (c in children) {
c.updateVisibility()
}
}
private suspend fun updateRows(startTime: Int? = null, length: Int = 0) { private suspend fun updateRows(startTime: Int? = null, length: Int = 0) {
if (calendarEntries.isEmpty() && startTime == null && !editable) { if (calendarEntries.isEmpty() && startTime == null && !editable) {
for (row in iterator().asSequence().toList()) { for (row in iterator().asSequence().toList()) {
@ -99,6 +105,8 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
while (max > last().time + 15) { while (max > last().time + 15) {
append(CalendarRow.create(this, last().time + 15)) append(CalendarRow.create(this, last().time + 15))
} }
calendar.updateVisibility()
} }
fun update(scroll: ScrollBehavior) { fun update(scroll: ScrollBehavior) {
@ -173,8 +181,11 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
updateRows(schedule.time, schedule.workGroup.length) updateRows(schedule.time, schedule.workGroup.length)
calendarEntries += CalendarEntry.create(this, schedule) calendarEntries += CalendarEntry.create(this, schedule)
calendar.updateVisibility()
} }
} }
ScheduleRepository.onUpdate { ScheduleRepository.onUpdate {
launch { launch {
val schedule = ScheduleRepository.get(it) ?: throw NoSuchElementException() val schedule = ScheduleRepository.get(it) ?: throw NoSuchElementException()

View file

@ -8,11 +8,17 @@ import org.w3c.dom.HTMLDivElement
import org.w3c.dom.HTMLElement import org.w3c.dom.HTMLElement
import org.w3c.dom.set 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 day = row.day
val time = row.time val time = row.time
val roomId = dataset["room"]?.toLongOrNull() ?: 0 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 private lateinit var room: Room
@ -25,6 +31,10 @@ class CalendarCell(row: CalendarRow, view: HTMLElement) : ViewCollection<Calenda
return room return room
} }
fun updateVisibility() {
hidden = row.calendar.calendar.isRoomHidden(roomId)
}
companion object { companion object {
fun create(row: CalendarRow, roomId: Long): CalendarCell { fun create(row: CalendarRow, roomId: Long): CalendarCell {
val view = createHtmlView<HTMLDivElement>() val view = createHtmlView<HTMLDivElement>()

View file

@ -13,6 +13,12 @@ class CalendarRow(val calendar: CalendarBody, view: HTMLElement) : ViewCollectio
val time = dataset["time"]?.toIntOrNull() ?: 0 val time = dataset["time"]?.toIntOrNull() ?: 0
fun updateVisibility() {
for (c in children) {
c.updateVisibility()
}
}
init { init {
wrapContent { wrapContent {
CalendarCell(this, it) CalendarCell(this, it)
@ -20,6 +26,7 @@ class CalendarRow(val calendar: CalendarBody, view: HTMLElement) : ViewCollectio
RoomRepository.onCreate { RoomRepository.onCreate {
+CalendarCell.create(this, it) +CalendarCell.create(this, it)
calendar.calendar.updateVisibility()
} }
RoomRepository.onDelete { id -> RoomRepository.onDelete { id ->
find { it.roomId == id }?.let(this@CalendarRow::remove) find { it.roomId == id }?.let(this@CalendarRow::remove)

View file

@ -169,7 +169,7 @@
background-color: var(--table-header-color) !important; background-color: var(--table-header-color) !important;
} }
.calendar-cell[data-empty = "true"] { .calendar-cell[data-hidden = "true"] {
display: none; display: none;
} }

View file

@ -152,7 +152,7 @@ fun DIV.renderCalendar(
div("calendar-cell") { div("calendar-cell") {
attributes["data-room"] = room.id.toString() attributes["data-room"] = room.id.toString()
attributes["data-blocked"] = blocked.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 title = room.name + " - " + timeString