From a6b4a11ac35cd31141e4e8c454a05b963dc15829 Mon Sep 17 00:00:00 2001 From: Yahaya Yusuf Date: Fri, 1 Sep 2023 23:40:53 +0100 Subject: [PATCH 1/9] pull refactor #202 --- apmis-flow/frontend/themes/apmis-theme/main-layout.css | 1 + .../main/java/com/cinoteck/application/views/MainLayout.java | 2 +- .../application/views/campaigndata/CampaignFormBuilder.java | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apmis-flow/frontend/themes/apmis-theme/main-layout.css b/apmis-flow/frontend/themes/apmis-theme/main-layout.css index 70e870b4ca0..a3c895e615f 100644 --- a/apmis-flow/frontend/themes/apmis-theme/main-layout.css +++ b/apmis-flow/frontend/themes/apmis-theme/main-layout.css @@ -686,6 +686,7 @@ vaadin-button#lougoutButton:hover { opacity: 1 !important; background: rgb(109, 93, 79) !important; box-shadow: none !important; +} vaadin-checkbox.custom-checkbox-class:checked { background-color: aquamarine; } diff --git a/apmis-flow/src/main/java/com/cinoteck/application/views/MainLayout.java b/apmis-flow/src/main/java/com/cinoteck/application/views/MainLayout.java index 1250708db1f..16b24d8ec2f 100644 --- a/apmis-flow/src/main/java/com/cinoteck/application/views/MainLayout.java +++ b/apmis-flow/src/main/java/com/cinoteck/application/views/MainLayout.java @@ -263,7 +263,7 @@ private AppNav createNavigation() { // // router.getRegistry().add(new RouteEntry("/dashboard", DashboardView.class)); // -======= +//======= if (nav != null) { nav.addClassName("active"); } diff --git a/apmis-flow/src/main/java/com/cinoteck/application/views/campaigndata/CampaignFormBuilder.java b/apmis-flow/src/main/java/com/cinoteck/application/views/campaigndata/CampaignFormBuilder.java index eaffb5c08d5..d529e37c0da 100644 --- a/apmis-flow/src/main/java/com/cinoteck/application/views/campaigndata/CampaignFormBuilder.java +++ b/apmis-flow/src/main/java/com/cinoteck/application/views/campaigndata/CampaignFormBuilder.java @@ -301,7 +301,7 @@ public CampaignFormBuilder(List formElements, List>>>>>" + comdto.getClusterNumber()); // - + if (!formuuid.equals("nul")) { CampaignFormDataDto formData = FacadeProvider.getCampaignFormDataFacade() From 1b2076bdff9c020ad7a8aebcdc751f04ef8e85e3 Mon Sep 17 00:00:00 2001 From: Yahaya Yusuf Date: Fri, 1 Sep 2023 23:41:28 +0100 Subject: [PATCH 2/9] refactor #202 --- .../main/java/de/symeda/sormas/backend/campaign/Campaign.java | 1 - 1 file changed, 1 deletion(-) diff --git a/sormas-backend/src/main/java/de/symeda/sormas/backend/campaign/Campaign.java b/sormas-backend/src/main/java/de/symeda/sormas/backend/campaign/Campaign.java index a8f960eabe2..b952673b96e 100644 --- a/sormas-backend/src/main/java/de/symeda/sormas/backend/campaign/Campaign.java +++ b/sormas-backend/src/main/java/de/symeda/sormas/backend/campaign/Campaign.java @@ -46,7 +46,6 @@ public class Campaign extends CoreAdo { public static final String CAMPAIGN_DISTRICT_TABLE_NAME = "campaign_district"; public static final String CAMPAIGN_COMMUNITY_TABLE_NAME = "campaign_community"; - public static final String NAME = "name"; public static final String ROUND = "round"; public static final String DESCRIPTION = "description"; From 6ccf5c071eda3fc5ede4ade3dfc253c19ed0c38b Mon Sep 17 00:00:00 2001 From: Yahaya Yusuf Date: Fri, 1 Sep 2023 23:42:20 +0100 Subject: [PATCH 3/9] maintab retained after refresh #202 --- .../views/dashboard/DashboardView.java | 94 ++++++++++++++----- 1 file changed, 68 insertions(+), 26 deletions(-) diff --git a/apmis-flow/src/main/java/com/cinoteck/application/views/dashboard/DashboardView.java b/apmis-flow/src/main/java/com/cinoteck/application/views/dashboard/DashboardView.java index 586ecff5a49..9e410461991 100644 --- a/apmis-flow/src/main/java/com/cinoteck/application/views/dashboard/DashboardView.java +++ b/apmis-flow/src/main/java/com/cinoteck/application/views/dashboard/DashboardView.java @@ -21,6 +21,7 @@ import com.vaadin.flow.component.html.Div; import com.vaadin.flow.component.icon.Icon; import com.vaadin.flow.component.icon.VaadinIcon; +import com.vaadin.flow.component.notification.Notification; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.component.orderedlayout.VerticalLayout; import com.vaadin.flow.component.select.Select; @@ -34,6 +35,7 @@ import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.Route; import com.vaadin.flow.router.RouterLayout; +import com.vaadin.flow.server.VaadinService; import com.vaadin.flow.server.VaadinSession; import de.symeda.sormas.api.FacadeProvider; @@ -61,7 +63,7 @@ @JavaScript("https://code.highcharts.com/modules/accessibility.js") @JavaScript("https://code.highcharts.com/modules/no-data-to-display.js") -public class DashboardView extends VerticalLayout implements RouterLayout , BeforeEnterObserver { +public class DashboardView extends VerticalLayout implements RouterLayout, BeforeEnterObserver { private static final long serialVersionUID = 1851726752523985165L; @@ -83,7 +85,7 @@ public class DashboardView extends VerticalLayout implements RouterLayout , Befo ComboBox cluster = new ComboBox<>(); Select groupby = new Select<>(); - List campaigns; + List campaigns, campaignss; List campaignPhases; List regions; List provinces; @@ -92,7 +94,7 @@ public class DashboardView extends VerticalLayout implements RouterLayout , Befo List campaingYears = new ArrayList<>(); boolean isCampaignChanged; - + private boolean isSubAvaialable = false; private CampaignJurisdictionLevel campaignJurisdictionLevel; @@ -101,6 +103,8 @@ public class DashboardView extends VerticalLayout implements RouterLayout , Befo private Div mainContentContainerx; UserProvider userProvider = new UserProvider(); + + String firstSubtabId = null; public DashboardView() { if (I18nProperties.getUserLanguage() == null) { @@ -115,6 +119,14 @@ public DashboardView() { setSpacing(false); // UI.getCurrent().getPage().reload(); // UI.getCurrent().setDirection(Direction.RIGHT_TO_LEFT); + + if(VaadinService.getCurrentRequest().getWrappedSession().getAttribute("mtabtrack") != null) { + + System.out.println(VaadinService.getCurrentRequest().getWrappedSession().getAttribute("mtabtrack") + + " Pluto is active"); + System.out.println(VaadinService.getCurrentRequest().getWrappedSession().getAttribute("stabtrack") + + " Elon is active"); + } dataProvider = new CampaignDashboardDataProvider(); // String deletab = FacadeProvider.getUserFacade().getCurrentUser().getUsertype().toString(); @@ -122,19 +134,20 @@ public DashboardView() { UserProvider usr = new UserProvider(); campaignYear.setLabel(I18nProperties.getCaption(Captions.campaignYear)); - campaigns = FacadeProvider.getCampaignFacade().getAllActiveCampaignsAsReference(); + campaigns = FacadeProvider.getCampaignFacade().getAllActiveCampaignsAsReference(); + for (CampaignReferenceDto cmfdto : campaigns) { - campaingYears.add(cmfdto.getCampaignYear() + ""); + campaingYears.add(cmfdto.getCampaignYear().trim()); } + campaingYears = campaingYears.stream().distinct().collect(Collectors.toList()); campaignYear.setItems(campaingYears); campaignYear.getStyle().set("padding-top", "0px"); campaignYear.setClassName("col-sm-6, col-xs-6"); - campaign.setLabel(I18nProperties.getCaption(Captions.Campaign)); campaigns = FacadeProvider.getCampaignFacade().getAllActiveCampaignsAsReference(); - + campaign.setItems(campaigns); campaign.getStyle().set("padding-top", "0px"); campaign.setClassName("col-sm-6, col-xs-6"); @@ -359,7 +372,6 @@ public DashboardView() { setSizeFull(); } - private Div drawDashboardAndTabs(String UIs) { Div mainContentContainer = new Div(); mainContentContainer.setId(UIs); @@ -386,7 +398,7 @@ private Div drawDashboardAndTabs(String UIs) { int defctr = 0; String firstMntabId = null; - String firstSubtabId = null; +// String firstSubtabId = null; // creating bucket tabs to hold tabs and subtabs for (String tabIdc : mainTabs) { @@ -408,7 +420,7 @@ private Div drawDashboardAndTabs(String UIs) { for (String sbTabId : subTabx) { defctr++; -// String sbtabId = WordUtils.capitalizeFully(tabIdc); + String sbtabId = WordUtils.capitalizeFully(tabIdc); Tab stabx = new Tab(sbTabId); stabx.setId("submain_" + sbTabId); stabx.getStyle().set("font-weight", "500"); @@ -425,7 +437,12 @@ private Div drawDashboardAndTabs(String UIs) { } } + mtabs.addSelectedChangeListener(e -> { + + VaadinService.getCurrentRequest().getWrappedSession().setAttribute("mtabtrack", mtabs.getSelectedIndex()); + + System.out.println("entered main tab"); int listnrCtr = 0; final List subTabx = new ArrayList<>( @@ -438,7 +455,9 @@ private Div drawDashboardAndTabs(String UIs) { for (String sbTabId : subTabx) { listnrCtr++; if (listnrCtr == 1) { - firstSbTabId = sbTabId; + + firstSbTabId = sbTabId; + System.out.println(firstSbTabId + " first subtab IDDDDDDDDDDDDDDDDDDDDDD"); } // String sbtabId = WordUtils.capitalizeFully(tabIdc); Tab stabx = new Tab(sbTabId); @@ -448,6 +467,14 @@ private Div drawDashboardAndTabs(String UIs) { sTabs.add(stabx); } + if (VaadinService.getCurrentRequest().getWrappedSession().getAttribute("stabtrack") != null) { + firstSbTabId = (String) VaadinService.getCurrentRequest().getWrappedSession().getAttribute("stabtrack"); + firstSbTabId = firstSbTabId.replaceAll("submain_", ""); + firstSubtabId = firstSbTabId; + System.out.println(firstSbTabId + " first subtab IIDDDDDDDDDDDDDDDDDDDDDD"); +// sTabs.setSelectedTab( +// (String) VaadinService.getCurrentRequest().getWrappedSession().getAttribute("stabtrack").toString()); + } // //Notification.show(e.getSelectedTab().getId().get().toString().replaceAll("main_", "")); // //Notification.show(firstSbTabId); @@ -462,11 +489,17 @@ private Div drawDashboardAndTabs(String UIs) { }); sTabs.addSelectedChangeListener(e -> { + System.out.println("Subtab enteredddddddddddddddddddddddd"); + String listnrCtr = listerCheck; + if (e.getSelectedTab() != null) { - // System.out.print(isSubAvaialable); + System.out.print(e.getSelectedTab().getId().get() + " hhhkkkkk " + e.getSelectedTab()); + VaadinService.getCurrentRequest().getWrappedSession().setAttribute("stabtrack", e.getSelectedTab().getId().get()); + + System.out.print(e.getSelectedTab().getId().get().toString() + " e.getSelectedTab().getId().get().toString() "); String listnrCtrx = e.getSelectedTab().getId().get().replaceAll("submain_", ""); - + System.out.print(listnrCtrx + " listnrCtrx"); // Notification.show(listnrCtr +" _____________________________ "+listnrCtrx); contentContainer.removeAll(); @@ -482,14 +515,23 @@ private Div drawDashboardAndTabs(String UIs) { contentContainer.add(campaignSummaryGridView.CampaignSummaryGridViewInit(firstMntabId, dataProvider, campaignPhase.getValue(), firstSubtabId)); } + contentContainer.getStyle().set("margin-top", "0.4rem"); - contentContainer.setId("tabsSheet"); contentContainer.setSizeFull(); + try { + if (VaadinService.getCurrentRequest().getWrappedSession().getAttribute("mtabtrack") != null) { + + mtabs.setSelectedIndex( + (int) VaadinService.getCurrentRequest().getWrappedSession().getAttribute("mtabtrack")); + } + } finally { + + } + mainContentContainer.add(mtabs, sTabs, contentContainer); return mainContentContainer; - } public class LazyComponent extends Div { @@ -525,7 +567,7 @@ private void changeCampaignJuridictionLevel(CampaignJurisdictionLevel campaignJu } } - + private String getLabelForEnum(CampaignPhase campaignPhase) { switch (campaignPhase) { case PRE: @@ -544,22 +586,22 @@ private String getLabelForEnum(CampaignPhase campaignPhase) { @Override public void beforeEnter(BeforeEnterEvent event) { - try { - UserProvider usrP = new UserProvider(); - System.out.println("trying ti use camp data "+usrP); - - System.out.println("trying ti use camp data "+usrP.getCurrent().hasUserRole(UserRole.CASE_OFFICER)); + try { + UserProvider usrP = new UserProvider(); + System.out.println("trying ti use camp data " + usrP); + + System.out.println("trying ti use camp data " + usrP.getCurrent().hasUserRole(UserRole.CASE_OFFICER)); if (!usrP.getCurrent().hasUserRole(UserRole.ADMIN)) { - event.rerouteTo(CampaignDataView.class); // Redirect to a different view - } + event.rerouteTo(CampaignDataView.class); // Redirect to a different view + } } catch (Exception e) { - - System.err.println("ubnable tooooooooooo trying ti use camp data "); + + System.err.println("ubnable tooooooooooo trying ti use camp data "); // TODO Auto-generated catch block e.printStackTrace(); } - + } } From 475458fd51eb4ee86aae4e6bdec5ea08ee1ad564 Mon Sep 17 00:00:00 2001 From: Yahaya Yusuf Date: Fri, 1 Sep 2023 23:43:05 +0100 Subject: [PATCH 4/9] pull refactor #202 --- .../views/campaigndata/CampaignDataView.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/apmis-flow/src/main/java/com/cinoteck/application/views/campaigndata/CampaignDataView.java b/apmis-flow/src/main/java/com/cinoteck/application/views/campaigndata/CampaignDataView.java index c21a1b335b5..1f62947c60b 100644 --- a/apmis-flow/src/main/java/com/cinoteck/application/views/campaigndata/CampaignDataView.java +++ b/apmis-flow/src/main/java/com/cinoteck/application/views/campaigndata/CampaignDataView.java @@ -639,7 +639,7 @@ public void deleteAllSelectedItems(Collection selected confirmationDialog.open(); confirmationDialog.setHeader("Delete Campaign Data"); //TODO: Language - .setText("Are you sure you want to Delete " + selectedRows.size() + " selected Campaign Data?"); + confirmationDialog.setText("Are you sure you want to Delete " + selectedRows.size() + " selected Campaign Data?"); confirmationDialog.addConfirmListener(e -> { List uuids = selectedRows.stream().map(CampaignFormDataIndexDto::getUuid) @@ -699,21 +699,20 @@ private void configureGrid(CampaignFormDataCriteria criteria) { // ======= grid.addColumn(CampaignFormDataIndexDto.CAMPAIGN).setHeader(I18nProperties.getCaption(Captions.Campaigns)) .setSortable(true).setResizable(true).setAutoWidth(true).setTooltipGenerator(e -> e.getCampaign()); - grid.addColumn(CampaignFormDataIndexDto.FORM) .setHeader(I18nProperties.getCaption(Captions.campaignCampaignForm)).setSortable(true) .setResizable(true).setAutoWidth(true).setTooltipGenerator(e -> e.getForm()); grid.addColumn(CampaignFormDataIndexDto.AREA).setHeader(I18nProperties.getCaption(Captions.area)) .setSortable(true).setResizable(true).setAutoWidth(true).setTooltipGenerator(e -> e.getArea()); grid.addColumn(CampaignFormDataIndexDto.RCODE).setHeader(I18nProperties.getCaption(Captions.Area_externalId)) - .setSortable(true).setResizable(true).setAutoWidth(true).setTooltipGenerator(e -> I18nProperties.getCaption(Captions.Area_externalId)); + +// grid.addColumn(CampaignFormDataIndexDto.REGION).setHeader(I18nProperties.getCaption(Captions.region)) +// .setSortable(true).setResizable(true).setAutoWidth(true) +// .setTooltipGenerator(e -> e.getRcode().toString()); + grid.addColumn(CampaignFormDataIndexDto.REGION).setHeader(I18nProperties.getCaption(Captions.region)) - - .setSortable(true).setResizable(true).setAutoWidth(true) - .setTooltipGenerator(e -> e.getRcode().toString()); - grid.addColumn(CampaignFormDataIndexDto.REGION).setHeader(I18nProperties.getCaption(Captions.region)) - .setSortable(true).setResizable(true).setAutoWidth(true).setTooltipGenerator(e -> e.getRegion()); + .setSortable(true).setResizable(true).setAutoWidth(true).setTooltipGenerator(e -> e.getRegion()); grid.addColumn(CampaignFormDataIndexDto.PCODE).setHeader(I18nProperties.getCaption(Captions.Region_externalID)) .setSortable(true).setResizable(true).setAutoWidth(true) .setTooltipGenerator(e -> I18nProperties.getCaption(Captions.Region_externalID)); From c36c8e16e2903eb4a000ba85806032f06f3a6a09 Mon Sep 17 00:00:00 2001 From: Yahaya Yusuf Date: Fri, 1 Sep 2023 23:55:52 +0100 Subject: [PATCH 5/9] change password textfields remove #202 --- .../myaccount/CredentialPassWordChanger.java | 72 +++++++++---------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/apmis-flow/src/main/java/com/cinoteck/application/views/myaccount/CredentialPassWordChanger.java b/apmis-flow/src/main/java/com/cinoteck/application/views/myaccount/CredentialPassWordChanger.java index d33bcf08143..b6b338670e7 100644 --- a/apmis-flow/src/main/java/com/cinoteck/application/views/myaccount/CredentialPassWordChanger.java +++ b/apmis-flow/src/main/java/com/cinoteck/application/views/myaccount/CredentialPassWordChanger.java @@ -42,14 +42,14 @@ public CredentialPassWordChanger(UserDto usedto) { if (I18nProperties.getUserLanguage() == null) { - I18nProperties.setUserLanguage(Language.EN); + I18nProperties.setUserLanguage(Language.EN); } else { I18nProperties.setUserLanguage(currentUser.getUser().getLanguage()); I18nProperties.getUserLanguage(); } FacadeProvider.getI18nFacade().setUserLanguage(currentUser.getUser().getLanguage()); - + this.userName = usedto; _dialog = new ConfirmDialog(); @@ -71,7 +71,7 @@ public CredentialPassWordChanger(UserDto usedto) { } protected void continuePasswrd() { - + accessControl = AccessControlFactory.getInstance().createAccessControl(); UserProvider userProvider = new UserProvider(); UserDto userxs = userProvider.getUser(); @@ -83,8 +83,8 @@ protected void continuePasswrd() { FormLayout layout = new FormLayout(); - PasswordField oldPassField = new PasswordField(I18nProperties.getCaption(Captions.oldPassword)); - oldPassField.setSizeFull(); +// PasswordField oldPassField = new PasswordField(I18nProperties.getCaption(Captions.oldPassword)); +// oldPassField.setSizeFull(); PasswordField passField1 = new PasswordField(I18nProperties.getString(Strings.headingNewPassword)); passField1.setSizeFull(); @@ -95,13 +95,13 @@ protected void continuePasswrd() { // layout.add(new Label("*Must be at least 8 characters")); // layout.add(new Label("*Must contain 1 Uppercase and 1 special character ")); - Label instructionLabel = new Label( I18nProperties.getString(Strings.mustBeAt8Char) +" \r\n
" + Label instructionLabel = new Label(I18nProperties.getString(Strings.mustBeAt8Char) + " \r\n
" + I18nProperties.getString(Strings.mustContain1UppercaseChar) + " \r\n" + ""); instructionLabel.getElement().setProperty("innerHTML", instructionLabel.getText()); instructionLabel.getElement().getStyle().set("font-size", "12px"); passField2.setSizeFull(); - layout.add(oldPassField, passField1, passField2, instructionLabel); + layout.add(passField1, passField2, instructionLabel); Button saveButton = new Button(I18nProperties.getCaption(Captions.actionSave)); // changePassword.setStyleName(CssStyles.VAADIN_BUTTON); @@ -109,40 +109,36 @@ protected void continuePasswrd() { // changePassword.setStyleName(CssStyles.FLOAT_RIGHT); saveButton.addClickListener(e -> { - String oldPass = oldPassField.getValue().trim(); +// String oldPass = oldPassField.getValue().trim(); String newpass1 = passField1.getValue().trim(); String newpass2 = passField2.getValue().trim(); - if ((oldPass != null && !oldPass.isEmpty()) && newpass1.equals(newpass2) && !newpass1.equals(oldPass)) { - if(accessControl.upDatePassWordCheck(userxs.getUserName(), oldPass)) { - - FacadeProvider.getUserFacade().changePassword(userxs.getUserName(), newpass1); - UI.getCurrent().getPage().reload(); - Notification.show(I18nProperties.getString(Strings.passwordChangedSuccessfully)); - } else { - - Notification.show(I18nProperties.getString(Strings.passwordChangedSuccessfully)); - } - } else { - Notification notification = new Notification(); - notification.addThemeVariants(NotificationVariant.LUMO_ERROR); - notification.setPosition(Position.MIDDLE); - Button closeButton = new Button(new Icon("lumo", "cross")); - closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE); - closeButton.getElement().setAttribute("aria-label", "Close"); - closeButton.addClickListener(event -> { - notification.close(); - }); - - Paragraph text = new Paragraph( - I18nProperties.getString(Strings.passwordDoesNotMatch) + " and New password must not be same with old."); - - HorizontalLayout errorLayout = new HorizontalLayout(text, closeButton); - errorLayout.setAlignItems(Alignment.CENTER); - - notification.add(errorLayout); - notification.open(); - } + if (newpass1.equals(newpass2)) { + if (accessControl.upDatePassWordCheck(userxs.getUserName(), newpass1)) { + + FacadeProvider.getUserFacade().changePassword(userxs.getUserName(), newpass1); + UI.getCurrent().getPage().reload(); + Notification.show(I18nProperties.getString(Strings.passwordChangedSuccessfully)); + } + } else { + Notification notification = new Notification(); + notification.addThemeVariants(NotificationVariant.LUMO_ERROR); + notification.setPosition(Position.MIDDLE); + Button closeButton = new Button(new Icon("lumo", "cross")); + closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE); + closeButton.getElement().setAttribute("aria-label", "Close"); + closeButton.addClickListener(event -> { + notification.close(); + }); + + Paragraph text = new Paragraph(I18nProperties.getString(Strings.passwordDoesNotMatch)); + + HorizontalLayout errorLayout = new HorizontalLayout(text, closeButton); + errorLayout.setAlignItems(Alignment.CENTER); + + notification.add(errorLayout); + notification.open(); + } }); dialog.add(layout); From 4b5bb1b18ddebd8ecc2c6aa3a8c943149a003a8a Mon Sep 17 00:00:00 2001 From: Yahaya Yusuf Date: Fri, 1 Sep 2023 23:57:14 +0100 Subject: [PATCH 6/9] discard changes button icon added #202 --- .../views/myaccount/MyAccountView.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/apmis-flow/src/main/java/com/cinoteck/application/views/myaccount/MyAccountView.java b/apmis-flow/src/main/java/com/cinoteck/application/views/myaccount/MyAccountView.java index 1b5d415f7c6..169f76e1b6d 100644 --- a/apmis-flow/src/main/java/com/cinoteck/application/views/myaccount/MyAccountView.java +++ b/apmis-flow/src/main/java/com/cinoteck/application/views/myaccount/MyAccountView.java @@ -7,6 +7,7 @@ import com.vaadin.flow.component.Direction; import com.vaadin.flow.component.UI; import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.button.ButtonVariant; import com.vaadin.flow.component.combobox.ComboBox; import com.vaadin.flow.component.combobox.MultiSelectComboBox; import com.vaadin.flow.component.dialog.Dialog; @@ -297,18 +298,20 @@ public MyAccountView() { Div actionss = new Div(); + Icon vadIcc = new Icon(VaadinIcon.CHECK_CIRCLE_O); + vadIcc.getStyle().set("color", "green"); + + Button discard = new Button(I18nProperties.getCaption(Captions.actionDiscard)); + Icon vadIc = new Icon(VaadinIcon.CLOSE_CIRCLE_O); vadIc.setId("fghf"); vadIc.getStyle().set("color", "green !important"); - - Icon vadIcc = new Icon(VaadinIcon.CHECK_CIRCLE_O); - vadIc.getStyle().set("color", "white"); - - Button discard = new Button(I18nProperties.getCaption(Captions.actionDiscard), vadIc); + discard.getStyle().set("margin-right", "20px"); - discard.getStyle().set("color", "green"); + discard.getStyle().set("color", "green !important"); discard.getStyle().set("background", "white"); discard.getStyle().set("border", "1px solid green"); + discard.setIcon(vadIc); Button savee = new Button(I18nProperties.getCaption(Captions.actionSave), vadIcc); savee.addClickListener(e -> { From d811ea98b8b1a46a26f1b6e9d835fa78dbf08b85 Mon Sep 17 00:00:00 2001 From: Yahaya Yusuf Date: Sat, 2 Sep 2023 00:03:10 +0100 Subject: [PATCH 7/9] username unique, create new password and enable and disable user add #202 --- .../application/views/user/UserForm.java | 210 ++++++++++++------ .../application/views/user/UserView.java | 52 ++++- 2 files changed, 187 insertions(+), 75 deletions(-) diff --git a/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserForm.java b/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserForm.java index 2cb2379cc9a..7a400377a94 100644 --- a/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserForm.java +++ b/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserForm.java @@ -27,15 +27,23 @@ import com.vaadin.flow.component.checkbox.CheckboxGroup; import com.vaadin.flow.component.combobox.ComboBox; import com.vaadin.flow.component.combobox.MultiSelectComboBox; +import com.vaadin.flow.component.confirmdialog.ConfirmDialog; import com.vaadin.flow.component.dialog.Dialog; import com.vaadin.flow.component.html.Anchor; import com.vaadin.flow.component.html.H2; +import com.vaadin.flow.component.html.H3; +import com.vaadin.flow.component.html.Label; +import com.vaadin.flow.component.html.Paragraph; import com.vaadin.flow.component.html.Span; import com.vaadin.flow.component.icon.Icon; import com.vaadin.flow.component.icon.VaadinIcon; import com.vaadin.flow.component.notification.NotificationVariant; +import com.vaadin.flow.component.notification.Notification; +import com.vaadin.flow.component.notification.Notification.Position; +import com.vaadin.flow.component.orderedlayout.FlexComponent.Alignment; import com.vaadin.flow.component.orderedlayout.FlexComponent.JustifyContentMode; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; +import com.vaadin.flow.component.orderedlayout.VerticalLayout; import com.vaadin.flow.component.textfield.TextField; import com.vaadin.flow.data.binder.BeanValidationBinder; import com.vaadin.flow.data.binder.Binder; @@ -44,7 +52,6 @@ import com.vaadin.flow.router.Route; import com.vaadin.flow.shared.Registration; - import de.symeda.sormas.api.AuthProvider; import de.symeda.sormas.api.CountryHelper; import de.symeda.sormas.api.FacadeProvider; @@ -94,8 +101,6 @@ public class UserForm extends FormLayout { ComboBox region = new ComboBox<>(I18nProperties.getCaption(Captions.area)); ComboBox province = new ComboBox<>(I18nProperties.getCaption(Captions.region)); ComboBox district = new ComboBox<>(I18nProperties.getCaption(Captions.district)); -// MultiSelectComboBox community = new MultiSelectComboBox<>( -// I18nProperties.getCaption(Captions.community)); TextField street = new TextField(I18nProperties.getCaption(Captions.Location_street)); TextField houseNumber = new TextField(I18nProperties.getCaption(Captions.Location_houseNumber)); @@ -122,7 +127,9 @@ public class UserForm extends FormLayout { Button delete = new Button(I18nProperties.getCaption(Captions.actionDelete)); Button close = new Button(I18nProperties.getCaption(Captions.actionCancel)); - Anchor createPassword = new Anchor("", I18nProperties.getCaption(Captions.userResetPassword)); + Button createPassword = new Button(I18nProperties.getCaption(Captions.userResetPassword)); + + ConfirmDialog _dialog = new ConfirmDialog(); Map map = new HashMap<>(); @@ -160,6 +167,7 @@ public UserForm(List regions, List provinc add(hor); // Configure what is passed to the fields here configureFields(user); + updatePasswordDialog(); } @SuppressWarnings("unchecked") @@ -262,20 +270,38 @@ public void configureFields(UserDto user) { clusterNo.setLabel(I18nProperties.getCaption(Captions.clusterNumber)); - //commented out not sure what - //UserDto currentUser = FacadeProvider.getUserFacade().getCurrentUser(); + // commented out not sure what + // UserDto currentUser = FacadeProvider.getUserFacade().getCurrentUser(); Set data = Collections.emptySet(); - //currentUser.setCommunity(data); - //FacadeProvider.getUserFacade().saveUser(currentUser); + // currentUser.setCommunity(data); + // FacadeProvider.getUserFacade().saveUser(currentUser); if (districtDto != null) { List items = FacadeProvider.getCommunityFacade() .getAllActiveByDistrict(districtDto.getUuid()); for (CommunityReferenceDto item : items) { - if(item.getNumber() == null) - Notification.show("Cluster Number cannot be empty, please contact support", Notification.Type.ERROR_MESSAGE); //I18nProperties.getString(Strings.clustNot) ) - + if (item.getNumber() == null) { + + Notification notification = new Notification(); + notification.addThemeVariants(NotificationVariant.LUMO_ERROR); + notification.setPosition(Position.MIDDLE); + Button closeButton = new Button(new Icon("lumo", "cross")); + closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE); + closeButton.getElement().setAttribute("aria-label", "Close"); + closeButton.addClickListener(event -> { + notification.close(); + }); + + Paragraph text = new Paragraph("Cluster Number cannot be empty, please contact support"); + + HorizontalLayout layout = new HorizontalLayout(text, closeButton); + layout.setAlignItems(Alignment.CENTER); + + notification.add(layout); + notification.open(); + } + item.setCaption(item.getNumber() != null ? item.getNumber().toString() : null); } Collections.sort(items, CommunityReferenceDto.clusternumber); @@ -291,7 +317,6 @@ public void configureFields(UserDto user) { } }); - // binder.forField(community).bind(UserDto::getCommunity, UserDto::setCommunity); street.setPlaceholder(I18nProperties.getCaption(Captions.enterStreetHere)); houseNumber.setPlaceholder(I18nProperties.getCaption(Captions.enterHouseNumberHere)); @@ -384,44 +409,74 @@ public void configureFields(UserDto user) { add(pInfo, firstName, lastName, userEmail, phone, userPosition, userOrganisation, fInfo, userRegion, userProvince, userDistrict, userCommunity, street, houseNumber, additionalInformation, postalCode, city, areaType, userData, userName, activeCheck, commusr, userRoles, formAccess, language, region, province, - district, clusterNo, createPassword); + district, clusterNo); createButtonsLayout(); } -// public void makeNewPassword(String userUuid, String userEmail, String userName) { -// String newPassword = FacadeProvider.getUserFacade().resetPassword(userUuid); -// -// if (StringUtils.isBlank(userEmail) -// || AuthProvider.getProvider(FacadeProvider.getConfigFacade()).isDefaultProvider()) { -// Dialog ttt = new Dialog(); -// ttt.add("UserName : " + userName); -// ttt.add("Password : " + newPassword); -// ttt.open(); -// -//// showPasswordResetInternalSuccessPopup(newPassword, userName); -// } else { -//// showPasswordResetExternalSuccessPopup(); -// } -// } - - public void showPasswordResetInternalSuccessPopup(String newPassword, String userName) { - neee = new Dialog(); - Label vvv = new Label(I18nProperties.getString(Strings.messageCopyPassword)); - - VerticalLayout layout = new VerticalLayout(); - layout.addComponent(new Label(I18nProperties.getString(Strings.messageCopyPassword))); - Label passwordLabel = new Label("Password: " + newPassword); - Label userNameLabel = new Label("Username: " + userName); - - layout.addComponent(userNameLabel); - layout.addComponent(passwordLabel); - Dialog popupWindow = new Dialog(); - popupWindow.setHeaderTitle(I18nProperties.getString(Strings.headingNewPassword)); - layout.setMargin(true); + public void updatePasswordDialog() { + + _dialog.setHeader("Update Password"); + + _dialog.setCloseOnEsc(false); + _dialog.setCancelable(true); + _dialog.addCancelListener(e -> _dialog.close()); + + _dialog.setRejectable(true); + _dialog.setRejectText("Cancel"); + _dialog.addRejectListener(e -> _dialog.close()); + + _dialog.setConfirmText("Really Update Password"); + _dialog.addConfirmListener(e -> makeNewPassword(binder.getBean().getUuid(), binder.getBean().getUserEmail(), + binder.getBean().getUserName())); } + public void makeNewPassword(String userUuid, String userEmail, String userName) { + String newPassword = FacadeProvider.getUserFacade().resetPassword(userUuid); + + if (StringUtils.isBlank(userEmail) + || AuthProvider.getProvider(FacadeProvider.getConfigFacade()).isDefaultProvider()) { + + Dialog newUserPop = new Dialog(); + newUserPop.setClassName("passwordsDialog"); + VerticalLayout infoLayout = new VerticalLayout(); + + Paragraph infoText = new Paragraph("Please , copy this password, it is shown only once."); + newUserPop.setHeaderTitle("Password Updated"); + + H3 username = new H3(I18nProperties.getCaption(Captions.Login_username) + " : " + userName); + username.getStyle().set("color", "#0D6938"); + H3 password = new H3(I18nProperties.getCaption(Captions.Login_password) + " : " + newPassword); + password.getStyle().set("color", "#0D6938"); + + infoLayout.add(username, password); + + newUserPop.add(infoLayout); + + newUserPop.setOpened(true); + + } else { + Dialog newUserPop = new Dialog(); + newUserPop.setClassName("passwordsDialog"); + VerticalLayout infoLayout = new VerticalLayout(); + + Paragraph infoText = new Paragraph("Please , copy this password, it is shown only once."); + newUserPop.setHeaderTitle("Password Updated"); + + H3 username = new H3(I18nProperties.getCaption(Captions.Login_username) + " : " + userName); + username.getStyle().set("color", "#0D6938"); + + H3 password = new H3(I18nProperties.getCaption(Captions.Login_password) + " : " + newPassword); + password.getStyle().set("color", "#0D6938"); + + infoLayout.add(username, password); + + newUserPop.add(infoLayout); + + newUserPop.setOpened(true); + } + } public void suggestUserName(boolean editMode) { @@ -441,7 +496,7 @@ public void suggestUserName(boolean editMode) { } private void createButtonsLayout() { -// save.addThemeVariants(ButtonVariant.LUMO_PRIMARY); + createPassword.addThemeVariants(ButtonVariant.LUMO_PRIMARY); delete.addThemeVariants(ButtonVariant.LUMO_ERROR); close.addThemeVariants(ButtonVariant.LUMO_ERROR); close.addClickShortcut(Key.ESCAPE); @@ -450,46 +505,61 @@ private void createButtonsLayout() { suggestUserName(true); }); + System.out.println("Editing mode ============= " + editmode); + save.addClickListener(event -> validateAndSave()); delete.addClickListener(event -> fireEvent(new DeleteEvent(this, binder.getBean()))); close.setEnabled(true); close.addClickListener(event -> fireEvent(new CloseEvent(this))); - HorizontalLayout horizontallayout = new HorizontalLayout(save, close); - horizontallayout.setJustifyContentMode(JustifyContentMode.END); - horizontallayout.setMargin(true); + createPassword.addClickListener(event -> { + _dialog.open(); + }); + + HorizontalLayout horizontallayout = new HorizontalLayout(); + + HorizontalLayout passwordlayout = new HorizontalLayout(createPassword); + passwordlayout.getStyle().set("margin-right", "auto"); + + HorizontalLayout savecloselayout = new HorizontalLayout(save, close); + savecloselayout.setMargin(true); + horizontallayout.add(passwordlayout, savecloselayout); add(horizontallayout); this.setColspan(horizontallayout, 2); } private void validateAndSave() { -// map.forEach((key, value) -> { -// Component formField = map.get(key); -// if (value instanceof TextField) { -// -// TextField formFieldxx = (TextField) value; -// ValidationResult requiredValidation = emailVal.apply(formFieldxx.getValue(), null); -//// ValidationResult secondRequiredValidation = patternValidator.apply(formFieldxx.getValue(), null); -// if (requiredValidation.isError()) { -// -// // Handle required field validation error -// formFieldxx.setInvalid(true); -// formFieldxx.setErrorMessage(requiredValidation.getErrorMessage()); -// } else { - fireEvent(new SaveEvent(this, binder.getBean())); -// } -// } -// -// }); + if (binder.validate().isOk()) { + if (FacadeProvider.getUserFacade().getByUserName(binder.getBean().getUserName()) != null) { + + Notification notification = new Notification(); + notification.addThemeVariants(NotificationVariant.LUMO_ERROR); + notification.setPosition(Position.MIDDLE); + Button closeButton = new Button(new Icon("lumo", "cross")); + closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE); + closeButton.getElement().setAttribute("aria-label", "Close"); + closeButton.addClickListener(event -> { + notification.close(); + }); + + Paragraph text = new Paragraph("Error : Username id not unique"); + + HorizontalLayout layout = new HorizontalLayout(text, closeButton); + layout.setAlignItems(Alignment.CENTER); + + notification.add(layout); + notification.open(); + } else { + fireEvent(new SaveEvent(this, binder.getBean())); + } + } } - + private void resetpassword() { fireEvent(new ResetPasswordEvent(this, binder.getBean())); } - - public void setUser(UserDto user) { binder.setBean(user); } @@ -533,7 +603,7 @@ public static class CloseEvent extends UserFormEvent { } public static class ResetPasswordEvent extends UserFormEvent { - ResetPasswordEvent(UserForm source , UserDto user) { + ResetPasswordEvent(UserForm source, UserDto user) { super(source, new UserDto()); } } @@ -596,7 +666,7 @@ private void updateFieldsByUserRole(Set userRoles) { } } - + public static void updateItems(CheckboxGroup select, Set items) { Set value = select.getSelectedItems(); boolean readOnly = select.isReadOnly(); diff --git a/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserView.java b/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserView.java index d2fe035b52e..22262b1bab7 100644 --- a/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserView.java +++ b/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserView.java @@ -127,6 +127,8 @@ public class UserView extends VerticalLayout { Button exportUsers = new Button("Export"); Button displayFilters; + + ConfirmDialog confirmationPopup = new ConfirmDialog(); private static final String CSV_FILE_PATH = "./result.csv"; UserDto userDto; @@ -231,14 +233,19 @@ public void addFilters() { bulkModeButton.setVisible(true); leaveBulkModeButton.setVisible(false); menuBar.setVisible(false); + grid.getDataProvider().refreshAll(); }); menuBar.setVisible(false); MenuItem item = menuBar.addItem(I18nProperties.getCaption(Captions.bulkActions)); SubMenu subMenu = item.getSubMenu(); - subMenu.addItem(new Checkbox(I18nProperties.getCaption(Captions.actionEnable))); - subMenu.addItem(new Checkbox(I18nProperties.getCaption(Captions.actionDisable))); + Checkbox enable = new Checkbox(I18nProperties.getCaption(Captions.actionEnable)); + Checkbox disable = new Checkbox(I18nProperties.getCaption(Captions.actionDisable)); + subMenu.addItem(enable); + subMenu.addItem(disable); menuBar.getStyle().set("margin-top", "5px"); + enable.addClickListener(e -> enableUserPopup()); + disable.addClickListener(e -> disableUserPopup()); layout.add(menuBar); layout.setPadding(false); @@ -775,8 +782,7 @@ public void makeNewPassword(String userUuid, String userEmail, String userName) VerticalLayout infoLayout = new VerticalLayout(); newUserPop.setHeaderTitle("New User Password"); - newUserPop.getElement().executeJs("this.$.overlay.setAttribute('theme', 'center');"); // Center the dialog - // content + newUserPop.getElement().executeJs("this.$.overlay.setAttribute('theme', 'center');"); Paragraph infoText = new Paragraph("Please , copy this password, it is shown only once."); newUserPop.setHeaderTitle("New User Password"); @@ -816,7 +822,7 @@ public void enableUser(Collection selectedRows) { notification.open(); } } - + public void disableUser(Collection selectedRows) { if (selectedRows.size() == 0) { @@ -837,5 +843,41 @@ public void disableUser(Collection selectedRows) { notification.open(); } } + + void enableUserPopup() { + + confirmationPopup.setHeader("Enable User"); + + confirmationPopup.setText("You are about to Enable " + grid.getSelectedItems().size() + " User"); + confirmationPopup.setCloseOnEsc(false); + confirmationPopup.setCancelable(true); + confirmationPopup.addCancelListener(e -> confirmationPopup.close()); + + confirmationPopup.setRejectable(true); + confirmationPopup.setRejectText("Cancel"); + confirmationPopup.addRejectListener(e -> confirmationPopup.close()); + + confirmationPopup.setConfirmText("Enable"); + confirmationPopup.addConfirmListener(e -> enableUser(grid.getSelectedItems())); + confirmationPopup.open(); + } + + void disableUserPopup() { + + confirmationPopup.setHeader("Disable User"); + + confirmationPopup.setText("You are about to Disable " + grid.getSelectedItems().size() + " User"); + confirmationPopup.setCloseOnEsc(false); + confirmationPopup.setCancelable(true); + confirmationPopup.addCancelListener(e -> confirmationPopup.close()); + + confirmationPopup.setRejectable(true); + confirmationPopup.setRejectText("Cancel"); + confirmationPopup.addRejectListener(e -> confirmationPopup.close()); + + confirmationPopup.setConfirmText("Disable"); + confirmationPopup.addConfirmListener(e -> disableUser(grid.getSelectedItems())); + confirmationPopup.open(); + } } \ No newline at end of file From 81b4e3b21894bae04ce74d2e9742fe046b193821 Mon Sep 17 00:00:00 2001 From: Yahaya Yusuf Date: Wed, 6 Sep 2023 18:15:42 +0100 Subject: [PATCH 8/9] new user username suggesting fix, create user new password #202 --- .../views/configurations/ClusterView.java | 11 +- .../application/views/user/UserForm.java | 181 ++++++++++-------- .../application/views/user/UserView.java | 60 ++++-- .../main/resources/captions_en-AF.properties | 1 + .../sormas/backend/campaign/Campaign.java | 1 + .../src/main/resources/sql/sormas_schema.sql | 2 +- 6 files changed, 148 insertions(+), 108 deletions(-) diff --git a/apmis-flow/src/main/java/com/cinoteck/application/views/configurations/ClusterView.java b/apmis-flow/src/main/java/com/cinoteck/application/views/configurations/ClusterView.java index a629074382a..b193635509a 100644 --- a/apmis-flow/src/main/java/com/cinoteck/application/views/configurations/ClusterView.java +++ b/apmis-flow/src/main/java/com/cinoteck/application/views/configurations/ClusterView.java @@ -710,9 +710,7 @@ public boolean createOrEditCluster(CommunityDto communityDto) { for (DistrictIndexDto districtIndexDto : pcode) { String checkerName = districtIndexDto.getName(); - if (checkerName.trim().equals(districtOfCluster.getValue().toString().trim())) { - System.out.println("shout you catch me egbon: pcode here == " - + districtIndexDto.getExternalId() + " my name is " + districtIndexDto.getName()); + if (checkerName.trim().equals(districtOfCluster.getValue().toString().trim())) { DistrictReferenceDto nuller = new DistrictReferenceDto(districtIndexDto.getUuid(), districtIndexDto.getName(), districtIndexDto.getExternalId()); dcex.setDistrict(nuller); @@ -750,9 +748,12 @@ public boolean createOrEditCluster(CommunityDto communityDto) { notification.close(); }); - Paragraph text = new Paragraph( - "An unexpected error occurred. Please contact your supervisor or administrator and inform them about it."); +// Paragraph text = new Paragraph( +// "An unexpected error occurred. Please contact your supervisor or administrator and inform them about it."); + Paragraph text = new Paragraph( + "Cluster number taken, choose another"); + HorizontalLayout layout = new HorizontalLayout(text, closeButton); layout.setAlignItems(Alignment.CENTER); diff --git a/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserForm.java b/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserForm.java index eeba3d2d81c..d299bb601bb 100644 --- a/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserForm.java +++ b/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserForm.java @@ -150,12 +150,14 @@ public class UserForm extends FormLayout { private final UserProvider userProvider = new UserProvider(); boolean editmode = false; + UserDto user; // Button resetUserPassword = new Button(); public UserForm(List regions, List provinces, - List districts, UserDto user) { + List districts, UserDto user, boolean editmode) { + this.user = user; addClassName("contact-form"); HorizontalLayout hor = new HorizontalLayout(); Icon vaadinIcon = new Icon(VaadinIcon.ARROW_CIRCLE_LEFT_O); @@ -342,12 +344,11 @@ public void configureFields(UserDto user) { // userRoles.setItems(UserRole.getAssignableRoles(FacadeProvider.getUserRoleConfigFacade().getEnabledUserRoles())); roles = FacadeProvider.getUserRoleConfigFacade().getEnabledUserRoles(); roles.remove(UserRole.BAG_USER); - + List rolesz = new ArrayList<>(roles); // Convert Set to List roles.remove(UserRole.BAG_USER); - - - //Sorting the user roles usng comprtor + + // Sorting the user roles usng comprtor Collections.sort(rolesz, new UserRoleCustomComparator()); // then i'm converting back to a set for facade to handle save properly. @@ -359,7 +360,8 @@ public void configureFields(UserDto user) { // TODO: Change implemenation to only add assignable roles sormas style. // userRoles.setItems(UserRole.getAssignableRoles(FacadeProvider.getUserRoleConfigFacade().getEnabledUserRoles())); - binder.forField(userRoles).withValidator(new UserRolesValidator()).asRequired(I18nProperties.getCaption(Captions.userRoleRequired)) + binder.forField(userRoles).withValidator(new UserRolesValidator()) + .asRequired(I18nProperties.getCaption(Captions.userRoleRequired)) .bind(UserDto::getUserRoles, UserDto::setUserRoles); this.setColspan(userRoles, 1); @@ -367,7 +369,6 @@ public void configureFields(UserDto user) { updateFieldsByUserRole(e.getValue()); validateUserRoles(); }); - formAccess.setLabel(I18nProperties.getCaption(Captions.formAccess)); formAccess.setItems(UserUiHelper.getAssignableForms()); @@ -428,7 +429,7 @@ public void configureFields(UserDto user) { binder.forField(language).asRequired(I18nProperties.getString(Strings.languageRequired)) .bind(UserDto::getLanguage, UserDto::setLanguage); - + add(pInfo, firstName, lastName, userEmail, phone, userPosition, userOrganisation, fInfo, userRegion, userProvince, userDistrict, userCommunity, street, houseNumber, additionalInformation, postalCode, city, areaType, userData, userName, activeCheck, commusr, userRoles, formAccess, language, region, province, @@ -524,13 +525,7 @@ private void createButtonsLayout() { close.addThemeVariants(ButtonVariant.LUMO_ERROR); close.addClickShortcut(Key.ESCAPE); - lastName.addValueChangeListener(e -> { - suggestUserName(true); - }); - - System.out.println("Editing mode ============= " + editmode); - - save.addClickListener(event -> validateAndSave()); +// save.addClickListener(event -> validateAndSave()); delete.addClickListener(event -> fireEvent(new DeleteEvent(this, binder.getBean()))); close.setEnabled(true); close.addClickListener(event -> fireEvent(new CloseEvent(this))); @@ -541,17 +536,53 @@ private void createButtonsLayout() { HorizontalLayout horizontallayout = new HorizontalLayout(); - HorizontalLayout passwordlayout = new HorizontalLayout(createPassword); - passwordlayout.getStyle().set("margin-right", "auto"); + createPassword.getStyle().set("margin-right", "auto"); + save.getStyle().set("margin-left", "auto"); - HorizontalLayout savecloselayout = new HorizontalLayout(save, close); - savecloselayout.setMargin(true); - horizontallayout.add(passwordlayout, savecloselayout); + horizontallayout.add(createPassword, save, close); add(horizontallayout); this.setColspan(horizontallayout, 2); } - private void validateAndSave() { + public void validateAndSave(UserDto editedUser) { + if (binder.validate().isOk()) { + + UserDto binderUser = FacadeProvider.getUserFacade().getByUserName(binder.getBean().getUserName()); + if (binderUser.getUserName().trim().equals(editedUser.getUserName().trim()) + && !editedUser.getUserName().isEmpty()) { + + fireEvent(new SaveEvent(this, binder.getBean())); + } else { + + if (FacadeProvider.getUserFacade().getByUserName(binder.getBean().getUserName()) != null) { + + Notification notification = new Notification(); + notification.addThemeVariants(NotificationVariant.LUMO_ERROR); + notification.setPosition(Position.MIDDLE); + Button closeButton = new Button(new Icon("lumo", "cross")); + closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE); + closeButton.getElement().setAttribute("aria-label", "Close"); + closeButton.addClickListener(event -> { + notification.close(); + }); + + Paragraph text = new Paragraph("Error : Username not unique"); + + HorizontalLayout layout = new HorizontalLayout(text, closeButton); + layout.setAlignItems(Alignment.CENTER); + + notification.add(layout); + notification.open(); + } +// else { +// fireEvent(new SaveEvent(this, binder.getBean())); +// } + } + } + } + + public void validateAndSaveDup() { + if (binder.validate().isOk()) { if (FacadeProvider.getUserFacade().getByUserName(binder.getBean().getUserName()) != null) { @@ -565,7 +596,7 @@ private void validateAndSave() { notification.close(); }); - Paragraph text = new Paragraph("Error : Username id not unique"); + Paragraph text = new Paragraph("Error : Username not unique"); HorizontalLayout layout = new HorizontalLayout(text, closeButton); layout.setAlignItems(Alignment.CENTER); @@ -578,7 +609,6 @@ private void validateAndSave() { } } - // private void validateUserRoles() { // map.forEach((key, value) -> { // Component formField = map.get(key); @@ -599,67 +629,56 @@ private void validateAndSave() { // // }); // } - + class UserRoleCustomComparator implements Comparator { - private final String[] customOrder = { - "Admin", - "National Data Manager", - "National Officer", - "National Observer / Partner", - "Regional Observer", - "Regional Data Manager", - "Regional Officer", - "Provincial Observer", - "Provincial Data Clerk", - "Provincial Officer", - "District Officer", - "District Observer" - }; - - @Override - public int compare(UserRole role1, UserRole role2) { - // Get the indexes of the roles in the custom order - int index1 = indexOfRole(role1); - int index2 = indexOfRole(role2); - - // Compare based on their indexes in the custom order - return Integer.compare(index1, index2); - } - - private int indexOfRole(UserRole role) { - for (int i = 0; i < customOrder.length; i++) { - if (customOrder[i].equals(role.name())) { - return i; - } - } - return customOrder.length; // Role not found, place it at the end - } + private final String[] customOrder = { "Admin", "National Data Manager", "National Officer", + "National Observer / Partner", "Regional Observer", "Regional Data Manager", "Regional Officer", + "Provincial Observer", "Provincial Data Clerk", "Provincial Officer", "District Officer", + "District Observer" }; + + @Override + public int compare(UserRole role1, UserRole role2) { + // Get the indexes of the roles in the custom order + int index1 = indexOfRole(role1); + int index2 = indexOfRole(role2); + + // Compare based on their indexes in the custom order + return Integer.compare(index1, index2); + } + + private int indexOfRole(UserRole role) { + for (int i = 0; i < customOrder.length; i++) { + if (customOrder[i].equals(role.name())) { + return i; + } + } + return customOrder.length; // Role not found, place it at the end + } } - + class IndexedUserRole implements Comparable { - private UserRole role; - private int index; - - public IndexedUserRole(UserRole role, int index) { - this.role = role; - this.index = index; - } - - public UserRole getRole() { - return role; - } - - public int getIndex() { - return index; - } - - @Override - public int compareTo(IndexedUserRole other) { - // Compare based on the assigned indexes - return Integer.compare(this.index, other.index); - } - } + private UserRole role; + private int index; + + public IndexedUserRole(UserRole role, int index) { + this.role = role; + this.index = index; + } + + public UserRole getRole() { + return role; + } + public int getIndex() { + return index; + } + + @Override + public int compareTo(IndexedUserRole other) { + // Compare based on the assigned indexes + return Integer.compare(this.index, other.index); + } + } private void validateUserRoles() { map.forEach((key, value) -> { @@ -676,7 +695,7 @@ private void validateUserRoles() { formFieldxx.setErrorMessage(validation.getErrorMessage()); formFieldxx.setTooltipText(validation.getErrorMessage()); } else { - + } } }); diff --git a/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserView.java b/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserView.java index 7c744573d7e..ee4f88c89a8 100644 --- a/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserView.java +++ b/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserView.java @@ -85,9 +85,6 @@ @Route(value = "user", layout = MainLayout.class) public class UserView extends VerticalLayout { -// public static final String ACTIVE_FILTER = I18nProperties.getString(Strings.active); -// public static final String INACTIVE_FILTER = I18nProperties.getString(Strings.inactive); - Binder binder = new BeanValidationBinder<>(UserDto.class, false); boolean overide = false; private ComboBox activeFilter; @@ -127,7 +124,7 @@ public class UserView extends VerticalLayout { Button exportUsers = new Button("Export"); Button displayFilters; - + ConfirmDialog confirmationPopup = new ConfirmDialog(); private static final String CSV_FILE_PATH = "./result.csv"; @@ -602,9 +599,9 @@ private void configureGrid() { private void configureForm(UserDto user) { System.out.println(user + "userddddddddddddto in formconfigure"); - form = new UserForm(regions, provinces, districts, user); + form = new UserForm(regions, provinces, districts, user, false); form.setSizeFull(); - form.addUserFieldValueChangeEventListener(this::suggestUserName); +// form.addUserFieldValueChangeEventListener(this::suggestUserName); // form.addResetPasswordListener(event -> resetUserPassword(event, user)); // Use the resetUserPassword method form.addResetPasswordListener(this::resetUserPassWord); form.addSaveListener(this::saveUser); @@ -627,6 +624,7 @@ private Component getContent() { } public void editUser(Optional userr, boolean isEdMode) { + UserDto user; isEditingMode = isEdMode; if (userr.isPresent()) { @@ -637,22 +635,33 @@ public void editUser(Optional userr, boolean isEdMode) { grid.setVisible(false); setFiltersVisible(false); addClassName("editing"); - + form.save.addClickListener(event -> form.validateAndSave(userr.get())); } + + isEditingModeActive = true; + System.out.println(isEditingModeActive + " isEditingModeActive"); } public void editUser(boolean isEdMode) { - isEditingMode = isEdMode; + form.createPassword.setVisible(false); + isEditingMode = isEdMode; UserDto user = new UserDto(); form.setUser(user); - form.addUserFieldValueChangeEventListener(this::suggestUserName); +// form.addUserFieldValueChangeEventListener(this::suggestUserName); form.setVisible(true); form.setSizeFull(); grid.setVisible(false); setFiltersVisible(false); + form.save.addClickListener(event -> form.validateAndSaveDup()); + if (!isEdMode) { - isEditingModeActive = true; + form.firstName.addValueChangeListener(e -> suggestUserNameDup()); + form.lastName.addValueChangeListener(e -> suggestUserNameDup()); + System.out.println("I dey see ur hand work brusssssssssssssssssssss"); + } + + isEditingModeActive = false; System.out.println(isEditingModeActive + "isEditingModeActive"); } @@ -713,7 +722,7 @@ private void saveUser(UserForm.SaveEvent event) { } grid.getDataProvider().refreshAll(); closeEditor(); - UI.getCurrent().getPage().reload(); +// UI.getCurrent().getPage().reload(); } private void resetUserPassWord(UserForm.ResetPasswordEvent event) { @@ -741,7 +750,16 @@ private void suggestUserName(UserForm.UserFieldValueChangeEvent event) { System.out.println(isEditingModeActive + "___________isEditingModeActive"); formLayout.suggestUserName(isEditingModeActive); if (isEditingModeActive) { - + + } + + } + + private void suggestUserNameDup() { + + if (!form.firstName.isEmpty() && !form.lastName.isEmpty() && form.userName.isEmpty()) { + form.userName + .setValue(UserHelper.getSuggestedUsername(form.firstName.getValue(), form.lastName.getValue())); } } @@ -761,8 +779,9 @@ public void makeInitialPassword(String userUuid, String userEmail, String userNa VerticalLayout infoLayout = new VerticalLayout(); newUserPop.setHeaderTitle(I18nProperties.getString(Strings.newUserPassword)); - newUserPop.getElement().executeJs("this.$.overlay.setAttribute('theme', 'center');"); // Center the dialog content - + newUserPop.getElement().executeJs("this.$.overlay.setAttribute('theme', 'center');"); // Center the dialog + // content + Paragraph infoText = new Paragraph(I18nProperties.getString(Strings.pleaseCopyPassword)); H3 username = new H3(I18nProperties.getCaption(Captions.Login_username) + " : " + userName); username.getStyle().set("color", "#0D6938"); @@ -777,7 +796,6 @@ public void makeInitialPassword(String userUuid, String userEmail, String userNa newUserPop.setOpened(true); } - } public void makeNewPassword(String userUuid, String userEmail, String userName) { @@ -831,7 +849,7 @@ public void enableUser(Collection selectedRows) { notification.open(); } } - + public void disableUser(Collection selectedRows) { if (selectedRows.size() == 0) { @@ -852,9 +870,9 @@ public void disableUser(Collection selectedRows) { notification.open(); } } - + void enableUserPopup() { - + confirmationPopup.setHeader("Enable User"); confirmationPopup.setText("You are about to Enable " + grid.getSelectedItems().size() + " User"); @@ -870,9 +888,9 @@ void enableUserPopup() { confirmationPopup.addConfirmListener(e -> enableUser(grid.getSelectedItems())); confirmationPopup.open(); } - + void disableUserPopup() { - + confirmationPopup.setHeader("Disable User"); confirmationPopup.setText("You are about to Disable " + grid.getSelectedItems().size() + " User"); @@ -887,6 +905,6 @@ void disableUserPopup() { confirmationPopup.setConfirmText("Disable"); confirmationPopup.addConfirmListener(e -> disableUser(grid.getSelectedItems())); confirmationPopup.open(); - } + } } \ No newline at end of file diff --git a/sormas-api/src/main/resources/captions_en-AF.properties b/sormas-api/src/main/resources/captions_en-AF.properties index 201e61d443f..e8476b0b30a 100644 --- a/sormas-api/src/main/resources/captions_en-AF.properties +++ b/sormas-api/src/main/resources/captions_en-AF.properties @@ -22,6 +22,7 @@ city=City postcode=Postcode address=Address + #New added by Yahaya, end by the next big space community=Cluster clusterNumber=Cluster Number diff --git a/sormas-backend/src/main/java/de/symeda/sormas/backend/campaign/Campaign.java b/sormas-backend/src/main/java/de/symeda/sormas/backend/campaign/Campaign.java index b952673b96e..a8f960eabe2 100644 --- a/sormas-backend/src/main/java/de/symeda/sormas/backend/campaign/Campaign.java +++ b/sormas-backend/src/main/java/de/symeda/sormas/backend/campaign/Campaign.java @@ -46,6 +46,7 @@ public class Campaign extends CoreAdo { public static final String CAMPAIGN_DISTRICT_TABLE_NAME = "campaign_district"; public static final String CAMPAIGN_COMMUNITY_TABLE_NAME = "campaign_community"; + public static final String NAME = "name"; public static final String ROUND = "round"; public static final String DESCRIPTION = "description"; diff --git a/sormas-backend/src/main/resources/sql/sormas_schema.sql b/sormas-backend/src/main/resources/sql/sormas_schema.sql index ef712917351..3a25d585e79 100644 --- a/sormas-backend/src/main/resources/sql/sormas_schema.sql +++ b/sormas-backend/src/main/resources/sql/sormas_schema.sql @@ -9039,6 +9039,6 @@ EXECUTE PROCEDURE update_updated_on_user_task(); -INSERT INTO schema_version (version_number, comment) VALUES (44, 'adding platform/source of data and improving the log audit'); +INSERT INTO schema_version (version_number, comment) VALUES (447, 'adding platform/source of data and improving the log audit'); -- *** Insert new sql commands BEFORE this line. Remember to always consider _history tables. *** From 7f0c706dd57a262e46ee8bf1a7749a7027fca26b Mon Sep 17 00:00:00 2001 From: Yahaya Yusuf Date: Wed, 6 Sep 2023 21:04:20 +0100 Subject: [PATCH 9/9] Refactor #202 --- .../application/views/user/UserForm.java | 21 ++++---------- .../application/views/user/UserView.java | 29 +++++++------------ 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserForm.java b/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserForm.java index d299bb601bb..cafc656f371 100644 --- a/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserForm.java +++ b/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserForm.java @@ -180,8 +180,7 @@ public UserForm(List regions, List provinc } @SuppressWarnings("unchecked") - public void configureFields(UserDto user) { - System.out.println(user + " userrrr value in configure field "); + public void configureFields(UserDto user) { H2 pInfo = new H2(I18nProperties.getString(Strings.headingPersonData)); @@ -193,7 +192,7 @@ public void configureFields(UserDto user) { H2 userData = new H2(I18nProperties.getString(Strings.headingUserData)); this.setColspan(userData, 2); - binder.forField(firstName).asRequired(I18nProperties.getString(Strings.headingUserData)) + binder.forField(firstName).asRequired(I18nProperties.getCaption(Captions.firstNameRequired)) .bind(UserDto::getFirstName, UserDto::setFirstName); binder.forField(lastName).asRequired(I18nProperties.getCaption(Captions.lastNameRequired)) @@ -203,9 +202,7 @@ public void configureFields(UserDto user) { .bind(UserDto::getUserEmail, UserDto::setUserEmail); map.put("email", userEmail); - binder.forField(phone) - .withValidator(e -> e.length() >= 13, I18nProperties.getCaption(Captions.enterValidPhoneNumber)) - .bind(UserDto::getPhone, UserDto::setPhone); + binder.forField(phone).bind(UserDto::getPhone, UserDto::setPhone); binder.forField(userPosition).bind(UserDto::getUserPosition, UserDto::setUserPosition); @@ -505,9 +502,7 @@ public void makeNewPassword(String userUuid, String userEmail, String userName) public void suggestUserName(boolean editMode) { // fireEvent(new UserFieldValueChangeEvent(this, binder.getBean())); - if (editMode) { - - System.out.println(lastName.getValue() + "xxxxxxxxxchecking edit mode eeeeeeeeeeeeeeeeeeeeeeeeeeeeee"); + if (editMode) { lastName.addValueChangeListener(e -> { @@ -525,7 +520,6 @@ private void createButtonsLayout() { close.addThemeVariants(ButtonVariant.LUMO_ERROR); close.addClickShortcut(Key.ESCAPE); -// save.addClickListener(event -> validateAndSave()); delete.addClickListener(event -> fireEvent(new DeleteEvent(this, binder.getBean()))); close.setEnabled(true); close.addClickListener(event -> fireEvent(new CloseEvent(this))); @@ -544,7 +538,7 @@ private void createButtonsLayout() { this.setColspan(horizontallayout, 2); } - public void validateAndSave(UserDto editedUser) { + public void validateAndSaveEdit(UserDto editedUser) { if (binder.validate().isOk()) { UserDto binderUser = FacadeProvider.getUserFacade().getByUserName(binder.getBean().getUserName()); @@ -574,14 +568,11 @@ public void validateAndSave(UserDto editedUser) { notification.add(layout); notification.open(); } -// else { -// fireEvent(new SaveEvent(this, binder.getBean())); -// } } } } - public void validateAndSaveDup() { + public void validateAndSaveNew() { if (binder.validate().isOk()) { if (FacadeProvider.getUserFacade().getByUserName(binder.getBean().getUserName()) != null) { diff --git a/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserView.java b/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserView.java index ee4f88c89a8..a6bfed98bb5 100644 --- a/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserView.java +++ b/apmis-flow/src/main/java/com/cinoteck/application/views/user/UserView.java @@ -188,7 +188,7 @@ public void addFilters() { isEditingModeActive = true; }); - exportUsers.setIcon(new Icon(VaadinIcon.UPLOAD)); + exportUsers.setIcon(new Icon(VaadinIcon.CLOUD_DOWNLOAD_O)); exportUsers.addClickListener(e -> { anchor.getElement().callJsFunction("click"); @@ -588,17 +588,12 @@ private void configureGrid() { }); } -// grid.asSingleSelect(e->{ -// editUser(e.getFirstSelectedItem(), true); -// }); - return; } private void configureForm(UserDto user) { - - System.out.println(user + "userddddddddddddto in formconfigure"); + form = new UserForm(regions, provinces, districts, user, false); form.setSizeFull(); // form.addUserFieldValueChangeEventListener(this::suggestUserName); @@ -606,9 +601,9 @@ private void configureForm(UserDto user) { form.addResetPasswordListener(this::resetUserPassWord); form.addSaveListener(this::saveUser); form.addDeleteListener(this::deleteContact); - form.addCloseListener(e -> { - closeEditor(); + form.addCloseListener(e -> { UI.getCurrent().getPage().reload(); + closeEditor(); }); } @@ -635,9 +630,9 @@ public void editUser(Optional userr, boolean isEdMode) { grid.setVisible(false); setFiltersVisible(false); addClassName("editing"); - form.save.addClickListener(event -> form.validateAndSave(userr.get())); + form.save.addClickListener(event -> form.validateAndSaveEdit(userr.get())); } - + isEditingModeActive = true; System.out.println(isEditingModeActive + " isEditingModeActive"); } @@ -653,12 +648,11 @@ public void editUser(boolean isEdMode) { form.setSizeFull(); grid.setVisible(false); setFiltersVisible(false); - form.save.addClickListener(event -> form.validateAndSaveDup()); + form.save.addClickListener(event -> form.validateAndSaveNew()); if (!isEdMode) { - form.firstName.addValueChangeListener(e -> suggestUserNameDup()); - form.lastName.addValueChangeListener(e -> suggestUserNameDup()); - System.out.println("I dey see ur hand work brusssssssssssssssssssss"); + form.firstName.addValueChangeListener(e -> suggestUserNameWorking()); + form.lastName.addValueChangeListener(e -> suggestUserNameWorking()); } isEditingModeActive = false; @@ -721,8 +715,7 @@ private void saveUser(UserForm.SaveEvent event) { } grid.getDataProvider().refreshAll(); - closeEditor(); -// UI.getCurrent().getPage().reload(); + closeEditor();; } private void resetUserPassWord(UserForm.ResetPasswordEvent event) { @@ -755,7 +748,7 @@ private void suggestUserName(UserForm.UserFieldValueChangeEvent event) { } - private void suggestUserNameDup() { + private void suggestUserNameWorking() { if (!form.firstName.isEmpty() && !form.lastName.isEmpty() && form.userName.isEmpty()) { form.userName