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