Mark old schedules as finished

This commit is contained in:
Lars Westermann 2019-06-12 14:03:26 +02:00
parent 6d243f2903
commit 90b4a990af
Signed by: lars.westermann
GPG key ID: 9D417FA5BB9D5E1D
5 changed files with 56 additions and 26 deletions

View file

@ -126,6 +126,10 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
calendar.scrollHorizontalTo((activeRow.offsetLeft - 100).toDouble(), scroll)
}
}
for (entry in calendarEntries) {
entry.updateTime(diff, currentTime)
}
}
init {

View file

@ -35,6 +35,13 @@ class CalendarEntry(private val calendar: CalendarBody, view: HTMLElement) : Vie
var startTime = dataset["time"]?.toIntOrNull() ?: 0
var length = dataset["length"]?.toIntOrNull() ?: 0
private val finishedProperty = dataset.property("finished")
var finished: Boolean
get() = finishedProperty.value == "true"
set(value) {
finishedProperty.value = value.toString()
}
var pending by classList.property("pending")
private var error by classList.property("error")
private var nextScroll = 0.0
@ -218,6 +225,7 @@ class CalendarEntry(private val calendar: CalendarBody, view: HTMLElement) : Vie
if (schedule.id != null) scheduleId = schedule.id
this.schedule.set(schedule)
html.removeAttribute("style")
style {
val pos = (schedule.time % CALENDAR_GRID_WIDTH) / CALENDAR_GRID_WIDTH.toDouble()
@ -251,7 +259,6 @@ class CalendarEntry(private val calendar: CalendarBody, view: HTMLElement) : Vie
language = workGroup.language.code
this.workGroup = workGroup
html.removeAttribute("style")
style {
val size = workGroup.length / CALENDAR_GRID_WIDTH.toDouble()
@ -274,6 +281,10 @@ class CalendarEntry(private val calendar: CalendarBody, view: HTMLElement) : Vie
calendarErrors?.setErrors(errors)
}
fun updateTime(diff: Int, currentTime: Int) {
finished = (diff < 0 || diff == 0 && startTime + length < currentTime)
}
companion object {
fun create(calendar: CalendarBody, schedule: Schedule): CalendarEntry {
val entry = CalendarEntry(calendar, createHtmlView())

View file

@ -31,7 +31,7 @@
bottom: 0;
left: 100%;
margin-left: 1rem;
border-right: solid 1px var(--input-border-color);
border-right: solid 1px var(--table-border-color);
}
}

View file

@ -302,6 +302,18 @@
outline: solid 0.4rem var(--error-color);
}
&[data-finished = "true"]::before {
content: '';
display: block;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: var(--background-primary-color);
opacity: 0.6;
}
@include no-select()
}

View file

@ -32,8 +32,7 @@ import kotlin.math.min
const val MINUTES_OF_DAY = 24 * 60
private fun DIV.calendarCell(schedule: Schedule?) {
if (schedule != null) {
private fun DIV.calendarEntry(schedule: Schedule, diff: Int, currentTime: Int) {
span("calendar-entry") {
attributes["style"] = CSSBuilder().apply {
val size = schedule.workGroup.length / CALENDAR_GRID_WIDTH.toDouble()
@ -56,11 +55,13 @@ private fun DIV.calendarCell(schedule: Schedule?) {
attributes["data-time"] = schedule.time.toString()
attributes["data-length"] = schedule.workGroup.length.toString()
val finished = (diff < 0 || diff == 0 && schedule.time + schedule.workGroup.length < currentTime)
attributes["data-finished"] = finished.toString()
span("calendar-entry-name") {
+schedule.workGroup.name
}
}
}
}
fun DIV.renderCalendar(
@ -145,7 +146,9 @@ fun DIV.renderCalendar(
val schedule = (start..end).mapNotNull { schedules[room]?.get(it) }.firstOrNull()
calendarCell(schedule)
if (schedule != null) {
calendarEntry(schedule, diff, currentTime)
}
}
}
}