From 9b42d4f186a01db5b66dabd15d2fc81fbaee2138 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 27 Nov 2020 22:43:48 +0300 Subject: [PATCH] Plugin to 0.7.0 --- build.gradle.kts | 6 +-- demo/gdml/build.gradle.kts | 5 +-- .../vision/gdml/demo/GdmlJsDemoApp.kt | 4 +- .../ru/mipt/npm/muon/monitor/MMDemoApp.kt | 4 +- .../kotlin/ru/mipt/npm/sat/SatDemoApp.kt | 6 +-- demo/spatial-showcase/build.gradle.kts | 1 - .../vision/solid/demo/ThreeDemoApp.kt | 4 +- gradle/wrapper/gradle-wrapper.properties | 2 +- playground/src/jsMain/kotlin/PlayGroundApp.kt | 4 +- settings.gradle.kts | 6 +-- .../dataforge/vision/html/HtmlOutputScope.kt | 8 ++-- .../hep/dataforge/{js => }/Application.kt | 2 +- .../vision/client/ClientVisionManager.kt | 43 +++++++++++++++++++ .../vision/{html => client}/elementOutput.kt | 9 ++-- visionforge-fx/build.gradle.kts | 2 - .../dataforge/vision/server/VisionServer.kt | 12 ++++-- .../vision/solid/three/ThreePlugin.kt | 2 +- 17 files changed, 84 insertions(+), 36 deletions(-) rename visionforge-core/src/jsMain/kotlin/hep/dataforge/{js => }/Application.kt (98%) create mode 100644 visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/client/ClientVisionManager.kt rename visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/{html => client}/elementOutput.kt (82%) diff --git a/build.gradle.kts b/build.gradle.kts index 9cc59d77..f3709349 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,10 +2,10 @@ plugins { id("ru.mipt.npm.project") } -val dataforgeVersion by extra("0.2.0-dev-8") +val dataforgeVersion by extra("0.2.0") val ktorVersion by extra("1.4.2") val htmlVersion by extra("0.7.2") -val kotlinWrappersVersion by extra("pre.129-kotlin-1.4.10") +val kotlinWrappersVersion by extra("pre.129-kotlin-1.4.20") val fxVersion by extra("14") @@ -17,7 +17,7 @@ allprojects { } group = "hep.dataforge" - version = "0.2.0-dev-2" + version = "0.2.0-dev-3" } val githubProject by extra("visionforge") diff --git a/demo/gdml/build.gradle.kts b/demo/gdml/build.gradle.kts index 86e8b80c..ef958795 100644 --- a/demo/gdml/build.gradle.kts +++ b/demo/gdml/build.gradle.kts @@ -1,6 +1,5 @@ import ru.mipt.npm.gradle.DependencyConfiguration import ru.mipt.npm.gradle.FXModule -import ru.mipt.npm.gradle.useFx plugins { id("ru.mipt.npm.mpp") @@ -24,8 +23,8 @@ kotlin { implementation(project(":visionforge-gdml")) } } - jvmMain{ - dependencies{ + jvmMain { + dependencies { implementation(project(":visionforge-fx")) } } diff --git a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlJsDemoApp.kt b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlJsDemoApp.kt index 352d645c..7aa28b22 100644 --- a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlJsDemoApp.kt +++ b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlJsDemoApp.kt @@ -1,8 +1,8 @@ package hep.dataforge.vision.gdml.demo +import hep.dataforge.Application import hep.dataforge.context.Global -import hep.dataforge.js.Application -import hep.dataforge.js.startApplication +import hep.dataforge.startApplication import hep.dataforge.vision.gdml.toVision import kotlinx.browser.document import react.child diff --git a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt index 0ca23130..7ac877f5 100644 --- a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt +++ b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt @@ -1,8 +1,8 @@ package ru.mipt.npm.muon.monitor +import hep.dataforge.Application import hep.dataforge.context.Global -import hep.dataforge.js.Application -import hep.dataforge.js.startApplication +import hep.dataforge.startApplication import io.ktor.client.HttpClient import io.ktor.client.features.json.JsonFeature import io.ktor.client.features.json.serializer.KotlinxSerializer diff --git a/demo/sat-demo/src/jsMain/kotlin/ru/mipt/npm/sat/SatDemoApp.kt b/demo/sat-demo/src/jsMain/kotlin/ru/mipt/npm/sat/SatDemoApp.kt index dad0e45f..39f2541d 100644 --- a/demo/sat-demo/src/jsMain/kotlin/ru/mipt/npm/sat/SatDemoApp.kt +++ b/demo/sat-demo/src/jsMain/kotlin/ru/mipt/npm/sat/SatDemoApp.kt @@ -1,9 +1,9 @@ package ru.mipt.npm.sat +import hep.dataforge.Application import hep.dataforge.context.Global -import hep.dataforge.js.Application -import hep.dataforge.js.startApplication import hep.dataforge.meta.invoke +import hep.dataforge.startApplication import hep.dataforge.vision.solid.three.ThreePlugin import hep.dataforge.vision.solid.three.render import kotlinx.browser.document @@ -16,7 +16,7 @@ private class SatDemoApp : Application { ?: error("Element with id 'canvas' not found on page") val three = Global.plugins.fetch(ThreePlugin) val sat = visionOfSatellite( - ySegments = 5, + ySegments = 3, ) three.render(element, sat){ minSize = 500 diff --git a/demo/spatial-showcase/build.gradle.kts b/demo/spatial-showcase/build.gradle.kts index f984b9b3..e3b4d0f4 100644 --- a/demo/spatial-showcase/build.gradle.kts +++ b/demo/spatial-showcase/build.gradle.kts @@ -1,6 +1,5 @@ import ru.mipt.npm.gradle.DependencyConfiguration import ru.mipt.npm.gradle.FXModule -import ru.mipt.npm.gradle.useFx plugins { id("ru.mipt.npm.mpp") diff --git a/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/solid/demo/ThreeDemoApp.kt b/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/solid/demo/ThreeDemoApp.kt index ba76b024..2e613622 100644 --- a/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/solid/demo/ThreeDemoApp.kt +++ b/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/solid/demo/ThreeDemoApp.kt @@ -1,7 +1,7 @@ package hep.dataforge.vision.solid.demo -import hep.dataforge.js.Application -import hep.dataforge.js.startApplication +import hep.dataforge.Application +import hep.dataforge.startApplication import hep.dataforge.vision.solid.x import hep.dataforge.vision.solid.y import kotlinx.browser.document diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index be52383e..4d9ca164 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/playground/src/jsMain/kotlin/PlayGroundApp.kt b/playground/src/jsMain/kotlin/PlayGroundApp.kt index a1e46705..33de3028 100644 --- a/playground/src/jsMain/kotlin/PlayGroundApp.kt +++ b/playground/src/jsMain/kotlin/PlayGroundApp.kt @@ -1,6 +1,6 @@ +import hep.dataforge.Application import hep.dataforge.context.Global -import hep.dataforge.js.Application -import hep.dataforge.js.startApplication +import hep.dataforge.startApplication import hep.dataforge.vision.bootstrap.visionPropertyEditor import hep.dataforge.vision.react.ThreeCanvasComponent import hep.dataforge.vision.react.objectTree diff --git a/settings.gradle.kts b/settings.gradle.kts index b4de270e..e21ae40c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,9 +1,9 @@ pluginManagement { - val kotlinVersion = "1.4.20-M2" - val toolsVersion = "0.6.4-dev-1.4.20-M2" + val kotlinVersion = "1.4.20" + val toolsVersion = "0.7.0" repositories { -// mavenLocal() + mavenLocal() jcenter() gradlePluginPortal() maven("https://dl.bintray.com/kotlin/kotlin-eap") diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/html/HtmlOutputScope.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/html/HtmlOutputScope.kt index c04ef207..0fcd81dd 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/html/HtmlOutputScope.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/html/HtmlOutputScope.kt @@ -13,10 +13,10 @@ public class HtmlOutput( public abstract class HtmlOutputScope( private val root: TagConsumer, - public val prefix: String? = null, + public val idPrefix: String? = null, ) : TagConsumer by root { - public open fun resolveId(name: Name): String = (prefix ?: "output:") + name.toString() + public open fun resolveId(name: Name): String = (idPrefix ?: "output:") + name.toString() /** * Create a placeholder but do not attach any [Vision] to it @@ -27,7 +27,7 @@ public abstract class HtmlOutputScope( ): T = div { id = resolveId(name) classes = setOf(OUTPUT_CLASS) - attributes[NAME_ATTRIBUTE] = name.toString() + attributes[OUTPUT_NAME_ATTRIBUTE] = name.toString() @Suppress("UNCHECKED_CAST") HtmlOutput(this@HtmlOutputScope, name, this).block() } @@ -62,6 +62,6 @@ public abstract class HtmlOutputScope( public companion object { public const val OUTPUT_CLASS: String = "visionforge-output" - public const val NAME_ATTRIBUTE: String = "data-output-name" + public const val OUTPUT_NAME_ATTRIBUTE: String = "data-output-name" } } \ No newline at end of file diff --git a/visionforge-core/src/jsMain/kotlin/hep/dataforge/js/Application.kt b/visionforge-core/src/jsMain/kotlin/hep/dataforge/Application.kt similarity index 98% rename from visionforge-core/src/jsMain/kotlin/hep/dataforge/js/Application.kt rename to visionforge-core/src/jsMain/kotlin/hep/dataforge/Application.kt index 92a55e20..fb182522 100644 --- a/visionforge-core/src/jsMain/kotlin/hep/dataforge/js/Application.kt +++ b/visionforge-core/src/jsMain/kotlin/hep/dataforge/Application.kt @@ -1,4 +1,4 @@ -package hep.dataforge.js +package hep.dataforge import kotlinx.browser.document import kotlinx.dom.hasClass diff --git a/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/client/ClientVisionManager.kt b/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/client/ClientVisionManager.kt new file mode 100644 index 00000000..7866c814 --- /dev/null +++ b/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/client/ClientVisionManager.kt @@ -0,0 +1,43 @@ +package hep.dataforge.vision.client + +import hep.dataforge.context.Context +import hep.dataforge.context.Global +import hep.dataforge.vision.VisionManager +import hep.dataforge.vision.html.HtmlOutputScope +import kotlinx.browser.window +import org.w3c.dom.Element +import org.w3c.dom.get +import org.w3c.dom.url.URL + +@JsExport +public class ClientVisionManager { + private val visionForgeContext: Context = Global.context("client") { + plugin(VisionManager) + } + + private val visionManager: VisionManager = visionForgeContext.plugins.fetch(VisionManager) + + /** + * Up-going tree traversal in search for endpoint attribute + */ + private fun resolveEndpoint(element: Element?): String { + if(element == null) return DEFAULT_ENDPOINT + val attribute = element.attributes[OUTPUT_ENDPOINT_ATTRIBUTE] + return attribute?.value ?: resolveEndpoint(element.parentElement) + } + + public fun renderVision(element: Element){ + if(!element.classList.contains(HtmlOutputScope.OUTPUT_CLASS)) error("The element $element is not an output element") + val endpoint = URL(resolveEndpoint(element)) + window.fetch("$endpoint/vision").then {response-> + TODO() + } + } + + public companion object { + public const val OUTPUT_ENDPOINT_ATTRIBUTE: String = "data-output-endpoint" + public const val DEFAULT_ENDPOINT: String = ".." + } +} + + diff --git a/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/html/elementOutput.kt b/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/client/elementOutput.kt similarity index 82% rename from visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/html/elementOutput.kt rename to visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/client/elementOutput.kt index 2a9f60c0..9fe3b43e 100644 --- a/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/html/elementOutput.kt +++ b/visionforge-core/src/jsMain/kotlin/hep/dataforge/vision/client/elementOutput.kt @@ -1,8 +1,11 @@ -package hep.dataforge.vision.html +package hep.dataforge.vision.client import hep.dataforge.names.Name import hep.dataforge.names.toName import hep.dataforge.vision.Vision +import hep.dataforge.vision.html.BindingHtmlOutputScope +import hep.dataforge.vision.html.HtmlOutputScope +import hep.dataforge.vision.html.HtmlVisionFragment import kotlinx.browser.document import kotlinx.html.TagConsumer import org.w3c.dom.* @@ -21,9 +24,9 @@ public fun Map.bind(renderer: ElementVisionRenderer) public fun Element.renderVisions(renderer: ElementVisionRenderer, visionProvider: (Name) -> V?) { val elements = getElementsByClassName(HtmlOutputScope.OUTPUT_CLASS) elements.asList().forEach { element -> - val name = element.attributes[HtmlOutputScope.NAME_ATTRIBUTE]?.value + val name = element.attributes[HtmlOutputScope.OUTPUT_NAME_ATTRIBUTE]?.value if (name == null) { - console.error("Attribute ${HtmlOutputScope.NAME_ATTRIBUTE} not defined in the output element") + console.error("Attribute ${HtmlOutputScope.OUTPUT_NAME_ATTRIBUTE} not defined in the output element") return@forEach } val vision = visionProvider(name.toName()) diff --git a/visionforge-fx/build.gradle.kts b/visionforge-fx/build.gradle.kts index c7626def..4cc5286d 100644 --- a/visionforge-fx/build.gradle.kts +++ b/visionforge-fx/build.gradle.kts @@ -1,5 +1,3 @@ -import ru.mipt.npm.gradle.useFx - plugins { id("ru.mipt.npm.jvm") } diff --git a/visionforge-server/src/main/kotlin/hep/dataforge/vision/server/VisionServer.kt b/visionforge-server/src/main/kotlin/hep/dataforge/vision/server/VisionServer.kt index aeb43f41..77f18d81 100644 --- a/visionforge-server/src/main/kotlin/hep/dataforge/vision/server/VisionServer.kt +++ b/visionforge-server/src/main/kotlin/hep/dataforge/vision/server/VisionServer.kt @@ -1,7 +1,10 @@ package hep.dataforge.vision.server import hep.dataforge.context.Context -import hep.dataforge.meta.* +import hep.dataforge.meta.Config +import hep.dataforge.meta.Configurable +import hep.dataforge.meta.boolean +import hep.dataforge.meta.long import hep.dataforge.names.Name import hep.dataforge.names.toName import hep.dataforge.vision.Vision @@ -12,16 +15,19 @@ import hep.dataforge.vision.server.VisionServer.Companion.DEFAULT_PAGE import io.ktor.application.* import io.ktor.features.CORS import io.ktor.html.respondHtml -import io.ktor.http.* +import io.ktor.http.ContentType +import io.ktor.http.HttpStatusCode import io.ktor.http.cio.websocket.Frame import io.ktor.http.content.resources import io.ktor.http.content.static +import io.ktor.http.withCharset import io.ktor.response.respond import io.ktor.response.respondText import io.ktor.routing.* import io.ktor.server.engine.ApplicationEngine import io.ktor.websocket.WebSockets import io.ktor.websocket.webSocket +import kotlinx.coroutines.flow.collect import kotlinx.html.* import kotlinx.html.stream.createHTML import java.awt.Desktop @@ -106,7 +112,7 @@ public class VisionServer internal constructor( application.log.debug("Opened server socket for $name") val vision: Vision = visions[name.toName()] ?: error("Plot with id='$name' not registered") try { - vision.flowChanges(this, updateInterval.milliseconds).collect { update -> + vision.flowChanges(this, updateInterval.milliseconds).collect { update -> val json = visionManager.encodeToString(update) outgoing.send(Frame.Text(json)) } diff --git a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreePlugin.kt b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreePlugin.kt index 242edca9..cd6c76c6 100644 --- a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreePlugin.kt +++ b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreePlugin.kt @@ -4,7 +4,7 @@ import hep.dataforge.context.* import hep.dataforge.meta.Meta import hep.dataforge.names.* import hep.dataforge.vision.Vision -import hep.dataforge.vision.html.ElementVisionRenderer +import hep.dataforge.vision.client.ElementVisionRenderer import hep.dataforge.vision.solid.* import hep.dataforge.vision.solid.specifications.Canvas3DOptions import hep.dataforge.vision.visible