use of com.axelor.meta.schema.views.AbstractWidget in project axelor-open-suite by axelor.
the class DashboardBuilderService method build.
/**
* Method to generate Dashboard (meta schema) from View Builder.
*
* @param viewBuilder ViewBuilder of type dashboard.
* @return Dashboard.
*/
public MetaView build(DashboardBuilder dashboardBuilder) {
log.debug("Processing dashboard: {}", dashboardBuilder.getName());
log.debug("Dashlet list: {}", dashboardBuilder.getDashletBuilderList());
if (dashboardBuilder.getDashletBuilderList() == null || dashboardBuilder.getDashletBuilderList().isEmpty()) {
return null;
}
Dashboard dashboard = new Dashboard();
String boardName = dashboardBuilder.getName();
dashboard.setTitle(dashboardBuilder.getTitle());
dashboard.setName(dashboardBuilder.getName());
List<AbstractWidget> dashlets = new ArrayList<AbstractWidget>();
dashboardBuilder.clearGeneratedActions();
for (DashletBuilder dashletBuilder : dashboardBuilder.getDashletBuilderList()) {
Dashlet dashlet = new Dashlet();
String name = null;
String model = null;
MetaView metaView = dashletBuilder.getMetaView();
MetaAction action = dashletBuilder.getAction();
String actionName = null;
if (metaView != null) {
name = metaView.getName();
model = metaView.getModel();
MetaAction metaAction = getAction(boardName, name, model, dashletBuilder);
actionName = metaAction.getName();
dashboardBuilder.addGeneratedAction(metaAction);
} else if (action != null) {
model = action.getModel();
actionName = action.getName();
}
dashlet.setAction(actionName);
dashlet.setHeight("350");
Integer colSpan = dashletBuilder.getColspan();
if (colSpan > 12) {
colSpan = 12;
} else if (colSpan <= 0) {
colSpan = 6;
}
dashlet.setColSpan(colSpan);
dashlets.add(dashlet);
}
if (dashlets.isEmpty()) {
return null;
}
dashboard.setItems(dashlets);
MetaStore.clear();
return metaService.generateMetaView(dashboard);
}
use of com.axelor.meta.schema.views.AbstractWidget in project axelor-open-suite by axelor.
the class ReportBuilderService method createTable.
/**
* Process panelRelated to find right grid view of reference model. Grid view used to create html
* table.
*
* @param panelRelated PanelRelated to use.
* @param refModel Name of model refer by panelRelated.
* @return Html table string created.
*/
private String createTable(PanelRelated panelRelated, String refModel) {
List<AbstractWidget> items = panelRelated.getItems();
if (items != null && !items.isEmpty()) {
return getHtmlTable(panelRelated.getName(), items, refModel);
}
MetaView gridView = findGridView(panelRelated.getGridView(), refModel);
if (gridView != null) {
try {
ObjectViews views = XMLViews.fromXML(gridView.getXml());
GridView grid = (GridView) views.getViews().get(0);
return getHtmlTable(panelRelated.getName(), grid.getItems(), refModel);
} catch (JAXBException e) {
e.printStackTrace();
}
}
return "";
}
use of com.axelor.meta.schema.views.AbstractWidget in project axelor-open-suite by axelor.
the class ReportBuilderService method processView.
/**
* Method parse given xml to create html.
*
* @param xml View xml passed.
* @throws JAXBException Xml parsing exception.
*/
private void processView(String xml) throws JAXBException {
ObjectViews objectViews = XMLViews.fromXML(xml);
AbstractView view = objectViews.getViews().get(0);
FormView formView = (FormView) view;
for (AbstractWidget widget : formView.getItems()) {
if (widget instanceof PanelTabs) {
PanelTabs panelTabs = (PanelTabs) widget;
AbstractWidget tabItem = panelTabs.getItems().get(0);
processAbstractWidget(tabItem, false);
continue;
}
processAbstractWidget(widget, false);
}
}
use of com.axelor.meta.schema.views.AbstractWidget in project axelor-open-suite by axelor.
the class ReportBuilderService method processPanel.
/**
* Process panel to create html from it and to process items of panels. It add panel title in full
* row span of html table.
*
* @param panel Panels to process.
* @param sidePanel Boolean to check if panel is sidePanel.
*/
private void processPanel(Panel panel, Boolean sidePanel) {
sidePanel = sidePanel != null && sidePanel ? sidePanel : panel.getSidebar();
String title = panel.getTitle();
if (title != null) {
title = "<td><h4><u>" + title + "</u></h4></td>";
if (sidePanel != null && sidePanel) {
sidePanels.add(new String[] { "12", title });
} else {
panels.add(new String[] { "12", title });
}
}
for (AbstractWidget widget : panel.getItems()) {
processAbstractWidget(widget, sidePanel);
}
}
use of com.axelor.meta.schema.views.AbstractWidget in project axelor-open-suite by axelor.
the class ReportBuilderService method getHtmlTable.
/**
* Create html table string from list of widgets(Items of grd view).
*
* @param fieldName Name of relational field.
* @param widgets List of widgets in reference model's grid view.
* @param refModel Name of reference model.
* @return Html table created.
*/
private String getHtmlTable(String fieldName, List<AbstractWidget> widgets, String refModel) {
String header = "";
String row = "";
for (AbstractWidget widget : widgets) {
if (widget instanceof Field) {
Field field = (Field) widget;
String name = field.getName();
String title = field.getTitle();
MetaField metaField = getMetaField(name, refModel);
if (Strings.isNullOrEmpty(title)) {
title = getFieldTitle(name, metaField);
}
name = processRelational(name, metaField);
header += "<th>" + title + "</th>";
row += "<td>$" + fieldName + "." + name + "$</td>";
}
}
String table = "<td colSpan=\"2\"><table class=\"table table-bordered table-header\">" + "<tr>" + header + "</tr>" + "<tr>" + row + "</tr>" + "</table></td>";
return table;
}
Aggregations