Change things
This commit is contained in:
parent
a458d8c684
commit
5dba14c368
|
@ -1,8 +1,5 @@
|
|||
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.calendar.initCalendar
|
||||
import de.kif.frontend.views.initAnnouncement
|
||||
|
@ -65,6 +62,7 @@ fun main() = init {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
val url = window.location.pathname
|
||||
if ("brett" in url || "wand" in url) {
|
||||
ScheduleRepository.onCreate {
|
||||
|
@ -95,4 +93,5 @@ fun main() = init {
|
|||
window.location.reload()
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class Calendar(calendar: HTMLElement) : View(calendar) {
|
|||
|
||||
val day = (calendarTable.dataset["day"]?.toIntOrNull() ?: -1)
|
||||
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 nowDate = (calendarTable.dataset["now"]?.toLongOrNull() ?: -1L)
|
||||
val timeDifference = (Date.now().toLong() - nowDate)
|
||||
|
@ -128,6 +128,12 @@ class Calendar(calendar: HTMLElement) : View(calendar) {
|
|||
|
||||
fun updateVisibility() {
|
||||
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 {
|
||||
|
|
|
@ -28,11 +28,12 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
|
|||
val editable = calendar.editable
|
||||
val day = calendar.day
|
||||
|
||||
var calendarEntries: List<CalendarEntry> = emptyList()
|
||||
|
||||
val calendarCells: List<CalendarCell>
|
||||
get() = iterator().asSequence().flatten().toList()
|
||||
|
||||
val calendarEntries: List<CalendarEntry>
|
||||
get() = calendarCells.asSequence().flatten().toList()
|
||||
|
||||
var maxTime = 0
|
||||
var minTime = 0
|
||||
|
||||
|
@ -167,20 +168,17 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
|
|||
init {
|
||||
calendarBodies += this
|
||||
|
||||
calendarEntries = view.getElementsByClassName("calendar-entry")
|
||||
.iterator().asSequence().map { CalendarEntry(this, it) }.toList()
|
||||
|
||||
wrapContent {
|
||||
CalendarRow(this, it)
|
||||
}
|
||||
|
||||
ScheduleRepository.onCreate {
|
||||
launch {
|
||||
val schedule = ScheduleRepository.get(it) ?: throw NoSuchElementException()
|
||||
val schedule = ScheduleRepository.get(it) ?: return@launch
|
||||
|
||||
updateRows(schedule.time, schedule.workGroup.length)
|
||||
|
||||
calendarEntries += CalendarEntry.create(this, schedule)
|
||||
CalendarEntry.create(this, schedule)
|
||||
|
||||
calendar.updateVisibility()
|
||||
}
|
||||
|
@ -188,7 +186,7 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
|
|||
|
||||
ScheduleRepository.onUpdate {
|
||||
launch {
|
||||
val schedule = ScheduleRepository.get(it) ?: throw NoSuchElementException()
|
||||
val schedule = ScheduleRepository.get(it) ?: return@launch
|
||||
|
||||
updateRows(schedule.time, schedule.workGroup.length)
|
||||
|
||||
|
@ -200,7 +198,7 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
|
|||
}
|
||||
}
|
||||
if (!found) {
|
||||
calendarEntries += CalendarEntry.create(this, schedule)
|
||||
CalendarEntry.create(this, schedule)
|
||||
}
|
||||
|
||||
updateRows()
|
||||
|
@ -211,7 +209,6 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
|
|||
for (entry in calendarEntries) {
|
||||
if (entry.scheduleId == it) {
|
||||
entry.html.remove()
|
||||
calendarEntries -= entry
|
||||
|
||||
launch {
|
||||
updateRows()
|
||||
|
|
|
@ -35,6 +35,12 @@ class CalendarCell(val row: CalendarRow, view: HTMLElement) : ViewCollection<Cal
|
|||
hidden = row.calendar.calendar.isRoomHidden(roomId)
|
||||
}
|
||||
|
||||
init {
|
||||
wrapContent("calendar-entry") {
|
||||
CalendarEntry(row.calendar, it)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun create(row: CalendarRow, roomId: Long): CalendarCell {
|
||||
val view = createHtmlView<HTMLDivElement>()
|
||||
|
|
|
@ -3,10 +3,7 @@ package de.kif.frontend.views.calendar
|
|||
import de.kif.frontend.repository.RoomRepository
|
||||
import de.westermann.kwebview.ViewCollection
|
||||
import de.westermann.kwebview.createHtmlView
|
||||
import org.w3c.dom.HTMLDivElement
|
||||
import org.w3c.dom.HTMLElement
|
||||
import org.w3c.dom.HTMLSpanElement
|
||||
import org.w3c.dom.set
|
||||
import org.w3c.dom.*
|
||||
|
||||
class CalendarRow(val calendar: CalendarBody, view: HTMLElement) : ViewCollection<CalendarCell>(view) {
|
||||
val day = calendar.day
|
||||
|
@ -21,7 +18,9 @@ class CalendarRow(val calendar: CalendarBody, view: HTMLElement) : ViewCollectio
|
|||
|
||||
init {
|
||||
wrapContent {
|
||||
if (it.dataset["room"] != null)
|
||||
CalendarCell(this, it)
|
||||
else null
|
||||
}
|
||||
|
||||
RoomRepository.onCreate {
|
||||
|
|
|
@ -10,13 +10,15 @@ abstract class ViewCollection<V : View>(view: HTMLElement = createHtmlView()) :
|
|||
|
||||
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()) {
|
||||
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) {
|
||||
children += view
|
||||
|
|
Loading…
Reference in a new issue