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/07/06 15:21:10 UTC

[isis] 04/07: ISIS-2505 (some) columns hidden, Properties/PropertyFacade introduced

This is an automated email from the ASF dual-hosted git repository.

joergrade pushed a commit to branch ISIS-2505_Catch_Up_With_Demo_Examples
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 9aaf69c46935190734e836f78b70469515b0fc10
Author: Jörg Rade <jo...@kuehne-nagel.com>
AuthorDate: Thu Jul 1 21:20:45 2021 +0200

    ISIS-2505 (some) columns hidden, Properties/PropertyFacade introduced
---
 .../kroviz/core/model/DisplayModelWithLayout.kt    | 40 +++--------
 .../isis/client/kroviz/core/model/Properties.kt    | 82 ++++++++++++++++++++++
 .../apache/isis/client/kroviz/layout/PropertyLt.kt |  4 +-
 .../apache/isis/client/kroviz/to/bs3/Property.kt   |  4 +-
 .../isis/client/kroviz/ui/builder/ColBuilder.kt    |  7 +-
 .../isis/client/kroviz/ui/core/ColumnFactory.kt    | 24 ++++---
 6 files changed, 114 insertions(+), 47 deletions(-)

diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/model/DisplayModelWithLayout.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/model/DisplayModelWithLayout.kt
index b6d9f70..467680a 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/model/DisplayModelWithLayout.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/model/DisplayModelWithLayout.kt
@@ -21,7 +21,6 @@ package org.apache.isis.client.kroviz.core.model
 import org.apache.isis.client.kroviz.layout.Layout
 import org.apache.isis.client.kroviz.layout.PropertyLt
 import org.apache.isis.client.kroviz.layout.RowLt
-import org.apache.isis.client.kroviz.to.Extensions
 import org.apache.isis.client.kroviz.to.Property
 import org.apache.isis.client.kroviz.to.bs3.Grid
 
@@ -29,42 +28,20 @@ abstract class DisplayModelWithLayout : DisplayModel() {
 
     var layout: Layout? = null
     var grid: Grid? = null
-    var propertyDescriptionList = mutableMapOf<String, String>()
-    var propertyList = mutableListOf<Property>()
+    var propertyDescriptionList = mutableListOf<Property>()
     var propertyLayoutList = mutableListOf<PropertyLt>()
+    val properties = Properties()
 
     override fun canBeDisplayed(): Boolean {
-//        testPropertyNamesMatch()
         return when {
             isRendered -> false
             layout == null -> false
             grid == null -> false
-            else -> {
-                val pls = propertyLayoutList.size
-                val pds = propertyDescriptionList.size
-                val descriptionsComplete = pds >= pls
-                descriptionsComplete
-            }
+            propertyDescriptionList.isEmpty() -> false
+            else -> true
         }
     }
 
-    /*
-    check that property names match in:
-    * propertyList
-    * propertyLayoutList
-    * propertyDescriptionList
-     */
-    fun testPropertyNamesMatch() {
-        val ps = propertyList.size
-        val pls = propertyLayoutList.size
-        val pds = propertyDescriptionList.size
-        val sizeOK = (ps >= pds) && (pds >= pls)
-        console.log("[DMWL.testPropertyNamesMatch] $sizeOK")
-        console.log(propertyList)
-        console.log(propertyLayoutList)
-        console.log(propertyDescriptionList)
-    }
-
     fun addLayout(layout: Layout) {
         this.layout = layout
         initPropertyLayoutList(layout)
@@ -83,6 +60,7 @@ abstract class DisplayModelWithLayout : DisplayModel() {
                 console.log("[DMWL.initLayout4Row]")
                 console.log(fs.property)
                 propertyLayoutList.addAll(fs.property)
+                properties.addAllPropertyLayout(fs.property)
             }
             c.tabGroup.forEach { tg ->
                 tg.tab.forEach { t ->
@@ -95,14 +73,12 @@ abstract class DisplayModelWithLayout : DisplayModel() {
     }
 
     fun addPropertyDescription(p: Property) {
-        val id = p.id
-        val e: Extensions = p.extensions!!
-        val friendlyName = e.friendlyName
-        propertyDescriptionList.put(id, friendlyName)
+        propertyDescriptionList.add(p)
+        properties.addPropertyDescription(p)
     }
 
     fun addProperty(property: Property) {
-        propertyList.add(property)
+        properties.addProperty(property)
     }
 
 }
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/model/Properties.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/model/Properties.kt
new file mode 100644
index 0000000..6c00954
--- /dev/null
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/model/Properties.kt
@@ -0,0 +1,82 @@
+/*
+ *  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.layout.PropertyLt
+import org.apache.isis.client.kroviz.to.Extensions
+import org.apache.isis.client.kroviz.to.Property
+
+class Properties() {
+    val list = mutableListOf<PropertyFacade>()
+
+    fun addProperty(property: Property) {
+        val id = property.id
+        val pf = findOrCreate(id)
+        pf.property = property
+    }
+
+    fun addAllPropertyLayout(layoutList: List<PropertyLt>) {
+        fun addPropertyLayout(layout: PropertyLt) {
+            val id = layout.id!!
+            val pf = findOrCreate(id)
+            pf.layout = layout
+        }
+        layoutList.forEach { addPropertyLayout(it) }
+    }
+
+    fun addPropertyDescription(description: Property) {
+        val id = description.id
+        val pf = findOrCreate(id)
+        val e: Extensions = description.extensions!!
+        pf.friendlyName = e.friendlyName
+    }
+
+    private fun findOrCreate(id: String): PropertyFacade {
+        var pf = list.find { it.key == id }
+        if (pf == null) {
+            pf = PropertyFacade(id)
+            list.add(pf)
+        }
+        return pf
+    }
+
+}
+
+/**
+ * Properties have three aspects:
+ *
+ * - Member of a DomainObject
+ * - Description (labels, friendlyName)
+ * - Layout
+ *
+ * All three are required in order to display correctly in a table.
+ */
+class PropertyFacade(val key: String) {
+    var property: Property? = null
+    var friendlyName: String = ""
+    var layout: PropertyLt? = null
+
+    fun hidden(): Boolean {
+        if (layout != null) {
+            return (layout!!.hidden != null)
+        }
+        return false
+    }
+
+}
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/layout/PropertyLt.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/layout/PropertyLt.kt
index e5c3896..8b7ce90 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/layout/PropertyLt.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/layout/PropertyLt.kt
@@ -22,12 +22,12 @@ import kotlinx.serialization.Serializable
 import org.apache.isis.client.kroviz.to.Link
 
 @Serializable
-data class PropertyLt(val named: String? = null,
+data class PropertyLt(val id: String? = null,
+                      val named: String? = null,
                       val describedAs: String? = null,
                       val action: List<ActionLt> = emptyList(),
                       var metadataError: String? = null,
                       val link: Link? = null,
-                      val id: String? = null,
                       val cssClass: String? = null,
                       val hidden: String? = null,  //ALL_TABLES
                       val labelPosition: String? = null,
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/to/bs3/Property.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/to/bs3/Property.kt
index 9485d6a..d1683b2 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/to/bs3/Property.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/to/bs3/Property.kt
@@ -25,17 +25,17 @@ import org.w3c.dom.asList
 //IMPROVE class differs in many aspects from org.ro.to.Property - to be refactored?
 class Property(node: Node) {
     var id: String
+    var named = ""
     var link: Link? = null
     var hidden: String = "" // USE ENUM Where? = null
     var typicalLength: Int = 0
     var multiLine: Int = 1
     var describedAs: String? = null
-    var named = ""
     lateinit var action: Action
 
     init {
         val dn = node.asDynamic()
-        id = dn.getAttribute("hidden")
+        hidden = dn.getAttribute("hidden")
         id = dn.getAttribute("id") as String
         typicalLength = dn.getAttribute("typicalLength")
         multiLine = dn.getAttribute("multiLine")
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/builder/ColBuilder.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/builder/ColBuilder.kt
index 91876ad..5274df1 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/builder/ColBuilder.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/builder/ColBuilder.kt
@@ -27,6 +27,7 @@ import org.apache.isis.client.kroviz.to.bs3.Col
 import org.apache.isis.client.kroviz.ui.core.MenuFactory
 import org.apache.isis.client.kroviz.ui.core.RoDisplay
 import org.apache.isis.client.kroviz.ui.core.RoTable
+import org.apache.isis.client.kroviz.utils.Utils
 
 class ColBuilder : UiBuilder() {
 
@@ -44,7 +45,11 @@ class ColBuilder : UiBuilder() {
         }
         for (fs in col.fieldSetList) {
             val fsCpt = FieldSetBuilder().create(fs, tObject, dsp)!!
-            val fsPanel = FieldsetPanel(legend = fs.name).add(fsCpt)
+            var legend = fs.name
+            if (legend.trim().length == 0) {
+                legend = Utils.enCamel(fs.id) //IMPROVE uppercase firstchar
+            }
+            val fsPanel = FieldsetPanel(legend = legend).add(fsCpt)
             val tto = TooltipOptions(title = fs.id)
             fsPanel.enableTooltip(tto)
             panel.add(fsPanel)
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/ColumnFactory.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/ColumnFactory.kt
index 6c3b951..31ed7d6 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/ColumnFactory.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/ColumnFactory.kt
@@ -69,18 +69,22 @@ class ColumnFactory {
             columns.add(icon)
         }
 
-        val propertyLabels = displayCollection.propertyDescriptionList
+        val propertyLabels = displayCollection.properties.list
         for (pl in propertyLabels) {
-            val id = pl.key
-            val friendlyName = pl.value
-            var cd = ColumnDefinition<Exposer>(
-                    title = friendlyName,
-                    field = id,
-                    headerFilter = Editor.INPUT)
-            if (id == "object") {
-                cd = buildLink()
+            console.log("[CF.buildColumns]")
+            console.log(pl.hidden())
+            if (!pl.hidden()) {
+                val id = pl.key
+                val friendlyName = pl.friendlyName
+                var cd = ColumnDefinition<Exposer>(
+                        title = friendlyName,
+                        field = id,
+                        headerFilter = Editor.INPUT)
+                if (id == "object") {
+                    cd = buildLink()
+                }
+                columns.add(cd)
             }
-            columns.add(cd)
         }
         return columns
     }