Skip to content

Commit

Permalink
metric widget implementation, wip. reverted new dashboard configurati…
Browse files Browse the repository at this point in the history
…on fow now
  • Loading branch information
1azyman committed Jan 26, 2023
1 parent 882996c commit fd60520
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,6 @@ <h3 class="m-0 pt-1 font-weight-normal">
Simulation view
</h3>
</div>
<div class="card">
<div class="card-body">
<div class="d-flex">
<div class="mr-2">
icon
</div>
<div class="d-flex flex-column flex-grow-1">
<h4>Simulation #006 <span class="text-secondary">(sim-006)</span></h4>
<span class="text-gray">Lorem ipsum dolor sit amet, consectetur adipiscing elit</span>
</div>

</div>
</div>
<div class="card-footer d-flex gap-2">
<a href="#" class="btn btn-primary">
<i class="mr-1 fa-solid fa-eye"></i>
View report
</a>
<a href="#" class="btn btn-outline-primary">
<i class="mr-1 fa-solid fa-play"></i>
Run again
</a>
</div>
</div>

<div class="row">
<div class="col-3">
Expand All @@ -58,21 +34,10 @@ <h5 class="mb-0">Simulation task details</h5>
</div>
</div>
</div>
</div>

<hr class="my-5"/>

<div class="row">
<div class="col-12 col-md-6 col-lg-3" wicket:id="widgets">
<div class="mb-4" wicket:id="widget"/>
</div>
</div>
<h3>Available tags</h3>
<div class="row">
<div class="col-12">
<form wicket:id="form">
<div wicket:id="table"/>
</form>
<div class="col-7">
<div class="col-12 col-md-6 col-lg-3" wicket:id="widgets">
<div class="mb-4" wicket:id="widget"/>
</div>
</div>
</div>
</wicket:extend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ public static Component createWidgetPanel(String id, IModel<WidgetType> model) {
WidgetType w = model.getObject();

// todo fix via some widget factory...
if (w instanceof ContainerWidgetType) {
return new ContainerWidgetPanel(id, () -> (ContainerWidgetType) model.getObject());
} else if (w instanceof SimulationMetricWidgetType) {
return new SimulationMetricWidgetPanel(id, () -> (SimulationMetricWidgetType) model.getObject());
} else {
// if (w instanceof ContainerWidgetType) {
// return new ContainerWidgetPanel(id, () -> (ContainerWidgetType) model.getObject());
// } else if (w instanceof SimulationMetricWidgetType) {
// return new MetricWidgetPanel(id, () -> (SimulationMetricWidgetType) model.getObject());
// } else {
return new Label(id, () -> model.getObject().getIdentifier());
}
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<body>
<wicket:panel>
<div class="d-flex w-100">
<small wicket:id="title" class="flex-grow-1"/>
<span wicket:id="title" class="flex-grow-1"/>
<a class="btn btn-xs"> <!-- TODO: viliam, menu -->
<i class="fas fa-ellipsis-h"/>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

import com.evolveum.midpoint.gui.api.component.Badge;
import com.evolveum.midpoint.gui.api.component.BadgePanel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SimulationMetricWidgetType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.DashboardWidgetType;

/**
* Created by Viliam Repan (lazyman).
*/
public class SimulationMetricWidgetPanel extends WidgetPanel<SimulationMetricWidgetType> {
public class MetricWidgetPanel extends WidgetPanel<DashboardWidgetType> {

private static final long serialVersionUID = 1L;

Expand All @@ -35,7 +35,7 @@ public class SimulationMetricWidgetPanel extends WidgetPanel<SimulationMetricWid
private static final String ID_ICON = "";
private static final String ID_CHART_CONTAINER = "chartContainer";

public SimulationMetricWidgetPanel(String id, IModel<SimulationMetricWidgetType> model) {
public MetricWidgetPanel(String id, IModel<DashboardWidgetType> model) {
super(id, model);

initLayout();
Expand All @@ -57,17 +57,17 @@ public void renderHead(IHeaderResponse response) {
return;
}

Object[] array = new Object[0];
Object[] array = new Object[0]; // todo data

if (array == null || array.length == 0) {
return;
}

String options = "{ height: 85, lineColor: '#92c1dc', endColor: '#92c1dc' }";
String data = StringUtils.join(array, ", ");
String data = "[" + StringUtils.join(array, ", ") + "]";

response.render(OnDomReadyHeaderItem.forScript(
"MidPointTheme.createSparkline('#" + comp.getMarkupId() + "', " + options + ", " + data));
"MidPointTheme.createSparkline('#" + comp.getMarkupId() + "', " + options + ", " + data + ");"));
}

private void initLayout() {
Expand All @@ -85,14 +85,22 @@ private void initLayout() {
});
add(trendBadge);

Label value = new Label(ID_VALUE);
Label value = new Label(ID_VALUE, createValueModel());
add(value);

Label valueDescription = new Label(ID_VALUE_DESCRIPTION);
Label valueDescription = new Label(ID_VALUE_DESCRIPTION, createDescriptionModel());
add(valueDescription);

WebMarkupContainer chartContainer = new WebMarkupContainer(ID_CHART_CONTAINER);
chartContainer.setOutputMarkupId(true);
add(chartContainer);
}

private IModel<String> createValueModel() {
return () -> "asdf";
}

private IModel<String> createDescriptionModel() {
return () -> "jklo";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
<div class="mb-4" wicket:id="widget"/>
</div>
</div>

<hr class="my-5"/>

<wicket:container wicket:id="widgetsNew">
<div wicket:id="widgetNew"/>
</wicket:container>
</wicket:extend>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@
*/
package com.evolveum.midpoint.web.page.admin.home;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.util.string.StringValue;

import com.evolveum.midpoint.authentication.api.authorization.AuthorizationAction;
import com.evolveum.midpoint.authentication.api.authorization.PageDescriptor;
import com.evolveum.midpoint.authentication.api.authorization.Url;
Expand All @@ -15,7 +31,7 @@
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.gui.impl.component.box.SmallBox;
import com.evolveum.midpoint.gui.impl.component.box.SmallBoxData;
import com.evolveum.midpoint.gui.impl.page.admin.simulation.widget.ContainerWidgetPanel;
import com.evolveum.midpoint.gui.impl.page.admin.simulation.widget.MetricWidgetPanel;
import com.evolveum.midpoint.model.api.interaction.DashboardWidget;
import com.evolveum.midpoint.model.api.util.DashboardUtils;
import com.evolveum.midpoint.prism.PrismObject;
Expand All @@ -42,25 +58,6 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.util.string.StringValue;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author skublik
*/
Expand Down Expand Up @@ -154,34 +151,27 @@ private void initInfoBoxes() {

@Override
protected void populateItem(ListItem<DashboardWidgetType> item) {
item.add(populateDashboardWidget(item.getModel()));
DashboardWidgetType dw = item.getModelObject();
DashboardWidgetSourceTypeType sourceType = dw.getData() != null ? dw.getData().getSourceType() : null;
if (DashboardWidgetSourceTypeType.METRIC == sourceType) {
item.add(populateMetricWidget(ID_WIDGET, item.getModel()));
} else {
item.add(populateDashboardWidget(ID_WIDGET, item.getModel()));
}
}
});
}

add(new ListView<WidgetType>("widgetsNew", () -> {
WidgetsType widgets = dashboardModel.getObject().getWidgets();
return widgets != null ?
widgets.getWidget().stream().map(je -> je.getValue()).collect(Collectors.toUnmodifiableList())
: Collections.emptyList();
}) {

@Override
protected void populateItem(ListItem<WidgetType> item) {
WidgetType wt = item.getModelObject();
if (wt instanceof DashboardWidgetType) {
item.add(populateDashboardWidget((IModel) item.getModel()));
return;
}
private Component populateMetricWidget(String id, IModel<DashboardWidgetType> model) {
MetricWidgetPanel widget = new MetricWidgetPanel(id, model);

item.add(ContainerWidgetPanel.createWidgetPanel("widgetNew", item.getModel()));
}
});
return widget;
}

private Component populateDashboardWidget(IModel<DashboardWidgetType> model) {
private Component populateDashboardWidget(String id, IModel<DashboardWidgetType> model) {
IModel<DashboardWidgetDto> widgetModel = loadWidgetData(model);

SmallBox box = new SmallBox(ID_WIDGET, () -> {
SmallBox box = new SmallBox(id, () -> {
DashboardWidgetDto widget = widgetModel.getObject();

SmallBoxData data = new SmallBoxData();
Expand Down

0 comments on commit fd60520

Please sign in to comment.