This commit is contained in:
Lars Westermann 2019-06-13 05:00:34 +02:00
parent 6db71915b4
commit f02124cbe8
Signed by: lars.westermann
GPG key ID: 9D417FA5BB9D5E1D
5 changed files with 54 additions and 21 deletions

View file

@ -164,8 +164,8 @@ fun checkConstraints(
if ( if (
s.workGroup.id == constraint.workGroup && s.workGroup.id == constraint.workGroup &&
schedule.day == s.day && schedule.day == s.day &&
start <= s.getAbsoluteEndTime() && start < s.getAbsoluteEndTime() &&
s.getAbsoluteStartTime() <= end s.getAbsoluteStartTime() < end
) { ) {
errors += ConstraintError("Work group requires not same time with ${s.workGroup.name}!") errors += ConstraintError("Work group requires not same time with ${s.workGroup.name}!")
} }

View file

@ -26,11 +26,11 @@ class Calendar(calendar: HTMLElement) : View(calendar) {
private val htmlBody = document.body ?: createHtmlView() private val htmlBody = document.body ?: createHtmlView()
val day = calendarTable.dataset["day"]?.toIntOrNull() ?: -1 val day = (calendarTable.dataset["day"]?.toIntOrNull() ?: -1).also { println(it) }
val reloadOnFinish = calendarTable.dataset["reload"]?.toBoolean() ?: false val reloadOnFinish = (calendarTable.dataset["reload"]?.toBoolean() ?: false).also { println(it) }
val referenceDate = calendarTable.dataset["reference"]?.toLongOrNull() ?: -1L val referenceDate = (calendarTable.dataset["reference"]?.toLongOrNull() ?: -1L).also { println(it) }
val nowDate = calendarTable.dataset["now"]?.toLongOrNull() ?: -1L val nowDate = (calendarTable.dataset["now"]?.toLongOrNull() ?: -1L).also { println(it) }
val timeDifference = Date.now().toLong() - nowDate val timeDifference = (Date.now().toLong() - nowDate).also { println(it) }
fun scrollVerticalBy(pixel: Double, scrollBehavior: ScrollBehavior = ScrollBehavior.SMOOTH) { fun scrollVerticalBy(pixel: Double, scrollBehavior: ScrollBehavior = ScrollBehavior.SMOOTH) {
scrollAllVerticalBy(pixel, scrollBehavior) scrollAllVerticalBy(pixel, scrollBehavior)

View file

@ -15,6 +15,13 @@ import kotlin.js.Date
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
fun getYearOfDate(date: Date): Int {
return ((Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) - Date.UTC(
date.getFullYear(),
0,
0
)) / 24 / 60 / 60 / 1000).toInt()
}
class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<CalendarRow>(view) { class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<CalendarRow>(view) {
@ -26,6 +33,9 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
val calendarCells: List<CalendarCell> val calendarCells: List<CalendarCell>
get() = iterator().asSequence().flatten().toList() get() = iterator().asSequence().flatten().toList()
var maxTime = 0
var minTime = 0
private suspend fun updateRows(startTime: Int? = null, length: Int = 0) { private suspend fun updateRows(startTime: Int? = null, length: Int = 0) {
if (calendarEntries.isEmpty() && startTime == null && !editable) { if (calendarEntries.isEmpty() && startTime == null && !editable) {
for (row in iterator().asSequence().toList()) { for (row in iterator().asSequence().toList()) {
@ -64,6 +74,18 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
min = (min / 60 - 1) * 60 min = (min / 60 - 1) * 60
max = (max / 60 + 2) * 60 max = (max / 60 + 2) * 60
if (min == minTime && max == maxTime) return
minTime = min
maxTime = max
min = calendarBodies.map { it.minTime }.min() ?: min
max = calendarBodies.map { it.maxTime }.max() ?: max
calendarBodies.filter { it != this }.forEach {
it.updateRows()
}
while (isNotEmpty() && min > first().time) { while (isNotEmpty() && min > first().time) {
remove(first()) remove(first())
} }
@ -87,10 +109,11 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
fun update(scroll: ScrollBehavior) { fun update(scroll: ScrollBehavior) {
val now = Date.now().toLong() - calendar.timeDifference val now = Date.now().toLong() - calendar.timeDifference
val refDay = calendar.referenceDate / (1000 * 60 * 60 * 24) val refDay = getYearOfDate(Date(calendar.referenceDate))
val nowDay = now / (1000 * 60 * 60 * 24) val nowDay = getYearOfDate(Date(now))
val d = nowDay - refDay val d = nowDay - refDay
val diff = (day - d).toInt() val diff = (day - d)
val date = Date(now) val date = Date(now)
val currentTime = date.getHours() * 60 + date.getMinutes() + (diff * 60 * 24) val currentTime = date.getHours() * 60 + date.getMinutes() + (diff * 60 * 24)
@ -140,6 +163,8 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
} }
init { init {
calendarBodies += this
calendarEntries = view.getElementsByClassName("calendar-entry") calendarEntries = view.getElementsByClassName("calendar-entry")
.iterator().asSequence().map { CalendarEntry(this, it) }.toList() .iterator().asSequence().map { CalendarEntry(this, it) }.toList()
@ -198,4 +223,8 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection<C
update(ScrollBehavior.SMOOTH) update(ScrollBehavior.SMOOTH)
} }
} }
companion object {
val calendarBodies: MutableList<CalendarBody> = mutableListOf()
}
} }

View file

@ -51,10 +51,11 @@ fun Route.board() {
val referenceTime = Configuration.Schedule.referenceDate.time val referenceTime = Configuration.Schedule.referenceDate.time
val refDate = Configuration.Schedule.referenceDate val refDate = Configuration.Schedule.referenceDate
val todayDate = now
val refDay = refDate.time / (1000 * 60 * 60 * 24) val refDay = Calendar.getInstance().also { it.time = todayDate }.get(Calendar.DAY_OF_YEAR)
val todayDay = now.time / (1000 * 60 * 60 * 24) val todayDay = Calendar.getInstance().also { it.time = refDate }.get(Calendar.DAY_OF_YEAR)
val day = (todayDay - refDay).toInt() val day = todayDay - refDay
val list = ScheduleRepository.getByDay(day) val list = ScheduleRepository.getByDay(day)
val rooms = RoomRepository.all() val rooms = RoomRepository.all()

View file

@ -1,7 +1,7 @@
package de.kif.backend.route package de.kif.backend.route
import com.soywiz.klock.* import com.soywiz.klock.DateTime
import com.soywiz.klock.jvm.toDateTime import com.soywiz.klock.days
import de.kif.backend.Configuration import de.kif.backend.Configuration
import de.kif.backend.isAuthenticated import de.kif.backend.isAuthenticated
import de.kif.backend.prefix import de.kif.backend.prefix
@ -77,10 +77,13 @@ fun DIV.renderCalendar(
val gridLabelWidth = 60 val gridLabelWidth = 60
val minutesOfDay = to - from val minutesOfDay = to - from
val refDate = Configuration.Schedule.referenceDate
val todayDate = Date()
val now = Calendar.getInstance() val now = Calendar.getInstance()
val d = (now.timeInMillis / (1000 * 60 * 60 * 24) - val refDay = Calendar.getInstance().also { it.time = todayDate }.get(Calendar.DAY_OF_YEAR)
Configuration.Schedule.referenceDate.time / (1000 * 60 * 60 * 24)).toInt() val todayDay = Calendar.getInstance().also { it.time = refDate }.get(Calendar.DAY_OF_YEAR)
val diff = day - d val diff = day - (todayDay - refDay)
val currentTime = now.get(Calendar.HOUR_OF_DAY) * 60 + now.get(Calendar.MINUTE) + (diff * 60 * 24) val currentTime = now.get(Calendar.HOUR_OF_DAY) * 60 + now.get(Calendar.MINUTE) + (diff * 60 * 24)
div("calendar-table") { div("calendar-table") {
@ -188,8 +191,8 @@ fun Route.calendar() {
val refDate = Configuration.Schedule.referenceDate val refDate = Configuration.Schedule.referenceDate
val todayDate = Date() val todayDate = Date()
val refDay = refDate.time / (1000 * 60 * 60 * 24) val refDay = Calendar.getInstance().also { it.time = todayDate }.get(Calendar.DAY_OF_YEAR)
val todayDay = todayDate.time / (1000 * 60 * 60 * 24) val todayDay = Calendar.getInstance().also { it.time = refDate }.get(Calendar.DAY_OF_YEAR)
val day = todayDay - refDay val day = todayDay - refDay
call.respondRedirect("$prefix/calendar/$day", false) call.respondRedirect("$prefix/calendar/$day", false)