Bugfixes + project editor added to route
authorelgekko <vasary@elgekko.net>
Sat, 27 May 2023 19:39:32 +0000 (21:39 +0200)
committerelgekko <vasary@elgekko.net>
Sat, 27 May 2023 19:39:32 +0000 (21:39 +0200)
13 files changed:
lis-ui/src/main/java/hu/user/lis/ui/data/ProjectSelectorDataModel.java
lis-ui/src/main/java/hu/user/lis/ui/editor/PartnerEditorModel.java
lis-ui/src/main/java/hu/user/lis/ui/editor/ProjectEditorModel.java
lis-ui/src/main/java/hu/user/lis/ui/editor/ServiceRecordEditorModel.java
lis-ui/src/main/java/hu/user/lis/ui/session/SessionSettings.java [new file with mode: 0644]
lis-ui/src/main/java/hu/user/lis/ui/view/AssociatesViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/IndexViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/PartnersViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/ProjectsViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/ServiceRecordsViewModel.java
lis-ui/src/main/resources/web/associate-editor.zul
lis-ui/src/main/resources/web/incoming-invoice-editor.zul
lis-ui/src/main/resources/web/outgoing-invoice-editor.zul

index 48c4786d941cbaa251f1befb7de613be8a5a6cd5..39a7117ea7bb3239f06032026b4e03c35066e52f 100644 (file)
@@ -22,26 +22,20 @@ public class ProjectSelectorDataModel extends CachedDataModel<Project> {
     static private final int SEARCH_LIMIT = 10;
     @Autowired
     ProjectService projectService;
-    private String partialName;
-    private String partialPartnerName;
-    private String partialHumanId;
+    private String partialSearch;
 
     private boolean filter(Project project) {
-        if (StringUtils.isBlank(partialHumanId) && StringUtils.isBlank(partialName) && StringUtils.isBlank(partialPartnerName)) {
+        if (StringUtils.isBlank(partialSearch)) {
             return true;
         }
-        if (StringUtils.isNotBlank(partialHumanId)) {
-            if (project.getHumanId().toLowerCase().contains(partialHumanId.toLowerCase())) {
+        if (StringUtils.isNotBlank(partialSearch)) {
+            if (project.getHumanId().toLowerCase().contains(partialSearch.toLowerCase())) {
                 return true;
             }
-        }
-        if (StringUtils.isNotBlank(partialName)) {
-            if (project.getName().toLowerCase().contains(partialName.toLowerCase())) {
+            if (project.getName().toLowerCase().contains(partialSearch.toLowerCase())) {
                 return true;
             }
-        }
-        if (StringUtils.isNotBlank(partialPartnerName)) {
-            if (project.getPartner().getName().toLowerCase().contains(partialPartnerName.toLowerCase())) {
+            if (project.getPartner().getName().toLowerCase().contains(partialSearch.toLowerCase())) {
                 return true;
             }
         }
@@ -67,20 +61,16 @@ public class ProjectSelectorDataModel extends CachedDataModel<Project> {
         return result;
     }
 
-    public void search(String partialName, String partialPartnerName, String partialHumanId) {
-        log.info("Searching projects using filter {} {} {}", partialHumanId, partialName, partialHumanId);
-        this.partialPartnerName = partialPartnerName;
-        this.partialHumanId = partialHumanId;
-        this.partialName = partialName;
+    public void search(String partialSearch) {
+        log.info("Searching projects using filter {}", partialSearch);
+        this.partialSearch = partialSearch;
         super.reset();
         BindUtils.postNotifyChange(null, null, this, "*");
     }
 
     public void getLimited() {
         log.info("Searching projects using limit {}", SEARCH_LIMIT);
-        this.partialPartnerName = null;
-        this.partialHumanId = null;
-        this.partialName = null;
+        this.partialSearch = null;
         super.reset();
         BindUtils.postNotifyChange(null, null, this, "*");
     }
index 2009fe1c46877f4304670d236d3eb1ed08d79c13..6cbf94b016c33553bea6021115ef4ebddc856440 100644 (file)
@@ -22,7 +22,6 @@ import org.zkoss.zkplus.spring.DelegatingVariableResolver;
 import org.zkoss.zul.Window;
 
 import java.util.Objects;
-import java.util.regex.Pattern;
 
 @Log4j2
 @Getter
@@ -83,10 +82,12 @@ public class PartnerEditorModel extends AbstractValidator {
     }
 
     private boolean isVatNumber(String vatNr) {
-        Pattern pattern = Pattern.compile(VAT_NR_PATTERN);
-        boolean result = pattern.matcher(vatNr).matches();
-        log.info("Vat number regex match {}", result);
-        return result;
+        return true;
+        //TODO not working properly
+//        Pattern pattern = Pattern.compile(VAT_NR_PATTERN);
+//        boolean result = pattern.matcher(vatNr).matches();
+//        log.info("Vat number regex match {}", result);
+//        return result;
     }
 
     private void updateFormInvalid(boolean invalid) {
index 2b871a9cb19b682d1ed493c62470f8c87fd58b38..9fb45938a29abd08d7d59d6b66540d327372593c 100644 (file)
@@ -11,6 +11,7 @@ import hu.user.lis.ui.Constants;
 import hu.user.lis.ui.converter.ProjectStatusConverter;
 import hu.user.lis.ui.data.*;
 import hu.user.lis.ui.event.EventBus;
+import hu.user.lis.ui.session.SessionSettings;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.extern.log4j.Log4j2;
@@ -28,6 +29,7 @@ import org.zkoss.zk.ui.event.InputEvent;
 import org.zkoss.zk.ui.event.OpenEvent;
 import org.zkoss.zk.ui.select.annotation.VariableResolver;
 import org.zkoss.zk.ui.select.annotation.WireVariable;
+import org.zkoss.zk.ui.util.Clients;
 import org.zkoss.zkplus.spring.DelegatingVariableResolver;
 import org.zkoss.zul.Center;
 import org.zkoss.zul.Panel;
@@ -46,6 +48,8 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen
     ProjectAssociateService projectAssociateServiceImpl;
     @WireVariable
     ServiceRecordService serviceRecordServiceImpl;
+    @WireVariable
+    SessionSettings sessionSettings;
     private Project formDocument;
     private Project origDocument;
     private Map<String, Boolean> origAssociates;
@@ -84,13 +88,33 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen
     @Override
     public void onEvent(Event evt) {
         if (Constants.SET_PROJECT_EDITOR_DATA.equals(evt.getName())) {
-            Map<String, Object> data = (Map<String, Object>) evt.getData();
-            origDocument = (Project) data.get("origDocument");
-            formDocument = (Project) data.get("formDocument");
-            serviceRecordsDataModel.search(formDocument, true);
-            associatesDataModel.listAll();
-            incomeMarginsDataModel.recalculate(formDocument);
-            BindUtils.postNotifyChange(this, "formDocument");
+            log.info("Got event {}", Constants.SET_PROJECT_EDITOR_DATA);
+            Object data = evt.getData();
+            if (data instanceof Map) {
+                Map<String, Object> mapData = (Map<String, Object>) evt.getData();
+                origDocument = (Project) mapData.get("origDocument");
+                formDocument = (Project) mapData.get("formDocument");
+            }
+
+            if (data instanceof String) {
+                String id = (String) data;
+                log.info("Loading entity {} to editor", id);
+                origDocument = projectServiceImpl.getById(id);
+                formDocument = projectServiceImpl.copy(origDocument);
+            }
+            
+            if (Objects.isNull(data)) {
+                formDocument = projectServiceImpl.createNew();
+                log.info("Loading new entity {} to editor", formDocument.getId());
+            }
+
+            if (Objects.nonNull(formDocument)) {
+                Clients.evalJavaScript(String.format("pushNav('/project/%s')", formDocument.getId()));
+                serviceRecordsDataModel.search(formDocument, true);
+                associatesDataModel.listAll();
+                incomeMarginsDataModel.recalculate(formDocument);
+                BindUtils.postNotifyChange(this, "formDocument");
+            }
         }
     }
 
@@ -143,8 +167,8 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen
     @Command
     public void onPopupPartners() {
         String page = "~./suppliers.zul";
-        Window suppliersWindow = (Window) Executions.createComponents(page, null, null);
-        suppliersWindow.addEventListener("onClose", e -> {
+        Window editorWindow = (Window) Executions.createComponents(page, null, null);
+        editorWindow.addEventListener("onClose", e -> {
             log.info("Suppliers popup result {}", e.getData());
             if (e.getData() != null) {
                 partnerSelectorDataModel.clearSelection();
@@ -152,8 +176,8 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen
                 BindUtils.postNotifyChange(this, "selectedSupplierId");
             }
         });
-
-        suppliersWindow.doModal();
+        editorWindow.doModal();
+        editorWindow.setFocus(true);
     }
 
     @Override
@@ -206,6 +230,7 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen
             }
         });
         editorWindow.doModal();
+        editorWindow.setFocus(true);
     }
 
     @Command
@@ -230,6 +255,7 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen
             }
         });
         editorWindow.doModal();
+        editorWindow.setFocus(true);
     }
 
     @Command
@@ -260,6 +286,7 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen
             }
         });
         editorWindow.doModal();
+        editorWindow.setFocus(true);
     }
 
     @Command
@@ -284,6 +311,7 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen
             }
         });
         editorWindow.doModal();
+        editorWindow.setFocus(true);
     }
 
     @Command
@@ -314,6 +342,7 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen
             }
         });
         editorWindow.doModal();
+        editorWindow.setFocus(true);
     }
 
     @Command
@@ -336,6 +365,7 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen
             }
         });
         editorWindow.doModal();
+        editorWindow.setFocus(true);
     }
 
     @Command
index 3e9bdb750f3a6df435c761eb9931267679723e9a..5fd2e3de398dd7289706f8c92975a26fb505cc23 100644 (file)
@@ -50,7 +50,7 @@ public class ServiceRecordEditorModel extends AbstractValidator {
     public void onProjectBandChanging(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) {
         InputEvent event = (InputEvent) ctx.getTriggerEvent();
         log.info("onProjectBandChanging: {}", event.getValue());
-        projectSelectorDataModel.search(event.getValue(), null, null);
+        projectSelectorDataModel.search(event.getValue());
     }
 
     @Command
diff --git a/lis-ui/src/main/java/hu/user/lis/ui/session/SessionSettings.java b/lis-ui/src/main/java/hu/user/lis/ui/session/SessionSettings.java
new file mode 100644 (file)
index 0000000..c2be049
--- /dev/null
@@ -0,0 +1,35 @@
+package hu.user.lis.ui.session;
+
+import lombok.extern.log4j.Log4j2;
+import org.springframework.stereotype.Service;
+import org.zkoss.zk.ui.Executions;
+import org.zkoss.zk.ui.Sessions;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+@Service
+@Log4j2
+public class SessionSettings {
+
+    public SessionSettings() {
+        log.info("SessionSettings created");
+    }
+
+    private HttpServletRequest getNativeRequest() {
+        return (HttpServletRequest) Executions.getCurrent().getNativeRequest();
+    }
+
+    private HttpSession getNativeSession() {
+        return (HttpSession) Sessions.getCurrent().getNativeSession();
+    }
+
+    public String getCurrentPath() {
+        HttpServletRequest nativeRequest = getNativeRequest();
+        return (String) Executions.getCurrent().getAttribute("javax.servlet.forward.servlet_path");
+    }
+
+    public String getSessionId() {
+        return getNativeSession().getId();
+    }
+}
index 91565310860e6f000ba78ff3263e1ac850cf6f47..0c4a58fd36372f1c4fc6fbec4b6022e1d1b80b30 100644 (file)
@@ -88,6 +88,7 @@ public class AssociatesViewModel {
             }
         });
         editorWindow.doModal();
+        editorWindow.setFocus(true);
     }
 
     @Command
@@ -113,6 +114,7 @@ public class AssociatesViewModel {
             }
         });
         editorWindow.doModal();
+        editorWindow.setFocus(true);
     }
 
 
index 9fa78cab804c1b7f721c00b9c4fe495bf3d22afe..fc374c54f647a77e04b79b04cc84b48cd4214f6b 100644 (file)
@@ -3,6 +3,7 @@ package hu.user.lis.ui.view;
 import com.google.common.collect.ImmutableMap;
 import hu.user.lis.ui.Constants;
 import hu.user.lis.ui.event.EventBus;
+import hu.user.lis.ui.session.SessionSettings;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.extern.log4j.Log4j2;
@@ -12,15 +13,11 @@ import org.zkoss.bind.annotation.BindingParam;
 import org.zkoss.bind.annotation.Command;
 import org.zkoss.bind.annotation.Destroy;
 import org.zkoss.bind.annotation.Init;
-import org.zkoss.zk.ui.Executions;
-import org.zkoss.zk.ui.Sessions;
 import org.zkoss.zk.ui.event.Event;
 import org.zkoss.zk.ui.event.EventListener;
 import org.zkoss.zk.ui.select.annotation.VariableResolver;
 import org.zkoss.zk.ui.select.annotation.WireVariable;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
 import java.util.Map;
 
 @Log4j2
@@ -38,6 +35,9 @@ public class IndexViewModel implements EventListener {
 
     @WireVariable
     BuildProperties buildProperties;
+    @WireVariable
+    SessionSettings sessionSettings;
+
     @WireVariable
     EventBus eventBus;
     String searchPhrase;
@@ -54,19 +54,31 @@ public class IndexViewModel implements EventListener {
 
     @Init
     public void init() {
-        HttpSession s = (HttpSession) Sessions.getCurrent().getNativeSession();
-        log.info("Current session is {}", s.getId());
-        HttpServletRequest nativeRequest = (HttpServletRequest) Executions.getCurrent().getNativeRequest();
-        String path = (String) Executions.getCurrent().getAttribute("javax.servlet.forward.servlet_path");
-        if (navigation.containsKey(path)) {
-            setPage(navigation.get(path));
-        } else {
-            setPage(PARTNERS_LIST);
-        }
         eventBus.register(this);
+        log.info("Current session is {}", sessionSettings.getSessionId());
+        String path = sessionSettings.getCurrentPath();
+
+        //project editor
+        route(path);
+
         log.info("Init {}", path);
     }
 
+    private void route(String path) {
+        if (path.startsWith("/project/") && path.split("/").length > 2) {
+            String id = path.split("/")[2];
+            selectPage(PROJECT_EDITOR);
+//            eventBus.setProjectEditorData(Collections.singletonMap("id", id));
+            eventBus.setProjectEditorData(id);
+        } else {
+            if (navigation.containsKey(path)) {
+                setPage(navigation.get(path));
+            } else {
+                setPage(PARTNERS_LIST);
+            }
+        }
+    }
+
 
     @Command
     public void selectPage(@BindingParam("page") String page) {
index 35864f3faae1f3bdfe4812bee3f5e21fd8f07bd3..a6ecd8853a81b2a3aeb19e5f267170e3477e277a 100644 (file)
@@ -101,6 +101,7 @@ public class PartnersViewModel extends AsyncBaseModel {
             }
         });
         editorWindow.doModal();
+        editorWindow.setFocus(true);
     }
 
     @Command
@@ -126,6 +127,7 @@ public class PartnersViewModel extends AsyncBaseModel {
             }
         });
         editorWindow.doModal();
+        editorWindow.setFocus(true);
     }
 
 
index 3a1afb3ac1f33b3c7687da81a9413f10c50f0179..88cac06b58a9b3e44b34f944e2abd4404d73941b 100644 (file)
@@ -1,6 +1,5 @@
 package hu.user.lis.ui.view;
 
-import com.google.common.collect.ImmutableMap;
 import hu.user.lis.db.Project;
 import hu.user.lis.db.ProjectStatus;
 import hu.user.lis.services.data.ProjectStatusService;
@@ -87,7 +86,8 @@ public class ProjectsViewModel extends AsyncBaseModel implements EventListener {
     @Command
     public void onAdd() {
         Project newEntity = projectsDataModel.getProjectService().createNew();
-        eventBus.showProjectEditor(ImmutableMap.of("formDocument", newEntity));
+//        eventBus.showProjectEditor(ImmutableMap.of("formDocument", newEntity));
+        eventBus.showProjectEditor(null);
     }
 
     @Command
@@ -95,8 +95,9 @@ public class ProjectsViewModel extends AsyncBaseModel implements EventListener {
         if (Objects.isNull(selectedProject)) {
             return;
         }
-        Project editEntity = projectsDataModel.getProjectService().copy(selectedProject);
-        eventBus.showProjectEditor(ImmutableMap.of("origDocument", selectedProject, "formDocument", editEntity));
+//        Project editEntity = projectsDataModel.getProjectService().copy(selectedProject);
+//        eventBus.showProjectEditor(ImmutableMap.of("origDocument", selectedProject, "formDocument", editEntity));
+        eventBus.showProjectEditor(selectedProject.getId());
     }
 
     public boolean isFilterShowInActive() {
index 10f93037136b3ddb054221c56998b24639c50a12..4befd0f2cde8b3e42d748dd18de43574ded8149b 100644 (file)
@@ -64,7 +64,7 @@ public class ServiceRecordsViewModel implements EventListener {
     public void onProjectFilterBandChanging(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) {
         InputEvent event = (InputEvent) ctx.getTriggerEvent();
         log.info("onProjectFilterBandChanging: {}", event.getValue());
-        projectSelectorDataModel.search(event.getValue(), null, null);
+        projectSelectorDataModel.search(event.getValue());
     }
 
     @Command
@@ -127,6 +127,7 @@ public class ServiceRecordsViewModel implements EventListener {
             }
         });
         editorWindow.doModal();
+        editorWindow.setFocus(true);
     }
 
     @Command
@@ -150,6 +151,7 @@ public class ServiceRecordsViewModel implements EventListener {
             }
         });
         editorWindow.doModal();
+        editorWindow.setFocus(true);
     }
 
     public void setFilterProject(Project filterProject) {
index 527c27500df47b8d8467702ea8bf357de0b33a2b..aa484cd15c1acfe26d8b4636b074a0136d0b6e6a 100644 (file)
@@ -31,7 +31,7 @@
                                            format="locale:hu-HU" instant="true"
                                            forward="onOK=submit.onClick, onCancel=cancel.onClick"/>
                                 <label value="Aktív"/>
-                                <checkbox mold="switch" checked="@bind(vm.formDocument.active)  @validator(vm)"/>
+                                <checkbox mold="switch" checked="@bind(vm.formDocument.active) @validator(vm)"/>
                             </vlayout>
                         </tabpanel>
                     </tabpanels>
index 285a3f92fffa0a49194ae0bbc378227bde025194..fe8e52ed63bf91a9f6fa24a885caa9d025079a02 100644 (file)
@@ -6,7 +6,7 @@
         import hu.user.lis.db.Currency;
         ListModelList currencies = new ListModelList(Currency.values());
     </zscript>
-    <window id="invoicePopup" width="50%" height="500px" closable="true"
+    <window id="invoicePopup" width="50%" height="400px" closable="true"
             maximizable="true" sizable="true" viewModel="@id('vm') @init('hu.user.lis.ui.editor.InvoiceEditorModel')">
         <caption label="Bejövő számla szerkesztés"/>
         <borderlayout>
@@ -19,8 +19,6 @@
                     <tabpanels>
                         <tabpanel>
                             <vlayout hflex="true">
-                                <label value="Tervezett"/>
-                                <checkbox mold="switch" checked="@bind(vm.formDocument.planned)"/>
                                 <label value="Leírás"/>
                                 <textbox hflex="true" instant="true"
                                          value="@bind(vm.formDocument.title) @validator(vm)"
@@ -81,6 +79,8 @@
                                                  forward="onOK=submit.onClick, onCancel=cancel.onClick"/>
                                     </vlayout>
                                 </hlayout>
+                                <label value="Tervezett"/>
+                                <checkbox mold="switch" checked="@bind(vm.formDocument.planned)"/>
                             </vlayout>
                         </tabpanel>
                         <tabpanel>
index 416fd6ff50631ea7f5376ce4b27ae4fc37bc8e19..d5e4c9ad61aa07a7d69c6a3586a29f88597d3d84 100644 (file)
@@ -6,7 +6,7 @@
         import hu.user.lis.db.Currency;
         ListModelList currencies = new ListModelList(Currency.values());
     </zscript>
-    <window id="invoicePopup" width="50%" height="500px" closable="true"
+    <window id="invoicePopup" width="50%" height="400px" closable="true"
             maximizable="true" sizable="true" viewModel="@id('vm') @init('hu.user.lis.ui.editor.InvoiceEditorModel')">
         <caption label="Kimenő számla szerkesztés"/>
         <borderlayout>
@@ -19,8 +19,6 @@
                     <tabpanels>
                         <tabpanel>
                             <vlayout hflex="true">
-                                <label value="Tervezett"/>
-                                <checkbox mold="switch" checked="@bind(vm.formDocument.planned)"/>
                                 <label value="Leírás"/>
                                 <textbox hflex="true" instant="true"
                                          value="@bind(vm.formDocument.title) @validator(vm)"
@@ -81,6 +79,8 @@
                                                  forward="onOK=submit.onClick, onCancel=cancel.onClick"/>
                                     </vlayout>
                                 </hlayout>
+                                <label value="Tervezett"/>
+                                <checkbox mold="switch" checked="@bind(vm.formDocument.planned)"/>
                             </vlayout>
                         </tabpanel>
                         <tabpanel>