Search in sources :

Example 1 with ProjectViewModel

use of io.imunity.furms.ui.project.ProjectViewModel in project furms by unity-idm.

the class SettingsView method createUpdateButton.

private Button createUpdateButton() {
    Button updateButton = new Button(getTranslation("view.project-admin.settings.button.update"));
    updateButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
    updateButton.addClickListener(x -> {
        binder.validate();
        if (binder.isValid()) {
            ProjectViewModel projectViewModel = new ProjectViewModel(binder.getBean());
            ProjectAdminControlledAttributes project = new ProjectAdminControlledAttributes(projectViewModel.id, projectViewModel.description, projectViewModel.researchField, projectViewModel.logo);
            getResultOrException(() -> projectService.update(project)).getException().ifPresentOrElse(e -> showErrorNotification(getTranslation("base.error.message")), () -> {
                if (isLogoChange(oldProject, projectViewModel)) {
                    callReloadLogo(this.getClass());
                }
                oldProject = projectViewModel;
                disableEditorMode();
                showSuccessNotification(getTranslation("view.project-admin.settings.update.success"));
            });
        }
    });
    return updateButton;
}
Also used : ProjectAdminControlledAttributes(io.imunity.furms.domain.projects.ProjectAdminControlledAttributes) Button(com.vaadin.flow.component.button.Button) ProjectViewModel(io.imunity.furms.ui.project.ProjectViewModel)

Example 2 with ProjectViewModel

use of io.imunity.furms.ui.project.ProjectViewModel in project furms by unity-idm.

the class ProjectFormView method setParameter.

@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
    ProjectViewModel projectViewModel = ofNullable(parameter).flatMap(id -> handleExceptions(() -> resolver.resolve(id, UIContext.getCurrent().getZone()))).orElseGet(() -> new ProjectViewModel(ResourceGetter.getCurrentResourceId()));
    String trans = parameter == null ? "view.community-admin.project.form.parameter.new" : "view.community-admin.project.form.parameter.update";
    breadCrumbParameter = new BreadCrumbParameter(parameter, getTranslation(trans));
    projectFormComponent.setFormPools(projectViewModel);
}
Also used : VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) Project(io.imunity.furms.domain.projects.Project) ProjectViewModel(io.imunity.furms.ui.project.ProjectViewModel) Binder(com.vaadin.flow.data.binder.Binder) NotificationUtils(io.imunity.furms.ui.utils.NotificationUtils) PageTitle(io.imunity.furms.ui.components.PageTitle) BeforeEvent(com.vaadin.flow.router.BeforeEvent) Route(com.vaadin.flow.router.Route) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) FurmsViewUserModelMapper(io.imunity.furms.ui.user_context.FurmsViewUserModelMapper) OptionalException(io.imunity.furms.ui.utils.OptionalException) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) Key(com.vaadin.flow.component.Key) UI(com.vaadin.flow.component.UI) UserService(io.imunity.furms.api.users.UserService) CommunityAdminMenu(io.imunity.furms.ui.views.community.CommunityAdminMenu) VaadinExceptionHandler.getResultOrException(io.imunity.furms.ui.utils.VaadinExceptionHandler.getResultOrException) FormButtons(io.imunity.furms.ui.components.FormButtons) FurmsViewUserModel(io.imunity.furms.ui.user_context.FurmsViewUserModel) UIContext(io.imunity.furms.ui.user_context.UIContext) ButtonVariant(com.vaadin.flow.component.button.ButtonVariant) ProjectFormComponent(io.imunity.furms.ui.project.ProjectFormComponent) Optional.ofNullable(java.util.Optional.ofNullable) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) OptionalParameter(com.vaadin.flow.router.OptionalParameter) ProjectViewModelMapper(io.imunity.furms.ui.project.ProjectViewModelMapper) List(java.util.List) Button(com.vaadin.flow.component.button.Button) ResourceGetter(io.imunity.furms.ui.utils.ResourceGetter) Optional(java.util.Optional) ProjectService(io.imunity.furms.api.projects.ProjectService) ProjectModelResolver(io.imunity.furms.ui.project.ProjectModelResolver) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) ProjectViewModel(io.imunity.furms.ui.project.ProjectViewModel)

Example 3 with ProjectViewModel

use of io.imunity.furms.ui.project.ProjectViewModel in project furms by unity-idm.

the class ProjectFormView method saveProject.

private void saveProject() {
    ProjectViewModel projectViewModel = binder.getBean();
    Project project = ProjectViewModelMapper.map(projectViewModel);
    OptionalException<Void> optionalException;
    if (project.getId() == null)
        optionalException = getResultOrException(() -> {
            projectService.create(project);
        });
    else
        optionalException = getResultOrException(() -> projectService.update(project));
    optionalException.getException().ifPresentOrElse(throwable -> NotificationUtils.showErrorNotification(getTranslation(throwable.getMessage())), () -> UI.getCurrent().navigate(ProjectsView.class));
}
Also used : Project(io.imunity.furms.domain.projects.Project) ProjectViewModel(io.imunity.furms.ui.project.ProjectViewModel)

Aggregations

ProjectViewModel (io.imunity.furms.ui.project.ProjectViewModel)3 Button (com.vaadin.flow.component.button.Button)2 Project (io.imunity.furms.domain.projects.Project)2 Key (com.vaadin.flow.component.Key)1 UI (com.vaadin.flow.component.UI)1 ButtonVariant (com.vaadin.flow.component.button.ButtonVariant)1 BeanValidationBinder (com.vaadin.flow.data.binder.BeanValidationBinder)1 Binder (com.vaadin.flow.data.binder.Binder)1 BeforeEvent (com.vaadin.flow.router.BeforeEvent)1 OptionalParameter (com.vaadin.flow.router.OptionalParameter)1 Route (com.vaadin.flow.router.Route)1 ProjectService (io.imunity.furms.api.projects.ProjectService)1 UserService (io.imunity.furms.api.users.UserService)1 ProjectAdminControlledAttributes (io.imunity.furms.domain.projects.ProjectAdminControlledAttributes)1 FormButtons (io.imunity.furms.ui.components.FormButtons)1 FurmsViewComponent (io.imunity.furms.ui.components.FurmsViewComponent)1 PageTitle (io.imunity.furms.ui.components.PageTitle)1 BreadCrumbParameter (io.imunity.furms.ui.components.layout.BreadCrumbParameter)1 ProjectFormComponent (io.imunity.furms.ui.project.ProjectFormComponent)1 ProjectModelResolver (io.imunity.furms.ui.project.ProjectModelResolver)1