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,6 +49,26 @@ class Calendar(calendar: HTMLElement) : View(calendar) {
Orientation.ROOM_TO_TIME
}
private var autoCheck: Boolean = false
fun autoCheck() {
if (autoCheck) checkConstraints()
}
private fun checkConstraints() {
launch {
val errors = ScheduleRepository.checkConstraints()
for ((s, l) in errors.map) {
for (entry in body.calendarEntries) {
if (entry.scheduleId == s) {
entry.setError(l)
}
}
}
}
}
init {
scroll += calendarTable
@ -56,18 +76,29 @@ class Calendar(calendar: HTMLElement) : View(calendar) {
CalendarEdit(this, calendar.querySelector(".calendar-edit") as HTMLElement)
}
(document.getElementById("calendar-check-constraints") as? HTMLElement)?.let { wrap(it) }
?.onClick?.addListener {
launch {
val errors = ScheduleRepository.checkConstraints()
val checkConstraintsBtn =
(document.getElementById("calendar-check-constraints") as? HTMLElement)?.let { wrap(it) }
if (checkConstraintsBtn != null) {
checkConstraintsBtn.onClick.addListener {
checkConstraints()
}
}
for ((s, l) in errors.map) {
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) {
if (entry.scheduleId == s) {
entry.setError(l)
}
entry.setError(emptyList())
}
autoCheck = false
} else {
autoCheck = true
autoCheck()
}
autoCheckConstraintsBtn.classList["btn-primary"] = autoCheck
}
}

View file

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

View file

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

View file

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