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));
}
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;
}
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;
}
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;
}
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));
}
Aggregations