Search in sources :

Example 36 with MetaField

use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.

the class ReportBuilderService method processField.

/**
 * Process PanelField and extend html table of html template.
 *
 * @param field PanelField to process.
 * @param sidePanel Boolean to check if field is in sidePanel.
 * @param colSpan Colspan of field.
 */
private void processField(PanelField field, Boolean sidePanel) {
    String title = field.getTitle();
    String name = field.getName();
    MetaField metaField = getMetaField(name, model);
    if (Strings.isNullOrEmpty(title)) {
        title = getFieldTitle(name, metaField);
    }
    name = processRelational(name, metaField);
    String value = "<td><b>" + title + "</b> : $" + name + "$</td>";
    String colSpan = "6";
    if (field.getColSpan() != null && field.getColSpan() == 12) {
        colSpan = "12";
        value = "<td colSpan=\"2\"><b>" + title + "</b> : $" + name + "$</td>";
    } else {
        value = "<td><b>" + title + "</b> : $" + name + "$</td>";
    }
    if (sidePanel != null && sidePanel) {
        sidePanels.add(new String[] { "12", value });
    } else {
        panels.add(new String[] { colSpan, value });
    }
}
Also used : MetaField(com.axelor.meta.db.MetaField)

Example 37 with MetaField

use of com.axelor.meta.db.MetaField 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)

Example 38 with MetaField

use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.

the class FilterGroovyService method getJsonFieldType.

private String getJsonFieldType(MetaJsonField jsonField, String targetField) throws AxelorException {
    if (targetField == null || !targetField.contains(".")) {
        return jsonField.getType();
    }
    targetField = targetField.substring(targetField.indexOf(".") + 1);
    String targetName = targetField.contains(".") ? targetField.substring(0, targetField.indexOf(".")) : targetField;
    if (jsonField.getTargetJsonModel() != null) {
        MetaJsonField subJson = metaJsonFieldRepo.all().filter("self.name = ?1 and self.jsonModel = ?2", targetName, jsonField.getTargetJsonModel()).fetchOne();
        if (subJson == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "No sub field found model: %s field %s ", jsonField.getTargetJsonModel().getName(), targetName);
        }
        return getJsonFieldType(subJson, targetField);
    } else {
        MetaField subMeta = filterSqlService.findMetaField(targetName, jsonField.getTargetModel());
        if (subMeta == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "No sub field found model: %s field %s ", jsonField.getTargetModel(), targetName);
        }
        return getMetaFieldType(subMeta, targetField, true);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) MetaField(com.axelor.meta.db.MetaField) MetaJsonField(com.axelor.meta.db.MetaJsonField)

Example 39 with MetaField

use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.

the class ActionScriptBuilderService method addFieldsBinding.

private String addFieldsBinding(String target, List<ActionBuilderLine> lines, int level) {
    StringBuilder stb = new StringBuilder();
    lines.sort((l1, l2) -> {
        if (l1.getDummy() && !l2.getDummy()) {
            return -1;
        }
        if (!l1.getDummy() && l2.getDummy()) {
            return 1;
        }
        return 0;
    });
    for (ActionBuilderLine line : lines) {
        String name = line.getName();
        String value = line.getValue();
        if (value != null && value.contains(".sum(")) {
            value = getSum(value, line.getFilter());
        }
        if (line.getDummy()) {
            stb.append(format("_$." + name + " = " + value + ";", level));
            continue;
        }
        MetaJsonField jsonField = line.getMetaJsonField();
        MetaField metaField = line.getMetaField();
        if (jsonField != null && (jsonField.getTargetJsonModel() != null || jsonField.getTargetModel() != null)) {
            value = addRelationalBinding(line, target, true);
        } else if (metaField != null && metaField.getRelationship() != null) {
            value = addRelationalBinding(line, target, false);
        }
        if (value != null && metaField != null && metaField.getTypeName().equals(BigDecimal.class.getSimpleName())) {
            value = "new BigDecimal(" + value + ")";
        }
        String condition = line.getConditionText();
        if (condition != null) {
            stb.append(format("if(" + condition + "){" + target + "." + name + " = " + value + ";}", level));
        } else {
            stb.append(format(target + "." + name + " = " + value + ";", level));
        }
    }
    return stb.toString();
}
Also used : ActionBuilderLine(com.axelor.studio.db.ActionBuilderLine) MetaField(com.axelor.meta.db.MetaField) MetaJsonField(com.axelor.meta.db.MetaJsonField)

Example 40 with MetaField

use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.

the class ActionScriptBuilderService method getTargetModel.

private String getTargetModel(ActionBuilderLine line) {
    MetaJsonField jsonField = line.getMetaJsonField();
    String targetModel = "";
    if (jsonField != null && jsonField.getTargetModel() != null) {
        targetModel = jsonField.getTargetModel();
    }
    MetaField field = line.getMetaField();
    if (field != null && field.getTypeName() != null) {
        targetModel = field.getTypeName();
    }
    return targetModel;
}
Also used : MetaField(com.axelor.meta.db.MetaField) MetaJsonField(com.axelor.meta.db.MetaJsonField)

Aggregations

MetaField (com.axelor.meta.db.MetaField)45 MetaJsonField (com.axelor.meta.db.MetaJsonField)15 MetaModel (com.axelor.meta.db.MetaModel)10 Mapper (com.axelor.db.mapper.Mapper)9 AxelorException (com.axelor.exception.AxelorException)8 ArrayList (java.util.ArrayList)6 Property (com.axelor.db.mapper.Property)5 Filter (com.axelor.studio.db.Filter)4 Model (com.axelor.db.Model)3 MetaFieldRepository (com.axelor.meta.db.repo.MetaFieldRepository)3 MetaModelRepository (com.axelor.meta.db.repo.MetaModelRepository)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Company (com.axelor.apps.base.db.Company)2 FileField (com.axelor.apps.base.db.FileField)2 ProductCompany (com.axelor.apps.base.db.ProductCompany)2 Context (com.axelor.rpc.Context)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Transactional (com.google.inject.persist.Transactional)2 BigInteger (java.math.BigInteger)2