Add auto constraint check

This commit is contained in:
Lars Westermann 2019-06-11 15:57:39 +02:00
parent e7bdaabca8
commit 7d3a279ff1
Signed by: lars.westermann
GPG key ID: 9D417FA5BB9D5E1D
4 changed files with 76 additions and 26 deletions

View file

@ -49,15 +49,13 @@ class Calendar(calendar: HTMLElement) : View(calendar) {
Orientation.ROOM_TO_TIME Orientation.ROOM_TO_TIME
} }
init { private var autoCheck: Boolean = false
scroll += calendarTable
if (editable) { fun autoCheck() {
CalendarEdit(this, calendar.querySelector(".calendar-edit") as HTMLElement) if (autoCheck) checkConstraints()
} }
(document.getElementById("calendar-check-constraints") as? HTMLElement)?.let { wrap(it) } private fun checkConstraints() {
?.onClick?.addListener {
launch { launch {
val errors = ScheduleRepository.checkConstraints() val errors = ScheduleRepository.checkConstraints()
@ -71,6 +69,39 @@ class Calendar(calendar: HTMLElement) : View(calendar) {
} }
} }
init {
scroll += calendarTable
if (editable) {
CalendarEdit(this, calendar.querySelector(".calendar-edit") as HTMLElement)
}
val checkConstraintsBtn =
(document.getElementById("calendar-check-constraints") as? HTMLElement)?.let { wrap(it) }
if (checkConstraintsBtn != null) {
checkConstraintsBtn.onClick.addListener {
checkConstraints()
}
}
val autoCheckConstraintsBtn =
(document.getElementById("calendar-auto-check-constraints") as? HTMLElement)?.let { wrap(it) }
if (autoCheckConstraintsBtn != null) {
autoCheckConstraintsBtn.onClick.addListener {
if (autoCheck) {
for (entry in body.calendarEntries) {
entry.setError(emptyList())
}
autoCheck = false
} else {
autoCheck = true
autoCheck()
}
autoCheckConstraintsBtn.classList["btn-primary"] = autoCheck
}
}
onWheel { onWheel {
autoScroll = false autoScroll = false

View file

@ -243,6 +243,8 @@ class CalendarEntry(private val calendar: CalendarBody, view: HTMLElement) : Vie
if (cell != null && cell.html != html.parentElement) { if (cell != null && cell.html != html.parentElement) {
cell += this cell += this
} }
calendar.calendar.autoCheck()
} }
fun load(workGroup: WorkGroup) { fun load(workGroup: WorkGroup) {

View file

@ -216,12 +216,6 @@ fun Route.calendar() {
val range = ScheduleRepository.getDayRange() val range = ScheduleRepository.getDayRange()
/*
if (!editable && day !in range) {
return@get
}
*/
val rooms = RoomRepository.all() val rooms = RoomRepository.all()
val tracks = TrackRepository.all() val tracks = TrackRepository.all()
@ -283,6 +277,7 @@ fun Route.calendar() {
} }
} }
div("header-right") { div("header-right") {
div {
a("$prefix/calendar/$day/rtt", classes = "form-btn") { a("$prefix/calendar/$day/rtt", classes = "form-btn") {
+"Vertikal" +"Vertikal"
} }
@ -290,13 +285,22 @@ fun Route.calendar() {
+"Horizontal" +"Horizontal"
} }
if (editable) { if (editable) {
button(classes = "form-btn") {
id = "calendar-edit-button"
+"Bearbeiten"
}
}
}
if (editable) {
div {
button(classes = "form-btn") { button(classes = "form-btn") {
id = "calendar-check-constraints" id = "calendar-check-constraints"
+"Constraints überprüfen" +"Constraints überprüfen"
} }
button(classes = "form-btn") { button(classes = "form-btn") {
id = "calendar-edit-button" id = "calendar-auto-check-constraints"
+"Bearbeiten" +"Auto check"
}
} }
} }
} }

View file

@ -11,6 +11,8 @@ import io.ktor.application.call
import io.ktor.http.HttpStatusCode import io.ktor.http.HttpStatusCode
import io.ktor.routing.Route import io.ktor.routing.Route
import io.ktor.routing.get import io.ktor.routing.get
import kotlinx.html.currentTimeMillis
import kotlin.concurrent.thread
object PushService { object PushService {
@ -101,4 +103,15 @@ fun Route.pushService() {
WorkGroupRepository.registerPushService() WorkGroupRepository.registerPushService()
PostRepository.registerPushService() PostRepository.registerPushService()
AnnouncementRepository.registerPushService() AnnouncementRepository.registerPushService()
thread(
start = true,
isDaemon = true,
name = "PushServiceGC"
) {
while (true) {
PushService.gc(currentTimeMillis() - 1000 * 60)
Thread.sleep(1000 * 60 * 5)
}
}
} }