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

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 95cb0ad42d ISIS-3328: refactors DocumentationService to provide a 
ViewModel instead of just a Markup
95cb0ad42d is described below

commit 95cb0ad42d9871f293bb721af8697a42dea4939c
Author: Andi Huber <ahu...@apache.org>
AuthorDate: Thu Jan 19 19:43:32 2023 +0100

    ISIS-3328: refactors DocumentationService to provide a ViewModel instead
    of just a Markup
    
    - adding the new Help menu entry to the dem
---
 api/applib/src/main/java/module-info.java          |  2 +-
 .../causeway/applib/CausewayModuleApplib.java      |  2 +
 .../DocumentationMenu.java}                        | 49 +++++++++--------
 .../DocumentationService.java                      | 12 +++--
 .../runtimeservices/src/main/java/module-info.java |  2 +-
 .../CausewayModuleCoreRuntimeServices.java         |  2 +
 .../core/runtimeservices/helpui/DefaultHelpVm.java | 62 ++++++++++++++++++++++
 .../helpui/DefaultHelpVm.layout.xml                | 37 +++++++++++++
 .../DocumentationServiceDefault.java               | 24 +++++----
 .../src/main/java/demoapp/dom/menubars.layout.xml  |  5 ++
 10 files changed, 158 insertions(+), 39 deletions(-)

diff --git a/api/applib/src/main/java/module-info.java 
b/api/applib/src/main/java/module-info.java
index 76d70a5c0c..02c7873e8b 100644
--- a/api/applib/src/main/java/module-info.java
+++ b/api/applib/src/main/java/module-info.java
@@ -64,7 +64,7 @@ module org.apache.causeway.applib {
     exports org.apache.causeway.applib.services.commanddto;
     exports org.apache.causeway.applib.services.confview;
     exports org.apache.causeway.applib.services.conmap;
-    exports org.apache.causeway.applib.services.documentation;
+    exports org.apache.causeway.applib.services.helpui;
     exports org.apache.causeway.applib.services.email;
     exports org.apache.causeway.applib.services.error;
     exports org.apache.causeway.applib.services.eventbus;
diff --git 
a/api/applib/src/main/java/org/apache/causeway/applib/CausewayModuleApplib.java 
b/api/applib/src/main/java/org/apache/causeway/applib/CausewayModuleApplib.java
index 028b920a9d..f4712d1177 100644
--- 
a/api/applib/src/main/java/org/apache/causeway/applib/CausewayModuleApplib.java
+++ 
b/api/applib/src/main/java/org/apache/causeway/applib/CausewayModuleApplib.java
@@ -43,6 +43,7 @@ import 
org.apache.causeway.applib.services.commanddto.conmap.ContentMappingServi
 import 
org.apache.causeway.applib.services.commanddto.processor.spi.CommandDtoProcessorServiceIdentity;
 import org.apache.causeway.applib.services.confview.ConfigurationMenu;
 import org.apache.causeway.applib.services.confview.ConfigurationProperty;
+import org.apache.causeway.applib.services.helpui.DocumentationMenu;
 import org.apache.causeway.applib.services.layout.LayoutServiceMenu;
 import org.apache.causeway.applib.services.metamodel.MetaModelServiceMenu;
 import org.apache.causeway.applib.services.queryresultscache.QueryResultsCache;
@@ -90,6 +91,7 @@ import org.apache.causeway.schema.CausewayModuleSchema;
     QueryResultsCache.class,
     ApplicationFeatureMenu.class,
     UserMenu.class,
+    DocumentationMenu.class,
 
     // @Service(s)
     CommandDtoProcessorServiceIdentity.class,
diff --git 
a/api/applib/src/main/java/org/apache/causeway/applib/services/documentation/DocumentationServiceMenu.java
 
b/api/applib/src/main/java/org/apache/causeway/applib/services/helpui/DocumentationMenu.java
similarity index 56%
rename from 
api/applib/src/main/java/org/apache/causeway/applib/services/documentation/DocumentationServiceMenu.java
rename to 
api/applib/src/main/java/org/apache/causeway/applib/services/helpui/DocumentationMenu.java
index 1b45aeaada..4efc888425 100644
--- 
a/api/applib/src/main/java/org/apache/causeway/applib/services/documentation/DocumentationServiceMenu.java
+++ 
b/api/applib/src/main/java/org/apache/causeway/applib/services/helpui/DocumentationMenu.java
@@ -16,8 +16,9 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package org.apache.causeway.applib.services.documentation;
+package org.apache.causeway.applib.services.helpui;
 
+import javax.inject.Inject;
 import javax.inject.Named;
 
 import org.apache.causeway.applib.CausewayModuleApplib;
@@ -26,51 +27,49 @@ import org.apache.causeway.applib.annotation.ActionLayout;
 import org.apache.causeway.applib.annotation.DomainService;
 import org.apache.causeway.applib.annotation.DomainServiceLayout;
 import org.apache.causeway.applib.annotation.MemberSupport;
+import org.apache.causeway.applib.annotation.NatureOfService;
 import org.apache.causeway.applib.annotation.PriorityPrecedence;
-import org.apache.causeway.applib.annotation.RestrictTo;
 import org.apache.causeway.applib.annotation.SemanticsOf;
-import org.apache.causeway.applib.value.Markup;
+
+import lombok.RequiredArgsConstructor;
 
 /**
- * Simply provides a UI to for the generation of a documentation (obtained 
from {@link DocumentationService}).
+ * Provides entries for a <i>Documentation</i> sub-menu section utilizing the 
{@link DocumentationService}.
+ * <p>
+ * Currently there is only one, namely (<i>help</i>).
  *
+ * @see DocumentationService
  * @since 2.x {@index}
  */
-@Named(DocumentationServiceMenu.LOGICAL_TYPE_NAME)
-@DomainService()
+@Named(DocumentationMenu.LOGICAL_TYPE_NAME)
+@DomainService(nature = NatureOfService.VIEW)
 @DomainServiceLayout(
-        named = "Prototyping",
-        menuBar = DomainServiceLayout.MenuBar.SECONDARY
+        menuBar = DomainServiceLayout.MenuBar.TERTIARY
 )
 @javax.annotation.Priority(PriorityPrecedence.EARLY)
-public class DocumentationServiceMenu {
+@RequiredArgsConstructor(onConstructor_ = {@Inject})
+public class DocumentationMenu {
 
-    public static final String LOGICAL_TYPE_NAME = 
CausewayModuleApplib.NAMESPACE + ".DocumentationServiceMenu";
+    public static final String LOGICAL_TYPE_NAME = 
CausewayModuleApplib.NAMESPACE + ".DocumentationMenu";
 
     public static abstract class ActionDomainEvent<T> extends 
CausewayModuleApplib.ActionDomainEvent<T> {}
 
     private final DocumentationService documentationService;
 
-    public DocumentationServiceMenu(final DocumentationService 
DocumentationService) {
-        this.documentationService = DocumentationService;
-    }
-
     @Action(
-            domainEvent = downloadDocumentation.ActionDomainEvent.class,
-            semantics = SemanticsOf.NON_IDEMPOTENT, //disable client-side 
caching
-            restrictTo = RestrictTo.PROTOTYPING
+            domainEvent = help.ActionDomainEvent.class,
+            semantics = SemanticsOf.NON_IDEMPOTENT //disable client-side 
caching
             )
     @ActionLayout(
-            cssClassFa = "fa-download",
-            named = "The application-level help & documentation",
-            sequence="500.450.2")
-    public class downloadDocumentation{
+            cssClassFa = "fa-regular fa-circle-question",
+            named = "Help",
+            sequence = "100")
+    public class help{
 
-        public class ActionDomainEvent extends 
DocumentationServiceMenu.ActionDomainEvent<downloadDocumentation> {}
+        public class ActionDomainEvent extends 
DocumentationMenu.ActionDomainEvent<help> {}
 
-        @MemberSupport public Markup act() {
-            final String html = documentationService.toDocumentationHtml();
-            return new Markup(html);
+        @MemberSupport public Object act() {
+            return documentationService.getHelp();
         }
 
     }
diff --git 
a/api/applib/src/main/java/org/apache/causeway/applib/services/documentation/DocumentationService.java
 
b/api/applib/src/main/java/org/apache/causeway/applib/services/helpui/DocumentationService.java
similarity index 71%
rename from 
api/applib/src/main/java/org/apache/causeway/applib/services/documentation/DocumentationService.java
rename to 
api/applib/src/main/java/org/apache/causeway/applib/services/helpui/DocumentationService.java
index de0bae1f74..787568aafb 100644
--- 
a/api/applib/src/main/java/org/apache/causeway/applib/services/documentation/DocumentationService.java
+++ 
b/api/applib/src/main/java/org/apache/causeway/applib/services/helpui/DocumentationService.java
@@ -16,15 +16,21 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package org.apache.causeway.applib.services.documentation;
+package org.apache.causeway.applib.services.helpui;
+
+import org.apache.causeway.applib.ViewModel;
 
 /**
- * Provides a documentation based on the menu bar layout.
+ * Provides the content for the {@link DocumentationMenu} entries.
+ * <p>
+ * Currently there is only one, namely (<i>help</i>).
  *
+ * @see DocumentationMenu
  * @since 2.x {@index}
  */
 public interface DocumentationService {
 
-    String toDocumentationHtml();
+    /** Returns the view-model that represents the application's primary help 
page. */
+    ViewModel getHelp();
 
 }
diff --git a/core/runtimeservices/src/main/java/module-info.java 
b/core/runtimeservices/src/main/java/module-info.java
index f9ddd0c862..483fc21bad 100644
--- a/core/runtimeservices/src/main/java/module-info.java
+++ b/core/runtimeservices/src/main/java/module-info.java
@@ -20,7 +20,7 @@ module org.apache.causeway.core.runtimeservices {
     exports org.apache.causeway.core.runtimeservices;
     exports org.apache.causeway.core.runtimeservices.bookmarks;
     exports org.apache.causeway.core.runtimeservices.command;
-    exports org.apache.causeway.core.runtimeservices.documentation;
+    exports org.apache.causeway.core.runtimeservices.helpui;
     exports org.apache.causeway.core.runtimeservices.email;
     exports org.apache.causeway.core.runtimeservices.eventbus;
     exports org.apache.causeway.core.runtimeservices.executor;
diff --git 
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/CausewayModuleCoreRuntimeServices.java
 
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/CausewayModuleCoreRuntimeServices.java
index 6fd8fbdacb..1e8eb77770 100644
--- 
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/CausewayModuleCoreRuntimeServices.java
+++ 
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/CausewayModuleCoreRuntimeServices.java
@@ -36,6 +36,7 @@ import 
org.apache.causeway.core.runtimeservices.email.EmailServiceDefault;
 import org.apache.causeway.core.runtimeservices.eventbus.EventBusServiceSpring;
 import 
org.apache.causeway.core.runtimeservices.executor.MemberExecutorServiceDefault;
 import org.apache.causeway.core.runtimeservices.factory.FactoryServiceDefault;
+import 
org.apache.causeway.core.runtimeservices.helpui.DocumentationServiceDefault;
 import 
org.apache.causeway.core.runtimeservices.homepage.HomePageResolverServiceDefault;
 import org.apache.causeway.core.runtimeservices.i18n.po.TranslationServicePo;
 import 
org.apache.causeway.core.runtimeservices.i18n.po.TranslationServicePoMenu;
@@ -86,6 +87,7 @@ import 
org.apache.causeway.core.runtimeservices.xmlsnapshot.XmlSnapshotServiceDe
         CommandDtoFactoryDefault.class,
         CommandExecutorServiceDefault.class,
         CommandPublisherDefault.class,
+        DocumentationServiceDefault.class,
         EmailNotificationServiceDefault.class,
         EmailServiceDefault.class,
         EntityChangesPublisherDefault.class,
diff --git 
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/helpui/DefaultHelpVm.java
 
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/helpui/DefaultHelpVm.java
new file mode 100644
index 0000000000..e53cc1764a
--- /dev/null
+++ 
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/helpui/DefaultHelpVm.java
@@ -0,0 +1,62 @@
+/*
+ *  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.causeway.core.runtimeservices.helpui;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.apache.causeway.applib.ViewModel;
+import org.apache.causeway.applib.annotation.DomainObject;
+import org.apache.causeway.applib.annotation.DomainObjectLayout;
+import org.apache.causeway.applib.annotation.LabelPosition;
+import org.apache.causeway.applib.annotation.Nature;
+import org.apache.causeway.applib.annotation.ObjectSupport;
+import org.apache.causeway.applib.annotation.Property;
+import org.apache.causeway.applib.annotation.PropertyLayout;
+import org.apache.causeway.applib.value.Markup;
+import 
org.apache.causeway.core.runtimeservices.CausewayModuleCoreRuntimeServices;
+
+import lombok.RequiredArgsConstructor;
+
+@DomainObject(nature = Nature.VIEW_MODEL)
+@DomainObjectLayout(
+        named = "Application Help",
+        cssClassFa = "fa-regular fa-circle-question")
+@Named(CausewayModuleCoreRuntimeServices.NAMESPACE + ".DefaultHelpVm")
+@RequiredArgsConstructor(onConstructor_ = {@Inject})
+public class DefaultHelpVm implements ViewModel {
+
+    private final DocumentationServiceDefault documentationServiceDefault;
+
+    @ObjectSupport
+    public String title() {
+        return "Application Help";
+    }
+
+    @Property
+    @PropertyLayout(labelPosition = LabelPosition.NONE)
+    public Markup getHelpContent() {
+        return new 
Markup(documentationServiceDefault.getDocumentationAsHtml());
+    }
+
+    @Override
+    public String viewModelMemento() {
+        return "DefaultHelpVm";
+    }
+}
diff --git 
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/helpui/DefaultHelpVm.layout.xml
 
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/helpui/DefaultHelpVm.layout.xml
new file mode 100644
index 0000000000..1c25442981
--- /dev/null
+++ 
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/helpui/DefaultHelpVm.layout.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!-- 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. -->
+<bs:grid
+    xmlns:cpt="http://causeway.apache.org/applib/layout/component";
+    xmlns:bs="http://causeway.apache.org/applib/layout/grid/bootstrap3";
+    xmlns:lnk="http://causeway.apache.org/applib/layout/links";
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+    xsi:schemaLocation="http://causeway.apache.org/applib/layout/component 
http://causeway.apache.org/applib/layout/component/component.xsd 
http://causeway.apache.org/applib/layout/links 
http://causeway.apache.org/applib/layout/links/links.xsd 
http://causeway.apache.org/applib/layout/grid/bootstrap3 
http://causeway.apache.org/applib/layout/grid/bootstrap3/bootstrap3.xsd";>
+    <bs:row>
+        <bs:col span="12" unreferencedActions="true">
+            <cpt:domainObject />
+        </bs:col>
+    </bs:row>
+    <bs:row>
+        <bs:col span="12">
+            <bs:row>
+                <bs:col span="12">
+                    <cpt:fieldSet name=""
+                        unreferencedProperties="true"
+                        id="details" />
+                </bs:col>
+            </bs:row>
+        </bs:col>
+        <bs:col span="8">
+            <bs:tabGroup unreferencedCollections="true" />
+        </bs:col>
+    </bs:row>
+</bs:grid>
\ No newline at end of file
diff --git 
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/documentation/DocumentationServiceDefault.java
 
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/helpui/DocumentationServiceDefault.java
similarity index 97%
rename from 
core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/documentation/DocumentationServiceDefault.java
rename to 
core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/helpui/DocumentationServiceDefault.java
index 246e45f2a7..2c3fe06623 100644
--- 
a/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/documentation/DocumentationServiceDefault.java
+++ 
b/core/runtimeservices/src/main/java/org/apache/causeway/core/runtimeservices/helpui/DocumentationServiceDefault.java
@@ -16,7 +16,7 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-package org.apache.causeway.core.runtimeservices.documentation;
+package org.apache.causeway.core.runtimeservices.helpui;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -26,6 +26,10 @@ import javax.annotation.Priority;
 import javax.inject.Inject;
 import javax.inject.Named;
 
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Service;
+
+import org.apache.causeway.applib.ViewModel;
 import org.apache.causeway.applib.annotation.DomainObject;
 import org.apache.causeway.applib.annotation.PriorityPrecedence;
 import org.apache.causeway.applib.layout.component.ActionLayoutData;
@@ -36,7 +40,7 @@ import 
org.apache.causeway.applib.layout.component.ServiceActionLayoutData;
 import org.apache.causeway.applib.layout.grid.Grid;
 import org.apache.causeway.applib.layout.menubars.MenuBars;
 import org.apache.causeway.applib.layout.menubars.bootstrap.BSMenuBars;
-import org.apache.causeway.applib.services.documentation.DocumentationService;
+import org.apache.causeway.applib.services.helpui.DocumentationService;
 import org.apache.causeway.applib.services.homepage.HomePageResolverService;
 import org.apache.causeway.applib.services.i18n.TranslationContext;
 import org.apache.causeway.applib.services.i18n.TranslationService;
@@ -51,9 +55,8 @@ import 
org.apache.causeway.core.metamodel.spec.ObjectSpecification;
 import org.apache.causeway.core.metamodel.spec.feature.ObjectAction;
 import org.apache.causeway.core.metamodel.specloader.SpecificationLoader;
 import 
org.apache.causeway.core.runtimeservices.CausewayModuleCoreRuntimeServices;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Service;
 
+import lombok.Getter;
 import lombok.RequiredArgsConstructor;
 
 @Service
@@ -69,8 +72,12 @@ public class DocumentationServiceDefault implements 
DocumentationService {
     private final HomePageResolverService homePageResolverService;
     private final TranslationService translationService;
 
-    @Override
-    public String toDocumentationHtml() {
+    @Getter(onMethod_={@Override}, lazy = true)
+    private final ViewModel help = new DefaultHelpVm(this);
+
+    // -- HELPER
+
+    String getDocumentationAsHtml() {
         final StringBuilder html = new StringBuilder();
         Object homePage = homePageResolverService.getHomePage();
         if (homePage != null) {
@@ -153,9 +160,7 @@ public class DocumentationServiceDefault implements 
DocumentationService {
         return html.toString();
     }
 
-    // -- HELPER
-
-    private StringBuffer documentationForObjectType(ObjectSpecification 
objectSpec) {
+    private StringBuffer documentationForObjectType(final ObjectSpecification 
objectSpec) {
         StringBuffer html = new StringBuffer();
 
         Grid grid = toGrid(objectSpec.getCorrespondingClass());
@@ -266,4 +271,5 @@ public class DocumentationServiceDefault implements 
DocumentationService {
                 .map(gridFacet -> gridFacet.getGrid(null))
                 .orElse(null);
     }
+
 }
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/menubars.layout.xml 
b/examples/demo/domain/src/main/java/demoapp/dom/menubars.layout.xml
index 5bf6971c5c..0f3fe7b54f 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/menubars.layout.xml
+++ b/examples/demo/domain/src/main/java/demoapp/dom/menubars.layout.xml
@@ -390,6 +390,10 @@ For latest we use: 
https://raw.githubusercontent.com/apache/causeway/master/anto
     <mb3:tertiary>
         <mb3:menu>
             <mb3:named/>
+            <mb3:section>
+                <mb3:named>Documentation</mb3:named>
+                <mb3:serviceAction 
objectType="causeway.applib.DocumentationMenu" id="help"/>
+            </mb3:section>
             <mb3:section>
                 <mb3:named>Configuration</mb3:named>
                 <mb3:serviceAction 
objectType="causeway.conf.ConfigurationMenu" id="configuration"/>
@@ -408,6 +412,7 @@ For latest we use: 
https://raw.githubusercontent.com/apache/causeway/master/anto
                 <mb3:serviceAction objectType="causeway.applib.UserMenu" 
id="me"/>
                    <mb3:serviceAction 
objectType="causeway.security.LogoutMenu" id="logout"/>
                </mb3:section>
+
         </mb3:menu>
     </mb3:tertiary>
 </mb3:menuBars>

Reply via email to