Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
omoluabidotcom committed Dec 18, 2024
1 parent 44cc8c4 commit b1fb5ff
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.html.Anchor;
Expand Down Expand Up @@ -46,6 +47,8 @@
import de.symeda.sormas.api.campaign.form.CampaignFormElement;
import de.symeda.sormas.api.campaign.form.CampaignFormMetaDto;
import de.symeda.sormas.api.campaign.form.CampaignFormMetaReferenceDto;
import de.symeda.sormas.api.infrastructure.area.AreaReferenceDto;
import de.symeda.sormas.api.messaging.MessageDto;
import de.symeda.sormas.api.user.FormAccess;
import de.symeda.sormas.api.user.UserActivitySummaryDto;

Expand All @@ -60,11 +63,13 @@ public class FormBuilderLayout extends VerticalLayout {
TextField formId;
ComboBox<CampaignPhase> formType;
ComboBox<FormAccess> formCategory;
MultiSelectComboBox<AreaReferenceDto> areaSelector;
ComboBox<Modality> modality;
IntegerField daysExpired;
ComboBox<Boolean> districtEntry;
ComboBox<String> languageCode;

List<AreaReferenceDto> regions = FacadeProvider.getAreaFacade().getAllActiveAsReference();

FormGridComponent formGridComponent;
TranslationGridComponent translationGridComponent;

Expand Down Expand Up @@ -120,6 +125,8 @@ void configureFields() {
formType.setItems(CampaignPhase.values());
formCategory = new ComboBox<FormAccess>("Form Category");
formCategory.setItems(FormAccess.values());
areaSelector = new MultiSelectComboBox<AreaReferenceDto>("Region");
areaSelector.setItems(regions);
modality = new ComboBox<Modality>("Modality");
modality.setItems(Modality.values());
daysExpired = new IntegerField("Days Expired");
Expand All @@ -140,19 +147,21 @@ void configureFields() {
binder.forField(formCategory).asRequired("Form Category is Required").bind(CampaignFormMetaDto::getFormCategory,
CampaignFormMetaDto::setFormCategory);

binder.forField(areaSelector).bind(CampaignFormMetaDto::getArea, CampaignFormMetaDto::setArea);

binder.forField(modality).asRequired("Modality is Required").bind(CampaignFormMetaDto::getModality,
CampaignFormMetaDto::setModality);

binder.forField(daysExpired).asRequired("Days Expired is Required").bind(CampaignFormMetaDto::getDaysExpired,
CampaignFormMetaDto::setDaysExpired);

binder.forField(districtEntry).asRequired("Dsitrict Entry is Required")
binder.forField(districtEntry).asRequired("District Entry is Required")
.bind(CampaignFormMetaDto::isDistrictentry, CampaignFormMetaDto::setDistrictentry);

binder.forField(languageCode).asRequired("Language Code is Required").bind(CampaignFormMetaDto::getLanguageCode,
CampaignFormMetaDto::setLanguageCode);

formLayout.add(formBasics, formName, formId, formType, formCategory, modality, daysExpired, languageCode,
formLayout.add(formBasics, formName, formId, formType, formCategory, areaSelector, modality, daysExpired, languageCode,
districtEntry);

formLayout.setColspan(formBasics, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
Expand All @@ -29,6 +30,7 @@
import com.vaadin.flow.component.grid.Grid.SelectionMode;
import com.vaadin.flow.component.grid.dataview.GridListDataView;
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.Notification;
Expand All @@ -41,6 +43,7 @@
import com.vaadin.flow.data.provider.ConfigurableFilterDataProvider;
import com.vaadin.flow.data.provider.DataProvider;
import com.vaadin.flow.data.provider.ListDataProvider;
import com.vaadin.flow.data.renderer.ComponentRenderer;
import com.vaadin.flow.data.renderer.TextRenderer;
import com.vaadin.flow.data.value.ValueChangeMode;
import com.vaadin.flow.router.PageTitle;
Expand All @@ -59,6 +62,7 @@
import de.symeda.sormas.api.i18n.Captions;
import de.symeda.sormas.api.i18n.I18nProperties;
import de.symeda.sormas.api.i18n.Strings;
import de.symeda.sormas.api.infrastructure.area.AreaReferenceDto;
import de.symeda.sormas.api.user.FormAccess;
import de.symeda.sormas.api.user.UserCriteria;
import de.symeda.sormas.api.user.UserDto;
Expand Down Expand Up @@ -356,6 +360,17 @@ public void configureGrid() {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
return dateFormat.format(timestamp);
});

TextRenderer<CampaignFormMetaDto> regionRenderer = new TextRenderer<>(dto -> {
List<AreaReferenceDto> areasReferenceDto = new ArrayList<>(dto.getArea());
String listOfRegion = "";
String value = String.valueOf(areasReferenceDto).replace("[", "").replace("]", "")
.replace("null,", "").replace("null", "");
Span label = new Span(value);
label.getStyle().set("color", "var(--lumo-body-text-color) !important");
return value;
});


grid.setSelectionMode(SelectionMode.SINGLE);
grid.setMultiSort(true, MultiSortPriority.APPEND);
Expand All @@ -374,7 +389,8 @@ public void configureGrid() {
.setResizable(true);
grid.addColumn(CampaignFormMetaDto.DISTRICTENTRY).setHeader("District Data Entry").setSortable(true)
.setResizable(true);
grid.addColumn(CampaignFormMetaDto.LANGUAGE_CODE).setHeader("Language Code").setSortable(true);
grid.addColumn(regionRenderer).setHeader("Region").setSortable(true);
grid.addColumn(CampaignFormMetaDto.LANGUAGE_CODE).setHeader("Language Code").setSortable(true);

grid.setVisible(true);
grid.setWidthFull();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.symeda.sormas.api.campaign.form;

import java.util.List;
import java.util.Set;

import javax.persistence.EnumType;
import javax.persistence.Enumerated;
Expand All @@ -13,6 +14,8 @@
import de.symeda.sormas.api.Modality;
import de.symeda.sormas.api.campaign.CampaignPhase;
import de.symeda.sormas.api.i18n.Validations;
import de.symeda.sormas.api.infrastructure.area.AreaReferenceDto;
import de.symeda.sormas.api.infrastructure.region.RegionReferenceDto;
import de.symeda.sormas.api.user.FormAccess;
import de.symeda.sormas.api.utils.DataHelper;
import de.symeda.sormas.api.utils.FieldConstraints;
Expand All @@ -34,6 +37,7 @@ public class CampaignFormMetaDto extends EntityDto {
public static final String FORM_NAME_PASHTO = "formname_ps_af";
public static final String FORM_NAME_DARI = "formname_fa_af";
public static final String ARCHIVED = "archived";
public static final String AREA = "area";

@Size(max = FieldConstraints.CHARACTER_LIMIT_SMALL, message = Validations.textTooLong)
private String formId;
Expand Down Expand Up @@ -67,11 +71,7 @@ public class CampaignFormMetaDto extends EntityDto {
private String fielType;
private String fieldCaption;
private String fieldExpression;





private Set<AreaReferenceDto> area;

public boolean getArchived() {
return archived;
Expand Down Expand Up @@ -215,6 +215,11 @@ public void setDistrictentry(boolean districtentry) {
this.districtentry = districtentry;
}


public Set<AreaReferenceDto> getArea() {
return area;
}
public void setArea(Set<AreaReferenceDto> area) {
this.area = area;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.Type;
Expand All @@ -29,6 +34,9 @@
import de.symeda.sormas.api.user.FormAccess;
import de.symeda.sormas.api.utils.ValidationRuntimeException;
import de.symeda.sormas.backend.common.AbstractDomainObject;
import de.symeda.sormas.backend.infrastructure.area.Area;
import de.symeda.sormas.backend.infrastructure.region.Region;
import de.symeda.sormas.backend.messaging.Message;
import de.symeda.sormas.backend.util.ModelConstants;

@Entity
Expand All @@ -52,6 +60,7 @@ public class CampaignFormMeta extends AbstractDomainObject {
public static final String FORM_NAME_PASHTO = "formname_ps_af";
public static final String FORM_NAME_DARI = "formname_fa_af";
public static final String ARCHIVED = "archived";
public static final String AREA = "area";

private String formId;
private String formType;
Expand All @@ -76,6 +85,7 @@ public class CampaignFormMeta extends AbstractDomainObject {
// private String campaignFormTranslations;
// private List<CampaignFormTranslations> campaignFormTranslationsList;
private boolean archived = false;
private Set<Area> area;

@Column
public boolean getArchived() {
Expand Down Expand Up @@ -247,7 +257,23 @@ public String getModality() {
public void setModality(String modality) {
this.modality = modality;
}


@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "campaignformmeta_areas",
joinColumns = @JoinColumn(name = "campaignformmeta_id", referencedColumnName = CampaignFormMeta.ID, nullable = false),
uniqueConstraints = @UniqueConstraint(columnNames = {
"campaignformmeta_id",
"area_id" }))
@ManyToMany(cascade = {})
public Set<Area> getArea() {
return area;
}

public void setArea(Set<Area> area) {
this.area = area;
}


// @Transient
// public List<CampaignFormTranslations> getCampaignFormTranslationsList() {
// if (campaignFormTranslationsList == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -58,6 +59,9 @@
import de.symeda.sormas.api.utils.SortProperty;
import de.symeda.sormas.api.utils.ValidationRuntimeException;
import de.symeda.sormas.backend.disease.DiseaseConfigurationFacadeEjb;
import de.symeda.sormas.backend.infrastructure.area.Area;
import de.symeda.sormas.backend.infrastructure.area.AreaFacadeEjb;
import de.symeda.sormas.backend.infrastructure.area.AreaService;
import de.symeda.sormas.backend.user.User;
import de.symeda.sormas.backend.user.UserService;
import de.symeda.sormas.backend.util.DtoHelper;
Expand All @@ -76,6 +80,8 @@ public class CampaignFormMetaFacadeEjb implements CampaignFormMetaFacade {
private CampaignFormMetaService service;
@EJB
private UserService userService;
@EJB
private AreaService areaService;

public CampaignFormMeta fromDto(@NotNull CampaignFormMetaDto source, boolean checkChangeDate) {
CampaignFormMeta target = DtoHelper.fillOrBuildEntity(source, service.getByUuid(source.getUuid()),
Expand All @@ -89,6 +95,7 @@ public CampaignFormMeta fromDto(@NotNull CampaignFormMetaDto source, boolean che
target.setFormName(source.getFormName());
target.setModality(source.getModality().toString());
target.setFormCategory(source.getFormCategory());
if (source.getArea() != null) {target.setArea(areaService.getByReferenceDto(source.getArea()));}
target.setLanguageCode(source.getLanguageCode());
target.setCampaignFormElements(source.getCampaignFormElements());
target.setCampaignFormTranslations(source.getCampaignFormTranslations());
Expand Down Expand Up @@ -120,6 +127,7 @@ public static CampaignFormMetaDto toDto(CampaignFormMeta source) {
: source.getModality().equals(Modality.HF2HF.toString()) ? Modality.HF2HF
: source.getModality().equals(Modality.M2M.toString()) ? Modality.M2M : Modality.H2H);
target.setFormCategory(source.getFormCategory());
if (source.getArea() != null) {target.setArea(AreaFacadeEjb.toReferenceDto(source.getArea()));}
target.setLanguageCode(source.getLanguageCode());
target.setCampaignFormElements(source.getCampaignFormElements());
target.setCampaignFormTranslations(source.getCampaignFormTranslations());
Expand Down

0 comments on commit b1fb5ff

Please sign in to comment.