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 2021/10/20 16:09:34 UTC

[isis] 02/05: ISIS-2348 Replay User Events (2/n)

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 399c946bbb30175ef3b0e3b78db50a79cfd4810d
Author: Jörg Rade <jo...@kuehne-nagel.com>
AuthorDate: Fri Oct 15 18:22:30 2021 +0200

    ISIS-2348 Replay User Events (2/n)
---
 .../kotlin/org/apache/isis/client/kroviz/App.kt    | 12 +++-
 .../core/aggregator/DomainTypesAggregator.kt       |  3 +-
 .../isis/client/kroviz/core/event/ReplayCommand.kt | 66 +++++++++++++++++++---
 .../org/apache/isis/client/kroviz/ui/core/RoApp.kt | 30 +++-------
 .../apache/isis/client/kroviz/ui/core/RoIconBar.kt |  2 +-
 .../apache/isis/client/kroviz/ui/core/RoMenuBar.kt |  5 +-
 .../isis/client/kroviz/ui/core/RoStatusBar.kt      |  2 +-
 .../apache/isis/client/kroviz/ui/core/RoView.kt    |  1 -
 .../apache/isis/client/kroviz/ui/core/UiManager.kt | 41 +++++++++-----
 .../client/kroviz/ui/dialog/NotificationDialog.kt  |  3 +-
 .../apache/isis/client/kroviz/ui/panel/GeoMap.kt   |  3 +-
 11 files changed, 116 insertions(+), 52 deletions(-)

diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/App.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/App.kt
index c452081..1024b93 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/App.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/App.kt
@@ -23,24 +23,34 @@ import io.kvision.pace.Pace
 import io.kvision.panel.VPanel
 import io.kvision.panel.root
 import org.apache.isis.client.kroviz.ui.core.RoApp
+import org.apache.isis.client.kroviz.ui.core.UiManager
 
 class App : Application() {
 
+    var roApp : RoApp? = null
+
     init {
         Pace.init()
         require("css/kroviz.css")
+        initRoApp()
     }
 
     override fun start() {
         val r = root("kroviz", addRow = true)
         val v = VPanel()
-        v.add(RoApp)
+        v.add(roApp!!)
         r.add(v)
     }
 
     override fun dispose(): Map<String, Any> {
         return mapOf()
     }
+
+    fun initRoApp() {
+        roApp = RoApp()
+        UiManager.app = this
+    }
+
 }
 
 fun main() {
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/aggregator/DomainTypesAggregator.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/aggregator/DomainTypesAggregator.kt
index 07be0ed..dab1653 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/aggregator/DomainTypesAggregator.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/aggregator/DomainTypesAggregator.kt
@@ -22,6 +22,7 @@ import org.apache.isis.client.kroviz.core.event.LogEntry
 import org.apache.isis.client.kroviz.core.model.DiagramDM
 import org.apache.isis.client.kroviz.to.*
 import org.apache.isis.client.kroviz.ui.core.RoStatusBar
+import org.apache.isis.client.kroviz.ui.core.UiManager
 
 class DomainTypesAggregator(val url: String) : BaseAggregator() {
 
@@ -39,7 +40,7 @@ class DomainTypesAggregator(val url: String) : BaseAggregator() {
         }
 
         if (dpm.canBeDisplayed()) {
-            RoStatusBar.updateDiagram(dpm as DiagramDM)
+            UiManager.getRoStatusBar().updateDiagram(dpm as DiagramDM)
             dpm.isRendered = true
         }
     }
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/ReplayCommand.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/ReplayCommand.kt
index 4352db4..9ae653e 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/ReplayCommand.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/ReplayCommand.kt
@@ -19,32 +19,82 @@
 package org.apache.isis.client.kroviz.core.event
 
 import io.kvision.utils.createInstance
+import kotlinx.coroutines.GlobalScope
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.launch
+import org.apache.isis.client.kroviz.core.aggregator.AggregatorWithLayout
 import org.apache.isis.client.kroviz.core.aggregator.BaseAggregator
+import org.apache.isis.client.kroviz.main
 import org.apache.isis.client.kroviz.to.Link
 import org.apache.isis.client.kroviz.to.Represention
-import org.apache.isis.client.kroviz.ui.core.RoApp
 
 class ReplayCommand {
 
     fun execute() {
-        val events = EventStore.log
+        val events = copyEvents(EventStore.log)
         EventStore.reset()
-        RoApp.reset()
+        main()
 
         console.log("[ReplayCommand.execute]")
         console.log(events)
+        console.log(events.size)
         val userActions = events.filter {
-            it.type == Represention.HOMEPAGE.name ||
-                    it.type == Represention.OBJECT_ACTION.name
+            (it.type == Represention.HOMEPAGE.type) ||
+                    it.type == Represention.OBJECT_ACTION.type ||
+                    it.type == Represention.OBJECT.type ||
+                    it.hasDisplayModel()
         }
+        console.log(userActions)
+        console.log(userActions.size)
 
         userActions.forEach {
             val link = Link(href = it.url)
-            val clazz = it.getAggregator()::class
-            val aggregator = clazz.createInstance<BaseAggregator>()
+            var aggregator: BaseAggregator? = null
+            if (it.nOfAggregators > 0) {
+                val clazz = it.getAggregator()::class
+                aggregator = clazz.createInstance<BaseAggregator>()
+            }
             //eventually put a thinkTime here
-            ResourceProxy().fetch(link,aggregator, it.subType)
+            wait(1000)
+            console.log(link)
+            console.log(aggregator)
+            ResourceProxy().fetch(link, aggregator, it.subType)
         }
 
     }
+
+    private fun copyEvents(inputList: List<LogEntry>): List<LogEntry> {
+        val outputList = mutableListOf<LogEntry>()
+        inputList.forEach {
+            outputList.add(copyEvent(it))
+        }
+        return outputList
+    }
+
+    private fun copyEvent(input: LogEntry): LogEntry {
+        val resourceSpecification = ResourceSpecification(input.url, input.subType)
+        val output = LogEntry(
+            resourceSpecification,
+            input.title,
+            input.request,
+            input.createdAt
+        )
+        output.type = input.type
+        return output
+    }
+
+    fun wait(milliseconds: Long) {
+        GlobalScope.launch {
+            delay(milliseconds)
+        }
+    }
+
+    private fun LogEntry.hasDisplayModel(): Boolean {
+        if (this.nOfAggregators > 0) {
+            val aggregator = this.getAggregator()
+            return (aggregator is AggregatorWithLayout)
+        }
+        return false
+    }
+
 }
\ No newline at end of file
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoApp.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoApp.kt
index e6d5ef0..9aab4ba 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoApp.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoApp.kt
@@ -23,37 +23,25 @@ import io.kvision.core.UNIT
 import io.kvision.panel.HPanel
 import io.kvision.panel.SimplePanel
 
-object RoApp : SimplePanel() {
+class RoApp : SimplePanel() {
 
-    private var roView: RoView? = null
+    val roView = RoView()
+    val roMenuBar = RoMenuBar()
+    val roIconBar = RoIconBar()
+    val roStatusBar = RoStatusBar()
 
     init {
-        setup()
-    }
-
-    private fun setup() {
-        this.add(RoMenuBar.navbar)
-        roView = RoView()
+        this.add(roMenuBar.navbar)
 
         val view = HPanel() {
             width = CssSize(100, UNIT.perc)
         }
         view.addCssClass("main")
-        view.add(RoIconBar.panel)
-        view.add(roView!!.tabPanel)
+        view.add(roIconBar.panel)
+        view.add(roView.tabPanel)
         this.add(view)
 
-        this.add(RoStatusBar.navbar)
-    }
-
-    fun reset() {
-        val kids = this.children
-        kids?.clear()
-        setup()
-    }
-
-    fun getRoView(): RoView {
-        return roView!!
+        this.add(roStatusBar.navbar)
     }
 
 }
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoIconBar.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoIconBar.kt
index 0d98ec5..ceece35 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoIconBar.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoIconBar.kt
@@ -36,7 +36,7 @@ import io.kvision.html.ButtonStyle
 import io.kvision.panel.SimplePanel
 import io.kvision.panel.VPanel
 
-object RoIconBar : SimplePanel() {
+class RoIconBar : SimplePanel() {
 
     val panel = VPanel()
     private val icons = mutableListOf<SimplePanel>()
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoMenuBar.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoMenuBar.kt
index e841014..b8715a5 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoMenuBar.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoMenuBar.kt
@@ -20,7 +20,6 @@ package org.apache.isis.client.kroviz.ui.core
 
 import io.kvision.core.CssSize
 import io.kvision.core.UNIT
-import io.kvision.core.style
 import io.kvision.dropdown.DropDown
 import io.kvision.html.Button
 import io.kvision.html.ButtonStyle
@@ -40,7 +39,7 @@ import org.apache.isis.client.kroviz.ui.panel.*
 import org.apache.isis.client.kroviz.utils.IconManager
 import org.apache.isis.client.kroviz.utils.Point
 
-object RoMenuBar : SimplePanel() {
+class RoMenuBar : SimplePanel() {
     lateinit var navbar: Navbar
     private lateinit var nav: Nav
 
@@ -80,7 +79,7 @@ object RoMenuBar : SimplePanel() {
         )
 
         mainMenu.add(
-            buildMenuEntry("Toolbar", "Toolbar", { RoIconBar.toggle() })
+            buildMenuEntry("Toolbar", "Toolbar", { UiManager.getRoIconBar().toggle() })
         )
 
         mainMenu.add(
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoStatusBar.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoStatusBar.kt
index 4159af2..b94ee36 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoStatusBar.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoStatusBar.kt
@@ -34,7 +34,7 @@ import org.apache.isis.client.kroviz.ui.dialog.DiagramDialog
 import org.apache.isis.client.kroviz.ui.dialog.NotificationDialog
 import org.apache.isis.client.kroviz.utils.IconManager
 
-object RoStatusBar {
+class RoStatusBar {
     val navbar = Navbar(type = NavbarType.FIXEDBOTTOM)
 
     private val nav = Nav(rightAlign = true)
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoView.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoView.kt
index 300e313..ac32af2 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoView.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/RoView.kt
@@ -59,7 +59,6 @@ class RoView() {
     }
 
     fun removeTab(tab: SimplePanel) {
-        console.log("[RoView.removeTab]")
         tabCount--
         UiManager.closeView(tab)
     }
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/UiManager.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/UiManager.kt
index 625fd9d..a6f9a77 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/UiManager.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/UiManager.kt
@@ -23,6 +23,7 @@ import io.kvision.dropdown.ContextMenu
 import io.kvision.panel.SimplePanel
 import io.kvision.utils.ESC_KEY
 import kotlinx.browser.window
+import org.apache.isis.client.kroviz.App
 import org.apache.isis.client.kroviz.core.Session
 import org.apache.isis.client.kroviz.core.aggregator.BaseAggregator
 import org.apache.isis.client.kroviz.core.aggregator.ObjectAggregator
@@ -46,6 +47,7 @@ import org.w3c.dom.events.KeyboardEvent
  */
 object UiManager {
 
+    var app: App? = null
     private var session: Session? = null
     private val popups = mutableListOf<Widget>()
     private val settings = mutableMapOf<String, Any>()
@@ -68,8 +70,24 @@ object UiManager {
         })
     }
 
+    private fun getRoApp(): RoApp {
+        return app!!.roApp!!
+    }
+
+    private fun getRoView(): RoView {
+        return getRoApp().roView
+    }
+
+    fun getRoIconBar(): RoIconBar {
+        return getRoApp().roIconBar
+    }
+
+    fun getRoStatusBar(): RoStatusBar {
+        return getRoApp().roStatusBar
+    }
+
     private fun activeObject(): ObjectDM? {
-        val activeTab = RoApp.getRoView().findActive()
+        val activeTab = getRoView().findActive()
         if (activeTab != null) {
             return (activeTab as RoDisplay).displayModel
         }
@@ -77,14 +95,12 @@ object UiManager {
     }
 
     fun add(title: String, panel: SimplePanel, aggregator: BaseAggregator = UndefinedDispatcher()) {
-        RoApp.getRoView().addTab(title, panel)
+        getRoView().addTab(title, panel)
         EventStore.addView(title, aggregator, panel)
     }
 
     fun remove(panel: SimplePanel) {
-        console.log("[UiManager.remove]")
- //       EventStore.closeView(title)
-        RoApp.getRoView().removeTab(panel)
+        getRoView().removeTab(panel)
     }
 
     /**
@@ -103,8 +119,8 @@ object UiManager {
         DomUtil.appendTo(uuid, svgCode)
 
         val panel = buildSvgPanel(uuid)
-        RoApp.getRoView().addTab(title, panel)
-        val tab = RoApp.getRoView().findActive()!! as RoTab
+        getRoView().addTab(title, panel)
+        val tab = getRoView().findActive()!! as RoTab
 
         val svg = ScalableVectorGraphic(svgCode, uuid)
         tab.svg = svg
@@ -114,7 +130,6 @@ object UiManager {
     }
 
     fun closeView(tab: SimplePanel) {
-        console.log("[UiManager.closeView]")
         val tt = tab.title
         if (tt != null) {
             EventStore.closeView(tt)
@@ -122,15 +137,15 @@ object UiManager {
     }
 
     fun amendMenu(menuBars: Menubars) {
-        RoMenuBar.amendMenu(menuBars)
+        getRoApp().roMenuBar.amendMenu(menuBars)
     }
 
     fun updateStatus(entry: LogEntry) {
-        RoStatusBar.update(entry)
+        getRoStatusBar().update(entry)
     }
 
     fun updateUser(user: String) {
-        RoStatusBar.updateUser(user)
+        getRoStatusBar().updateUser(user)
     }
 
     fun openCollectionView(aggregator: BaseAggregator) {
@@ -153,12 +168,12 @@ object UiManager {
     }
 
     fun openDialog(panel: RoDialog) {
-        RoApp.add(panel)
+        getRoApp().add(panel)
         push(panel)
     }
 
     fun closeDialog(panel: RoDialog) {
-        RoApp.remove(panel)
+        getRoApp().remove(panel)
         pop()
     }
 
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/dialog/NotificationDialog.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/dialog/NotificationDialog.kt
index bb4ff37..ab2d562 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/dialog/NotificationDialog.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/dialog/NotificationDialog.kt
@@ -22,6 +22,7 @@ import org.apache.isis.client.kroviz.to.ValueType
 import org.apache.isis.client.kroviz.ui.core.FormItem
 import org.apache.isis.client.kroviz.ui.core.RoDialog
 import org.apache.isis.client.kroviz.ui.core.RoStatusBar
+import org.apache.isis.client.kroviz.ui.core.UiManager
 
 class NotificationDialog(val message: String) : Command() {
 
@@ -39,7 +40,7 @@ class NotificationDialog(val message: String) : Command() {
     }
 
     override fun execute(action: String?) {
-        RoStatusBar.acknowledge()
+        UiManager.getRoStatusBar().acknowledge()
     }
 
 }
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/panel/GeoMap.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/panel/GeoMap.kt
index e92a122..8c863c0 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/panel/GeoMap.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/panel/GeoMap.kt
@@ -29,6 +29,7 @@ import io.kvision.maps.LatLng
 import io.kvision.maps.maps
 import io.kvision.panel.HPanel
 import io.kvision.utils.pc
+import org.apache.isis.client.kroviz.ui.core.UiManager
 
 /**
  * Sample to be called from RoMenuBar
@@ -50,7 +51,7 @@ class GeoMap : HPanel() {
         val reha = LatLng(53.6824359, 10.7661037)
         m.addMarker(reha)
 
-        RoIconBar.add(createLocationIcon())
+        UiManager.getRoIconBar().add(createLocationIcon())
 
         setDropTargetData(Constants.stdMimeType) { id ->
             val mrk = parseMarker(id!!)