UNPKG

@cuba-platform/front-generator

Version:
114 lines 4.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getFieldHtml = exports.getFieldModel = exports.getFieldType = exports.fieldDependencies = void 0; const cuba_model_1 = require("../../../../common/model/cuba-model"); const ejs_1 = require("ejs"); const fs = require("fs"); const path = require("path"); exports.fieldDependencies = { ["boolean" /* BOOLEAN */]: [ 'vaadin-checkbox/vaadin-checkbox.html' ], ["date" /* DATE */]: [ 'vaadin-text-field/vaadin-text-field.html', 'vaadin-date-picker/vaadin-date-picker-light.html', 'iron-icons/iron-icons.html' ], ["dateTime" /* DATE_TIME */]: [ 'vaadin-text-field/vaadin-text-field.html' ], ["enum" /* ENUM */]: [ 'vaadin-combo-box/vaadin-combo-box.html' ], ["file" /* FILE */]: [ 'cuba-file-field/cuba-file-field.html' ], ["fpNumber" /* FP_NUMBER */]: [ 'vaadin-text-field/vaadin-text-field.html' ], ["number" /* NUMBER */]: [ 'vaadin-text-field/vaadin-text-field.html' ], ["lookup" /* LOOKUP */]: [ 'cuba-ui/cuba-lookup.html', 'cuba-data/cuba-entities.html', 'vaadin-combo-box/vaadin-combo-box.html' ], ["text" /* TEXT */]: [ 'vaadin-text-field/vaadin-text-field.html' ], ["time" /* TIME */]: [ 'vaadin-text-field/vaadin-text-field.html' ] }; const getFieldType = (attribute) => { if (attribute.mappingType === 'ENUM') { return "enum" /* ENUM */; } if (isFile(attribute)) { return "file" /* FILE */; } if (isToOneRelation(attribute)) { return "lookup" /* LOOKUP */; } if (attribute.mappingType === 'DATATYPE') { if (isAttributeTypeOf(attribute, 'java.lang.Boolean')) { return "boolean" /* BOOLEAN */; } if (isAttributeTypeOf(attribute, 'java.lang.Integer') || isAttributeTypeOf(attribute, 'java.lang.Long')) { return "number" /* NUMBER */; } if (isAttributeTypeOf(attribute, 'java.math.BigDecimal') || isAttributeTypeOf(attribute, 'java.lang.Double')) { return "fpNumber" /* FP_NUMBER */; } if (isAttributeTypeOf(attribute, 'java.lang.String')) { return "text" /* TEXT */; } if (isAttributeTypeOf(attribute, 'java.util.Date') && attribute.temporalType != null) { if (attribute.temporalType === 'DATE') return "date" /* DATE */; if (attribute.temporalType == 'TIMESTAMP') return "dateTime" /* DATE_TIME */; if (attribute.temporalType == 'TIME') return "time" /* TIME */; } } return "text" /* TEXT */; }; exports.getFieldType = getFieldType; const getFieldModel = (attribute) => { const fieldType = (0, exports.getFieldType)(attribute); let model = { type: fieldType, bindPath: 'entity.' + attribute.name, errorBindPath: 'serverErrors.' + attribute.name, label: `[[msg('${attribute.name}')]]`, required: attribute.mandatory, maxLength: attribute.length }; if (fieldType === "enum" /* ENUM */) { model.enumItems = `[[enumValues('${attribute.type.fqn}')]]`; } if (fieldType === "lookup" /* LOOKUP */ && attribute.type.entityName) { model.lookupEntityName = attribute.type.entityName; model.itemsBindPath = `entity_${attribute.name}Options`; } return model; }; exports.getFieldModel = getFieldModel; const getFieldHtml = (model) => { return (0, ejs_1.render)(fs.readFileSync(path.join(__dirname, 'template', model.type + 'Field.html'), 'utf8'), model); }; exports.getFieldHtml = getFieldHtml; function isFile(attribute) { return isToOneRelation(attribute) && isAttributeTypeOf(attribute, cuba_model_1.FILE_DESCRIPTOR_FQN); } function isToOneRelation(attribute) { return (attribute.mappingType === 'ASSOCIATION' || attribute.mappingType === 'COMPOSITION') && (attribute.cardinality === 'MANY_TO_ONE' || attribute.cardinality === 'ONE_TO_ONE'); } // todo extensions inheritance function isAttributeTypeOf(attribute, fqn) { return attribute.type != null && attribute.type.fqn === fqn; } //# sourceMappingURL=index.js.map