Add auto constraint check
This commit is contained in:
parent
e7bdaabca8
commit
7d3a279ff1
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue