From: elgekko Date: Wed, 26 Jul 2023 21:55:48 +0000 (+0200) Subject: Entity selector for project partner implemented X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=58cea0c63dc8b1c73d886848b6f22d8bcaeb24dd;p=sly-crm.git Entity selector for project partner implemented --- diff --git a/lis-app/src/main/resources/application-dev.yaml b/lis-app/src/main/resources/application-dev.yaml index ed967ff..fe83809 100644 --- a/lis-app/src/main/resources/application-dev.yaml +++ b/lis-app/src/main/resources/application-dev.yaml @@ -9,7 +9,7 @@ spring: jpa: hibernate: use-new-id-generator-mappings: false - show-sql: true + show-sql: false properties: hibernate: format_sql: true @@ -24,8 +24,8 @@ spring: logging: level: org.hibernate.engine.jdbc.spi.SqlExceptionHelper: ERROR - org.springframework.security: DEBUG - org.springframework.security.web: INFO +# org.springframework.security: DEBUG +# org.springframework.security.web: INFO # pattern: # console: "%d %-5level %logger : %msg%n" # file: "%d %-5level [%thread] %logger : %msg%n" \ No newline at end of file diff --git a/lis-app/src/main/resources/application.yaml b/lis-app/src/main/resources/application.yaml index 3f2d8e4..0607c5e 100644 --- a/lis-app/src/main/resources/application.yaml +++ b/lis-app/src/main/resources/application.yaml @@ -9,7 +9,7 @@ spring: jpa: hibernate: use-new-id-generator-mappings: false - show-sql: true + show-sql: false properties: hibernate: format_sql: true @@ -24,8 +24,8 @@ spring: logging: level: org.hibernate.engine.jdbc.spi.SqlExceptionHelper: ERROR - org.springframework.security: DEBUG - org.springframework.security.web: INFO +# org.springframework.security: DEBUG +# org.springframework.security.web: INFO # pattern: # console: "%d %-5level %logger : %msg%n" # file: "%d %-5level [%thread] %logger : %msg%n" \ No newline at end of file diff --git a/lis-db/migrations/environments/development.properties b/lis-db/migrations/environments/development.properties index 7f3b454..8ca0d80 100644 --- a/lis-db/migrations/environments/development.properties +++ b/lis-db/migrations/environments/development.properties @@ -1,15 +1,12 @@ ## Base time zone to ensure times are consistent across machines time_zone=GMT+0:00 - ## The character set that scripts are encoded with script_char_set=UTF-8 - ## JDBC connection properties. driver=com.ibm.db2.jcc.DB2Driver url=jdbc:db2://localhost:50000/lis username=db2admin password=password - # # A NOTE ON STORED PROCEDURES AND DELIMITERS # @@ -25,13 +22,11 @@ password=password # or databases don't support creating procs, functions or # even tables in a transaction, and others require it. # - # This ignores the line delimiters and # simply sends the entire script at once. # Use with JDBC drivers that can accept large # blocks of delimited text at once. send_full_script=false - # This controls how statements are delimited. # By default statements are delimited by an # end of line semicolon. Some databases may @@ -40,25 +35,20 @@ send_full_script=false # These are ignored if send_full_script is true. delimiter=; full_line_delimiter=false - # If set to true, each statement is isolated # in its own transaction. Otherwise the entire # script is executed in one transaction. # Few databases should need this set to true, # but some do. auto_commit=false - # If set to false, warnings from the database will interrupt migrations. -ignore_warnings=false - +ignore_warnings=true # Custom driver path to allow you to centralize your driver files # Default requires the drivers to be in the drivers directory of your # initialized migration directory (created with "migrate init") # driver_path= - # Name of the table that tracks changes to the database changelog=CHANGELOG - # Migrations support variable substitutions in the form of ${variable} # in the migration scripts. All of the above properties will be ignored though, # with the exception of changelog. diff --git a/lis-db/migrations/environments/prod.properties b/lis-db/migrations/environments/prod.properties index 52d2dfd..c5d02a9 100644 --- a/lis-db/migrations/environments/prod.properties +++ b/lis-db/migrations/environments/prod.properties @@ -1,15 +1,12 @@ ## Base time zone to ensure times are consistent across machines time_zone=GMT+0:00 - ## The character set that scripts are encoded with script_char_set=UTF-8 - ## JDBC connection properties. driver=com.ibm.db2.jcc.DB2Driver url=jdbc:db2://dvdev.in.useribm.hu:50000/lis username=db2admin password=password - # # A NOTE ON STORED PROCEDURES AND DELIMITERS # @@ -25,13 +22,11 @@ password=password # or databases don't support creating procs, functions or # even tables in a transaction, and others require it. # - # This ignores the line delimiters and # simply sends the entire script at once. # Use with JDBC drivers that can accept large # blocks of delimited text at once. send_full_script=false - # This controls how statements are delimited. # By default statements are delimited by an # end of line semicolon. Some databases may @@ -40,25 +35,20 @@ send_full_script=false # These are ignored if send_full_script is true. delimiter=; full_line_delimiter=false - # If set to true, each statement is isolated # in its own transaction. Otherwise the entire # script is executed in one transaction. # Few databases should need this set to true, # but some do. auto_commit=false - # If set to false, warnings from the database will interrupt migrations. -ignore_warnings=false - +ignore_warnings=true # Custom driver path to allow you to centralize your driver files # Default requires the drivers to be in the drivers directory of your # initialized migration directory (created with "migrate init") # driver_path= - # Name of the table that tracks changes to the database changelog=CHANGELOG - # Migrations support variable substitutions in the form of ${variable} # in the migration scripts. All of the above properties will be ignored though, # with the exception of changelog. diff --git a/lis-db/migrations/scripts/004_create_default_user.sql b/lis-db/migrations/scripts/004_create_default_user.sql deleted file mode 100644 index 77589d4..0000000 --- a/lis-db/migrations/scripts/004_create_default_user.sql +++ /dev/null @@ -1,10 +0,0 @@ --- // create default user --- Migration SQL that makes the change goes here. - -INSERT INTO ASSOCIATE (login, password, monthly_cost, active) VALUES ('user', 'password', 1, 1); - --- //@UNDO --- SQL to undo the change goes here. - -DELETE FROM ASSOCIATE WHERE login = 'user'; - diff --git a/lis-db/migrations/scripts/004_create_test_data.sql b/lis-db/migrations/scripts/004_create_test_data.sql new file mode 100644 index 0000000..2549b12 --- /dev/null +++ b/lis-db/migrations/scripts/004_create_test_data.sql @@ -0,0 +1,33 @@ +-- // create test data +-- Migration SQL that makes the change goes here. + +INSERT INTO ASSOCIATE + (name, login, password, monthly_cost, active) +VALUES + ('Test User', 'user', 'password', 1, 1); + +INSERT INTO PARTNER + (ID, NAME, VAT_NR, ACTIVE) +VALUES + (1, 'NYÍRŐ', '00000000-00-0', 1), + (2, 'KOLOS', '00000000-00-0', 1); + + +INSERT INTO PROJECT_STATUS + (ID, NAME, ACTIVE, "ORDER") +VALUES + (1, 'START', 1, 1); + +INSERT INTO PROJECT + (ID, PROJECT_STATUS_ID, NAME, HUMAN_ID, CONTACT_NAME, PARTNER_ID, ACTIVE) +VALUES + (1, 1, 'Halászat', '2023-01', 'Kovács', 1, 1); + + +-- //@UNDO +-- SQL to undo the change goes here. + +DELETE FROM ASSOCIATE; +DELETE FROM PARTNER; +DELETE FROM PROJECT_STATUS; +DELETE FROM PROJECT; diff --git a/lis-services/src/main/java/hu/user/lis/services/data/AssociateEntityDataService.java b/lis-services/src/main/java/hu/user/lis/services/data/AssociateEntityDataService.java deleted file mode 100644 index 24789b3..0000000 --- a/lis-services/src/main/java/hu/user/lis/services/data/AssociateEntityDataService.java +++ /dev/null @@ -1,6 +0,0 @@ -package hu.user.lis.services.data; - -import hu.user.lis.db.Associate; - -public class AssociateEntityDataService extends EntityDataService { -} diff --git a/lis-services/src/main/java/hu/user/lis/services/data/EntityDataService.java b/lis-services/src/main/java/hu/user/lis/services/data/EntityDataService.java index 9220531..6863607 100644 --- a/lis-services/src/main/java/hu/user/lis/services/data/EntityDataService.java +++ b/lis-services/src/main/java/hu/user/lis/services/data/EntityDataService.java @@ -32,7 +32,7 @@ public class EntityDataService { field.set(entity, value); result = true; } catch (Exception e) { - //log.error(e.getMessage()); + log.error(e); } return result; } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/Constants.java b/lis-ui/src/main/java/hu/user/lis/ui/Constants.java index f669779..04ef7d4 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/Constants.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/Constants.java @@ -1,8 +1,10 @@ package hu.user.lis.ui; public class Constants { + public static final String BINDING_QUEUE = "$ZKBIND_DEFQUE$"; public static final String SHOW_PROJECT_EDITOR = "SHOW_PROJECT_EDITOR"; public static final String SHOW_PROJECTS_LIST = "SHOW_PROJECTS_LIST"; + public static final String SHOW_SERVICE_RECORDS_LIST = "SHOW_SERVICE_RECORDS_LIST"; public static final String SET_SERVICE_RECORDS_LIST_DATA = "SET_SERVICE_RECORDS_LIST_DATA"; public static final String SET_PROJECT_EDITOR_DATA = "SET_PROJECT_EDITOR_DATA"; diff --git a/lis-ui/src/main/java/hu/user/lis/ui/converter/PartnerToNameConverter.java b/lis-ui/src/main/java/hu/user/lis/ui/converter/PartnerToNameConverter.java index 8422789..c152fff 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/converter/PartnerToNameConverter.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/converter/PartnerToNameConverter.java @@ -1,10 +1,15 @@ package hu.user.lis.ui.converter; import hu.user.lis.db.Partner; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; import org.zkoss.bind.BindContext; import org.zkoss.bind.Converter; import org.zkoss.zul.Bandbox; +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class PartnerToNameConverter implements Converter { @Override diff --git a/lis-ui/src/main/java/hu/user/lis/ui/editor/EntityEditorModel.java b/lis-ui/src/main/java/hu/user/lis/ui/editor/EntityEditorModel.java index ca9927d..ce7ed17 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/editor/EntityEditorModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/editor/EntityEditorModel.java @@ -1,40 +1,46 @@ package hu.user.lis.ui.editor; import hu.user.lis.services.data.EntityDataService; +import hu.user.lis.ui.editor.selector.EntitySelectorRouter; +import hu.user.lis.ui.event.EventBus; import lombok.Getter; import lombok.extern.log4j.Log4j2; import org.zkoss.bind.BindUtils; +import org.zkoss.bind.PropertyChangeEvent; import org.zkoss.bind.ValidationContext; -import org.zkoss.bind.annotation.*; +import org.zkoss.bind.annotation.BindingParam; +import org.zkoss.bind.annotation.Command; import org.zkoss.bind.validator.AbstractValidator; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.event.Event; +import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; -import org.zkoss.zk.ui.select.Selectors; import org.zkoss.zk.ui.select.annotation.VariableResolver; import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zkplus.spring.DelegatingVariableResolver; import org.zkoss.zul.Window; import java.io.Serializable; +import java.util.Objects; @Log4j2 @VariableResolver(DelegatingVariableResolver.class) -public abstract class EntityEditorModel extends AbstractValidator { +public abstract class EntityEditorModel extends AbstractValidator implements EventListener { + @WireVariable + protected EventBus eventBus; @Getter T formDocument; - T origDocument; - @Getter boolean saveEnabled; - @WireVariable EntityDataService entityDataService; - + @Getter + @WireVariable + EntitySelectorRouter entitySelectorRouter; @Command public void onCloseWindow(@BindingParam("target") Window target, @BindingParam("save") boolean save) { @@ -53,14 +59,10 @@ public abstract class EntityEditorModel extends Abstract BindUtils.postNotifyChange(this, "saveEnabled"); } - @AfterCompose - public void onAfterCompose(@ContextParam(ContextType.VIEW) Component view) { - Selectors.wireComponents(view, this, false); - Selectors.wireEventListeners(view, this); - } - - @Init public void init() { + eventBus.register(this); + eventBus.registerForBinding(this); + origDocument = (T) Executions.getCurrent().getArg().get("origDocument"); formDocument = (T) Executions.getCurrent().getArg().get("formDocument"); } @@ -89,4 +91,19 @@ public abstract class EntityEditorModel extends Abstract setSaveEnabled(enable); } + protected void validate() { + validate(formDocument); + } + + @Override + public void onEvent(Event evt) { + if (evt instanceof PropertyChangeEvent) { + PropertyChangeEvent propertyEvent = (PropertyChangeEvent) evt; + if (Objects.nonNull(propertyEvent.getBase()) && Objects.nonNull(formDocument) && propertyEvent.getBase().equals(formDocument)) { + log.info("Event {}", evt.getName()); + validate(); + } + } + } + } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/editor/InvoiceEditorModel.java b/lis-ui/src/main/java/hu/user/lis/ui/editor/InvoiceEditorModel.java index 1f897d2..9dfa198 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/editor/InvoiceEditorModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/editor/InvoiceEditorModel.java @@ -41,7 +41,7 @@ public class InvoiceEditorModel extends EntityEditorModel { formDocument.setGrossAmount(formDocument.getNetAmount() * 1.27); formDocument.setVatAmount(formDocument.getGrossAmount() - formDocument.getNetAmount()); BindUtils.postNotifyChange(this.formDocument, "grossAmount", "vatAmount"); - validate(formDocument); + validate(); } } @@ -82,13 +82,13 @@ public class InvoiceEditorModel extends EntityEditorModel { } formDocument.setFile(evt.getMedia().getByteData()); BindUtils.postNotifyChange(this.formDocument, "file"); - validate(formDocument); + validate(); } @Command public void onRemoveFile() { formDocument.setFile(null); BindUtils.postNotifyChange(this.formDocument, "file"); - validate(formDocument); + validate(); } } 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 0128c81..519cc58 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 @@ -6,7 +6,6 @@ import hu.user.lis.db.*; 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 lombok.Getter; import lombok.Setter; import lombok.extern.log4j.Log4j2; @@ -15,7 +14,6 @@ import org.zkoss.bind.BindContext; import org.zkoss.bind.BindUtils; import org.zkoss.bind.annotation.*; import org.zkoss.zk.ui.event.Event; -import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.InputEvent; import org.zkoss.zk.ui.event.OpenEvent; import org.zkoss.zk.ui.select.annotation.WireVariable; @@ -27,82 +25,95 @@ import org.zkoss.zul.Window; import java.util.*; @Log4j2 -@Getter -@Setter -public class ProjectEditorModel extends EntityEditorModel implements EventListener { +public class ProjectEditorModel extends EntityEditorModel { + @Getter + @Setter @WireVariable AssociatesDataModel associatesDataModel; - @WireVariable ProjectsDataModel projectsDataModel; - @WireVariable private PartnerSelectorDataModel partnerSelectorDataModel; - @WireVariable private InvoiceDataModel invoiceDataModel; - @WireVariable private TreasuryDataModel treasuryDataModel; - + @Getter + @Setter @WireVariable private ServiceRecordsDataModel serviceRecordsDataModel; - + @Getter + @Setter @WireVariable private ProjectStatusDataModel projectStatusDataModel; - + @Getter + @Setter @WireVariable private IncomeMarginsDataModel incomeMarginsDataModel; - @WireVariable private ProjectAssociatesDataModel projectAssociatesDataModel; - + @Getter + @Setter @WireVariable private ProjectStatusConverter projectStatusConverter; - - @WireVariable - private EventBus eventBus; - private Map origAssociates; - + @Getter + @Setter private Map formAssociates; - + @Getter + @Setter private IncomingInvoice selectedIncomingInvoice; - + @Getter + @Setter private OutgoingInvoice selectedOutgoingInvoice; - + @Getter + @Setter private Treasury selectedTreasury; - + @Getter + @Setter private String partialAssociateName; @Init public void init() { + super.init(); projectStatusDataModel.listAll(); - eventBus.register(this); + } + + @Command + public void onSelectedEntityChanged(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) { + Event event = (Event) ctx.getTriggerEvent(); + log.info("{}", event); } @Override public void onEvent(Event evt) { + super.onEvent(evt); if (Constants.SET_PROJECT_EDITOR_DATA.equals(evt.getName())) { - log.info("Got event {}", Constants.SET_PROJECT_EDITOR_DATA); Object data = evt.getData(); - if (Objects.isNull(data)) { - formDocument = projectsDataModel.createNew(); - log.info("Loading new entity {} to editor", formDocument.getId()); - } else { - Long id = (Long) data; - - Clients.evalJavaScript(String.format("pushNav('/project/%d')", id)); - log.info("Loading entity {} to editor", id); - formDocument = projectsDataModel.getById(id); - origDocument = projectsDataModel.clone(formDocument); - } + initDocuments(data); + initDetails(); + } + } + + private void initDetails() { + initAssociates(); + serviceRecordsDataModel.search(formDocument, true); + incomeMarginsDataModel.recalculate(formDocument); + entitySelectorRouter.setFormDocument(Partner.class, formDocument, "partner"); + } - initAssociates(); - serviceRecordsDataModel.search(formDocument, true); - incomeMarginsDataModel.recalculate(formDocument); - BindUtils.postNotifyChange(this, "formDocument"); + private void initDocuments(Object data) { + if (Objects.isNull(data)) { + formDocument = projectsDataModel.createNew(); + log.info("Loading new entity {} to editor", formDocument.getId()); + } else { + Long id = (Long) data; + Clients.evalJavaScript(String.format("pushNav('/project/%d')", id)); + log.info("Loading entity {} to editor", id); + formDocument = projectsDataModel.getById(id); + origDocument = projectsDataModel.clone(formDocument); } + BindUtils.postNotifyChange(this, "formDocument"); } @NotifyChange("associatesDataModel") @@ -173,7 +184,7 @@ public class ProjectEditorModel extends EntityEditorModel implements Ev Editors.doEdit(Editors.INCOMING_INVOICE, entity, modifiedEntity -> { formDocument.getIncomingInvoices().add(modifiedEntity); selectedIncomingInvoice = modifiedEntity; - validate(formDocument); + validate(); BindUtils.postNotifyChange(this, "selectedIncomingInvoice"); BindUtils.postNotifyChange(this.formDocument, "incomingInvoices"); }); @@ -187,7 +198,7 @@ public class ProjectEditorModel extends EntityEditorModel implements Ev incomingInvoices.remove(selectedIncomingInvoice); incomingInvoices.add(modifiedEntity); selectedIncomingInvoice = modifiedEntity; - validate(formDocument); + validate(); BindUtils.postNotifyChange(this, "selectedIncomingInvoice"); BindUtils.postNotifyChange(this.formDocument, "incomingInvoices"); }); @@ -198,7 +209,7 @@ public class ProjectEditorModel extends EntityEditorModel implements Ev if (Objects.nonNull(selectedIncomingInvoice)) { formDocument.getIncomingInvoices().remove(selectedIncomingInvoice); selectedIncomingInvoice = null; - validate(formDocument); + validate(); BindUtils.postNotifyChange(this, "selectedIncomingInvoice"); BindUtils.postNotifyChange(this.formDocument, "incomingInvoices"); } @@ -210,7 +221,7 @@ public class ProjectEditorModel extends EntityEditorModel implements Ev Editors.doEdit(Editors.OUTGOING_INVOICE, entity, modifiedEntity -> { formDocument.getOutgoingInvoices().add(modifiedEntity); selectedOutgoingInvoice = modifiedEntity; - validate(formDocument); + validate(); BindUtils.postNotifyChange(this, "selectedOutgoingInvoice"); BindUtils.postNotifyChange(this.formDocument, "outgoingInvoices"); }); @@ -224,7 +235,7 @@ public class ProjectEditorModel extends EntityEditorModel implements Ev outgoingInvoices.remove(selectedOutgoingInvoice); outgoingInvoices.add(modifiedEntity); selectedOutgoingInvoice = modifiedEntity; - validate(formDocument); + validate(); BindUtils.postNotifyChange(this, "selectedOutgoingInvoice"); BindUtils.postNotifyChange(this.formDocument, "outgoingInvoices"); }); @@ -235,7 +246,7 @@ public class ProjectEditorModel extends EntityEditorModel implements Ev if (Objects.nonNull(selectedOutgoingInvoice)) { formDocument.getOutgoingInvoices().remove(selectedOutgoingInvoice); selectedOutgoingInvoice = null; - validate(formDocument); + validate(); BindUtils.postNotifyChange(this, "selectedOutgoingInvoice"); BindUtils.postNotifyChange(this.formDocument, "outgoingInvoice"); } @@ -247,7 +258,7 @@ public class ProjectEditorModel extends EntityEditorModel implements Ev Editors.doEdit(Editors.TREASURY, entity, modifiedEntity -> { formDocument.getTreasuries().add(modifiedEntity); selectedTreasury = modifiedEntity; - validate(formDocument); + validate(); BindUtils.postNotifyChange(this, "selectedTreasury"); BindUtils.postNotifyChange(this.formDocument, "treasuries"); }); @@ -261,7 +272,7 @@ public class ProjectEditorModel extends EntityEditorModel implements Ev treasuries.remove(selectedTreasury); treasuries.add(modifiedEntity); selectedTreasury = modifiedEntity; - validate(formDocument); + validate(); BindUtils.postNotifyChange(this, "selectedTreasury"); BindUtils.postNotifyChange(this.formDocument, "treasuries"); }); @@ -272,7 +283,7 @@ public class ProjectEditorModel extends EntityEditorModel implements Ev if (Objects.nonNull(selectedTreasury)) { formDocument.getTreasuries().remove(selectedTreasury); selectedTreasury = null; - validate(formDocument); + validate(); BindUtils.postNotifyChange(this, "selectedTreasury"); BindUtils.postNotifyChange(this.formDocument, "treasuries"); } @@ -341,7 +352,7 @@ public class ProjectEditorModel extends EntityEditorModel implements Ev @Command public void onAssociateChecked() { log.info("Associate checked"); - validate(formDocument); + validate(); } } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/editor/selector/EntitySelectorModel.java b/lis-ui/src/main/java/hu/user/lis/ui/editor/selector/EntitySelectorModel.java new file mode 100644 index 0000000..cfba1ed --- /dev/null +++ b/lis-ui/src/main/java/hu/user/lis/ui/editor/selector/EntitySelectorModel.java @@ -0,0 +1,76 @@ +package hu.user.lis.ui.editor.selector; + +import hu.user.lis.ui.data.CachedSpringDataModel; +import lombok.extern.log4j.Log4j2; +import org.zkoss.bind.BindContext; +import org.zkoss.bind.BindUtils; +import org.zkoss.bind.Converter; +import org.zkoss.bind.annotation.Command; +import org.zkoss.bind.annotation.ContextParam; +import org.zkoss.bind.annotation.ContextType; +import org.zkoss.zk.ui.event.InputEvent; +import org.zkoss.zk.ui.event.OpenEvent; +import org.zkoss.zul.Bandbox; + +import java.lang.reflect.Field; + +@Log4j2 +public abstract class EntitySelectorModel { + + private T selectedEntity; + private Object formDocument; + private String member; + + public abstract String selectorIdentifier(); + + public abstract Converter getDisplayConverter(); + + public abstract CachedSpringDataModel getDataModel(); + + @Command + public void onEntityBandChanging(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) { + InputEvent event = (InputEvent) ctx.getTriggerEvent(); + log.info("onEntityBandChanging: {}", event.getValue()); + search(event.getValue()); + } + + @Command + public void onEntityBandOpen(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) { + OpenEvent event = (OpenEvent) ctx.getTriggerEvent(); + log.info("onEntityBandOpen: {}", event.isOpen()); + reset(); + } + + protected abstract void search(String filter); + + protected abstract void reset(); + + public T getSelectedEntity() { + return selectedEntity; + } + + public void setSelectedEntity(T selectedEntity) { + this.selectedEntity = selectedEntity; + try { + Field field = formDocument.getClass().getDeclaredField(member); + field.setAccessible(true); + field.set(formDocument, selectedEntity); + BindUtils.postNotifyChange(formDocument, member); + } catch (Exception e) { + log.error(e); + } + } + + public void setFormDocument(Object formDocument, String member) { + this.formDocument = formDocument; + this.member = member; + try { + Field field = formDocument.getClass().getDeclaredField(member); + field.setAccessible(true); + selectedEntity = (T) field.get(formDocument); + BindUtils.postNotifyChange(this, "selectedEntity"); + } catch (Exception e) { + log.error(e); + } + } +} diff --git a/lis-ui/src/main/java/hu/user/lis/ui/editor/selector/EntitySelectorRouter.java b/lis-ui/src/main/java/hu/user/lis/ui/editor/selector/EntitySelectorRouter.java new file mode 100644 index 0000000..a45643e --- /dev/null +++ b/lis-ui/src/main/java/hu/user/lis/ui/editor/selector/EntitySelectorRouter.java @@ -0,0 +1,46 @@ +package hu.user.lis.ui.editor.selector; + +import lombok.Getter; +import lombok.Setter; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +@Log4j2 +@Getter +@Setter +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class EntitySelectorRouter { + + private Map models; + + private List usedModels = new ArrayList<>(); + + @Autowired + public EntitySelectorRouter(List modelList) { + models = modelList.stream() + .collect(Collectors.toMap(EntitySelectorModel::selectorIdentifier, Function.identity())); + } + + public EntitySelectorModel getEntitySelectorModel(String entityName) { + EntitySelectorModel result = models.get(entityName); + usedModels.add(result); + return result; + } + + public void setFormDocument(Class entityClass, Object formDocument, String member) { + usedModels.stream() + .filter(m -> m.selectorIdentifier().equals(entityClass.getSimpleName())) + .forEach(m -> m.setFormDocument(formDocument, member)); + } + +} diff --git a/lis-ui/src/main/java/hu/user/lis/ui/editor/selector/PartnerSelectorModel.java b/lis-ui/src/main/java/hu/user/lis/ui/editor/selector/PartnerSelectorModel.java new file mode 100644 index 0000000..c07efbf --- /dev/null +++ b/lis-ui/src/main/java/hu/user/lis/ui/editor/selector/PartnerSelectorModel.java @@ -0,0 +1,52 @@ +package hu.user.lis.ui.editor.selector; + +import hu.user.lis.db.Partner; +import hu.user.lis.ui.converter.PartnerToNameConverter; +import hu.user.lis.ui.data.CachedSpringDataModel; +import hu.user.lis.ui.data.PartnerSelectorDataModel; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; +import org.zkoss.bind.Converter; +import org.zkoss.zul.Bandbox; + +@Log4j2 +@Getter +@Setter +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class PartnerSelectorModel extends EntitySelectorModel { + @Autowired + PartnerToNameConverter partnerToNameConverter; + @Autowired + PartnerSelectorDataModel partnerSelectorDataModel; + + @Override + public String selectorIdentifier() { + return Partner.class.getSimpleName(); + } + + @Override + public Converter getDisplayConverter() { + return partnerToNameConverter; + } + + @Override + public CachedSpringDataModel getDataModel() { + return partnerSelectorDataModel; + } + + @Override + protected void search(String filter) { + partnerSelectorDataModel.search(filter); + } + + @Override + protected void reset() { + partnerSelectorDataModel.search(null); + } +} diff --git a/lis-ui/src/main/java/hu/user/lis/ui/editor/widget/EntitySelector.java b/lis-ui/src/main/java/hu/user/lis/ui/editor/widget/EntitySelector.java new file mode 100644 index 0000000..44c91a8 --- /dev/null +++ b/lis-ui/src/main/java/hu/user/lis/ui/editor/widget/EntitySelector.java @@ -0,0 +1,22 @@ +package hu.user.lis.ui.editor.widget; + +import lombok.extern.log4j.Log4j2; +import org.zkoss.zk.ui.Component; +import org.zkoss.zul.Include; + +@Log4j2 +public class EntitySelector extends Include { + + public EntitySelector() { + setSrc("~./entity-selector.zul"); + } + + @Override + public void setDynamicProperty(String name, Object value) { + super.setDynamicProperty(name, value); + setAttribute(name, value, Component.SPACE_SCOPE); + log.info("Setting {} = {}", name, value); + + } + +} diff --git a/lis-ui/src/main/java/hu/user/lis/ui/event/EventBus.java b/lis-ui/src/main/java/hu/user/lis/ui/event/EventBus.java index 21559db..92542ad 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/event/EventBus.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/event/EventBus.java @@ -11,14 +11,32 @@ import org.zkoss.zk.ui.event.EventQueues; @Service @Log4j2 public class EventBus { + + public EventBus() { +// EventQueue queue = EventQueues.lookup("$ZKBIND_DEFQUE$", EventQueues.SESSION, true); +// queue.subscribe(event -> { +// log.info("EVT: {}", event.getName()); +// }); + + + } + private EventQueue getQueue() { return EventQueues.lookup(Constants.PROJECT_EDITOR_QUEUE, EventQueues.SESSION, true); } + private EventQueue getBindingQueue() { + return EventQueues.lookup(Constants.BINDING_QUEUE, EventQueues.DESKTOP, true); + } + public void register(EventListener listener) { getQueue().subscribe(listener); } + public void registerForBinding(EventListener listener) { + getBindingQueue().subscribe(listener); + } + public void unregister(EventListener listener) { try { getQueue().unsubscribe(listener); diff --git a/lis-ui/src/main/resources/web/entity-selector.zul b/lis-ui/src/main/resources/web/entity-selector.zul new file mode 100644 index 0000000..1f71241 --- /dev/null +++ b/lis-ui/src/main/resources/web/entity-selector.zul @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + diff --git a/lis-ui/src/main/resources/web/login.zul b/lis-ui/src/main/resources/web/login.zul index 8f4a36c..158c21d 100644 --- a/lis-ui/src/main/resources/web/login.zul +++ b/lis-ui/src/main/resources/web/login.zul @@ -45,11 +45,11 @@ diff --git a/lis-ui/src/main/resources/web/partner-selector.zul b/lis-ui/src/main/resources/web/partner-selector.zul index 54ae1ec..ead141a 100644 --- a/lis-ui/src/main/resources/web/partner-selector.zul +++ b/lis-ui/src/main/resources/web/partner-selector.zul @@ -19,7 +19,9 @@ zk.$("$partnerBandBox").open(); zAu.send(new zk.Event(zk.Widget.$('$partnerBandBox'), "onOpen", {'open': true}, {toServer:true})); } - zk.$("$partenerList").focus(); + console.log("List", zk.$("$partnerList")); + + zk.$("$partnerList").focus(); return; } if (keyCode == 27){ @@ -31,7 +33,7 @@ ]]> - - \ No newline at end of file diff --git a/lis-ui/src/main/resources/web/project-editor.zul b/lis-ui/src/main/resources/web/project-editor.zul index 153ca3d..92c1d1a 100644 --- a/lis-ui/src/main/resources/web/project-editor.zul +++ b/lis-ui/src/main/resources/web/project-editor.zul @@ -1,4 +1,5 @@ - + + @@ -38,8 +39,9 @@ -