Search in sources :

Example 1 with Dashboard

use of io.jmix.dashboardsui.component.Dashboard in project jmix by jmix-framework.

the class DashboardImpl method refresh.

/**
 * Refreshes widget with passed parameters.
 * Dashboard will be refreshed with merged existed and new parameters.
 * If existed parameter has the same name as one of the param from passed map, it will be overwritten by param from map.
 *
 * @param params map with new dashboard parameters
 */
@Override
public void refresh(Map<String, Object> params) {
    DashboardModel dashboardModel = null;
    if (isNotBlank(jsonPath)) {
        dashboardModel = loadDashboardByJson(jsonPath);
    } else if (isNotBlank(code)) {
        dashboardModel = loadDashboardByCode(code);
    }
    if (MapUtils.isNotEmpty(params) && Objects.nonNull(dashboardModel)) {
        Map<String, Parameter> newParams = params.keySet().stream().map(key -> {
            Parameter parameter = metadata.create(Parameter.class);
            parameter.setName(key);
            parameter.setAlias(key);
            parameter.setValue(parameterTransformer.createParameterValue(params.get(key)));
            return parameter;
        }).collect(Collectors.toMap(Parameter::getName, Function.identity()));
        Map<String, Parameter> paramMap = dashboardModel.getParameters().stream().collect(Collectors.toMap(Parameter::getName, Function.identity()));
        paramMap.putAll(newParams);
        dashboardModel.setParameters(new ArrayList<>(paramMap.values()));
    }
    updateDashboard(dashboardModel);
}
Also used : ScreenFragment(io.jmix.ui.screen.ScreenFragment) PersistentDashboard(io.jmix.dashboards.entity.PersistentDashboard) Dashboard(io.jmix.dashboardsui.component.Dashboard) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ParamsMap(io.jmix.core.common.util.ParamsMap) StringUtils(org.apache.commons.lang3.StringUtils) Messages(io.jmix.core.Messages) DashboardEvent(io.jmix.dashboardsui.event.DashboardEvent) io.jmix.ui(io.jmix.ui) Method(java.lang.reflect.Method) Resource(org.springframework.core.io.Resource) DataManager(io.jmix.core.DataManager) UiEventListenerMethodAdapter(io.jmix.ui.sys.event.UiEventListenerMethodAdapter) ResourceLoader(org.springframework.core.io.ResourceLoader) DataUnit(io.jmix.ui.component.data.DataUnit) LookupWidget(io.jmix.dashboardsui.widget.LookupWidget) UiControllerReflectionInspector(io.jmix.ui.sys.UiControllerReflectionInspector) EventListener(org.springframework.context.event.EventListener) ApplicationListener(org.springframework.context.ApplicationListener) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOUtils(org.apache.commons.io.IOUtils) CanvasLayout(io.jmix.dashboardsui.component.CanvasLayout) Timer(io.jmix.ui.component.Timer) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) io.jmix.ui.component(io.jmix.ui.component) CODE(io.jmix.dashboardsui.screen.dashboard.view.DashboardViewScreen.CODE) AccessConstraintsHelper(io.jmix.dashboardsui.dashboard.tools.AccessConstraintsHelper) java.util(java.util) DashboardUpdatedEvent(io.jmix.dashboardsui.event.DashboardUpdatedEvent) Widget(io.jmix.dashboards.model.Widget) Function(java.util.function.Function) DASHBOARD(io.jmix.dashboardsui.screen.dashboard.editor.canvas.CanvasFragment.DASHBOARD) Parameter(io.jmix.dashboards.model.parameter.Parameter) UiEventsMulticaster(io.jmix.ui.sys.event.UiEventsMulticaster) RefreshableWidget(io.jmix.dashboardsui.widget.RefreshableWidget) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions) Nullable(javax.annotation.Nullable) MapUtils(org.apache.commons.collections4.MapUtils) Logger(org.slf4j.Logger) DashboardException(io.jmix.dashboardsui.DashboardException) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Metadata(io.jmix.core.Metadata) JsonConverter(io.jmix.dashboards.converter.JsonConverter) ItemsSelectedEvent(io.jmix.dashboardsui.event.ItemsSelectedEvent) ParameterTransformer(io.jmix.dashboardsui.transformation.ParameterTransformer) DashboardModel(io.jmix.dashboards.model.DashboardModel) ReflectionUtils(org.springframework.util.ReflectionUtils) BeanFactory(org.springframework.beans.factory.BeanFactory) CanvasFragment(io.jmix.dashboardsui.screen.dashboard.editor.canvas.CanvasFragment) DashboardViewAssistant(io.jmix.dashboardsui.dashboard.assistant.DashboardViewAssistant) DashboardModel(io.jmix.dashboards.model.DashboardModel) Parameter(io.jmix.dashboards.model.parameter.Parameter)

Example 2 with Dashboard

use of io.jmix.dashboardsui.component.Dashboard in project jmix by jmix-framework.

the class CanvasUiComponentsFactory method createCanvasWidgetLayout.

@Override
public CanvasWidgetLayout createCanvasWidgetLayout(CanvasFragment canvasFragment, WidgetLayout widgetLayout) {
    Widget widget = widgetLayout.getWidget();
    Optional<WidgetTypeInfo> widgetTypeOpt = widgetRepository.getWidgetTypesInfo().stream().filter(widgetType -> StringUtils.equals(widget.getFragmentId(), widgetType.getFragmentId())).findFirst();
    if (!widgetTypeOpt.isPresent()) {
        CanvasWidgetLayout layout = components.create(CanvasWidgetLayout.class).init(widgetLayout);
        Label<String> label = components.create(Label.class);
        String message = messages.formatMessage(CanvasUiComponentsFactory.class, "widgetNotFound", widget.getCaption(), widget.getName());
        label.setValue(message);
        layout.addComponent(label);
        log.error(message);
        return layout;
    }
    widget.setDashboard(canvasFragment.getDashboardModel());
    String fragmentId = widgetTypeOpt.get().getFragmentId();
    Map<String, Object> params = new HashMap<>(ParamsMap.of(WIDGET, widget, DASHBOARD_MODEL, canvasFragment.getDashboardModel(), DASHBOARD, canvasFragment.getDashboard()));
    params.putAll(widgetRepository.getWidgetParams(widget));
    ScreenFragment screenFragment = AppUI.getCurrent().getFragments().create(canvasFragment, fragmentId, new MapScreenOptions(params)).init();
    Fragment fragment = screenFragment.getFragment();
    fragment.setSizeFull();
    Component widgetComponent = fragment;
    if (BooleanUtils.isTrue(widget.getShowWidgetCaption())) {
        VBoxLayout vBoxLayout = components.create(VBoxLayout.class);
        vBoxLayout.setSpacing(true);
        vBoxLayout.setMargin(true);
        vBoxLayout.setSizeFull();
        Label<String> label = components.create(Label.class);
        label.setValue(widget.getCaption());
        label.setStyleName("h2");
        vBoxLayout.add(label);
        vBoxLayout.add(fragment);
        vBoxLayout.expand(fragment);
        widgetComponent = vBoxLayout;
    } else {
        fragment.setMargin(true);
    }
    CanvasWidgetLayout layout = components.create(CanvasWidgetLayout.class).init(widgetLayout);
    layout.setUuid(UUID.randomUUID());
    layout.addComponent(widgetComponent);
    layout.setWidgetComponent(screenFragment);
    layout.setInnerLayout(widgetComponent);
    layout.setWidget(widget);
    layout.getDelegate().expand(widgetComponent);
    layout.setSizeFull();
    return layout;
}
Also used : ScreenFragment(io.jmix.ui.screen.ScreenFragment) Dashboard(io.jmix.dashboardsui.component.Dashboard) Fragment(io.jmix.ui.component.Fragment) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ParamsMap(io.jmix.core.common.util.ParamsMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) HashMap(java.util.HashMap) Widget(io.jmix.dashboards.model.Widget) StringUtils(org.apache.commons.lang3.StringUtils) Messages(io.jmix.core.Messages) WidgetRepository(io.jmix.dashboardsui.repository.WidgetRepository) Component(io.jmix.ui.component.Component) CanvasComponentsFactory(io.jmix.dashboardsui.dashboard.tools.factory.CanvasComponentsFactory) UiComponents(io.jmix.ui.UiComponents) VBoxLayout(io.jmix.ui.component.VBoxLayout) Map(java.util.Map) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions) Logger(org.slf4j.Logger) UUID(java.util.UUID) io.jmix.dashboards.model.visualmodel(io.jmix.dashboards.model.visualmodel) CanvasLayout(io.jmix.dashboardsui.component.CanvasLayout) Label(io.jmix.ui.component.Label) AppUI(io.jmix.ui.AppUI) Optional(java.util.Optional) io.jmix.dashboardsui.component.impl(io.jmix.dashboardsui.component.impl) CanvasFragment(io.jmix.dashboardsui.screen.dashboard.editor.canvas.CanvasFragment) WidgetTypeInfo(io.jmix.dashboardsui.repository.WidgetTypeInfo) VBoxLayout(io.jmix.ui.component.VBoxLayout) HashMap(java.util.HashMap) Widget(io.jmix.dashboards.model.Widget) WidgetTypeInfo(io.jmix.dashboardsui.repository.WidgetTypeInfo) ScreenFragment(io.jmix.ui.screen.ScreenFragment) Fragment(io.jmix.ui.component.Fragment) CanvasFragment(io.jmix.dashboardsui.screen.dashboard.editor.canvas.CanvasFragment) ScreenFragment(io.jmix.ui.screen.ScreenFragment) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions) Component(io.jmix.ui.component.Component)

Example 3 with Dashboard

use of io.jmix.dashboardsui.component.Dashboard in project jmix by jmix-framework.

the class DashboardViewScreen method onInit.

@Subscribe
public void onInit(InitEvent event) {
    ScreenOptions options = event.getOptions();
    Map<String, Object> params = new HashMap<>();
    if (options instanceof MapScreenOptions) {
        params = ((MapScreenOptions) options).getParams();
    }
    if (params.containsKey(DISPLAY_NAME)) {
        getWindow().setCaption((String) params.get(DISPLAY_NAME));
    }
    Dashboard dashboardComponent = uiComponents.create(Dashboard.NAME);
    dashboardComponent.setFrame(getWindow().getFrame());
    dashboardComponent.init(params);
    getWindow().add(dashboardComponent);
    this.dashboard = dashboardComponent;
}
Also used : HashMap(java.util.HashMap) Dashboard(io.jmix.dashboardsui.component.Dashboard)

Aggregations

Dashboard (io.jmix.dashboardsui.component.Dashboard)3 Messages (io.jmix.core.Messages)2 ParamsMap (io.jmix.core.common.util.ParamsMap)2 Widget (io.jmix.dashboards.model.Widget)2 CanvasLayout (io.jmix.dashboardsui.component.CanvasLayout)2 CanvasFragment (io.jmix.dashboardsui.screen.dashboard.editor.canvas.CanvasFragment)2 MapScreenOptions (io.jmix.ui.screen.MapScreenOptions)2 ScreenFragment (io.jmix.ui.screen.ScreenFragment)2 HashMap (java.util.HashMap)2 DataManager (io.jmix.core.DataManager)1 Metadata (io.jmix.core.Metadata)1 JsonConverter (io.jmix.dashboards.converter.JsonConverter)1 PersistentDashboard (io.jmix.dashboards.entity.PersistentDashboard)1 DashboardModel (io.jmix.dashboards.model.DashboardModel)1 Parameter (io.jmix.dashboards.model.parameter.Parameter)1 io.jmix.dashboards.model.visualmodel (io.jmix.dashboards.model.visualmodel)1 DashboardException (io.jmix.dashboardsui.DashboardException)1 io.jmix.dashboardsui.component.impl (io.jmix.dashboardsui.component.impl)1 DashboardViewAssistant (io.jmix.dashboardsui.dashboard.assistant.DashboardViewAssistant)1 AccessConstraintsHelper (io.jmix.dashboardsui.dashboard.tools.AccessConstraintsHelper)1