You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by jo...@apache.org on 2020/07/11 12:27:04 UTC
[isis] 01/04: ISIS-2342 Use OSM/leafleft alongside handcoded
scaling solution for displaying SVG's
This is an automated email from the ASF dual-hosted git repository.
joergrade pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 3442d2b2df9537b1b4f80a33ee3a753e6c00578a
Author: Jörg Rade <jo...@kuehne-nagel.com>
AuthorDate: Thu Jul 9 18:03:52 2020 +0200
ISIS-2342 Use OSM/leafleft alongside handcoded scaling solution for displaying SVG's
---
.../GeoMap.kt | 40 ++++++++---------
.../PlantumlPanel.kt | 21 ++++++++-
.../SvgMap.kt | 3 +-
.../kroviz/core/aggregator/DiagramDispatcher.kt | 10 ++++-
.../isis/client/kroviz/core/event/EventStore.kt | 9 ++--
.../client/kroviz/core/event/RoXmlHttpRequest.kt | 14 +++++-
.../isis/client/kroviz/core/model/DiagramDM.kt | 18 ++++++++
.../isis/client/kroviz/handler/DiagramHandler.kt | 18 ++++++++
.../org/apache/isis/client/kroviz/to/TypeMapper.kt | 19 ++++++++
.../org/apache/isis/client/kroviz/ui/FormItem.kt | 2 +-
.../apache/isis/client/kroviz/ui/ImageDialog.kt | 18 ++++----
.../apache/isis/client/kroviz/ui/kv/Constants.kt | 2 +
.../isis/client/kroviz/ui/kv/FormPanelFactory.kt | 15 ++++++-
.../apache/isis/client/kroviz/ui/kv/MapPanel.kt | 50 ++++++++++++++++++++++
.../apache/isis/client/kroviz/ui/kv/RoDialog.kt | 3 ++
.../apache/isis/client/kroviz/ui/kv/RoMenuBar.kt | 4 +-
.../apache/isis/client/kroviz/ui/kv/RoStatusBar.kt | 18 ++++++++
.../org/apache/isis/client/kroviz/utils/DomUtil.kt | 44 +++++++------------
.../client/kroviz/utils/{DomUtil.kt => UUID.kt} | 40 ++---------------
.../apache/isis/client/kroviz/utils/UmlUtils.kt | 36 ++++++++++++----
.../client/kroviz/core/event/EventStoreTest.kt | 18 ++++++++
21 files changed, 285 insertions(+), 117 deletions(-)
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/GeoMap.kt b/incubator/clients/kroviz/src/main/kotlin/org.apache.isis.client.kroviz.ui.samples/GeoMap.kt
similarity index 64%
rename from incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/GeoMap.kt
rename to incubator/clients/kroviz/src/main/kotlin/org.apache.isis.client.kroviz.ui.samples/GeoMap.kt
index 7b026c2..15019c1 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/GeoMap.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org.apache.isis.client.kroviz.ui.samples/GeoMap.kt
@@ -1,23 +1,25 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-package org.apache.isis.client.kroviz.ui.kv
+package org.apache.isis.client.kroviz.ui.samples
+import org.apache.isis.client.kroviz.ui.kv.Constants
+import org.apache.isis.client.kroviz.ui.kv.RoIconBar
import org.apache.isis.client.kroviz.utils.IconManager
import pl.treksoft.kvision.core.CssSize
import pl.treksoft.kvision.core.UNIT
@@ -70,17 +72,15 @@ class GeoMap : HPanel() {
return loc
}
-
-
private fun parseMarker(id: String): Marker? {
val raw = id.split("#")
- if (raw.isNotEmpty()) {
+ return if (raw.isNotEmpty()) {
val lat = raw[0].toDouble()
val lng = raw[1].toDouble()
val latLng = LatLng(lat, lng)
val title = if (raw.size >= 2) raw[2] else "no title set"
- return Marker(latLng, title)
- } else return null
+ Marker(latLng, title)
+ } else null
}
class Marker(val latLng: LatLng, val title: String)
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/PlantumlPanel.kt b/incubator/clients/kroviz/src/main/kotlin/org.apache.isis.client.kroviz.ui.samples/PlantumlPanel.kt
similarity index 64%
rename from incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/PlantumlPanel.kt
rename to incubator/clients/kroviz/src/main/kotlin/org.apache.isis.client.kroviz.ui.samples/PlantumlPanel.kt
index 30365d2..1d077e0 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/PlantumlPanel.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org.apache.isis.client.kroviz.ui.samples/PlantumlPanel.kt
@@ -1,4 +1,23 @@
-package org.apache.isis.client.kroviz.ui.kv
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.client.kroviz.ui.samples
import org.apache.isis.client.kroviz.utils.UmlUtils
import pl.treksoft.kvision.core.CssSize
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/SvgMap.kt b/incubator/clients/kroviz/src/main/kotlin/org.apache.isis.client.kroviz.ui.samples/SvgMap.kt
similarity index 98%
rename from incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/SvgMap.kt
rename to incubator/clients/kroviz/src/main/kotlin/org.apache.isis.client.kroviz.ui.samples/SvgMap.kt
index c0cfc55..3a161e9 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/SvgMap.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org.apache.isis.client.kroviz.ui.samples/SvgMap.kt
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.client.kroviz.ui.kv
+package org.apache.isis.client.kroviz.ui.samples
import org.apache.isis.client.kroviz.utils.ScalableVectorGraphic
import pl.treksoft.kvision.maps.*
@@ -94,7 +94,6 @@ class SvgMap : SimplePanel() {
"""
init {
- // 0 0 is in the Atlantic Ocean, south of 'towel states' -> blue background
val map = maps(0, 0, 11, baseLayerProvider = BaseLayerProvider.EMPTY, crs = CRS.Simple) {
width = 100.pc
height = 100.pc
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/aggregator/DiagramDispatcher.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/aggregator/DiagramDispatcher.kt
index b678713..0582ea3 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/aggregator/DiagramDispatcher.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/aggregator/DiagramDispatcher.kt
@@ -19,13 +19,19 @@
package org.apache.isis.client.kroviz.core.aggregator
import org.apache.isis.client.kroviz.core.event.LogEntry
+import org.apache.isis.client.kroviz.ui.kv.MapPanel
import org.apache.isis.client.kroviz.utils.DomUtil
+import org.apache.isis.client.kroviz.utils.UUID
-class DiagramDispatcher(private val uuid: String) : BaseAggregator() {
+class DiagramDispatcher(private val callBack: Any) : BaseAggregator() {
override fun update(logEntry: LogEntry, subType: String) {
val response = logEntry.response
- DomUtil.appendTo(response, uuid)
+ when (callBack) {
+ is UUID -> DomUtil.appendTo(callBack, response )
+ is MapPanel -> callBack.renderSvg(response)
+ else -> {}
+ }
}
}
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/EventStore.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/EventStore.kt
index 4f29db7..8b1c214 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/EventStore.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/EventStore.kt
@@ -120,15 +120,18 @@ object EventStore {
return null
}
- internal fun findExact(reSpec: ResourceSpecification): LogEntry? {
+ //public for test
+ fun findExact(reSpec: ResourceSpecification): LogEntry? {
return log.firstOrNull { it.matches(reSpec) }
}
- internal fun findView(title: String): LogEntry? {
+ //public for test
+ fun findView(title: String): LogEntry? {
return log.firstOrNull { it.title == title && it.isView() }
}
- internal fun findEquivalent(reSpec: ResourceSpecification): LogEntry? {
+ //public for test
+ fun findEquivalent(reSpec: ResourceSpecification): LogEntry? {
return log.firstOrNull { reSpec.matches(it) }
}
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/RoXmlHttpRequest.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/RoXmlHttpRequest.kt
index 4430ff1..f2447fa 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/RoXmlHttpRequest.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/RoXmlHttpRequest.kt
@@ -89,7 +89,17 @@ class RoXmlHttpRequest {
EventStore.start(reSpec, method, body, aggregator)
}
- fun processAnonymous(link: Link, aggregator: BaseAggregator?) {
+ fun invokeAnonymous(link: Link, aggregator: BaseAggregator?, subType: String = Constants.subTypeXml) {
+ val reSpec = ResourceSpecification(link.href)
+ console.log("[RXHR.invokeAnonymous]")
+ console.log(EventStore.isCached(reSpec, link.method))
+ when {
+ EventStore.isCached(reSpec, link.method) -> processCached(reSpec)
+ else -> processAnonymous(link, aggregator, subType)
+ }
+ }
+
+ private fun processAnonymous(link: Link, aggregator: BaseAggregator?, subType: String) {
val method = link.method
val url = link.href
@@ -98,7 +108,7 @@ class RoXmlHttpRequest {
xhr.setRequestHeader("Content-Type", Constants.stdMimeType)
xhr.setRequestHeader("Accept", Constants.svgMimeType)
- val reSpec = ResourceSpecification(url, Constants.subTypeXml)
+ val reSpec = ResourceSpecification(url, subType)
xhr.onload = { _ -> resultHandler(reSpec, xhr.responseText) }
xhr.onerror = { _ -> errorHandler(reSpec, xhr.responseText) }
xhr.ontimeout = { _ -> errorHandler(reSpec, xhr.responseText) }
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/model/DiagramDM.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/model/DiagramDM.kt
index 048a3e4..c22c0aa 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/model/DiagramDM.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/model/DiagramDM.kt
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.isis.client.kroviz.core.model
import org.apache.isis.client.kroviz.to.DomainType
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/handler/DiagramHandler.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/handler/DiagramHandler.kt
index 804bbf8..91a05c4 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/handler/DiagramHandler.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/handler/DiagramHandler.kt
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.isis.client.kroviz.handler
import org.apache.isis.client.kroviz.utils.XmlHelper
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/to/TypeMapper.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/to/TypeMapper.kt
index e0de44e..6c3499b 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/to/TypeMapper.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/to/TypeMapper.kt
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.isis.client.kroviz.to
import org.apache.isis.client.kroviz.utils.XmlHelper
@@ -14,6 +32,7 @@ enum class ValueType(val type: String) {
TIME("Time"),
SIMPLE_SELECT("SimpleSelect"),
SLIDER("Slider"),
+ SVG("Map"),
IFRAME("IFrame")
}
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/FormItem.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/FormItem.kt
index 82f35e1..8194133 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/FormItem.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/FormItem.kt
@@ -28,7 +28,7 @@ class FormItem(
val description: String? = "not set",
val member: Member? = null,
var dspl: Displayable? = null,
- val callBackId: String? = null) {
+ var callBack: Any? = null) {
private var originalContent: Any? = content
var readOnly = false
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/ImageDialog.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/ImageDialog.kt
index 931201b..49274cd 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/ImageDialog.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/ImageDialog.kt
@@ -20,37 +20,37 @@ package org.apache.isis.client.kroviz.ui
import org.apache.isis.client.kroviz.to.ValueType
import org.apache.isis.client.kroviz.ui.kv.RoDialog
-import org.apache.isis.client.kroviz.utils.Direction
-import org.apache.isis.client.kroviz.utils.DomUtil
-import org.apache.isis.client.kroviz.utils.ScalableVectorGraphic
-import org.apache.isis.client.kroviz.utils.UmlUtils
+import org.apache.isis.client.kroviz.utils.*
class ImageDialog(
var label: String,
private var pumlCode: String) : Command() {
- private val uuid: String = DomUtil.uuid()
+ private var callBack: Any = UUID()
private var dialog: RoDialog
private val formItems = mutableListOf<FormItem>()
fun open() {
dialog.open()
- UmlUtils.generateDiagram(pumlCode, uuid)
+ UmlUtils.generateDiagram(pumlCode, callBack)
}
init {
- val img = FormItem("svg", ValueType.IMAGE.type, callBackId = uuid)
- formItems.add(img)
+ val fi = FormItem("svg", ValueType.IMAGE.type, callBack = callBack)
+ formItems.add(fi)
dialog = RoDialog(
widthPerc = 80,
caption = "Diagram",
items = formItems,
command = this)
+ //callBack = fi.callBack!!
}
+ @Deprecated("use leaflet/svg")
fun scale(direction: Direction) {
- val oldElement = DomUtil.getById(uuid)!!
+ val uuid = callBack as UUID
+ val oldElement = DomUtil.getById(uuid.value)!!
val oldStr = oldElement.innerHTML
val newImage = ScalableVectorGraphic(oldStr)
when (direction) {
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/Constants.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/Constants.kt
index de40b39..84a2a26 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/Constants.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/Constants.kt
@@ -26,4 +26,6 @@ object Constants {
const val actionSeparator = "\n"
const val subTypeJson = "json"
const val subTypeXml = "xml"
+ const val plantUmlUrl = "https://kroki.io/" //see: https://github.com/yuzutech/kroki
+
}
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/FormPanelFactory.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/FormPanelFactory.kt
index 4e5a263..3545ebf 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/FormPanelFactory.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/FormPanelFactory.kt
@@ -21,6 +21,7 @@ package org.apache.isis.client.kroviz.ui.kv
import org.apache.isis.client.kroviz.to.ValueType
import org.apache.isis.client.kroviz.ui.FormItem
import org.apache.isis.client.kroviz.utils.DateHelper
+import org.apache.isis.client.kroviz.utils.UUID
import pl.treksoft.kvision.core.Component
import pl.treksoft.kvision.core.Overflow
import pl.treksoft.kvision.core.StringPair
@@ -66,6 +67,7 @@ class FormPanelFactory(items: List<FormItem>) : VPanel() {
ValueType.IMAGE.type -> add(createImage(fi))
ValueType.SLIDER.type -> add(createSlider(fi))
ValueType.IFRAME.type -> add(createIFrame(fi))
+ ValueType.SVG.type -> add(createSvg(fi))
}
}
}
@@ -151,14 +153,23 @@ class FormPanelFactory(items: List<FormItem>) : VPanel() {
private fun createImage(fi: FormItem): VPanel {
val item = VPanel {
// add InnerPanel to be replaced by callback with svg
- vPanel { id = fi.callBackId }
+ vPanel {
+ id = (fi.callBack as UUID).value
+ }
}
item.height = auto
item.width = 100.perc
-// item.border = Border(width = 1.px, color = Color.name(Col.LIGHTGRAY), style = BorderStyle.DOTTED )
return item
}
+ private fun createSvg(fi: FormItem): MapPanel {
+ val panel = MapPanel()
+ panel.height = 100.perc
+ panel.width = 100.perc
+ fi.callBack = panel
+ return panel
+ }
+
private fun createSlider(fi: FormItem): Range {
//IMPROVE this needs to be amended for other ranges
val item = Range(label = fi.label, min = 0, max = 1.0, step = 0.1, value = fi.content as Float)
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/MapPanel.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/MapPanel.kt
new file mode 100644
index 0000000..9249a67
--- /dev/null
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/MapPanel.kt
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.client.kroviz.ui.kv
+
+import org.apache.isis.client.kroviz.utils.ScalableVectorGraphic
+import pl.treksoft.kvision.maps.*
+import pl.treksoft.kvision.panel.HPanel
+import pl.treksoft.kvision.utils.pc
+
+class MapPanel : HPanel() {
+
+ val map: Maps = maps(0, 0, 11, baseLayerProvider = BaseLayerProvider.EMPTY, crs = CRS.Simple) {
+ width = 100.pc
+ height = 100.pc
+ }
+
+ init {
+ add(map)
+ }
+
+ fun renderSvg(str: String) {
+ val svg = ScalableVectorGraphic(str)
+ svg.scaleHorizontally()
+ val svgDoc = svg.document
+ val svgElement = svgDoc.documentElement!!
+
+ val bounds = LatLngBounds(
+ LatLng(0, 0),
+ LatLng(0.05, 0.05))
+ map.svgOverlay(svgElement, bounds)
+ }
+
+}
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/RoDialog.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/RoDialog.kt
index 2210380..4b9188f 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/RoDialog.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/RoDialog.kt
@@ -62,6 +62,7 @@ class RoDialog(
close()
}
+ @Deprecated("remove once leaflet/svg is fully operational")
private val scaleUpButton = Button(
"",
"fas fa-plus",
@@ -70,6 +71,7 @@ class RoDialog(
(command as ImageDialog).scale(Direction.UP)
}
+ @Deprecated("remove once leaflet/svg is fully operational")
private val scaleDownButton = Button(
"",
"fas fa-minus",
@@ -128,6 +130,7 @@ class RoDialog(
dispose()
}
+ @Deprecated("remove once leaflet/svg is fully operational")
private fun hasScalableContent(): Boolean {
val scalable = items.firstOrNull { it.type == ValueType.IMAGE.type }
return scalable != null
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/RoMenuBar.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/RoMenuBar.kt
index ed0201c..5621725 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/RoMenuBar.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/RoMenuBar.kt
@@ -21,6 +21,8 @@ package org.apache.isis.client.kroviz.ui.kv
import org.apache.isis.client.kroviz.core.event.EventStore
import org.apache.isis.client.kroviz.to.mb.Menubars
import org.apache.isis.client.kroviz.ui.ExportDialog
+import org.apache.isis.client.kroviz.ui.samples.GeoMap
+import org.apache.isis.client.kroviz.ui.samples.SvgMap
import org.apache.isis.client.kroviz.utils.IconManager
import org.apache.isis.client.kroviz.utils.Point
import pl.treksoft.kvision.core.CssSize
@@ -97,7 +99,7 @@ object RoMenuBar : SimplePanel() {
UiManager.add(chartTitle, ChartFactory().build())
}
- val geoMapTitle = "Geo Map"
+ val geoMapTitle = "Sample Geo Map"
ddLink(geoMapTitle,
icon = IconManager.find("Map")
).onClick {
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/RoStatusBar.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/RoStatusBar.kt
index cc17cb2..6862a15 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/RoStatusBar.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/kv/RoStatusBar.kt
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.isis.client.kroviz.ui.kv
import org.apache.isis.client.kroviz.core.event.EventState
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/DomUtil.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/DomUtil.kt
index a13a190..0548604 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/DomUtil.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/DomUtil.kt
@@ -18,9 +18,9 @@
*/
package org.apache.isis.client.kroviz.utils
+import org.w3c.dom.Document
import org.w3c.dom.Element
import kotlin.browser.document
-import kotlin.random.Random
external fun encodeURIComponent(encodedURI: String): String
@@ -29,17 +29,24 @@ external fun encodeURIComponent(encodedURI: String): String
*/
object DomUtil {
- fun appendTo(response: String, elementId: String) {
+ fun appendTo(uuid: UUID, response: String) {
val svgDoc = ScalableVectorGraphic(response).document
- val element = getById(elementId)
- element.asDynamic().appendChild(svgDoc.documentElement)
+ append(uuid, svgDoc, false)
}
- fun replaceWith(elementId: String, newImage: ScalableVectorGraphic) {
+ fun replaceWith(uuid: UUID, newImage: ScalableVectorGraphic) {
val svgDoc = newImage.document
- val element = getById(elementId)!!
- element.firstChild?.let { element.removeChild(it) }
- element.asDynamic().appendChild(svgDoc.documentElement)
+ append(uuid, svgDoc, true)
+ }
+
+ private fun append(uuid: UUID, svgDoc: Document, replace: Boolean) {
+ val element = getById(uuid.value)
+ if (element != null) {
+ if (replace) {
+ element.firstChild?.let { element.removeChild(it) }
+ }
+ element.asDynamic().appendChild(svgDoc.documentElement)
+ }
}
fun download(filename: String, text: String) {
@@ -55,25 +62,4 @@ object DomUtil {
return document.getElementById(elementId)
}
- // Returns a 36-character string in the form
- // XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
- // 12345678 9012 3456 7890 123456789012
- fun uuid(): String {
- val abData = Random.Default.nextBytes(16)
- abData[6] = (0x40 or (abData[6].toInt() and 0xf)).toByte()
- abData[8] = (0x80 or (abData[8].toInt() and 0x3f)).toByte()
- val strHex = abData.toHexString()
- val s1 = strHex.substring(0, 8)
- val s2 = strHex.substring(8, 4)
- val s3 = strHex.substring(12, 4)
- val s4 = strHex.substring(16, 4)
- val s5 = strHex.substring(20, 12)
- return "$s1-$s2-$s3-$s4-$s5"
- }
-
- @OptIn(kotlin.ExperimentalUnsignedTypes::class)
- fun ByteArray.toHexString() = asUByteArray().joinToString("") {
- it.toString(16).padStart(2, '0')
- }
-
}
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/DomUtil.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/UUID.kt
similarity index 57%
copy from incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/DomUtil.kt
copy to incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/UUID.kt
index a13a190..2617019 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/DomUtil.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/UUID.kt
@@ -18,47 +18,15 @@
*/
package org.apache.isis.client.kroviz.utils
-import org.w3c.dom.Element
-import kotlin.browser.document
import kotlin.random.Random
-external fun encodeURIComponent(encodedURI: String): String
-
-/**
- * Dom ^= Document Object Model
- */
-object DomUtil {
-
- fun appendTo(response: String, elementId: String) {
- val svgDoc = ScalableVectorGraphic(response).document
- val element = getById(elementId)
- element.asDynamic().appendChild(svgDoc.documentElement)
- }
-
- fun replaceWith(elementId: String, newImage: ScalableVectorGraphic) {
- val svgDoc = newImage.document
- val element = getById(elementId)!!
- element.firstChild?.let { element.removeChild(it) }
- element.asDynamic().appendChild(svgDoc.documentElement)
- }
-
- fun download(filename: String, text: String) {
- val element = document.createElement("a")
- element.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(text))
- element.setAttribute("download", filename)
- document.body?.appendChild(element)
- element.asDynamic().click()
- document.body?.removeChild(element)
- }
-
- fun getById(elementId: String): Element? {
- return document.getElementById(elementId)
- }
+class UUID() {
+ val value: String
// Returns a 36-character string in the form
// XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
// 12345678 9012 3456 7890 123456789012
- fun uuid(): String {
+ init {
val abData = Random.Default.nextBytes(16)
abData[6] = (0x40 or (abData[6].toInt() and 0xf)).toByte()
abData[8] = (0x80 or (abData[8].toInt() and 0x3f)).toByte()
@@ -68,7 +36,7 @@ object DomUtil {
val s3 = strHex.substring(12, 4)
val s4 = strHex.substring(16, 4)
val s5 = strHex.substring(20, 12)
- return "$s1-$s2-$s3-$s4-$s5"
+ value = "$s1-$s2-$s3-$s4-$s5"
}
@OptIn(kotlin.ExperimentalUnsignedTypes::class)
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/UmlUtils.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/UmlUtils.kt
index b5f0aec..ec28cd9 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/UmlUtils.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/UmlUtils.kt
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.isis.client.kroviz.utils
import org.apache.isis.client.kroviz.core.aggregator.DiagramDispatcher
@@ -5,19 +23,19 @@ import org.apache.isis.client.kroviz.core.event.RoXmlHttpRequest
import org.apache.isis.client.kroviz.to.Argument
import org.apache.isis.client.kroviz.to.Link
import org.apache.isis.client.kroviz.to.Method
+import org.apache.isis.client.kroviz.ui.kv.Constants
object UmlUtils {
- fun generateDiagram(plantUmlCode: String, elementId: String) {
- // https://github.com/yuzutech/kroki
- val url = "https://kroki.io/"
+ fun generateDiagram(plantUmlCode: String, callBack: Any) {
val args = mutableMapOf<String, Argument>()
- args.put("diagram_source", Argument("\"diagram_source\"", plantUmlCode))
- args.put("diagram_type", Argument("\"diagram_type\"", "\"plantuml\""))
- args.put("output_format", Argument("\"output_format\"", "\"svg\""))
+ args["diagram_source"] = Argument(key = "\"diagram_source\"", value = plantUmlCode)
+ args["diagram_type"] = Argument(key = "\"diagram_type\"", value = "\"plantuml\"")
+ args["output_format"] = Argument(key = "\"output_format\"", value = "\"svg\"")
- val link = Link(href = url, method = Method.POST.operation, args = args)
- val agr = DiagramDispatcher(elementId)
- RoXmlHttpRequest().processAnonymous(link, agr)
+ val link = Link(href = Constants.plantUmlUrl, method = Method.POST.operation, args = args)
+ val agr = DiagramDispatcher(callBack)
+ RoXmlHttpRequest().invokeAnonymous(link, agr)
}
+
}
diff --git a/incubator/clients/kroviz/src/test/kotlin/org/apache/isis/client/kroviz/core/event/EventStoreTest.kt b/incubator/clients/kroviz/src/test/kotlin/org/apache/isis/client/kroviz/core/event/EventStoreTest.kt
index 0c2e8db..f2e639a 100644
--- a/incubator/clients/kroviz/src/test/kotlin/org/apache/isis/client/kroviz/core/event/EventStoreTest.kt
+++ b/incubator/clients/kroviz/src/test/kotlin/org/apache/isis/client/kroviz/core/event/EventStoreTest.kt
@@ -195,4 +195,22 @@ class EventStoreTest : IntegrationTest() {
assertNotNull(le2) //2
assertEquals(ol1, le2.url) //3
}
+
+ @Test
+ fun testAnonymousEntry() {
+ // given
+ EventStore.reset()
+ val method = Method.POST.operation
+ val url = Constants.plantUmlUrl
+ val rs = ResourceSpecification(url)
+ // when
+ EventStore.start(rs, method, body = "first invocation")
+ EventStore.start(rs, method, body = "second invocation")
+ EventStore.end(rs, "first response")
+ // then
+ val currentSize: Int = EventStore.log.size
+ assertEquals(2, currentSize) //1
+ val le = EventStore.find(rs)!!
+ assertEquals("first response", le.response)
+ }
}