2021-12-31 13:59:27 +03:00
|
|
|
package space.kscience.visionforge.examples
|
|
|
|
|
2022-12-02 22:38:37 +03:00
|
|
|
import io.ktor.server.cio.CIO
|
|
|
|
import io.ktor.server.engine.embeddedServer
|
2023-05-30 17:06:27 +03:00
|
|
|
import io.ktor.server.http.content.staticResources
|
2022-12-02 22:38:37 +03:00
|
|
|
import io.ktor.server.routing.routing
|
2021-12-31 13:59:27 +03:00
|
|
|
import kotlinx.html.*
|
|
|
|
import space.kscience.dataforge.context.Global
|
2023-05-14 18:33:30 +03:00
|
|
|
import space.kscience.dataforge.context.request
|
2021-12-31 13:59:27 +03:00
|
|
|
import space.kscience.visionforge.VisionManager
|
2022-12-06 15:54:34 +03:00
|
|
|
import space.kscience.visionforge.html.VisionOfHtmlForm
|
2022-11-17 21:49:14 +03:00
|
|
|
import space.kscience.visionforge.html.VisionPage
|
2022-12-06 15:54:34 +03:00
|
|
|
import space.kscience.visionforge.html.bindForm
|
2021-12-31 13:59:27 +03:00
|
|
|
import space.kscience.visionforge.onPropertyChange
|
2022-01-20 11:13:17 +03:00
|
|
|
import space.kscience.visionforge.server.close
|
|
|
|
import space.kscience.visionforge.server.openInBrowser
|
2022-12-02 22:38:37 +03:00
|
|
|
import space.kscience.visionforge.server.visionPage
|
2021-12-31 13:59:27 +03:00
|
|
|
|
2023-05-30 17:06:27 +03:00
|
|
|
@Suppress("ExtractKtorModule")
|
2021-12-31 13:59:27 +03:00
|
|
|
fun main() {
|
2023-05-14 18:33:30 +03:00
|
|
|
val visionManager = Global.request(VisionManager)
|
2021-12-31 13:59:27 +03:00
|
|
|
|
2023-05-30 17:06:27 +03:00
|
|
|
val server = embeddedServer(CIO) {
|
2022-12-02 22:38:37 +03:00
|
|
|
|
|
|
|
routing {
|
2023-05-30 17:06:27 +03:00
|
|
|
staticResources("/", null)
|
2022-12-03 13:53:34 +03:00
|
|
|
}
|
2021-12-31 13:59:27 +03:00
|
|
|
|
2022-12-06 15:54:34 +03:00
|
|
|
val form = VisionOfHtmlForm("form").apply {
|
|
|
|
onPropertyChange(visionManager.context) {
|
2022-12-06 17:04:13 +03:00
|
|
|
println(values)
|
2022-12-06 15:54:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
visionPage(
|
|
|
|
visionManager,
|
|
|
|
VisionPage.scriptHeader("js/visionforge-playground.js"),
|
|
|
|
) {
|
|
|
|
bindForm(form) {
|
2022-12-03 13:53:34 +03:00
|
|
|
label {
|
|
|
|
htmlFor = "fname"
|
|
|
|
+"First name:"
|
|
|
|
}
|
|
|
|
br()
|
|
|
|
input {
|
|
|
|
type = InputType.text
|
|
|
|
id = "fname"
|
|
|
|
name = "fname"
|
|
|
|
value = "John"
|
|
|
|
}
|
|
|
|
br()
|
|
|
|
label {
|
|
|
|
htmlFor = "lname"
|
|
|
|
+"Last name:"
|
|
|
|
}
|
|
|
|
br()
|
|
|
|
input {
|
|
|
|
type = InputType.text
|
|
|
|
id = "lname"
|
|
|
|
name = "lname"
|
|
|
|
value = "Doe"
|
|
|
|
}
|
|
|
|
br()
|
|
|
|
br()
|
|
|
|
input {
|
|
|
|
type = InputType.submit
|
|
|
|
value = "Submit"
|
2022-12-02 22:38:37 +03:00
|
|
|
}
|
2021-12-31 13:59:27 +03:00
|
|
|
}
|
2022-12-06 17:04:13 +03:00
|
|
|
println(form.values)
|
2022-12-06 15:54:34 +03:00
|
|
|
vision(form)
|
2021-12-31 13:59:27 +03:00
|
|
|
}
|
2022-12-03 13:53:34 +03:00
|
|
|
|
2022-12-02 22:38:37 +03:00
|
|
|
}.start(false)
|
2021-12-31 13:59:27 +03:00
|
|
|
|
|
|
|
server.openInBrowser()
|
|
|
|
|
|
|
|
while (readln() != "exit") {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
server.close()
|
|
|
|
}
|