Search in sources :

Example 1 with AbstractWidget

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);
}
Also used : DashletBuilder(com.axelor.studio.db.DashletBuilder) ArrayList(java.util.ArrayList) Dashboard(com.axelor.meta.schema.views.Dashboard) AbstractWidget(com.axelor.meta.schema.views.AbstractWidget) Dashlet(com.axelor.meta.schema.views.Dashlet) MetaView(com.axelor.meta.db.MetaView) MetaAction(com.axelor.meta.db.MetaAction)

Example 2 with AbstractWidget

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 "";
}
Also used : JAXBException(javax.xml.bind.JAXBException) AbstractWidget(com.axelor.meta.schema.views.AbstractWidget) ObjectViews(com.axelor.meta.schema.ObjectViews) MetaView(com.axelor.meta.db.MetaView) GridView(com.axelor.meta.schema.views.GridView)

Example 3 with AbstractWidget

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);
    }
}
Also used : AbstractView(com.axelor.meta.schema.views.AbstractView) PanelTabs(com.axelor.meta.schema.views.PanelTabs) ObjectViews(com.axelor.meta.schema.ObjectViews) AbstractWidget(com.axelor.meta.schema.views.AbstractWidget) FormView(com.axelor.meta.schema.views.FormView)

Example 4 with AbstractWidget

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);
    }
}
Also used : AbstractWidget(com.axelor.meta.schema.views.AbstractWidget)

Example 5 with AbstractWidget

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;
}
Also used : MetaField(com.axelor.meta.db.MetaField) Field(com.axelor.meta.schema.views.Field) PanelField(com.axelor.meta.schema.views.PanelField) MetaField(com.axelor.meta.db.MetaField) AbstractWidget(com.axelor.meta.schema.views.AbstractWidget)

Aggregations

AbstractWidget (com.axelor.meta.schema.views.AbstractWidget)5 MetaView (com.axelor.meta.db.MetaView)2 ObjectViews (com.axelor.meta.schema.ObjectViews)2 MetaAction (com.axelor.meta.db.MetaAction)1 MetaField (com.axelor.meta.db.MetaField)1 AbstractView (com.axelor.meta.schema.views.AbstractView)1 Dashboard (com.axelor.meta.schema.views.Dashboard)1 Dashlet (com.axelor.meta.schema.views.Dashlet)1 Field (com.axelor.meta.schema.views.Field)1 FormView (com.axelor.meta.schema.views.FormView)1 GridView (com.axelor.meta.schema.views.GridView)1 PanelField (com.axelor.meta.schema.views.PanelField)1 PanelTabs (com.axelor.meta.schema.views.PanelTabs)1 DashletBuilder (com.axelor.studio.db.DashletBuilder)1 ArrayList (java.util.ArrayList)1 JAXBException (javax.xml.bind.JAXBException)1