Search in sources :

Example 1 with SormasUI

use of de.symeda.sormas.ui.SormasUI 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 2 with SormasUI

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

the class SourceContactListComponent method createSourceContactListComponent.

private void createSourceContactListComponent(SourceContactList sourceContactList) {
    setWidth(100, Unit.PERCENTAGE);
    setMargin(false);
    setSpacing(false);
    HorizontalLayout componentHeader = new HorizontalLayout();
    componentHeader.setMargin(false);
    componentHeader.setSpacing(false);
    componentHeader.setWidth(100, Unit.PERCENTAGE);
    addComponent(componentHeader);
    list = sourceContactList;
    addComponent(list);
    list.reload();
    Label sourceContactsHeader = new Label(I18nProperties.getString(Strings.headingEpiDataSourceCaseContacts));
    sourceContactsHeader.addStyleName(CssStyles.H3);
    componentHeader.addComponent(sourceContactsHeader);
    if (UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_CREATE)) {
        Button createButton = ButtonHelper.createIconButton(Captions.contactNewContact, VaadinIcons.PLUS_CIRCLE, e -> view.showNavigationConfirmPopupIfDirty(() -> ControllerProvider.getContactController().create(caseReference, true, SormasUI::refreshView)), ValoTheme.BUTTON_PRIMARY);
        componentHeader.addComponent(createButton);
        componentHeader.setComponentAlignment(createButton, Alignment.MIDDLE_RIGHT);
    }
}
Also used : Button(com.vaadin.ui.Button) SormasUI(de.symeda.sormas.ui.SormasUI) Label(com.vaadin.ui.Label) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 3 with SormasUI

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

the class ExpressionProcessorTest method setupClass.

@BeforeClass
public static void setupClass() {
    UI ui = new SormasUI();
    final MockedStatic<UI> uiMockedStatic = Mockito.mockStatic(UI.class);
    uiMockedStatic.when(UI::getCurrent).thenReturn(ui);
    Page page = new Page(UI.getCurrent(), new PageState());
    MockedStatic<Page> pageMockedStatic = Mockito.mockStatic(Page.class);
    pageMockedStatic.when(Page::getCurrent).thenReturn(page);
}
Also used : UI(com.vaadin.ui.UI) SormasUI(de.symeda.sormas.ui.SormasUI) PageState(com.vaadin.shared.ui.ui.PageState) SormasUI(de.symeda.sormas.ui.SormasUI) Page(com.vaadin.server.Page) BeforeClass(org.junit.BeforeClass)

Example 4 with SormasUI

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

the class CaseControllerTest method initUI.

@Before
public void initUI() throws Exception {
    creator.createUser(null, null, null, "ad", "min", UserRole.ADMIN, UserRole.NATIONAL_USER);
    VaadinRequest request = Mockito.mock(VaadinServletRequest.class);
    when(request.getUserPrincipal()).thenReturn((Principal) () -> "admin");
    CurrentInstance.set(VaadinRequest.class, request);
    VaadinService service = Mockito.mock(VaadinService.class);
    CurrentInstance.set(VaadinService.class, service);
    VaadinSession session = Mockito.mock(VaadinSession.class);
    ConverterFactory converterFactory = new SormasDefaultConverterFactory();
    when(session.getConverterFactory()).thenReturn(converterFactory);
    when(session.getService()).thenReturn(service);
    CurrentInstance.set(VaadinSession.class, session);
    ui = new SormasUI();
    CurrentInstance.set(UI.class, ui);
    java.lang.reflect.Field pageField = UI.class.getDeclaredField("page");
    pageField.setAccessible(true);
    pageField.set(ui, Mockito.mock(Page.class));
}
Also used : SormasDefaultConverterFactory(de.symeda.sormas.ui.utils.SormasDefaultConverterFactory) VaadinSession(com.vaadin.server.VaadinSession) SormasUI(de.symeda.sormas.ui.SormasUI) VaadinService(com.vaadin.server.VaadinService) VaadinRequest(com.vaadin.server.VaadinRequest) ConverterFactory(com.vaadin.v7.data.util.converter.ConverterFactory) SormasDefaultConverterFactory(de.symeda.sormas.ui.utils.SormasDefaultConverterFactory) Page(com.vaadin.server.Page) Before(org.junit.Before)

Example 5 with SormasUI

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

the class EventParticipantDataView method initView.

@Override
protected void initView(String params) {
    EventParticipantDto eventParticipant = FacadeProvider.getEventParticipantFacade().getEventParticipantByUuid(getReference().getUuid());
    setHeightUndefined();
    DetailSubComponentWrapper container = new DetailSubComponentWrapper(() -> editComponent);
    container.setWidth(100, Unit.PERCENTAGE);
    container.setMargin(true);
    setSubComponent(container);
    CustomLayout layout = new CustomLayout();
    layout.addStyleName(CssStyles.ROOT_COMPONENT);
    layout.setTemplateContents(HTML_LAYOUT);
    layout.setWidth(100, Unit.PERCENTAGE);
    layout.setHeightUndefined();
    container.addComponent(layout);
    final EventParticipantReferenceDto eventParticipantRef = getReference();
    editComponent = ControllerProvider.getEventParticipantController().getEventParticipantDataEditComponent(eventParticipantRef.getUuid());
    editComponent.setMargin(false);
    editComponent.setWidth(100, Unit.PERCENTAGE);
    editComponent.getWrappedComponent().setWidth(100, Unit.PERCENTAGE);
    editComponent.addStyleName(CssStyles.MAIN_COMPONENT);
    layout.addComponent(editComponent, EDIT_LOC);
    EventDto event = FacadeProvider.getEventFacade().getEventByUuid(eventParticipant.getEvent().getUuid(), false);
    SampleCriteria sampleCriteria = new SampleCriteria().eventParticipant(eventParticipantRef);
    if (UserProvider.getCurrent().hasUserRight(UserRight.SAMPLE_VIEW)) {
        SampleListComponent sampleList = new SampleListComponent(sampleCriteria.sampleAssociationType(SampleAssociationType.EVENT_PARTICIPANT), e -> showNavigationConfirmPopupIfDirty(() -> ControllerProvider.getSampleController().create(eventParticipantRef, event.getDisease(), SormasUI::refreshView)));
        SampleListComponentLayout sampleListComponentLayout = new SampleListComponentLayout(sampleList, I18nProperties.getString(Strings.infoCreateNewSampleDiscardsChangesEventParticipant));
        layout.addComponent(sampleListComponentLayout, SAMPLES_LOC);
    }
    if (UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_VIEW)) {
        VerticalLayout contactsLayout = new VerticalLayout();
        contactsLayout.setMargin(false);
        contactsLayout.setSpacing(false);
        ContactListComponent contactList = new ContactListComponent(eventParticipantRef);
        contactList.addStyleName(CssStyles.SIDE_COMPONENT);
        contactsLayout.addComponent(contactList);
        layout.addComponent(contactsLayout, CONTACTS_LOC);
    }
    boolean sormasToSormasEnabled = FacadeProvider.getSormasToSormasFacade().isSharingEventsEnabledForUser();
    if (sormasToSormasEnabled || eventParticipant.getSormasToSormasOriginInfo() != null) {
        VerticalLayout sormasToSormasLocLayout = new VerticalLayout();
        sormasToSormasLocLayout.setMargin(false);
        sormasToSormasLocLayout.setSpacing(false);
        SormasToSormasListComponent sormasToSormasListComponent = new SormasToSormasListComponent(eventParticipant, sormasToSormasEnabled);
        sormasToSormasListComponent.addStyleNames(CssStyles.SIDE_COMPONENT);
        sormasToSormasLocLayout.addComponent(sormasToSormasListComponent);
        layout.addComponent(sormasToSormasLocLayout, SORMAS_TO_SORMAS_LOC);
    }
    VaccinationListCriteria vaccinationCriteria = new VaccinationListCriteria.Builder(eventParticipant.getPerson().toReference()).withDisease(event.getDisease()).build();
    QuarantineOrderDocumentsComponent.addComponentToLayout(layout, eventParticipantRef, DocumentWorkflow.QUARANTINE_ORDER_EVENT_PARTICIPANT, sampleCriteria, vaccinationCriteria);
    boolean isEditAllowed = FacadeProvider.getEventParticipantFacade().isEventParticipantEditAllowed(eventParticipantRef.getUuid());
    if (!isEditAllowed) {
        container.setEnabled(false);
    }
    if (FacadeProvider.getFeatureConfigurationFacade().isFeatureEnabled(FeatureType.IMMUNIZATION_MANAGEMENT) && UserProvider.getCurrent().hasUserRight(UserRight.IMMUNIZATION_VIEW) && event.getDisease() != null) {
        if (!FacadeProvider.getFeatureConfigurationFacade().isPropertyValueTrue(FeatureType.IMMUNIZATION_MANAGEMENT, FeatureTypeProperty.REDUCED)) {
            final ImmunizationListCriteria immunizationListCriteria = new ImmunizationListCriteria.Builder(eventParticipant.getPerson().toReference()).wihDisease(event.getDisease()).build();
            layout.addComponent(new SideComponentLayout(new ImmunizationListComponent(immunizationListCriteria)), IMMUNIZATION_LOC);
        } else {
            VaccinationListCriteria criteria = vaccinationCriteria;
            layout.addComponent(new SideComponentLayout(new VaccinationListComponent(getReference(), criteria, eventParticipant.getRegion() != null ? eventParticipant.getRegion() : event.getEventLocation().getRegion(), eventParticipant.getDistrict() != null ? eventParticipant.getDistrict() : event.getEventLocation().getDistrict(), this)), VACCINATIONS_LOC);
        }
    }
}
Also used : DetailSubComponentWrapper(de.symeda.sormas.ui.utils.DetailSubComponentWrapper) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) SampleListComponentLayout(de.symeda.sormas.ui.samples.sampleLink.SampleListComponentLayout) SormasToSormasListComponent(de.symeda.sormas.ui.sormastosormas.SormasToSormasListComponent) EventDto(de.symeda.sormas.api.event.EventDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) VaccinationListComponent(de.symeda.sormas.ui.vaccination.list.VaccinationListComponent) VaccinationListCriteria(de.symeda.sormas.api.vaccination.VaccinationListCriteria) SideComponentLayout(de.symeda.sormas.ui.utils.components.sidecomponent.SideComponentLayout) SampleListComponent(de.symeda.sormas.ui.samples.sampleLink.SampleListComponent) CustomLayout(com.vaadin.ui.CustomLayout) SormasUI(de.symeda.sormas.ui.SormasUI) ContactListComponent(de.symeda.sormas.ui.contact.ContactListComponent) EventParticipantReferenceDto(de.symeda.sormas.api.event.EventParticipantReferenceDto) VerticalLayout(com.vaadin.ui.VerticalLayout) ImmunizationListCriteria(de.symeda.sormas.api.immunization.ImmunizationListCriteria) ImmunizationListComponent(de.symeda.sormas.ui.immunization.immunizationlink.ImmunizationListComponent)

Aggregations

SormasUI (de.symeda.sormas.ui.SormasUI)5 Page (com.vaadin.server.Page)2 Button (com.vaadin.ui.Button)2 VaadinRequest (com.vaadin.server.VaadinRequest)1 VaadinService (com.vaadin.server.VaadinService)1 VaadinSession (com.vaadin.server.VaadinSession)1 PageState (com.vaadin.shared.ui.ui.PageState)1 CustomLayout (com.vaadin.ui.CustomLayout)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Label (com.vaadin.ui.Label)1 UI (com.vaadin.ui.UI)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 ConverterFactory (com.vaadin.v7.data.util.converter.ConverterFactory)1 EventDto (de.symeda.sormas.api.event.EventDto)1 EventGroupDto (de.symeda.sormas.api.event.EventGroupDto)1 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)1 EventParticipantReferenceDto (de.symeda.sormas.api.event.EventParticipantReferenceDto)1 ImmunizationListCriteria (de.symeda.sormas.api.immunization.ImmunizationListCriteria)1 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)1 SampleCriteria (de.symeda.sormas.api.sample.SampleCriteria)1