Search in sources :

Example 1 with OptionalParameter

use of com.vaadin.flow.router.OptionalParameter in project flow-components by vaadin.

the class TreeGridPreloadPage method setParameter.

@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
    Location location = event.getLocation();
    QueryParameters queryParameters = location.getQueryParameters();
    // query parameter: pageSize
    List<String> pageSize = queryParameters.getParameters().get("pageSize");
    if (pageSize != null) {
        grid.setPageSize(Integer.parseInt(pageSize.get(0)));
    }
    // query parameter: nodesPerLevel
    List<String> nodesPerLevel = queryParameters.getParameters().get("nodesPerLevel");
    // query parameter: depth
    List<String> depth = queryParameters.getParameters().get("depth");
    int dpNodesPerLevel = nodesPerLevel == null ? 3 : Integer.parseInt(nodesPerLevel.get(0));
    int dpDepth = depth == null ? 4 : Integer.parseInt(depth.get(0));
    setDataProvider(dpNodesPerLevel, dpDepth);
    // query parameter: expandedRootIndexes
    List<String> expandedRootIndexes = queryParameters.getParameters().get("expandedRootIndexes");
    if (expandedRootIndexes != null) {
        List<HierarchicalTestBean> expandedRootItems = Arrays.stream(expandedRootIndexes.get(0).split(",")).map(Integer::parseInt).map(expandedRootIndex -> new HierarchicalTestBean(null, 0, expandedRootIndex)).collect(java.util.stream.Collectors.toList());
        grid.expandRecursively(expandedRootItems, Integer.MAX_VALUE);
    }
    // query parameter: sortDirection
    List<String> sortDirection = queryParameters.getParameters().get("sortDirection");
    if (sortDirection != null) {
        SortDirection direction = SortDirection.valueOf(sortDirection.get(0).toUpperCase());
        GridSortOrderBuilder<HierarchicalTestBean> sorting = new GridSortOrderBuilder<HierarchicalTestBean>();
        Column<HierarchicalTestBean> column = grid.getColumns().get(0);
        if (direction == SortDirection.ASCENDING) {
            grid.sort(sorting.thenAsc(column).build());
        } else {
            grid.sort(sorting.thenDesc(column).build());
        }
    }
}
Also used : HierarchicalTestBean(com.vaadin.flow.data.bean.HierarchicalTestBean) Arrays(java.util.Arrays) SortDirection(com.vaadin.flow.data.provider.SortDirection) HasUrlParameter(com.vaadin.flow.router.HasUrlParameter) TextArea(com.vaadin.flow.component.textfield.TextArea) LitRenderer(com.vaadin.flow.data.renderer.LitRenderer) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) VaadinRequest(com.vaadin.flow.server.VaadinRequest) GridSortOrderBuilder(com.vaadin.flow.component.grid.GridSortOrderBuilder) BeforeEvent(com.vaadin.flow.router.BeforeEvent) HierarchicalQuery(com.vaadin.flow.data.provider.hierarchy.HierarchicalQuery) TreeGrid(com.vaadin.flow.component.treegrid.TreeGrid) Route(com.vaadin.flow.router.Route) OptionalParameter(com.vaadin.flow.router.OptionalParameter) List(java.util.List) Button(com.vaadin.flow.component.button.Button) Column(com.vaadin.flow.component.grid.Grid.Column) Stream(java.util.stream.Stream) VaadinService(com.vaadin.flow.server.VaadinService) Location(com.vaadin.flow.router.Location) HierarchicalTestBean(com.vaadin.flow.data.bean.HierarchicalTestBean) TextField(com.vaadin.flow.component.textfield.TextField) QueryParameters(com.vaadin.flow.router.QueryParameters) QueryParameters(com.vaadin.flow.router.QueryParameters) GridSortOrderBuilder(com.vaadin.flow.component.grid.GridSortOrderBuilder) SortDirection(com.vaadin.flow.data.provider.SortDirection) Location(com.vaadin.flow.router.Location)

Example 2 with OptionalParameter

use of com.vaadin.flow.router.OptionalParameter in project furms by unity-idm.

the class ProjectAllocationFormView method setParameter.

@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
    ProjectAllocationViewModel projectAllocationModel = ofNullable(parameter).flatMap(id -> handleExceptions(() -> projectAllocationService.findByIdWithRelatedObjects(communityId, id))).flatMap(Function.identity()).map(ProjectAllocationModelsMapper::map).orElseGet(() -> {
        String projectId = event.getLocation().getQueryParameters().getParameters().get("projectId").iterator().next();
        Project project = projectService.findById(projectId).get();
        return new ProjectAllocationViewModel(projectId, project.getName());
    });
    this.projectId = projectAllocationModel.getProjectId();
    String trans = parameter == null ? "view.community-admin.project-allocation.form.parameter.new" : "view.community-admin.project-allocation.form.parameter.update";
    breadCrumbParameter = new BreadCrumbParameter(parameter, getTranslation(trans));
    projectAllocationFormComponent.setFormPools(projectAllocationModel, () -> projectAllocationService.getOccupiedNames(communityId, projectId));
}
Also used : VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException(io.imunity.furms.api.validation.exceptions.ProjectHasMoreThenOneResourceTypeAllocationInGivenTimeException) Project(io.imunity.furms.domain.projects.Project) DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) ResourceGetter.getCurrentResourceId(io.imunity.furms.ui.utils.ResourceGetter.getCurrentResourceId) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) Binder(com.vaadin.flow.data.binder.Binder) CommunityAllocationService(io.imunity.furms.api.community_allocation.CommunityAllocationService) PageTitle(io.imunity.furms.ui.components.PageTitle) BeforeEvent(com.vaadin.flow.router.BeforeEvent) Function(java.util.function.Function) Route(com.vaadin.flow.router.Route) ProjectAllocationService(io.imunity.furms.api.project_allocation.ProjectAllocationService) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) Key(com.vaadin.flow.component.Key) UI(com.vaadin.flow.component.UI) ProjectAllocation(io.imunity.furms.domain.project_allocation.ProjectAllocation) CommunityAdminMenu(io.imunity.furms.ui.views.community.CommunityAdminMenu) ProjectAllocationIncreaseInExpiredProjectException(io.imunity.furms.api.validation.exceptions.ProjectAllocationIncreaseInExpiredProjectException) FormButtons(io.imunity.furms.ui.components.FormButtons) ProjectAllocationIsNotInTerminalStateException(io.imunity.furms.api.validation.exceptions.ProjectAllocationIsNotInTerminalStateException) ButtonVariant(com.vaadin.flow.component.button.ButtonVariant) Optional.ofNullable(java.util.Optional.ofNullable) ProjectAllocationDecreaseBeyondUsageException(io.imunity.furms.api.validation.exceptions.ProjectAllocationDecreaseBeyondUsageException) ProjectView(io.imunity.furms.ui.views.community.projects.ProjectView) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) OptionalParameter(com.vaadin.flow.router.OptionalParameter) Button(com.vaadin.flow.component.button.Button) ProjectService(io.imunity.furms.api.projects.ProjectService) Optional(java.util.Optional) ProjectAllocationWrongAmountException(io.imunity.furms.api.validation.exceptions.ProjectAllocationWrongAmountException) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) Project(io.imunity.furms.domain.projects.Project)

Example 3 with OptionalParameter

use of com.vaadin.flow.router.OptionalParameter in project furms by unity-idm.

the class AlarmFormView method setParameter.

@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
    AlarmFormModel alarm = ofNullable(parameter).map(UUID::fromString).flatMap(id -> handleExceptions(() -> alarmService.find(projectId, new AlarmId(id)))).flatMap(Function.identity()).map(AlarmFormModelMapper::map).orElseGet(AlarmFormModel::new);
    String trans = parameter == null ? "view.project-admin.alarms.form.parameter.new" : "view.project-admin.alarms.form.parameter.update";
    breadCrumbParameter = new BreadCrumbParameter(parameter, getTranslation(trans));
    binder.setBean(alarm);
    addCreateButtons();
    if (alarm.id != null) {
        setComboBoxInReadOnlyMode(alarm);
    }
}
Also used : DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) Label(com.vaadin.flow.component.html.Label) PageTitle(io.imunity.furms.ui.components.PageTitle) BeforeEvent(com.vaadin.flow.router.BeforeEvent) FurmsFormLayout(io.imunity.furms.ui.components.FurmsFormLayout) Route(com.vaadin.flow.router.Route) Map(java.util.Map) Key(com.vaadin.flow.component.Key) UI(com.vaadin.flow.component.UI) TextField(com.vaadin.flow.component.textfield.TextField) FormButtons(io.imunity.furms.ui.components.FormButtons) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) FormLayout(com.vaadin.flow.component.formlayout.FormLayout) OptionalParameter(com.vaadin.flow.router.OptionalParameter) Objects(java.util.Objects) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) EmailNotPresentException(io.imunity.furms.api.validation.exceptions.EmailNotPresentException) AlarmAlreadyExceedThresholdException(io.imunity.furms.api.validation.exceptions.AlarmAlreadyExceedThresholdException) AlarmService(io.imunity.furms.api.alarms.AlarmService) Optional(java.util.Optional) VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) ResourceGetter.getCurrentResourceId(io.imunity.furms.ui.utils.ResourceGetter.getCurrentResourceId) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) EmailValidator(com.vaadin.flow.data.validator.EmailValidator) Binder(com.vaadin.flow.data.binder.Binder) Div(com.vaadin.flow.component.html.Div) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Function(java.util.function.Function) HashSet(java.util.HashSet) AlarmWithUserEmails(io.imunity.furms.domain.alarms.AlarmWithUserEmails) TextFieldVariant(com.vaadin.flow.component.textfield.TextFieldVariant) MultiselectComboBox(org.vaadin.gatanaso.MultiselectComboBox) ProjectAllocationService(io.imunity.furms.api.project_allocation.ProjectAllocationService) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) IntegerField(com.vaadin.flow.component.textfield.IntegerField) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) ValueContext(com.vaadin.flow.data.binder.ValueContext) ProjectAllocation(io.imunity.furms.domain.project_allocation.ProjectAllocation) EAGER(com.vaadin.flow.data.value.ValueChangeMode.EAGER) ProjectAdminMenu(io.imunity.furms.ui.views.project.ProjectAdminMenu) FiredAlarmThresholdReduceException(io.imunity.furms.api.validation.exceptions.FiredAlarmThresholdReduceException) ButtonVariant(com.vaadin.flow.component.button.ButtonVariant) Optional.ofNullable(java.util.Optional.ofNullable) AlarmId(io.imunity.furms.domain.alarms.AlarmId) Button(com.vaadin.flow.component.button.Button) ProjectService(io.imunity.furms.api.projects.ProjectService) AlarmId(io.imunity.furms.domain.alarms.AlarmId) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) UUID(java.util.UUID)

Example 4 with OptionalParameter

use of com.vaadin.flow.router.OptionalParameter in project furms by unity-idm.

the class CommunityAllocationFormView method setParameter.

@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
    CommunityAllocationViewModel serviceViewModel = ofNullable(parameter).flatMap(id -> handleExceptions(() -> communityAllocationService.findByIdWithRelatedObjects(id))).flatMap(Function.identity()).map(CommunityAllocationModelsMapper::map).orElseGet(() -> {
        String communityId = event.getLocation().getQueryParameters().getParameters().get("communityId").iterator().next();
        return new CommunityAllocationViewModel(communityId, communityService.findById(communityId).get().getName());
    });
    this.communityId = serviceViewModel.getCommunityId();
    String trans = parameter == null ? "view.fenix-admin.resource-credits-allocation.form.parameter.new" : "view.fenix-admin.resource-credits-allocation.form.parameter.update";
    breadCrumbParameter = new BreadCrumbParameter(parameter, getTranslation(trans));
    communityAllocationFormComponent.setModelObject(serviceViewModel, () -> communityAllocationService.getOccupiedNames(communityId));
}
Also used : VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) CommunityAllocationViewModel(io.imunity.furms.ui.community.allocations.CommunityAllocationViewModel) CommunityAllocationModelsMapper(io.imunity.furms.ui.community.allocations.CommunityAllocationModelsMapper) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) Binder(com.vaadin.flow.data.binder.Binder) CommunityAllocationService(io.imunity.furms.api.community_allocation.CommunityAllocationService) PageTitle(io.imunity.furms.ui.components.PageTitle) BeforeEvent(com.vaadin.flow.router.BeforeEvent) Function(java.util.function.Function) Route(com.vaadin.flow.router.Route) BigDecimal(java.math.BigDecimal) CommunityAllocationComboBoxesModelsResolver(io.imunity.furms.ui.community.allocations.CommunityAllocationComboBoxesModelsResolver) ResourceTypeService(io.imunity.furms.api.resource_types.ResourceTypeService) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) OptionalException(io.imunity.furms.ui.utils.OptionalException) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) Key(com.vaadin.flow.component.Key) SiteService(io.imunity.furms.api.sites.SiteService) UI(com.vaadin.flow.component.UI) ResourceCreditService(io.imunity.furms.api.resource_credits.ResourceCreditService) VaadinExceptionHandler.getResultOrException(io.imunity.furms.ui.utils.VaadinExceptionHandler.getResultOrException) FormButtons(io.imunity.furms.ui.components.FormButtons) ButtonVariant(com.vaadin.flow.component.button.ButtonVariant) Optional.ofNullable(java.util.Optional.ofNullable) CommunityAllocation(io.imunity.furms.domain.community_allocation.CommunityAllocation) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) OptionalParameter(com.vaadin.flow.router.OptionalParameter) FenixAdminMenu(io.imunity.furms.ui.views.fenix.menu.FenixAdminMenu) Button(com.vaadin.flow.component.button.Button) CommunityView(io.imunity.furms.ui.views.fenix.communites.CommunityView) Optional(java.util.Optional) CommunityService(io.imunity.furms.api.communites.CommunityService) CommunityAllocationErrors(io.imunity.furms.ui.views.fenix.communites.CommunityAllocationErrors) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) CommunityAllocationViewModel(io.imunity.furms.ui.community.allocations.CommunityAllocationViewModel)

Example 5 with OptionalParameter

use of com.vaadin.flow.router.OptionalParameter in project furms by unity-idm.

the class ProjectAllocationsDetailsView method setParameter.

@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
    Optional<String> projectId = event.getLocation().getQueryParameters().getParameters().getOrDefault("projectId", List.of()).stream().findAny();
    Optional<ProjectAllocation> projectAllocation = ofNullable(parameter).filter(id -> projectId.isPresent()).flatMap(id -> handleExceptions(() -> projectAllocationService.findByProjectIdAndId(projectId.get(), id))).flatMap(Function.identity());
    if (projectAllocation.isPresent()) {
        getContent().removeAll();
        breadCrumbParameter = new BreadCrumbParameter(parameter, projectAllocation.get().name, getTranslation("view.user-settings.projects.page.details.bread-crumb"));
        ResourceAllocationChart resourceAllocationChart = new ResourceAllocationChart(chartPowerService.getChartDataForProjectAlloc(projectAllocation.get().projectId, projectAllocation.get().id), jsonExporter.getJsonForProjectAllocation(projectAllocation.get().projectId, projectAllocation.get().id), csvExporter.getCsvForProjectAllocation(projectAllocation.get().projectId, projectAllocation.get().id), true);
        getContent().add(resourceAllocationChart);
    }
}
Also used : VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) Optional.ofNullable(java.util.Optional.ofNullable) ResourceUsageJSONExporter(io.imunity.furms.api.export.ResourceUsageJSONExporter) ResourceAllocationChart(io.imunity.furms.ui.charts.ResourceAllocationChart) PageTitle(io.imunity.furms.ui.components.PageTitle) BeforeEvent(com.vaadin.flow.router.BeforeEvent) Function(java.util.function.Function) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) Route(com.vaadin.flow.router.Route) OptionalParameter(com.vaadin.flow.router.OptionalParameter) List(java.util.List) ProjectAllocationService(io.imunity.furms.api.project_allocation.ProjectAllocationService) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) Optional(java.util.Optional) ResourceUsageCSVExporter(io.imunity.furms.api.export.ResourceUsageCSVExporter) ProjectAllocation(io.imunity.furms.domain.project_allocation.ProjectAllocation) CommunityAdminMenu(io.imunity.furms.ui.views.community.CommunityAdminMenu) ChartPowerService(io.imunity.furms.ui.charts.ChartPowerService) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) ProjectAllocation(io.imunity.furms.domain.project_allocation.ProjectAllocation) ResourceAllocationChart(io.imunity.furms.ui.charts.ResourceAllocationChart)

Aggregations

BeforeEvent (com.vaadin.flow.router.BeforeEvent)16 OptionalParameter (com.vaadin.flow.router.OptionalParameter)16 Route (com.vaadin.flow.router.Route)16 FurmsViewComponent (io.imunity.furms.ui.components.FurmsViewComponent)14 PageTitle (io.imunity.furms.ui.components.PageTitle)14 BreadCrumbParameter (io.imunity.furms.ui.components.layout.BreadCrumbParameter)14 VaadinExceptionHandler.handleExceptions (io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions)14 Optional (java.util.Optional)14 Optional.ofNullable (java.util.Optional.ofNullable)14 Function (java.util.function.Function)13 UI (com.vaadin.flow.component.UI)11 Button (com.vaadin.flow.component.button.Button)11 Key (com.vaadin.flow.component.Key)10 ButtonVariant (com.vaadin.flow.component.button.ButtonVariant)10 BeanValidationBinder (com.vaadin.flow.data.binder.BeanValidationBinder)10 Binder (com.vaadin.flow.data.binder.Binder)10 FormButtons (io.imunity.furms.ui.components.FormButtons)10 ResourceGetter.getCurrentResourceId (io.imunity.furms.ui.utils.ResourceGetter.getCurrentResourceId)8 NotificationUtils.showErrorNotification (io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification)6 DuplicatedNameValidationError (io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError)5