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