Add exact time constraint

This commit is contained in:
Lars Westermann 2019-06-12 12:34:37 +02:00
parent d8c770054d
commit ea3324abed
Signed by: lars.westermann
GPG key ID: 9D417FA5BB9D5E1D
4 changed files with 87 additions and 0 deletions

View file

@ -126,6 +126,21 @@ fun checkConstraints(
}
}
ConstraintType.ExactTime -> {
for (it in constraints) {
if (it.time == null) continue
if (it.day == null) {
if (it.time != schedule.time) {
errors += ConstraintError("Work group requires exact time ${it.time}, but is on ${schedule.time}!")
}
} else {
if (it.day == schedule.day && it.time != schedule.time) {
errors += ConstraintError("Work group requires exact time ${it.time} on day ${it.day}, but is on ${schedule.time}!")
}
}
}
}
ConstraintType.NotAtSameTime -> {
for (constraint in constraints) {
for (s in against) {

View file

@ -32,6 +32,11 @@ enum class ConstraintType {
*/
OnlyBeforeTime,
/**
* Requires time, optionally allows day, permits workGroup
*/
ExactTime,
/**
* Requires workGroup, permits day and time.
*/

View file

@ -112,6 +112,27 @@ fun initWorkGroupConstraints() {
}.html)
}
}
addList.textView("Wenn an Tag x, dann Zeitpunkt t") {
onClick {
constraints.appendChild(View.wrap(createHtmlView<HTMLDivElement>()) {
classList += "input-group"
html.appendChild(TextView("Zeitpunkt").apply {
classList += "form-btn"
onClick { this@wrap.html.remove() }
}.html)
html.appendChild(InputView(InputType.TEXT).apply {
classList += "form-control"
html.name = "constraint-exact-time-day-${index}"
placeholder = "Tag (optional)"
}.html)
html.appendChild(InputView(InputType.TEXT).apply {
classList += "form-control"
html.name = "constraint-exact-time-${index++}"
placeholder = "HH:MM | Min"
}.html)
}.html)
}
}
addList.textView("Nicht zur selben Zeit wie AK x") {
onClick {
constraints.appendChild(View.wrap(createHtmlView<HTMLDivElement>()) {

View file

@ -480,6 +480,35 @@ fun Route.workGroup() {
placeholder = "HH:MM | Min"
}
}
ConstraintType.ExactTime -> {
span("form-btn") {
+"Zeitpunkt"
}
input(
name = "constraint-exact-time-day-$index",
classes = "form-control"
) {
value = constraint.day?.toString() ?: ""
placeholder = "Tag (optional)"
}
input(
name = "constraint-exact-time-$index",
classes = "form-control"
) {
val time = constraint.time ?: 0
value = if (time < 0 || time > 24 * 60) {
time.toString()
} else {
(time / 60).toString().padStart(
2,
'0'
) + ":" + (time % 60).toString().padStart(2, '0')
}
placeholder = "HH:MM | Min"
}
}
ConstraintType.NotAtSameTime -> {
span("form-btn") {
+"Nicht parallel"
@ -933,6 +962,23 @@ private fun parseConstraintParam(params: Map<String, String?>) = params.map { (k
} else null
}
}
key.startsWith("constraint-exact-time") -> {
if ("day" in key) {
WorkGroupConstraint(ConstraintType.ExactTime, day = value?.toIntOrNull())
} else {
val v = value ?: ""
if (":" in v) {
val h = v.substringBefore(":").toIntOrNull()
val m = v.substringAfter(":").toIntOrNull()
if (h != null && m != null) {
WorkGroupConstraint(ConstraintType.ExactTime, time = h * 60 + m)
} else {
v.toIntOrNull()?.let { WorkGroupConstraint(ConstraintType.ExactTime, time = it) }
}
} else null
}
}
key.startsWith("constraint-not-at-same-time") -> {
value?.toLongOrNull()?.let { WorkGroupConstraint(ConstraintType.NotAtSameTime, workGroup = it) }
}