Search in sources :

Example 1 with FurmsProgressBar

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

the class ResourceCreditsView method createResourceCreditGrid.

private Grid<ResourceCreditViewModel> createResourceCreditGrid() {
    Grid<ResourceCreditViewModel> grid = new DenseGrid<>(ResourceCreditViewModel.class);
    grid.addComponentColumn(c -> new RouterLink(c.getName(), ResourceCreditFormView.class, c.getId())).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.name")).setSortable(true).setFlexGrow(20).setComparator(x -> x.getName().toLowerCase());
    grid.addColumn(ResourceCreditViewModel::getId).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.id")).setSortable(true).setFlexGrow(20).setComparator(x -> x.getName().toLowerCase());
    grid.addColumn(ResourceCreditViewModel::getResourceTypeName).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.resourceType")).setSortable(true);
    grid.addColumn(ResourceCreditViewModel::getAmount).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.credit")).setSortable(true).setComparator(comparing(model -> model.getAmount().amount));
    grid.addColumn(ResourceCreditViewModel::getDistributed).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.distributed")).setSortable(true).setComparator(comparing(model -> model.getDistributed().amount));
    grid.addColumn(ResourceCreditViewModel::getRemaining).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.remaining")).setSortable(true).setComparator(comparing(model -> model.getRemaining().amount));
    grid.addColumn(c -> c.getCreateTime().toLocalDate()).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.created")).setSortable(true);
    grid.addColumn(c -> c.getStartTime().toLocalDate()).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.validFrom")).setSortable(true);
    grid.addColumn(c -> c.getEndTime().toLocalDate()).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.validTo")).setSortable(true);
    grid.addComponentColumn(model -> {
        double value = model.getConsumed().divide(model.getAmount().amount, 4, HALF_UP).doubleValue();
        return new FurmsProgressBar(value);
    }).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.consumption")).setComparator(comparing(ResourceCreditViewModel::getConsumed));
    grid.addComponentColumn(this::createLastColumnContent).setHeader(getTranslation("view.site-admin.resource-credits.grid.column.actions")).setWidth("4em").setTextAlign(ColumnTextAlign.END);
    return grid;
}
Also used : VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) ResourceGetter.getCurrentResourceId(io.imunity.furms.ui.utils.ResourceGetter.getCurrentResourceId) Component(com.vaadin.flow.component.Component) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) FurmsDialog(io.imunity.furms.ui.components.FurmsDialog) MenuButton(io.imunity.furms.ui.components.MenuButton) PageTitle(io.imunity.furms.ui.components.PageTitle) Route(com.vaadin.flow.router.Route) PLUS_CIRCLE(com.vaadin.flow.component.icon.VaadinIcon.PLUS_CIRCLE) DenseGrid(io.imunity.furms.ui.components.DenseGrid) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) Map(java.util.Map) RouterLink(com.vaadin.flow.router.RouterLink) UI(com.vaadin.flow.component.UI) Comparator.comparing(java.util.Comparator.comparing) SiteAdminMenu(io.imunity.furms.ui.views.site.SiteAdminMenu) ResourceCreditService(io.imunity.furms.api.resource_credits.ResourceCreditService) Grid(com.vaadin.flow.component.grid.Grid) UIContext(io.imunity.furms.ui.user_context.UIContext) TRASH(com.vaadin.flow.component.icon.VaadinIcon.TRASH) ResourceCreditHasAllocationException(io.imunity.furms.api.validation.exceptions.ResourceCreditHasAllocationException) EDIT(com.vaadin.flow.component.icon.VaadinIcon.EDIT) HALF_UP(java.math.RoundingMode.HALF_UP) GridActionMenu(io.imunity.furms.ui.components.GridActionMenu) GridActionsButtonLayout(io.imunity.furms.ui.components.GridActionsButtonLayout) ZoneId(java.time.ZoneId) Button(com.vaadin.flow.component.button.Button) FurmsProgressBar(io.imunity.furms.ui.components.FurmsProgressBar) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ColumnTextAlign(com.vaadin.flow.component.grid.ColumnTextAlign) Dialog(com.vaadin.flow.component.dialog.Dialog) Collections(java.util.Collections) ViewHeaderLayout(io.imunity.furms.ui.components.ViewHeaderLayout) RouterLink(com.vaadin.flow.router.RouterLink) DenseGrid(io.imunity.furms.ui.components.DenseGrid) FurmsProgressBar(io.imunity.furms.ui.components.FurmsProgressBar)

Aggregations

Component (com.vaadin.flow.component.Component)1 UI (com.vaadin.flow.component.UI)1 Button (com.vaadin.flow.component.button.Button)1 Dialog (com.vaadin.flow.component.dialog.Dialog)1 ColumnTextAlign (com.vaadin.flow.component.grid.ColumnTextAlign)1 Grid (com.vaadin.flow.component.grid.Grid)1 EDIT (com.vaadin.flow.component.icon.VaadinIcon.EDIT)1 PLUS_CIRCLE (com.vaadin.flow.component.icon.VaadinIcon.PLUS_CIRCLE)1 TRASH (com.vaadin.flow.component.icon.VaadinIcon.TRASH)1 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)1 Route (com.vaadin.flow.router.Route)1 RouterLink (com.vaadin.flow.router.RouterLink)1 ResourceCreditService (io.imunity.furms.api.resource_credits.ResourceCreditService)1 ResourceCreditHasAllocationException (io.imunity.furms.api.validation.exceptions.ResourceCreditHasAllocationException)1 DenseGrid (io.imunity.furms.ui.components.DenseGrid)1 FurmsDialog (io.imunity.furms.ui.components.FurmsDialog)1 FurmsProgressBar (io.imunity.furms.ui.components.FurmsProgressBar)1 FurmsViewComponent (io.imunity.furms.ui.components.FurmsViewComponent)1 GridActionMenu (io.imunity.furms.ui.components.GridActionMenu)1 GridActionsButtonLayout (io.imunity.furms.ui.components.GridActionsButtonLayout)1