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/11/22 19:34:59 UTC

[isis] 04/06: ISIS-2348 EventCompareDialog opens

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 13b4c73315a10e86e2ee3d164c3114430136e971
Author: Jörg Rade <jo...@kuehne-nagel.com>
AuthorDate: Sun Nov 21 21:27:02 2021 +0100

    ISIS-2348 EventCompareDialog opens
---
 .../client/kroviz/core/event/LogEntryComparison.kt |  25 +++--
 .../client/kroviz/ui/dialog/EventCompareDialog.kt  |   5 +-
 .../client/kroviz/ui/dialog/ReplayDiffDialog.kt    |   2 +-
 .../client/kroviz/ui/panel/EventComparisonTable.kt | 124 +++++++++++++++++++++
 4 files changed, 144 insertions(+), 12 deletions(-)

diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/LogEntryComparison.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/LogEntryComparison.kt
index 5274845..37119b9 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/LogEntryComparison.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/LogEntryComparison.kt
@@ -19,6 +19,7 @@
 package org.apache.isis.client.kroviz.core.event
 
 import io.kvision.html.ButtonStyle
+import kotlinx.serialization.Serializable
 
 enum class ChangeType(val id: String, val iconName: String, val style: ButtonStyle) {
     ADDED("ADDED", "fas fa-plus", ButtonStyle.INFO),
@@ -28,20 +29,28 @@ enum class ChangeType(val id: String, val iconName: String, val style: ButtonSty
     ERROR("ERROR", "fas fa-bug", ButtonStyle.OUTLINEDANGER),
 }
 
-class LogEntryComparison(val expected: LogEntry?, val actual: LogEntry?) {
+@Serializable
+data class LogEntryComparison(val expected: LogEntry?, val actual: LogEntry?) {
     var changeType: ChangeType
+    var title: String
     var iconName: String
-    var expectedResponse: String?
-    var actualResponse: String?
+    var expectedResponse: String? = null
+    var actualResponse: String? = null
 
     init {
         if (expected == null && actual == null) {
-            throw Throwable("[LogEntryComparison.init] actual and expected not set")
+            throw Throwable("[LogEntryComparison.init] neither actual nor expected set")
         } else {
             changeType = compare()
             iconName = changeType.iconName
-            expectedResponse = expected?.response
-            actualResponse = actual?.response
+            if (expected == null) {
+                actualResponse = actual?.response
+                title = actual?.title.toString()
+            } else {
+                expectedResponse = expected.response
+                title = expected.title
+            }
+
         }
     }
 
@@ -57,8 +66,8 @@ class LogEntryComparison(val expected: LogEntry?, val actual: LogEntry?) {
     }
 
     private fun areResponsesEqual(): Boolean {
-        val expectedBaseUrl: String = ""
-        val actualBaseUrl: String = "" //FIXME
+        val expectedBaseUrl = ""
+        val actualBaseUrl = "" //FIXME
         val expected = expectedResponse?.replace(expectedBaseUrl, "")
         val actual = actualResponse?.replace(actualBaseUrl, "")
         return (expected == actual)
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/dialog/EventCompareDialog.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/dialog/EventCompareDialog.kt
index d5804f5..2f4c960 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/dialog/EventCompareDialog.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/dialog/EventCompareDialog.kt
@@ -24,8 +24,7 @@ import io.kvision.core.UNIT
 import io.kvision.panel.VPanel
 import org.apache.isis.client.kroviz.core.event.LogEntryComparison
 import org.apache.isis.client.kroviz.ui.core.RoDialog
-import org.apache.isis.client.kroviz.ui.core.UiManager
-import org.apache.isis.client.kroviz.ui.panel.EventLogTable
+import org.apache.isis.client.kroviz.ui.panel.EventComparisonTable
 
 class EventCompareDialog(val data: List<LogEntryComparison>) : Command() {
 
@@ -43,7 +42,7 @@ class EventCompareDialog(val data: List<LogEntryComparison>) : Command() {
             heightPerc = 70,
         )
         //FIXME -> reuse -> ColumnFactory and RoTable if possible
-        val table = EventLogTable(UiManager.getEventStore().log)
+        val table = EventComparisonTable(data)
         table.tabulator.addCssClass("tabulator-in-dialog")
         panel.add(table)
 
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/dialog/ReplayDiffDialog.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/dialog/ReplayDiffDialog.kt
index c5d0a68..7f4a20e 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/dialog/ReplayDiffDialog.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/dialog/ReplayDiffDialog.kt
@@ -86,7 +86,7 @@ class ReplayDiffDialog(
         // second pass: iterate over actual
         val actualEvents = actualStore.log
         val expectedStore = EventStore()
-        expectedStore.log = expectedEvents as ObservableList<LogEntry>
+        expectedStore.log.addAll(expectedEvents)
         actualEvents.forEach {
             val rs = ResourceSpecification(it.url, it.subType)
             val expectedEvent = expectedStore.findBy(rs)
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/panel/EventComparisonTable.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/panel/EventComparisonTable.kt
new file mode 100644
index 0000000..d58c8c1
--- /dev/null
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/panel/EventComparisonTable.kt
@@ -0,0 +1,124 @@
+/*
+ *  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.panel
+
+import io.kvision.core.*
+import io.kvision.html.Button
+import io.kvision.html.ButtonStyle
+import io.kvision.panel.VPanel
+import io.kvision.panel.hPanel
+import io.kvision.tabulator.*
+import io.kvision.utils.px
+import org.apache.isis.client.kroviz.core.event.LogEntry
+import org.apache.isis.client.kroviz.core.event.LogEntryComparison
+import org.apache.isis.client.kroviz.to.TObject
+import org.apache.isis.client.kroviz.ui.core.Constants
+import org.apache.isis.client.kroviz.ui.dialog.EventLogDetail
+import org.apache.isis.client.kroviz.utils.StringUtils
+
+class EventComparisonTable(val model: List<LogEntryComparison>) : VPanel() {
+    val tabulator: Tabulator<LogEntryComparison>
+
+    private val columns = listOf(
+        ColumnDefinition<LogEntryComparison>(
+            download = false,
+            title = "",
+            field = "changeType",
+            width = "50",
+   //         headerMenu = DynamicMenuBuilder().buildTableMenu(this),
+            hozAlign = Align.CENTER,
+            vertAlign = VAlign.MIDDLE,
+            formatterComponentFunction = { _, _, data -> buildActionButton(data) }
+        ),
+        ColumnDefinition(
+            download = false,
+            title = "Title",
+            field = "title",
+            headerFilter = Editor.INPUT,
+            width = "200",
+            formatterComponentFunction = { _, _, data -> buildObjectButton(data) }
+        ),
+        ColumnDefinition(
+            download = false,
+            title = "expectedResponse",
+            field = "expectedResponse",
+            headerFilter = Editor.INPUT,
+            width = "400",
+        ),
+        ColumnDefinition(
+            download = false,
+            title = "actualResponse",
+            field = "actualResponse",
+            headerFilter = Editor.INPUT,
+            width = "400",
+        )
+    )
+
+    private fun buildObjectButton(data: LogEntryComparison): Button {
+        val b = Button(
+            text = StringUtils.shorten(data.title),
+            icon = data.changeType.iconName,
+            style = ButtonStyle.LINK
+        )
+        b.onClick {
+            kotlinx.browser.window.open(data.title) //IMPROVE should be URL
+        }
+        //val tto = TooltipOptions(title = data.title)
+        // tabulator tooltip is buggy: often the tooltip doesn't go away and the color is not settable
+        //b.enableTooltip(tto)
+    //    if (data.obj is TObject) b.setDragDropData(Constants.stdMimeType, data.url)
+        return b
+    }
+
+    private fun buildActionButton(data: LogEntryComparison): Button {
+        val b = Button(
+            text = "",
+            icon = "fa fa-info-circle",
+            style = data.changeType.style
+        )
+//        b.onClick { EventLogDetail(data).open() }
+        b.margin = CssSize(-10, UNIT.px)
+        b.addCssClass("btn-sm")
+        return b
+    }
+
+    init {
+        hPanel(
+            FlexWrap.NOWRAP,
+            alignItems = AlignItems.CENTER,
+            spacing = 20
+        ) {
+            border = Border(width = 1.px)
+        }
+
+        val options = TabulatorOptions(
+            movableColumns = true,
+            height = Constants.calcHeight,
+            layout = Layout.FITCOLUMNS,
+            columns = columns,
+            persistenceMode = false
+        )
+
+        tabulator = tabulator(model, options = options) {
+            setEventListener<Tabulator<LogEntryComparison>> {
+            }
+        }
+    }
+
+}