From 372c7887fbaeda6a4c8efdb9aa3aa6938163c71a Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Sun, 11 May 2025 10:32:38 +0200 Subject: [PATCH] dataview draft --- .../office/dataview/DataViewController.java | 82 +++++++++++++++---- .../dataview/DataViewSearchController.java | 39 --------- .../main/webapp/pages/dataviews/data.xhtml | 52 ++++++------ 3 files changed, 97 insertions(+), 76 deletions(-) delete mode 100644 office-alexander-logistics-app/src/main/java/org/imixs/workflow/office/dataview/DataViewSearchController.java diff --git a/office-alexander-logistics-app/src/main/java/org/imixs/workflow/office/dataview/DataViewController.java b/office-alexander-logistics-app/src/main/java/org/imixs/workflow/office/dataview/DataViewController.java index 08094be..9c467da 100644 --- a/office-alexander-logistics-app/src/main/java/org/imixs/workflow/office/dataview/DataViewController.java +++ b/office-alexander-logistics-app/src/main/java/org/imixs/workflow/office/dataview/DataViewController.java @@ -26,20 +26,27 @@ package org.imixs.workflow.office.dataview; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; +import java.util.Map; +import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; import org.imixs.workflow.ItemCollection; -import org.imixs.workflow.exceptions.AccessDeniedException; +import org.imixs.workflow.engine.DocumentService; import org.imixs.workflow.exceptions.ModelException; -import org.imixs.workflow.faces.data.AbstractDataController; +import org.imixs.workflow.exceptions.QueryException; +import org.imixs.workflow.faces.data.ViewController; +import org.imixs.workflow.faces.data.ViewHandler; import org.imixs.workflow.office.forms.CustomFormController; import org.imixs.workflow.office.forms.CustomFormSection; import jakarta.annotation.PostConstruct; +import jakarta.enterprise.context.Conversation; import jakarta.enterprise.context.ConversationScoped; +import jakarta.faces.context.FacesContext; import jakarta.inject.Inject; import jakarta.inject.Named; +import jakarta.servlet.http.HttpServletRequest; /** * The DataViewController is used to display a data view @@ -47,29 +54,46 @@ import jakarta.inject.Named; * @author rsoika * @version 1.0 */ +// @Named +// @ConversationScoped +// public class DataViewController extends AbstractDataController { + @Named @ConversationScoped -public class DataViewController extends AbstractDataController { +// @ViewScoped +public class DataViewController extends ViewController { private static final long serialVersionUID = 1L; private List sections; private String errorMessage; + @Inject + private Conversation conversation; + + @Inject + private DocumentService documentService; + @Inject CustomFormController customFormController; + @Inject + ViewHandler viewHandler; + + protected ItemCollection data = null; private ItemCollection filter; private String query; private static Logger logger = Logger.getLogger(DataViewController.class.getName()); - /** - * - * - */ + @Override @PostConstruct public void init() { - + super.init(); + // this.setQuery(dataViewController.getQuery()); + this.setSortBy("$modified"); + this.setSortReverse(false); + this.setPageSize(100); + this.setLoadStubs(false); } public ItemCollection getDefinition() { @@ -83,11 +107,25 @@ public class DataViewController extends AbstractDataController { /** * This method loads the custom form sections */ - @Override public void onLoad() { filter = new ItemCollection(); - super.onLoad(); + // super.onLoad(); startConversation(); + + FacesContext facesContext = FacesContext.getCurrentInstance(); + if (!facesContext.isPostback() && !facesContext.isValidationFailed()) { + // ... + FacesContext fc = FacesContext.getCurrentInstance(); + Map paramMap = fc.getExternalContext().getRequestParameterMap(); + // try to extract the uniqueid form the query string... + String uniqueid = paramMap.get("id"); + if (uniqueid == null || uniqueid.isEmpty()) { + // alternative 'workitem=...' + uniqueid = paramMap.get("workitem"); + } + data = documentService.load(uniqueid); + } + try { // Init new Filter.... if (data != null) { @@ -125,12 +163,12 @@ public class DataViewController extends AbstractDataController { * elements with the values from the filter * * - * @throws AccessDeniedException - if user has insufficient access rights. + * @throws QueryException */ - public void run() throws AccessDeniedException { - + public void run() throws QueryException { + reset(); Date date = filter.getItemValueDate("date.from"); - logger.info(" date=" + date); + logger.info("x date=" + date); query = data.getItemValueString("query"); @@ -156,6 +194,9 @@ public class DataViewController extends AbstractDataController { } logger.info("query=" + query); + // Prefetch data to update total count and page count + viewHandler.getData(this); + } /** @@ -191,4 +232,17 @@ public class DataViewController extends AbstractDataController { } + /** + * Starts a new conversation + */ + protected void startConversation() { + if (conversation.isTransient()) { + conversation.setTimeout( + ((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()) + .getSession().getMaxInactiveInterval() * 1000); + conversation.begin(); + logger.log(Level.FINEST, "......start new conversation, id={0}", conversation.getId()); + } + } + } diff --git a/office-alexander-logistics-app/src/main/java/org/imixs/workflow/office/dataview/DataViewSearchController.java b/office-alexander-logistics-app/src/main/java/org/imixs/workflow/office/dataview/DataViewSearchController.java deleted file mode 100644 index d5990a9..0000000 --- a/office-alexander-logistics-app/src/main/java/org/imixs/workflow/office/dataview/DataViewSearchController.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.imixs.workflow.office.dataview; - -import java.util.logging.Logger; - -import org.imixs.workflow.faces.data.ViewController; - -import jakarta.annotation.PostConstruct; -import jakarta.faces.view.ViewScoped; -import jakarta.inject.Inject; -import jakarta.inject.Named; - -@Named -@ViewScoped -public class DataViewSearchController extends ViewController { - - private static final long serialVersionUID = 1L; - private static Logger logger = Logger.getLogger(DataViewSearchController.class.getName()); - - @Inject - DataViewController dataViewController; - - @Override - @PostConstruct - public void init() { - super.init(); - this.setQuery(dataViewController.getQuery()); - this.setSortBy("$modified"); - this.setSortReverse(false); - this.setPageSize(100); - this.setLoadStubs(false); - } - - @Override - public String getQuery() { - logger.fine("query: " + dataViewController.getQuery()); - return dataViewController.getQuery(); - } - -} diff --git a/office-alexander-logistics-app/src/main/webapp/pages/dataviews/data.xhtml b/office-alexander-logistics-app/src/main/webapp/pages/dataviews/data.xhtml index 0b780d7..ff4be84 100644 --- a/office-alexander-logistics-app/src/main/webapp/pages/dataviews/data.xhtml +++ b/office-alexander-logistics-app/src/main/webapp/pages/dataviews/data.xhtml @@ -13,13 +13,8 @@ - + - - - -
@@ -30,9 +25,9 @@
-
+ -
+
@@ -42,19 +37,24 @@
- -
+
+ + + + + -
- + @@ -63,6 +63,9 @@
+ #{message.total_result} + #{dataViewController.getTotalCount()} + #{message.serach_hits}
- - + - - + @@ -106,9 +108,7 @@
-
#{message.total_result} #{searchresultCount} - #{message.serach_hits}
- @@ -148,6 +148,12 @@ }); + //ajax refresh... + function updateDataView(data, context) { + if (data.status === 'success') { + imixsOfficeMain.layoutAjaxEvent(data); + } + } /*]]>*/