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/30 13:43:56 UTC
[isis] 01/03: ISIS-2348 EventComparison with response diff
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 41d110a963ee5d9dacb069814b334645a37720bb
Author: Jörg Rade <jo...@kuehne-nagel.com>
AuthorDate: Fri Nov 26 18:10:27 2021 +0100
ISIS-2348 EventComparison with response diff
---
incubator/clients/kroviz/build.gradle.kts | 2 +
.../kroviz/ui/dialog/ResponseComparisonDialog.kt | 52 +++++++++++-----------
.../org/apache/isis/client/kroviz/utils/Diff.kt | 30 +++++++++++++
.../apache/isis/client/kroviz/utils/Diff2Html.kt | 27 +++++++++++
.../apache/isis/client/kroviz/utils/Diff2HtmlUI.kt | 27 +++++++++++
incubator/clients/kroviz/src/main/web/index.html | 1 +
6 files changed, 112 insertions(+), 27 deletions(-)
diff --git a/incubator/clients/kroviz/build.gradle.kts b/incubator/clients/kroviz/build.gradle.kts
index 0c3ac2f..935e657 100644
--- a/incubator/clients/kroviz/build.gradle.kts
+++ b/incubator/clients/kroviz/build.gradle.kts
@@ -102,6 +102,8 @@ kotlin {
implementation("io.kvision:kvision-maps:$kvisionVersion")
implementation(npm("xmltojson", "1.3.5", false))
implementation(npm("flatted", "3.2.2", false))
+ implementation(npm("diff", "5.0.0", false))
+ implementation(npm("diff2html", "3.4.13", false))
}
sourceSets["test"].dependencies {
implementation(kotlin("test-js"))
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/dialog/ResponseComparisonDialog.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/dialog/ResponseComparisonDialog.kt
index 7ab8970..0c5b521 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/dialog/ResponseComparisonDialog.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/dialog/ResponseComparisonDialog.kt
@@ -18,47 +18,45 @@
*/
package org.apache.isis.client.kroviz.ui.dialog
-import io.kvision.core.CssSize
-import io.kvision.core.FlexDirection
-import io.kvision.core.UNIT
-import io.kvision.form.text.TextArea
-import io.kvision.panel.Direction
-import io.kvision.panel.SplitPanel
-import io.kvision.panel.VPanel
+import io.kvision.utils.obj
import org.apache.isis.client.kroviz.core.event.LogEntryComparison
+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.utils.Diff
+import org.apache.isis.client.kroviz.utils.Diff2Html
class ResponseComparisonDialog(obj: LogEntryComparison) : Command() {
- private val title = "Response Diff"
-
- private val expectedPanel = VPanel(spacing = 3) {
- width = CssSize(50, UNIT.perc)
- }
- private val actualPanel = VPanel(spacing = 3) {
- width = CssSize(50, UNIT.perc)
- }
init {
+ val html = diff2Html(obj)
+ val fi = FormItem("Diff", ValueType.HTML, html, size = 30)
+ val formItems = mutableListOf<FormItem>()
+ formItems.add(fi)
+
+ val title = "Diff: " + obj.title
dialog = RoDialog(
caption = title,
- items = mutableListOf(),
+ items = formItems,
command = this,
widthPerc = 80,
heightPerc = 70,
customButtons = mutableListOf()
)
- val expectedText = TextArea(label = "Expected", value = obj.expectedResponse, rows = 30)
- expectedPanel.add(expectedText)
- val actualText = TextArea(label = "Actual", value = obj.actualResponse, rows = 30)
- actualPanel.add(actualText)
-
- val splitPanel = SplitPanel(direction = Direction.VERTICAL)
- splitPanel.addCssClass("dialog-content")
- splitPanel.flexDirection = FlexDirection.ROW
- splitPanel.add(expectedPanel)
- splitPanel.add(actualPanel)
- dialog.formPanel!!.add(splitPanel)
dialog.open()
}
+ private fun diff2Html(obj: LogEntryComparison): String {
+ val oldText: String = obj.expectedResponse!!
+ val newText: String = obj.actualResponse!!
+ val diff = Diff.createTwoFilesPatch("file", "file", oldText, newText);
+ val options = obj {
+ drawFileList = false
+ matching = "lines"
+ outputFormat = "line-by-line"
+ }
+ val html = Diff2Html.html(diff, options)
+ return html
+ }
+
}
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/Diff.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/Diff.kt
new file mode 100644
index 0000000..3a13593
--- /dev/null
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/Diff.kt
@@ -0,0 +1,30 @@
+/*
+ * 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
+
+@JsModule("diff")
+@JsNonModule
+external object Diff {
+ fun createTwoFilesPatch(
+ file1: String = definedExternally,
+ file2: String = definedExternally,
+ original: String,
+ revised: String
+ ): Diff
+}
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/Diff2Html.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/Diff2Html.kt
new file mode 100644
index 0000000..3ed2731
--- /dev/null
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/Diff2Html.kt
@@ -0,0 +1,27 @@
+/*
+ * 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 kotlin.js.Json
+
+@JsModule("diff2html")
+@JsNonModule
+external object Diff2Html {
+ fun html(diff: Diff, options: Json): String
+}
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/Diff2HtmlUI.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/Diff2HtmlUI.kt
new file mode 100644
index 0000000..575468a
--- /dev/null
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/Diff2HtmlUI.kt
@@ -0,0 +1,27 @@
+/*
+ * 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 kotlin.js.Json
+
+@JsModule("diff2html")
+@JsNonModule
+external object Diff2HtmlUI {
+ fun html(diff: Diff, options: Json): String
+}
diff --git a/incubator/clients/kroviz/src/main/web/index.html b/incubator/clients/kroviz/src/main/web/index.html
index d420ab9..b326627 100644
--- a/incubator/clients/kroviz/src/main/web/index.html
+++ b/incubator/clients/kroviz/src/main/web/index.html
@@ -6,6 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>kroViz</title>
+ <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/diff2html/bundles/css/diff2html.min.css" />
<script type="text/javascript" src="main.bundle.js"></script>
</head>
<body>