This commit is contained in:
Lars Westermann 2019-06-12 23:01:08 +02:00
parent 36bdad8036
commit 8cdebf7f3b
Signed by: lars.westermann
GPG key ID: 9D417FA5BB9D5E1D
7 changed files with 109 additions and 10 deletions

View file

@ -5,12 +5,12 @@ prefix = "/plan"
debug = false
[schedule]
reference = "2019-06-12"
reference = "2019-06-13"
offset = 7200000
wall_start = 1
wall_start = 0
[reso]
day = 3
day = 2
time = 900
[general]

View file

@ -10,6 +10,11 @@ fun formatDateTime(unix: Long) =
.withLocale(KlockLocale.german)
.format(unix)
fun formatDate(unix: Long) =
DateFormat("EEEE, d. MMMM y")
.withLocale(KlockLocale.german)
.format(unix)
fun formatTimeDiff(time: Long, now: Long): String {
var dt = (time - now) / 1000

View file

@ -1,14 +1,13 @@
package de.kif.frontend.views
import de.kif.common.formatDate
import de.westermann.kwebview.View
import de.westermann.kwebview.components.InputType
import de.westermann.kwebview.components.InputView
import de.westermann.kwebview.components.TextView
import de.westermann.kwebview.createHtmlView
import de.westermann.kwebview.iterator
import org.w3c.dom.HTMLDivElement
import org.w3c.dom.HTMLElement
import org.w3c.dom.get
import org.w3c.dom.*
import kotlin.browser.document
fun initRoomConstraints() {
@ -19,6 +18,14 @@ fun initRoomConstraints() {
val addButton =
View.wrap(document.getElementsByClassName("room-constraints-add")[0] as HTMLElement)
val referenceDate = constraints.dataset["reference"]?.toLongOrNull() ?: 0L
fun updateDateView(inputGroup: HTMLElement, day: Int) {
val date = referenceDate + (day * 1000 * 60 * 60 * 24)
val dateName = formatDate(date)
inputGroup.dataset["hint"] = dateName
}
addButton.onClick {
constraints.appendChild(View.wrap(createHtmlView<HTMLDivElement>()) {
classList += "input-group"
@ -26,10 +33,18 @@ fun initRoomConstraints() {
classList += "form-btn"
onClick { this@wrap.html.remove() }
}.html)
html.appendChild(InputView(InputType.TEXT).apply {
html.appendChild(InputView(InputType.NUMBER).apply {
classList += "form-control"
html.name = "constraint-room-day-${index}"
placeholder = "Tag"
min = -1337.0
max = 1337.0
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
valueProperty.onChange {
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
}
}.html)
html.appendChild(InputView(InputType.TEXT).apply {
classList += "form-control"
@ -52,6 +67,17 @@ fun initRoomConstraints() {
println("click")
child.remove()
})
for (e in child.children.iterator()) {
if (e.classList.contains("-day-")) {
val input = InputView.wrap(e as HTMLInputElement)
updateDateView(child, input.value.toIntOrNull() ?: 0)
input.valueProperty.onChange {
updateDateView(child, input.value.toIntOrNull() ?: 0)
}
}
}
}
}
}

View file

@ -1,5 +1,6 @@
package de.kif.frontend.views
import de.kif.common.formatDate
import de.kif.frontend.launch
import de.kif.frontend.repository.RoomRepository
import de.kif.frontend.repository.WorkGroupRepository
@ -23,6 +24,8 @@ fun initWorkGroupConstraints() {
val addList =
ListView.wrap<View>(document.getElementsByClassName("work-group-constraints-add-list")[0] as HTMLElement)
val referenceDate = constraints.dataset["reference"]?.toLongOrNull() ?: 0L
addButton.onClick {
addList.classList += "active"
@ -36,6 +39,12 @@ fun initWorkGroupConstraints() {
}
}
fun updateDateView(inputGroup: HTMLElement, day: Int) {
val date = referenceDate + (day * 1000 * 60 * 60 * 24)
val dateName = formatDate(date)
inputGroup.dataset["hint"] = dateName
}
addList.textView("Nur an Tag x") {
onClick {
constraints.appendChild(View.wrap(createHtmlView<HTMLDivElement>()) {
@ -50,6 +59,11 @@ fun initWorkGroupConstraints() {
min = -1337.0
max = 1337.0
placeholder = "Tag"
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
valueProperty.onChange {
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
}
}.html)
}.html)
}
@ -68,6 +82,11 @@ fun initWorkGroupConstraints() {
min = -1337.0
max = 1337.0
placeholder = "Tag"
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
valueProperty.onChange {
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
}
}.html)
}.html)
}
@ -84,6 +103,11 @@ fun initWorkGroupConstraints() {
classList += "form-control"
html.name = "constraint-only-before-time-day-${index}"
placeholder = "Tag (optional)"
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
valueProperty.onChange {
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
}
}.html)
html.appendChild(InputView(InputType.TEXT).apply {
classList += "form-control"
@ -105,6 +129,11 @@ fun initWorkGroupConstraints() {
classList += "form-control"
html.name = "constraint-only-after-time-day-${index}"
placeholder = "Tag (optional)"
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
valueProperty.onChange {
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
}
}.html)
html.appendChild(InputView(InputType.TEXT).apply {
classList += "form-control"
@ -126,6 +155,11 @@ fun initWorkGroupConstraints() {
classList += "form-control"
html.name = "constraint-exact-time-day-${index}"
placeholder = "Tag (optional)"
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
valueProperty.onChange {
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
}
}.html)
html.appendChild(InputView(InputType.TEXT).apply {
classList += "form-control"
@ -243,6 +277,17 @@ fun initWorkGroupConstraints() {
span.addEventListener("click", org.w3c.dom.events.EventListener {
child.remove()
})
for (e in child.children.iterator()) {
if (e.classList.contains("-day-")) {
val input = InputView.wrap(e as HTMLInputElement)
updateDateView(child, input.value.toIntOrNull() ?: 0)
input.valueProperty.onChange {
updateDateView(child, input.value.toIntOrNull() ?: 0)
}
}
}
}
}
}

View file

@ -206,4 +206,15 @@ form {
border-bottom-right-radius: 0;
}
}
&:after {
content: attr(data-hint);
position: absolute;
left: 100%;
color: var(--text-secondary-color);
line-height: 2.5rem;
margin-left: 1rem;
width: 100%;
top: 2.3rem;
}
}

View file

@ -1,5 +1,6 @@
package de.kif.backend.route
import de.kif.backend.Configuration
import de.kif.backend.authenticateOrRedirect
import de.kif.backend.prefix
import de.kif.backend.repository.RoomRepository
@ -237,6 +238,8 @@ fun Route.room() {
}
div("form-group room-constraints") {
attributes["data-reference"] = Configuration.Schedule.referenceDate.time.toString()
label {
+"Sperrzeiten"
}
@ -244,7 +247,6 @@ fun Route.room() {
i("material-icons") { +"add" }
}
for ((index, constraint) in editRoom.blocked.withIndex()) {
div("input-group") {
span("form-btn") {
@ -252,10 +254,14 @@ fun Route.room() {
}
input(
name = "constraint-room-day-$index",
classes = "form-control"
classes = "form-control",
type = InputType.number
) {
value = constraint.day.toString()
min = "-1337"
max = "1337"
placeholder = "Tag"
}
input(
@ -477,6 +483,7 @@ fun Route.room() {
}
div("form-group room-constraints") {
attributes["data-reference"] = Configuration.Schedule.referenceDate.time.toString()
label {
+"Sperrzeiten"
}

View file

@ -1,5 +1,6 @@
package de.kif.backend.route
import de.kif.backend.Configuration
import de.kif.backend.authenticateOrRedirect
import de.kif.backend.prefix
import de.kif.backend.repository.RoomRepository
@ -363,6 +364,8 @@ fun Route.workGroup() {
}
div("form-group work-group-constraints") {
attributes["data-reference"] = Configuration.Schedule.referenceDate.time.toString()
label {
+"Constraints"
}
@ -835,6 +838,8 @@ fun Route.workGroup() {
}
div("form-group work-group-constraints") {
attributes["data-reference"] = Configuration.Schedule.referenceDate.time.toString()
label {
+"Constraints"
}