Reload page on server restart
This commit is contained in:
parent
f9149bef25
commit
8913ccc3ce
|
@ -9,6 +9,7 @@ import kotlinx.serialization.modules.SerializersModule
|
||||||
@Serializable
|
@Serializable
|
||||||
data class MessageBox(
|
data class MessageBox(
|
||||||
val timestamp: Long,
|
val timestamp: Long,
|
||||||
|
val signature: String,
|
||||||
val valid: Boolean,
|
val valid: Boolean,
|
||||||
val messages: List<Message>
|
val messages: List<Message>
|
||||||
)
|
)
|
||||||
|
|
|
@ -20,6 +20,7 @@ class PushServiceClient {
|
||||||
private val parser = DynamicObjectParser()
|
private val parser = DynamicObjectParser()
|
||||||
|
|
||||||
private var timestamp = body.dataset["timestamp"]?.toLongOrNull() ?: 0L
|
private var timestamp = body.dataset["timestamp"]?.toLongOrNull() ?: 0L
|
||||||
|
private val signature = body.dataset["signature"] ?: ""
|
||||||
private var intervalId: Int? = null
|
private var intervalId: Int? = null
|
||||||
|
|
||||||
private fun reload() {
|
private fun reload() {
|
||||||
|
@ -33,7 +34,7 @@ class PushServiceClient {
|
||||||
private fun onMessage(messageBox: MessageBox) {
|
private fun onMessage(messageBox: MessageBox) {
|
||||||
body.classList.remove("offline")
|
body.classList.remove("offline")
|
||||||
|
|
||||||
if (messageBox.valid) {
|
if (messageBox.valid && signature == messageBox.signature) {
|
||||||
timestamp = messageBox.timestamp
|
timestamp = messageBox.timestamp
|
||||||
|
|
||||||
for (message in messageBox.messages) {
|
for (message in messageBox.messages) {
|
||||||
|
|
|
@ -85,6 +85,22 @@
|
||||||
.board-running {
|
.board-running {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
|
|
||||||
|
&:empty + .board-running-empty {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.board-running-empty {
|
||||||
|
position: absolute !important;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
height: 8rem;
|
||||||
|
line-height: 8rem;
|
||||||
|
width: 70%;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 1.7rem;
|
||||||
|
font-family: $headFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
.board-schedule {
|
.board-schedule {
|
||||||
|
|
|
@ -89,13 +89,12 @@ fun Route.board() {
|
||||||
val nowLocale = now.time + timeOffset
|
val nowLocale = now.time + timeOffset
|
||||||
respondMain(true, true) { theme ->
|
respondMain(true, true) { theme ->
|
||||||
content {
|
content {
|
||||||
|
|
||||||
val announcement = AnnouncementRepository.getAnnouncement()
|
val announcement = AnnouncementRepository.getAnnouncement()
|
||||||
var classes = "board-announcement announcement"
|
var announcementClasses = "board-announcement announcement"
|
||||||
if (announcement.isBlank()) {
|
if (announcement.isBlank()) {
|
||||||
classes += " announcement-blank"
|
announcementClasses += " announcement-blank"
|
||||||
}
|
}
|
||||||
div(classes) {
|
div(announcementClasses) {
|
||||||
span {
|
span {
|
||||||
+announcement
|
+announcement
|
||||||
}
|
}
|
||||||
|
@ -155,6 +154,11 @@ fun Route.board() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
div("board-running-empty") {
|
||||||
|
span {
|
||||||
|
+"Es sind keine weiteren AKs geplant"
|
||||||
|
}
|
||||||
|
}
|
||||||
div("board-logo") {
|
div("board-logo") {
|
||||||
img("KIF 47.0", "$prefix/static/images/logo.svg")
|
img("KIF 47.0", "$prefix/static/images/logo.svg")
|
||||||
div("board-header-date") {
|
div("board-header-date") {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import de.kif.common.Message
|
||||||
import de.kif.common.MessageBox
|
import de.kif.common.MessageBox
|
||||||
import de.kif.common.MessageType
|
import de.kif.common.MessageType
|
||||||
import de.kif.common.RepositoryType
|
import de.kif.common.RepositoryType
|
||||||
|
import de.kif.common.model.Post
|
||||||
import io.ktor.application.call
|
import io.ktor.application.call
|
||||||
import io.ktor.http.HttpStatusCode
|
import io.ktor.http.HttpStatusCode
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
|
@ -16,7 +17,8 @@ import kotlin.concurrent.thread
|
||||||
|
|
||||||
object PushService {
|
object PushService {
|
||||||
|
|
||||||
private var leastValidTimestamp = System.currentTimeMillis()
|
internal var leastValidTimestamp = System.currentTimeMillis()
|
||||||
|
val signature = Post.generateUrl()
|
||||||
|
|
||||||
private val messages: MutableList<Pair<Long, Message>> = mutableListOf()
|
private val messages: MutableList<Pair<Long, Message>> = mutableListOf()
|
||||||
|
|
||||||
|
@ -52,6 +54,7 @@ object PushService {
|
||||||
return if (timestamp < leastValidTimestamp) {
|
return if (timestamp < leastValidTimestamp) {
|
||||||
MessageBox(
|
MessageBox(
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
|
signature,
|
||||||
false,
|
false,
|
||||||
emptyList()
|
emptyList()
|
||||||
)
|
)
|
||||||
|
@ -63,6 +66,7 @@ object PushService {
|
||||||
|
|
||||||
MessageBox(
|
MessageBox(
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
|
signature,
|
||||||
true,
|
true,
|
||||||
m.map { it.second }
|
m.map { it.second }
|
||||||
)
|
)
|
||||||
|
@ -84,6 +88,8 @@ object PushService {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Route.pushService() {
|
fun Route.pushService() {
|
||||||
|
PushService.leastValidTimestamp = System.currentTimeMillis()
|
||||||
|
|
||||||
get("/api/updates") {
|
get("/api/updates") {
|
||||||
try {
|
try {
|
||||||
val timestamp = call.request.queryParameters["timestamp"]?.toLongOrNull() ?: 0
|
val timestamp = call.request.queryParameters["timestamp"]?.toLongOrNull() ?: 0
|
||||||
|
|
|
@ -4,6 +4,7 @@ import de.kif.backend.PortalSession
|
||||||
import de.kif.backend.Resources
|
import de.kif.backend.Resources
|
||||||
import de.kif.backend.prefix
|
import de.kif.backend.prefix
|
||||||
import de.kif.backend.repository.AnnouncementRepository
|
import de.kif.backend.repository.AnnouncementRepository
|
||||||
|
import de.kif.backend.util.PushService
|
||||||
import de.kif.common.model.User
|
import de.kif.common.model.User
|
||||||
import io.ktor.application.ApplicationCall
|
import io.ktor.application.ApplicationCall
|
||||||
import io.ktor.application.call
|
import io.ktor.application.call
|
||||||
|
@ -75,6 +76,7 @@ class MainTemplate(
|
||||||
}
|
}
|
||||||
body {
|
body {
|
||||||
attributes["data-timestamp"] = currentTimeMillis().toString()
|
attributes["data-timestamp"] = currentTimeMillis().toString()
|
||||||
|
attributes["data-signature"] = PushService.signature
|
||||||
|
|
||||||
if (!noMenu) {
|
if (!noMenu) {
|
||||||
insert(MenuTemplate(url, user)) {}
|
insert(MenuTemplate(url, user)) {}
|
||||||
|
|
Loading…
Reference in a new issue