UNPKG

@wbg-mde/repository

Version:

Managing all common method for file system CRUD operations.

129 lines (128 loc) 5.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const template_1 = require("../../master-data/template"); const _ = require('lodash'); class TemplateService { constructor() { this.template = new template_1.Template(); } getTreeViewSchema(templateType, language, afterSchemaGenerated) { this.template.getEditorSectionMappingSchema(templateType, language, (response) => { if (response.result == 'ok') { let editorMapSchema = _.find(response.schema.mappings, function (item) { return String(item.type).trim().toLowerCase() === String(templateType).trim().toLowerCase(); }); this.template.getBaseTemplateSchema(templateType, language, (tResponce) => { if (tResponce.result == 'ok') { let formSchema = tResponce.schema.form; let templateSchema = tResponce.schema.schema; this.createTreeViewSchema(editorMapSchema, templateSchema, formSchema, (schemaResponce) => { afterSchemaGenerated({ nodes: schemaResponce, schema: templateSchema, form: formSchema }); }); } }); } }); } createTreeViewSchema(editorMapSchema, templateSchema, formSchema, afterSchemaGenerated, parentItem, nodeArray) { let self = this, treeviewSchema = nodeArray || new Array(); _.forEach(editorMapSchema.items, (mapItem) => { let node = {}; if (typeof mapItem === 'string') { if (mapItem.indexOf('.') != -1) { mapItem = mapItem; } let tempItem = self.getPropDetailsFromEditorMapSchema(mapItem, templateSchema); } else { if (mapItem.isVirtual === true) { if (mapItem.items) { node['nodes'] = new Array(); let tempItem = self.getPropDetailsFromEditorMapSchema(mapItem.key, templateSchema); if (tempItem) { templateSchema = tempItem; } self.createTreeViewSchema(mapItem, templateSchema, formSchema, undefined, mapItem, node['nodes']); } } else if (mapItem.useTemplate === true) { editorMapSchema = _.find(formSchema, (uItem) => { return uItem.key === mapItem.key; }); this.resolveUseTemplate(mapItem, formSchema); if (!editorMapSchema) { let tempItem = self.getPropDetailsFromEditorMapSchema(mapItem.key, templateSchema); if (tempItem) { self.setTreeNodeData(node, mapItem); treeviewSchema.push(node); } return true; } if (editorMapSchema.isVirtual || editorMapSchema.items) { node['nodes'] = new Array(); } if (editorMapSchema.items) { let tempItem = self.getPropDetailsFromEditorMapSchema(editorMapSchema.key, templateSchema); self.createTreeViewSchema(editorMapSchema, tempItem, formSchema, undefined, editorMapSchema, node['nodes']); } } else if (!mapItem.useTemplate) { let tempItem = self.getPropDetailsFromEditorMapSchema(mapItem.key, templateSchema); if (mapItem.items && mapItem.type !== 'array' && mapItem.type !== 'table' && mapItem.type !== 'simple-array' && mapItem.type !== 'checkboxes') { node['nodes'] = new Array(); self.createTreeViewSchema(mapItem, tempItem, formSchema, undefined, mapItem, node['nodes']); } } } self.setTreeNodeData(node, mapItem); treeviewSchema.push(node); }); if (nodeArray) { return true; } afterSchemaGenerated(treeviewSchema); } getPropDetailsFromEditorMapSchema(keyName, editorMapSchema) { if (editorMapSchema.type == 'object') { return editorMapSchema.properties[keyName]; } else if (editorMapSchema.type == 'array' || editorMapSchema.type == 'table') { return editorMapSchema.items.properties[keyName]; } else { return _.find(editorMapSchema.items, function (item, index) { return item.key == keyName; }); } } resolveUseTemplate(mapItem, formSchema, item, isRec) { let self = this, it = item ? item : new Array(); _.forEach(formSchema, (sItem) => { if (sItem.key == mapItem.key) { it.push(sItem); return true; } if (sItem.items) { self.resolveUseTemplate(mapItem, sItem.items, it, true); } }); if (isRec) { return true; } if (it.length > 0) { _.assign(mapItem, it[0]); } } setTreeNodeData(node, formSchema) { node.key = formSchema.key; node['exportKey'] = formSchema.exportKey; node.title = formSchema.title || formSchema.key; node.formschema = formSchema || {}; node['treeView'] = formSchema.treeView ? formSchema.treeView : {}; node['treeView'].type = node['treeView'].type || "jsonform"; node.cssClasses = node['treeView'].cssClasses; } } exports.TemplateService = TemplateService;