Add auto constraint check
This commit is contained in:
parent
e7bdaabca8
commit
7d3a279ff1
4 changed files with 76 additions and 26 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue