Search in sources :

Example 1 with CommunityAllocationViewModel

use of io.imunity.furms.ui.community.allocations.CommunityAllocationViewModel 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 2 with CommunityAllocationViewModel

use of io.imunity.furms.ui.community.allocations.CommunityAllocationViewModel in project furms by unity-idm.

the class DashboardResourceAllocateFormView method resourceCreditField.

private ComboBox<ResourceCreditComboBoxModel> resourceCreditField(Label availableAmountLabel) {
    final ComboBox<ResourceCreditComboBoxModel> resourceCreditComboBox = new ComboBox<>();
    resourceCreditComboBox.setItemLabelGenerator(resourceType -> resourceType.name);
    resourceCreditComboBox.setReadOnly(true);
    ResourceCreditComboBoxModel resourceCredit = binder.getBean().getResourceCredit();
    resourceCreditComboBox.setItems(resourceCredit);
    availableAmount = communityAllocationService.getAvailableAmountForNew(resourceCredit.id);
    availableAmountLabel.setText(createAvailableLabelContent(resourceCredit.split));
    binder.forField(resourceCreditComboBox).bind(CommunityAllocationViewModel::getResourceCredit, CommunityAllocationViewModel::setResourceCredit);
    return resourceCreditComboBox;
}
Also used : CommunityAllocationViewModel(io.imunity.furms.ui.community.allocations.CommunityAllocationViewModel) ComboBox(com.vaadin.flow.component.combobox.ComboBox) ResourceCreditComboBoxModel(io.imunity.furms.ui.components.support.models.allocation.ResourceCreditComboBoxModel)

Example 3 with CommunityAllocationViewModel

use of io.imunity.furms.ui.community.allocations.CommunityAllocationViewModel in project furms by unity-idm.

the class DashboardResourceAllocateFormView method amountField.

private BigDecimalField amountField() {
    final BigDecimalField amountField = new BigDecimalField();
    amountField.setValueChangeMode(EAGER);
    amountField.setReadOnly(!binder.getBean().getResourceCredit().split);
    createUnitLabel(amountField, binder.getBean().getResourceType().unit);
    binder.forField(amountField).withValidator(Objects::nonNull, getTranslation("view.fenix-admin.resource-credits-allocation.form.error.validation.field.amount")).withValidator(this::isAmountCorrect, getTranslation("view.fenix-admin.resource-credits-allocation.form.error.validation.field.amount.range")).bind(CommunityAllocationViewModel::getAmount, CommunityAllocationViewModel::setAmount);
    amountField.setValue(availableAmount);
    return amountField;
}
Also used : CommunityAllocationViewModel(io.imunity.furms.ui.community.allocations.CommunityAllocationViewModel) Objects(java.util.Objects) BigDecimalField(com.vaadin.flow.component.textfield.BigDecimalField)

Example 4 with CommunityAllocationViewModel

use of io.imunity.furms.ui.community.allocations.CommunityAllocationViewModel in project furms by unity-idm.

the class DashboardResourceAllocateFormView method nameField.

private DefaultNameField nameField() {
    final DefaultNameField nameField = new DefaultNameField();
    binder.forField(nameField).withValidator(value -> Objects.nonNull(value) && !value.isBlank(), getTranslation("view.fenix-admin.resource-credits-allocation.form.error.validation.field.name")).bind(CommunityAllocationViewModel::getName, CommunityAllocationViewModel::setName);
    return nameField;
}
Also used : DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) CommunityAllocationViewModel(io.imunity.furms.ui.community.allocations.CommunityAllocationViewModel) DefaultNameField(io.imunity.furms.ui.components.DefaultNameField) CommunityAllocationModelsMapper(io.imunity.furms.ui.community.allocations.CommunityAllocationModelsMapper) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) ValueProvider(com.vaadin.flow.function.ValueProvider) ComponentUtil(com.vaadin.flow.component.ComponentUtil) Binder(com.vaadin.flow.data.binder.Binder) Label(com.vaadin.flow.component.html.Label) ComboBoxModel(io.imunity.furms.ui.components.support.models.ComboBoxModel) CommunityAllocationService(io.imunity.furms.api.community_allocation.CommunityAllocationService) PageTitle(io.imunity.furms.ui.components.PageTitle) ComboBox(com.vaadin.flow.component.combobox.ComboBox) FurmsFormLayout(io.imunity.furms.ui.components.FurmsFormLayout) Route(com.vaadin.flow.router.Route) BigDecimal(java.math.BigDecimal) ResourceMeasureUnit(io.imunity.furms.domain.resource_types.ResourceMeasureUnit) LUMO_TERTIARY(com.vaadin.flow.component.button.ButtonVariant.LUMO_TERTIARY) 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) Setter(com.vaadin.flow.data.binder.Setter) UI(com.vaadin.flow.component.UI) ResourceCreditComboBoxModel(io.imunity.furms.ui.components.support.models.allocation.ResourceCreditComboBoxModel) EAGER(com.vaadin.flow.data.value.ValueChangeMode.EAGER) Collectors.toSet(java.util.stream.Collectors.toSet) VaadinExceptionHandler.getResultOrException(io.imunity.furms.ui.utils.VaadinExceptionHandler.getResultOrException) FormButtons(io.imunity.furms.ui.components.FormButtons) BigDecimalField(com.vaadin.flow.component.textfield.BigDecimalField) CommunityAllocation(io.imunity.furms.domain.community_allocation.CommunityAllocation) Set(java.util.Set) ZERO(java.math.BigDecimal.ZERO) FormLayout(com.vaadin.flow.component.formlayout.FormLayout) FenixAdminMenu(io.imunity.furms.ui.views.fenix.menu.FenixAdminMenu) Objects(java.util.Objects) Button(com.vaadin.flow.component.button.Button) Optional(java.util.Optional) CommunityService(io.imunity.furms.api.communites.CommunityService) ResourceTypeComboBoxModel(io.imunity.furms.ui.components.support.models.allocation.ResourceTypeComboBoxModel) CommunityAllocationErrors(io.imunity.furms.ui.views.fenix.communites.CommunityAllocationErrors) ResourceAllocationsGridItem(io.imunity.furms.ui.components.resource_allocations.ResourceAllocationsGridItem) LUMO_PRIMARY(com.vaadin.flow.component.button.ButtonVariant.LUMO_PRIMARY) DefaultNameField(io.imunity.furms.ui.components.DefaultNameField) CommunityAllocationViewModel(io.imunity.furms.ui.community.allocations.CommunityAllocationViewModel)

Example 5 with CommunityAllocationViewModel

use of io.imunity.furms.ui.community.allocations.CommunityAllocationViewModel in project furms by unity-idm.

the class DashboardResourceAllocateFormView method saveCommunityAllocation.

private void saveCommunityAllocation() {
    final CommunityAllocationViewModel allocationViewModel = binder.getBean();
    final CommunityAllocation communityAllocation = CommunityAllocationModelsMapper.map(allocationViewModel);
    final OptionalException<Void> optionalException = getResultOrException(() -> communityAllocationService.create(communityAllocation), CommunityAllocationErrors.KNOWN_ERRORS);
    optionalException.getException().ifPresentOrElse(throwable -> {
        if (throwable.getCause() instanceof DuplicatedNameValidationError && nameField.isReadOnly()) {
            showErrorNotification(getTranslation("default.name.duplicated.error.message"));
            nameField.generateName();
        } else
            showErrorNotification(getTranslation(throwable.getMessage()));
    }, () -> UI.getCurrent().navigate(DashboardView.class));
}
Also used : DuplicatedNameValidationError(io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError) CommunityAllocationViewModel(io.imunity.furms.ui.community.allocations.CommunityAllocationViewModel) CommunityAllocation(io.imunity.furms.domain.community_allocation.CommunityAllocation)

Aggregations

CommunityAllocationViewModel (io.imunity.furms.ui.community.allocations.CommunityAllocationViewModel)6 DuplicatedNameValidationError (io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError)4 CommunityAllocation (io.imunity.furms.domain.community_allocation.CommunityAllocation)4 Key (com.vaadin.flow.component.Key)2 UI (com.vaadin.flow.component.UI)2 Button (com.vaadin.flow.component.button.Button)2 ComboBox (com.vaadin.flow.component.combobox.ComboBox)2 BigDecimalField (com.vaadin.flow.component.textfield.BigDecimalField)2 BeanValidationBinder (com.vaadin.flow.data.binder.BeanValidationBinder)2 Binder (com.vaadin.flow.data.binder.Binder)2 Route (com.vaadin.flow.router.Route)2 CommunityService (io.imunity.furms.api.communites.CommunityService)2 CommunityAllocationService (io.imunity.furms.api.community_allocation.CommunityAllocationService)2 CommunityAllocationModelsMapper (io.imunity.furms.ui.community.allocations.CommunityAllocationModelsMapper)2 FormButtons (io.imunity.furms.ui.components.FormButtons)2 FurmsViewComponent (io.imunity.furms.ui.components.FurmsViewComponent)2 PageTitle (io.imunity.furms.ui.components.PageTitle)2 ResourceCreditComboBoxModel (io.imunity.furms.ui.components.support.models.allocation.ResourceCreditComboBoxModel)2 NotificationUtils.showErrorNotification (io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification)2 OptionalException (io.imunity.furms.ui.utils.OptionalException)2