Update brett

This commit is contained in:
Lars Westermann 2019-06-10 17:56:21 +02:00
parent d52ada1726
commit 0026643a0a
Signed by: lars.westermann
GPG key ID: 9D417FA5BB9D5E1D
11 changed files with 197 additions and 71 deletions

View file

@ -26,7 +26,7 @@ object ScheduleRepository : Repository<Schedule> {
}
suspend fun getUpcoming(count: Int = 8): List<Schedule> {
val json = repositoryGet("$prefix/api/schedule/upcoming?count=$count") ?: return emptyList()
val json = repositoryGet("$prefix/api/schedules/upcoming?count=$count") ?: return emptyList()
return parser.parse(json, Schedule.serializer().list)
}

View file

@ -3,8 +3,9 @@ package de.kif.frontend.views.board
import com.soywiz.klock.DateFormat
import com.soywiz.klock.DateTimeTz
import com.soywiz.klock.KlockLocale
import com.soywiz.klock.format
import com.soywiz.klock.locale.german
import de.kif.frontend.launch
import de.kif.frontend.repository.ScheduleRepository
import de.kif.frontend.views.overview.getByClassOrCreate
import de.westermann.kwebview.interval
import de.westermann.kwebview.iterator
@ -12,6 +13,7 @@ import org.w3c.dom.HTMLElement
import org.w3c.dom.HTMLSpanElement
import org.w3c.dom.get
import kotlin.browser.document
import kotlin.dom.clear
import kotlin.js.Date
fun initBoard() {
@ -20,16 +22,37 @@ fun initBoard() {
val timeView = dateContainer.getByClassOrCreate<HTMLSpanElement>("board-header-date-time")
val dateView = dateContainer.getByClassOrCreate<HTMLSpanElement>("board-header-date-date")
val initTime = Date.now().toLong()
val initTime = Date.now().toLong()
val referenceInitTime = dateContainer.dataset["now"]?.toLongOrNull() ?: initTime
val diff = initTime - referenceInitTime
val boardRunning = document.getElementsByClassName("board-running")[0] as HTMLElement
val scheduleList = mutableListOf<BoardSchedule>()
val runningReferenceTime = boardRunning.dataset["reference"]?.toLongOrNull() ?: 0L
fun update() {
launch {
scheduleList.clear()
val list = ScheduleRepository.getUpcoming()
boardRunning.clear()
val now = Date.now().toLong() + diff
for (s in list) {
val v = BoardSchedule.create(s, runningReferenceTime, now)
scheduleList += v
boardRunning.appendChild(v.html)
}
}
}
for (bs in boardRunning.getElementsByClassName("board-schedule").iterator()) {
scheduleList += BoardSchedule(bs)
scheduleList += BoardSchedule(bs).also {
it.onRemove {
update()
}
}
}
interval(1000) {
@ -48,4 +71,14 @@ fun initBoard() {
scheduleList.forEach { it.updateTime(now) }
}
ScheduleRepository.onCreate {
update()
}
ScheduleRepository.onUpdate {
update()
}
ScheduleRepository.onDelete {
update()
}
}

View file

@ -1,36 +1,67 @@
package de.kif.frontend.views.board
import de.kif.common.formatDateTime
import de.kif.common.formatTimeDiff
import de.kif.common.model.Schedule
import de.kif.frontend.views.overview.getByClassOrCreate
import de.westermann.kobserve.event.EventHandler
import de.westermann.kwebview.View
import de.westermann.kwebview.createHtmlView
import org.w3c.dom.HTMLDivElement
import org.w3c.dom.HTMLElement
import org.w3c.dom.HTMLSpanElement
import org.w3c.dom.get
import kotlin.js.Date
class BoardSchedule(
view: HTMLElement
view: HTMLElement,
startTime: Long = 0L,
endTime: Long = 0L
) : View(view) {
private val colorView = view.getByClassOrCreate<HTMLDivElement>("board-schedule-color")
private val timeView = view.getByClassOrCreate<HTMLDivElement>("board-schedule-time")
private val nameView = view.getByClassOrCreate<HTMLDivElement>("board-schedule-name")
private val roomView = view.getByClassOrCreate<HTMLDivElement>("board-schedule-room")
val colorViewContainer = view.getByClassOrCreate<HTMLDivElement>("board-schedule-color")
val colorView = colorViewContainer.getByClassOrCreate<HTMLSpanElement>("bsc")
val timeView = view.getByClassOrCreate<HTMLDivElement>("board-schedule-time")
val nameView = view.getByClassOrCreate<HTMLDivElement>("board-schedule-name")
val roomView = view.getByClassOrCreate<HTMLDivElement>("board-schedule-room")
private val schedule: Long = view.dataset["id"]?.toLongOrNull() ?: 0L
private val startTime: Long = timeView.dataset["startTime"]?.toLongOrNull() ?: 0L
private val endTime: Long = timeView.dataset["endTime"]?.toLongOrNull() ?: 0L
val clockViewContainer = view.getByClassOrCreate<HTMLDivElement>("board-schedule-clock")
val clockView = clockViewContainer.getByClassOrCreate<HTMLElement>("material-icons", "i").also {
it.textContent = "alarm"
}
private val startTime: Long = timeView.dataset["startTime"]?.toLongOrNull() ?: startTime
private val endTime: Long = timeView.dataset["endTime"]?.toLongOrNull() ?: endTime
val onRemove = EventHandler<Unit>()
fun updateTime(now: Long) {
timeView.textContent = if (startTime >= now) {
"Start in ${formatTimeDiff(startTime - now)}"
} else {
"Ende in ${formatTimeDiff(endTime - now)}"
timeView.textContent = when {
startTime >= now -> "Start ${formatTimeDiff(startTime, now)}"
endTime >= now -> "Ende ${formatTimeDiff(endTime, now)}"
else -> {
onRemove.emit(Unit)
"---"
}
}
classList["board-schedule-running"] = now in startTime..endTime
}
init {
companion object {
fun create(schedule: Schedule, referenceTime: Long, now: Long): BoardSchedule {
val startTime = ((schedule.getAbsoluteStartTime() * 60 * 1000) + referenceTime)
val endTime = ((schedule.getAbsoluteEndTime() * 60 * 1000) + referenceTime)
val entry = BoardSchedule(createHtmlView(), startTime, endTime)
if (schedule.workGroup.track?.color != null) {
entry.colorView.style.backgroundColor = schedule.workGroup.track.color.toString()
}
entry.nameView.textContent = schedule.workGroup.name
entry.roomView.textContent = schedule.room.name
entry.updateTime(now)
return entry
}
}
}

View file

@ -22,6 +22,17 @@
&:first-child {
width: 70%;
float: left;
overflow: visible;
&:after {
content: '';
position: absolute;
top: -1rem;
bottom: 0;
left: 100%;
margin-left: 1rem;
border-right: solid 1px var(--table-border-color);
}
}
&:last-child {
@ -38,6 +49,16 @@
& > div {
height: 100%;
}
&:after {
content: '';
position: absolute;
left: 0;
width: 100%;
top: 100%;
margin-top: 0.5rem;
border-bottom: solid 1px var(--table-border-color);
}
}
.board-content {
@ -71,10 +92,23 @@
border-bottom: solid 1px var(--table-border-color);
width: calc(50% - 1rem);
margin-left: 1rem;
position: relative;
&:nth-last-child(1), &:nth-last-child(2) {
border-bottom: none;
}
.board-schedule-clock {
position: absolute;
left: 1rem;
top: 0;
display: none;
color: var(--primary-color);
}
&.board-schedule-running .board-schedule-clock {
display: block;
}
}
.board-schedule-color {

View file

@ -504,7 +504,7 @@
content: '';
display: block;
position: absolute;
top: 3rem;
top: 0.1rem;
bottom: 0;
width: 1px;
border-right: solid 1px var(--primary-color);
@ -514,7 +514,7 @@
content: '';
display: block;
position: absolute;
top: 3rem;
top: 0.1rem;
transform: scale(0.5, 1) rotate(45deg);
transform-origin: right;
border-bottom: solid 0.4rem var(--primary-color);