Search in sources :

Example 26 with CommitDiscardWrapperComponent

use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.

the class EventController method selectOrCreateEventForContactList.

public void selectOrCreateEventForContactList(List<ContactReferenceDto> contactRefs) {
    if (contactRefs == null || contactRefs.isEmpty()) {
        return;
    }
    List<ContactDto> contactDtos = FacadeProvider.getContactFacade().getByUuids(contactRefs.stream().map(ReferenceDto::getUuid).collect(Collectors.toList()));
    EventSelectionField eventSelect = new EventSelectionField(contactDtos.stream().findFirst().get().getDisease(), I18nProperties.getString(Strings.infoPickOrCreateEventForContact), null);
    eventSelect.setWidth(1100, Sizeable.Unit.PIXELS);
    final CommitDiscardWrapperComponent<EventSelectionField> component = new CommitDiscardWrapperComponent<>(eventSelect);
    component.addCommitListener(() -> {
        EventIndexDto selectedEvent = eventSelect.getValue();
        if (selectedEvent != null) {
            EventReferenceDto eventReferenceDto = new EventReferenceDto(selectedEvent.getUuid());
            linkContactsToEvent(eventReferenceDto, contactDtos);
        } else {
            createFromContactList(contactRefs);
            SormasUI.refreshView();
        }
    });
    eventSelect.setSelectionChangeCallback(commitAllowed -> component.getCommitButton().setEnabled(commitAllowed));
    VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingPickOrCreateEvent));
}
Also used : ReferenceDto(de.symeda.sormas.api.ReferenceDto) EventParticipantReferenceDto(de.symeda.sormas.api.event.EventParticipantReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) EventGroupReferenceDto(de.symeda.sormas.api.event.EventGroupReferenceDto) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) EventIndexDto(de.symeda.sormas.api.event.EventIndexDto) EventSelectionField(de.symeda.sormas.ui.events.eventLink.EventSelectionField)

Example 27 with CommitDiscardWrapperComponent

use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.

the class EventGroupController method selectOrCreate.

public void selectOrCreate(List<EventReferenceDto> eventReferences, Runnable callback) {
    Set<String> excludedEventGroupUuids = FacadeProvider.getEventGroupFacade().getCommonEventGroupsByEvents(eventReferences).stream().map(EventGroupReferenceDto::getUuid).collect(Collectors.toSet());
    EventGroupSelectionField selectionField = new EventGroupSelectionField(excludedEventGroupUuids);
    selectionField.setWidth(1024, Sizeable.Unit.PIXELS);
    final CommitDiscardWrapperComponent<EventGroupSelectionField> component = new CommitDiscardWrapperComponent<>(selectionField);
    component.addCommitListener(() -> {
        EventGroupIndexDto selectedEventGroup = selectionField.getValue();
        if (selectedEventGroup != null) {
            FacadeProvider.getEventGroupFacade().linkEventsToGroup(eventReferences, selectedEventGroup.toReference());
            FacadeProvider.getEventGroupFacade().notifyEventAddedToEventGroup(selectedEventGroup.toReference(), eventReferences);
            Notification.show(I18nProperties.getString(Strings.messageEventLinkedToGroup), Type.TRAY_NOTIFICATION);
            if (callback != null) {
                callback.run();
            } else {
                SormasUI.refreshView();
            }
        } else {
            create(eventReferences, callback);
        }
    });
    selectionField.setSelectionChangeCallback((commitAllowed) -> component.getCommitButton().setEnabled(commitAllowed));
    VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingPickOrCreateEventGroup));
}
Also used : EventGroupSelectionField(de.symeda.sormas.ui.events.groups.EventGroupSelectionField) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) EventGroupIndexDto(de.symeda.sormas.api.event.EventGroupIndexDto)

Example 28 with CommitDiscardWrapperComponent

use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.

the class EventGroupController method getEventGroupEditComponent.

public CommitDiscardWrapperComponent<?> getEventGroupEditComponent(String uuid) {
    EventGroupDto eventGroup = FacadeProvider.getEventGroupFacade().getEventGroupByUuid(uuid);
    EventGroupDataForm eventGroupEditForm = new EventGroupDataForm(false);
    eventGroupEditForm.setValue(eventGroup);
    UserProvider user = UserProvider.getCurrent();
    final CommitDiscardWrapperComponent<EventGroupDataForm> editView = new CommitDiscardWrapperComponent<>(eventGroupEditForm, user.hasUserRight(UserRight.EVENTGROUP_EDIT), eventGroupEditForm.getFieldGroup());
    List<RegionReferenceDto> regions = FacadeProvider.getEventGroupFacade().getEventGroupRelatedRegions(uuid);
    boolean hasRegion = user.hasNationalJurisdictionLevel() || regions.stream().allMatch(user::hasRegion);
    editView.setReadOnly(hasRegion);
    if (user.hasUserRight(UserRight.EVENTGROUP_EDIT) && hasRegion) {
        editView.addCommitListener(() -> {
            if (!eventGroupEditForm.getFieldGroup().isModified()) {
                EventGroupDto updatedEventGroup = eventGroupEditForm.getValue();
                FacadeProvider.getEventGroupFacade().saveEventGroup(updatedEventGroup);
                Notification.show(I18nProperties.getString(Strings.messageEventGroupSaved), Notification.Type.WARNING_MESSAGE);
                SormasUI.refreshView();
            }
        });
    }
    if (user.hasUserRight(UserRight.EVENTGROUP_DELETE) && hasRegion) {
        editView.addDeleteListener(() -> {
            deleteEventGroup(eventGroup);
            UI.getCurrent().getNavigator().navigateTo(EventsView.VIEW_NAME);
        }, I18nProperties.getString(Strings.entityEventGroup));
    }
    // Initialize 'Archive' button
    if (user.hasUserRight(UserRight.EVENTGROUP_ARCHIVE) && hasRegion) {
        boolean archived = FacadeProvider.getEventGroupFacade().isArchived(uuid);
        Button archiveEventButton = ButtonHelper.createButton(archived ? Captions.actionDearchive : Captions.actionArchive, e -> {
            archiveOrDearchiveEventGroup(uuid, !archived);
        }, ValoTheme.BUTTON_LINK);
        editView.getButtonsPanel().addComponentAsFirst(archiveEventButton);
        editView.getButtonsPanel().setComponentAlignment(archiveEventButton, Alignment.BOTTOM_LEFT);
    }
    editView.addDiscardListener(SormasUI::refreshView);
    return editView;
}
Also used : RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) UserProvider(de.symeda.sormas.ui.UserProvider) Button(com.vaadin.ui.Button) SormasUI(de.symeda.sormas.ui.SormasUI) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) EventGroupDto(de.symeda.sormas.api.event.EventGroupDto)

Example 29 with CommitDiscardWrapperComponent

use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.

the class LabMessageController method pickOrCreateEvent.

private void pickOrCreateEvent(LabMessageDto labMessageDto, PersonDto person) {
    EventSelectionField eventSelect = new EventSelectionField(labMessageDto.getTestedDisease(), I18nProperties.getString(Strings.infoPickOrCreateEventForLabMessage), null);
    eventSelect.setWidth(1024, Sizeable.Unit.PIXELS);
    Window window = VaadinUiUtil.createPopupWindow();
    final CommitDiscardWrapperComponent<EventSelectionField> component = new CommitDiscardWrapperComponent<>(eventSelect);
    component.addCommitListener(() -> {
        EventIndexDto selectedEvent = eventSelect.getValue();
        if (selectedEvent != null) {
            EventCriteria eventCriteria = new EventCriteria();
            eventCriteria.setPerson(person.toReference());
            eventCriteria.setUserFilterIncluded(false);
            List<EventIndexDto> eventIndexDtos = FacadeProvider.getEventFacade().getIndexList(eventCriteria, null, null, null);
            EventReferenceDto eventReferenceDto = new EventReferenceDto(selectedEvent.getUuid());
            if (!eventIndexDtos.contains(selectedEvent)) {
                createEventParticipant(FacadeProvider.getEventFacade().getEventByUuid(eventReferenceDto.getUuid(), false), labMessageDto, person);
            } else {
                CommitDiscardWrapperComponent<VerticalLayout> commitDiscardWrapperComponent = new CommitDiscardWrapperComponent<>(new VerticalLayout(new Label(I18nProperties.getString(Strings.infoEventParticipantAlreadyExisting))));
                commitDiscardWrapperComponent.getCommitButton().setCaption(I18nProperties.getCaption(Captions.actionContinue));
                commitDiscardWrapperComponent.getDiscardButton().setCaption(I18nProperties.getCaption(Captions.actionBack));
                commitDiscardWrapperComponent.addCommitListener(() -> {
                    EventParticipantReferenceDto participant = FacadeProvider.getEventParticipantFacade().getReferenceByEventAndPerson(selectedEvent.getUuid(), person.getUuid());
                    List<SampleDto> samples = FacadeProvider.getSampleFacade().getSimilarSamples(createSampleCriteria(labMessageDto).eventParticipant(participant));
                    if (samples.isEmpty()) {
                        createSample(SampleDto.build(UserProvider.getCurrent().getUserReference(), participant), labMessageDto, selectedEvent.getDisease(), false);
                    } else {
                        pickOrCreateSample(FacadeProvider.getEventParticipantFacade().getByUuid(participant.getUuid()), labMessageDto, samples);
                    }
                });
                commitDiscardWrapperComponent.addDiscardListener(() -> pickOrCreateEvent(labMessageDto, person));
                VaadinUiUtil.showModalPopupWindow(commitDiscardWrapperComponent, I18nProperties.getCaption(Captions.info));
            }
        } else {
            createEvent(labMessageDto, person);
        }
        window.close();
    });
    component.addDiscardListener(window::close);
    eventSelect.setSelectionChangeCallback((commitAllowed) -> component.getCommitButton().setEnabled(commitAllowed));
    window.setContent(component);
    window.setCaption(I18nProperties.getString(Strings.headingPickOrCreateEvent));
    UI.getCurrent().addWindow(window);
}
Also used : Window(com.vaadin.ui.Window) Label(com.vaadin.ui.Label) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) EventIndexDto(de.symeda.sormas.api.event.EventIndexDto) EventCriteria(de.symeda.sormas.api.event.EventCriteria) EventSelectionField(de.symeda.sormas.ui.events.eventLink.EventSelectionField) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) EventParticipantReferenceDto(de.symeda.sormas.api.event.EventParticipantReferenceDto) VerticalLayout(com.vaadin.ui.VerticalLayout) SampleDto(de.symeda.sormas.api.sample.SampleDto)

Example 30 with CommitDiscardWrapperComponent

use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent in project SORMAS-Project by hzi-braunschweig.

the class LabMessageController method confirmContinueProcessing.

private CompletionStage<Boolean> confirmContinueProcessing(LabMessageDto labMessageDto, SampleReferenceDto sample) {
    CompletableFuture<Boolean> ret = new CompletableFuture<>();
    Window window = VaadinUiUtil.createPopupWindow();
    Label label = new Label(I18nProperties.getString(Strings.confirmLabMessageCorrectionThrough));
    label.addStyleName(CssStyles.LABEL_WHITE_SPACE_NORMAL);
    CommitDiscardWrapperComponent<Label> confirmComponent = new CommitDiscardWrapperComponent<>(label);
    confirmComponent.getCommitButton().setCaption(I18nProperties.getCaption(Captions.actionYes));
    confirmComponent.getDiscardButton().setCaption(I18nProperties.getCaption(Captions.actionNo));
    confirmComponent.addCommitListener(() -> {
        ret.complete(true);
        window.close();
    });
    confirmComponent.addDiscardListener(window::close);
    window.addCloseListener((e) -> {
        if (!ret.isDone()) {
            ret.complete(false);
        }
        finishProcessingLabMessage(labMessageDto, sample);
    });
    showFormWithLabMessage(labMessageDto, confirmComponent, window, I18nProperties.getString(Strings.headingLabMessageCorrectionThrough), false);
    return ret;
}
Also used : Window(com.vaadin.ui.Window) CompletableFuture(java.util.concurrent.CompletableFuture) Label(com.vaadin.ui.Label) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)

Aggregations

CommitDiscardWrapperComponent (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)101 Window (com.vaadin.ui.Window)34 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)22 EventDto (de.symeda.sormas.api.event.EventDto)17 Button (com.vaadin.ui.Button)16 CommitListener (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.CommitListener)15 SimilarContactDto (de.symeda.sormas.api.contact.SimilarContactDto)13 PersonDto (de.symeda.sormas.api.person.PersonDto)13 ContactDto (de.symeda.sormas.api.contact.ContactDto)12 EventReferenceDto (de.symeda.sormas.api.event.EventReferenceDto)12 Label (com.vaadin.ui.Label)11 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)11 Notification (com.vaadin.ui.Notification)10 EventIndexDto (de.symeda.sormas.api.event.EventIndexDto)10 AutomaticDeletionLabel (de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel)10 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)9 UserDto (de.symeda.sormas.api.user.UserDto)9 EventSelectionField (de.symeda.sormas.ui.events.eventLink.EventSelectionField)9 AutomaticDeletionInfoDto (de.symeda.sormas.api.deletionconfiguration.AutomaticDeletionInfoDto)8 SampleDto (de.symeda.sormas.api.sample.SampleDto)8