Skip to content
This repository was archived by the owner on Sep 26, 2020. It is now read-only.

Commit 6c9923b

Browse files
committed
Make JobEditorForm.job non-nullable
1 parent c60575d commit 6c9923b

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

db/src/main/kotlin/edu/wpi/axon/db/JobDb.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,16 @@ internal object Jobs : IntIdTable() {
5151
}
5252
}
5353

54-
typealias JobCallback = (Job) -> Unit
54+
/**
55+
* The operations that you can do with a Job and the DB.
56+
*/
57+
sealed class JobDbOp {
58+
object Create : JobDbOp()
59+
object Update : JobDbOp()
60+
object Remove : JobDbOp()
61+
}
62+
63+
typealias JobCallback = (JobDbOp, Job) -> Unit
5564

5665
class JobDb(private val database: Database) {
5766

@@ -85,7 +94,7 @@ class JobDb(private val database: Database) {
8594
}
8695

8796
val newJob = job.copy(id = newId)
88-
observers.forEach { it(newJob) }
97+
observers.forEach { it(JobDbOp.Create, newJob) }
8998

9099
return newJob
91100
}
@@ -106,7 +115,7 @@ class JobDb(private val database: Database) {
106115
}
107116
}
108117

109-
observers.forEach { it(job) }
118+
observers.forEach { it(JobDbOp.Update, job) }
110119
}
111120

112121
fun count(): Int = transaction(database) {
@@ -136,6 +145,6 @@ class JobDb(private val database: Database) {
136145
Jobs.deleteWhere { Jobs.id eq job.id }
137146
}
138147

139-
observers.forEach { it(job) }
148+
observers.forEach { it(JobDbOp.Remove, job) }
140149
}
141150
}

ui-vaadin/src/main/kotlin/edu/wpi/axon/ui/service/JobProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class JobProvider : AbstractBackEndDataProvider<Job, Void>(), KoinComponent, Has
1616

1717
init {
1818
val ui = UI.getCurrent()
19-
jobs.subscribe {
19+
jobs.subscribe { _, jobFromDb ->
2020
ui.access {
21-
refreshItem(it)
21+
refreshItem(jobFromDb)
2222
}
2323
}
2424
}

ui-vaadin/src/main/kotlin/edu/wpi/axon/ui/view/jobs/JobEditorForm.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ class JobEditorForm : KComposite(), KoinComponent {
4545
set(value) {
4646
field = value
4747
isVisible = value is Some
48-
value.map {
49-
binder.readBean(it)
50-
}
5148
form.isEnabled = value.fold({ false }, { it.status == TrainingScriptProgress.NotStarted })
49+
value.map { binder.readBean(it) }
5250
}
5351

5452
private val root = ui {
@@ -73,7 +71,7 @@ class JobEditorForm : KComposite(), KoinComponent {
7371
formItem("Name") {
7472
textField {
7573
setWidthFull()
76-
bind(binder).asRequired().bind(Job::name)
74+
bind(binder).asRequired()
7775
}
7876
}
7977
formItem("Dataset") {

ui-vaadin/src/main/kotlin/edu/wpi/axon/ui/view/jobs/JobsView.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package edu.wpi.axon.ui.view.jobs
22

3+
import arrow.core.None
34
import arrow.core.Option
45
import arrow.core.Some
56
import com.github.mvysny.karibudsl.v10.KComposite
@@ -25,6 +26,7 @@ import com.vaadin.flow.router.OptionalParameter
2526
import com.vaadin.flow.router.Route
2627
import com.vaadin.flow.router.RouteAlias
2728
import edu.wpi.axon.db.JobDb
29+
import edu.wpi.axon.db.JobDbOp
2830
import edu.wpi.axon.dbdata.Job
2931
import edu.wpi.axon.ui.MainLayout
3032
import edu.wpi.axon.ui.service.JobProvider
@@ -77,10 +79,12 @@ class JobsView : KComposite(), HasUrlParameter<Int>, AfterNavigationObserver, En
7779

7880
init {
7981
val ui = UI.getCurrent()
80-
jobDb.subscribe { jobFromDb ->
82+
jobDb.subscribe { op, jobFromDb ->
8183
form.job.map { currentJob ->
8284
if (currentJob.id == jobFromDb.id) {
83-
ui.access { form.job = Some(jobFromDb) }
85+
ui.access {
86+
form.job = if (op == JobDbOp.Remove) None else Some(jobFromDb)
87+
}
8488
}
8589
}
8690
}

0 commit comments

Comments
 (0)