Change things

This commit is contained in:
Lars Westermann 2019-06-15 22:19:20 +02:00
parent a458d8c684
commit 5dba14c368
Signed by: lars.westermann
GPG key ID: 9D417FA5BB9D5E1D
6 changed files with 30 additions and 21 deletions

View file

@ -1,8 +1,5 @@
package de.kif.frontend package de.kif.frontend
import de.kif.frontend.repository.RoomRepository
import de.kif.frontend.repository.ScheduleRepository
import de.kif.frontend.repository.WorkGroupRepository
import de.kif.frontend.views.board.initBoard import de.kif.frontend.views.board.initBoard
import de.kif.frontend.views.calendar.initCalendar import de.kif.frontend.views.calendar.initCalendar
import de.kif.frontend.views.initAnnouncement import de.kif.frontend.views.initAnnouncement
@ -65,6 +62,7 @@ fun main() = init {
} }
} }
/*
val url = window.location.pathname val url = window.location.pathname
if ("brett" in url || "wand" in url) { if ("brett" in url || "wand" in url) {
ScheduleRepository.onCreate { ScheduleRepository.onCreate {
@ -95,4 +93,5 @@ fun main() = init {
window.location.reload() window.location.reload()
} }
} }
*/
} }

View file

@ -30,7 +30,7 @@ class Calendar(calendar: HTMLElement) : View(calendar) {
val day = (calendarTable.dataset["day"]?.toIntOrNull() ?: -1) val day = (calendarTable.dataset["day"]?.toIntOrNull() ?: -1)
val reloadOnFinish = (calendarTable.dataset["reload"]?.toBoolean() ?: false) val reloadOnFinish = (calendarTable.dataset["reload"]?.toBoolean() ?: false)
val hideEmpty = (calendarTable.dataset["hide-empty"]?.toBoolean() ?: false) val hideEmpty = (calendarTable.dataset["hideEmpty"]?.toBoolean() ?: false)
val referenceDate = (calendarTable.dataset["reference"]?.toLongOrNull() ?: -1L) val referenceDate = (calendarTable.dataset["reference"]?.toLongOrNull() ?: -1L)
val nowDate = (calendarTable.dataset["now"]?.toLongOrNull() ?: -1L) val nowDate = (calendarTable.dataset["now"]?.toLongOrNull() ?: -1L)
val timeDifference = (Date.now().toLong() - nowDate) val timeDifference = (Date.now().toLong() - nowDate)
@ -128,6 +128,12 @@ class Calendar(calendar: HTMLElement) : View(calendar) {
fun updateVisibility() { fun updateVisibility() {
visibleRooms = body.calendarCells.asSequence().filter { it.isNotEmpty() }.map { it.roomId }.toSet() visibleRooms = body.calendarCells.asSequence().filter { it.isNotEmpty() }.map { it.roomId }.toSet()
body.updateVisibility()
for (element in calendarTableHeader.children) {
val id = element.dataset["room"]?.toLongOrNull() ?: continue
element.dataset["hidden"] = isRoomHidden(id).toString()
}
} }
init { init {

View file

@ -28,11 +28,12 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
val editable = calendar.editable val editable = calendar.editable
val day = calendar.day val day = calendar.day
var calendarEntries: List<CalendarEntry> = emptyList()
val calendarCells: List<CalendarCell> val calendarCells: List<CalendarCell>
get() = iterator().asSequence().flatten().toList() get() = iterator().asSequence().flatten().toList()
val calendarEntries: List<CalendarEntry>
get() = calendarCells.asSequence().flatten().toList()
var maxTime = 0 var maxTime = 0
var minTime = 0 var minTime = 0
@ -167,20 +168,17 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
init { init {
calendarBodies += this calendarBodies += this
calendarEntries = view.getElementsByClassName("calendar-entry")
.iterator().asSequence().map { CalendarEntry(this, it) }.toList()
wrapContent { wrapContent {
CalendarRow(this, it) CalendarRow(this, it)
} }
ScheduleRepository.onCreate { ScheduleRepository.onCreate {
launch { launch {
val schedule = ScheduleRepository.get(it) ?: throw NoSuchElementException() val schedule = ScheduleRepository.get(it) ?: return@launch
updateRows(schedule.time, schedule.workGroup.length) updateRows(schedule.time, schedule.workGroup.length)
calendarEntries += CalendarEntry.create(this, schedule) CalendarEntry.create(this, schedule)
calendar.updateVisibility() calendar.updateVisibility()
} }
@ -188,7 +186,7 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
ScheduleRepository.onUpdate { ScheduleRepository.onUpdate {
launch { launch {
val schedule = ScheduleRepository.get(it) ?: throw NoSuchElementException() val schedule = ScheduleRepository.get(it) ?: return@launch
updateRows(schedule.time, schedule.workGroup.length) updateRows(schedule.time, schedule.workGroup.length)
@ -200,7 +198,7 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
} }
} }
if (!found) { if (!found) {
calendarEntries += CalendarEntry.create(this, schedule) CalendarEntry.create(this, schedule)
} }
updateRows() updateRows()
@ -211,7 +209,6 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
for (entry in calendarEntries) { for (entry in calendarEntries) {
if (entry.scheduleId == it) { if (entry.scheduleId == it) {
entry.html.remove() entry.html.remove()
calendarEntries -= entry
launch { launch {
updateRows() updateRows()

View file

@ -35,6 +35,12 @@ class CalendarCell(val row: CalendarRow, view: HTMLElement) : ViewCollection<Cal
hidden = row.calendar.calendar.isRoomHidden(roomId) hidden = row.calendar.calendar.isRoomHidden(roomId)
} }
init {
wrapContent("calendar-entry") {
CalendarEntry(row.calendar, it)
}
}
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

@ -3,10 +3,7 @@ package de.kif.frontend.views.calendar
import de.kif.frontend.repository.RoomRepository import de.kif.frontend.repository.RoomRepository
import de.westermann.kwebview.ViewCollection import de.westermann.kwebview.ViewCollection
import de.westermann.kwebview.createHtmlView import de.westermann.kwebview.createHtmlView
import org.w3c.dom.HTMLDivElement import org.w3c.dom.*
import org.w3c.dom.HTMLElement
import org.w3c.dom.HTMLSpanElement
import org.w3c.dom.set
class CalendarRow(val calendar: CalendarBody, view: HTMLElement) : ViewCollection<CalendarCell>(view) { class CalendarRow(val calendar: CalendarBody, view: HTMLElement) : ViewCollection<CalendarCell>(view) {
val day = calendar.day val day = calendar.day
@ -21,7 +18,9 @@ class CalendarRow(val calendar: CalendarBody, view: HTMLElement) : ViewCollectio
init { init {
wrapContent { wrapContent {
if (it.dataset["room"] != null)
CalendarCell(this, it) CalendarCell(this, it)
else null
} }
RoomRepository.onCreate { RoomRepository.onCreate {

View file

@ -10,13 +10,15 @@ abstract class ViewCollection<V : View>(view: HTMLElement = createHtmlView()) :
protected val children: MutableList<V> = mutableListOf() protected val children: MutableList<V> = mutableListOf()
protected inline fun <reified T : HTMLElement> wrapContent(transform: (T) -> V) { protected inline fun <reified T : HTMLElement> wrapContent(classes: String = "", transform: (T) -> V?) {
for (element in html.children.iterator()) { for (element in html.children.iterator()) {
children += transform(element as T) val html = element as? T ?: continue
if (classes !in html.className) continue
children += transform(html) ?: continue
} }
} }
protected inline fun wrapContent(transform: (HTMLElement) -> V) = wrapContent<HTMLElement>(transform) protected inline fun wrapContent(classes: String = "", transform: (HTMLElement) -> V?) = wrapContent<HTMLElement>(classes, transform)
fun append(view: V) { fun append(view: V) {
children += view children += view