From: elgekko Date: Sat, 27 May 2023 19:39:32 +0000 (+0200) Subject: Bugfixes + project editor added to route X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=d16997a6946adbe0352fcb6fa140d531d4f4b78c;p=sly-crm.git Bugfixes + project editor added to route --- diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectSelectorDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectSelectorDataModel.java index 48c4786..39a7117 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectSelectorDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectSelectorDataModel.java @@ -22,26 +22,20 @@ public class ProjectSelectorDataModel extends CachedDataModel { 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 { 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, "*"); } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/editor/PartnerEditorModel.java b/lis-ui/src/main/java/hu/user/lis/ui/editor/PartnerEditorModel.java index 2009fe1..6cbf94b 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/editor/PartnerEditorModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/editor/PartnerEditorModel.java @@ -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) { diff --git a/lis-ui/src/main/java/hu/user/lis/ui/editor/ProjectEditorModel.java b/lis-ui/src/main/java/hu/user/lis/ui/editor/ProjectEditorModel.java index 2b871a9..9fb4593 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/editor/ProjectEditorModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/editor/ProjectEditorModel.java @@ -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 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 data = (Map) 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 mapData = (Map) 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 diff --git a/lis-ui/src/main/java/hu/user/lis/ui/editor/ServiceRecordEditorModel.java b/lis-ui/src/main/java/hu/user/lis/ui/editor/ServiceRecordEditorModel.java index 3e9bdb7..5fd2e3d 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/editor/ServiceRecordEditorModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/editor/ServiceRecordEditorModel.java @@ -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 index 0000000..c2be049 --- /dev/null +++ b/lis-ui/src/main/java/hu/user/lis/ui/session/SessionSettings.java @@ -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(); + } +} diff --git a/lis-ui/src/main/java/hu/user/lis/ui/view/AssociatesViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/AssociatesViewModel.java index 9156531..0c4a58f 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/view/AssociatesViewModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/AssociatesViewModel.java @@ -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); } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/view/IndexViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/IndexViewModel.java index 9fa78ca..fc374c5 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/view/IndexViewModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/IndexViewModel.java @@ -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) { diff --git a/lis-ui/src/main/java/hu/user/lis/ui/view/PartnersViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/PartnersViewModel.java index 35864f3..a6ecd88 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/view/PartnersViewModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/PartnersViewModel.java @@ -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); } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/view/ProjectsViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/ProjectsViewModel.java index 3a1afb3..88cac06 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/view/ProjectsViewModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/ProjectsViewModel.java @@ -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() { diff --git a/lis-ui/src/main/java/hu/user/lis/ui/view/ServiceRecordsViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/ServiceRecordsViewModel.java index 10f9303..4befd0f 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/view/ServiceRecordsViewModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/ServiceRecordsViewModel.java @@ -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) { diff --git a/lis-ui/src/main/resources/web/associate-editor.zul b/lis-ui/src/main/resources/web/associate-editor.zul index 527c275..aa484cd 100644 --- a/lis-ui/src/main/resources/web/associate-editor.zul +++ b/lis-ui/src/main/resources/web/associate-editor.zul @@ -31,7 +31,7 @@ format="locale:hu-HU" instant="true" forward="onOK=submit.onClick, onCancel=cancel.onClick"/>