import { Component, OnInit, OnChanges, Input, Output, EventEmitter, ViewChild, TemplateRef } from '@angular/core'; import { TreeNode, TreeTableComponent } from '@farris/ui-treetable'; import { ExpressionEditorLocalePipe } from '../utils/expression-editor-locale.pipe'; import { Schema } from '../common/Schema'; import { NewSchema } from '../common/NewSchema'; import { SchemaToStructUtils } from "../checkSyntax/SchemaToStruct"; import { CurrentNode, InjectedEntity } from '../common/CommonEntity'; @Component({ selector: 'app-expression-entity-grid', templateUrl: './expression-entity-grid.component.html', styleUrls: ['./expression-entity-grid.component.css'] }) export class ExpressionEntityGridComponent implements OnInit, OnChanges { //定义i18n标识 private localeId: string; private localePipe: ExpressionEditorLocalePipe; currentNode: CurrentNode = new CurrentNode; entities: TreeNode[] = []; currentSchemaName: string = ""; currentNewSchemaName: string = ""; currentParent: string = ""; @Input() schema = new Map(); @Input() newSchemaMap = new Map(); @Input() injectedEntities: InjectedEntity[]; @Input() showChildSymbol: boolean = true; //是否展示[0] @Output() selectentitychange = new EventEmitter(); @Output() dbclickInsert = new EventEmitter(); @ViewChild('operCell') operCell: TemplateRef; //定义按钮操作 @ViewChild('tt') tt: TreeTableComponent; //使用farris-treetable特性 cols = []; allColumnsTitle: string = ""; //搜索框'所有列'显示信息 searchFields = []; //搜索框可以使用哪些字段 public treedata: TreeNode[] = []; //资源国际化 EntitySet: string; i18nTypes: { String: string, Byte: string, Boolean: string, Date: string, DateTime: string, Decimal: string, Integer: string }; //参数类型 constructor() { //初始化i18n标识 this.localeId = localStorage.getItem('languageCode'); this.localePipe = new ExpressionEditorLocalePipe(this.localeId); } ngOnInit() { //资源i18n this.EntitySet = this.localePipe.transform("EntitySet") this.i18nTypes = { String: this.localePipe.transform("NewDataTypeString"), Byte: this.localePipe.transform("NewDataTypeByte"), Boolean: this.localePipe.transform("NewDataTypeBoolean"), Date: this.localePipe.transform("NewDataTypeDate"), DateTime: this.localePipe.transform("NewDataTypeDateTime"), Decimal: this.localePipe.transform("NewDataTypeDecimal"), Integer: this.localePipe.transform("NewDataTypeInteger") }; this.cols = [ { field: 'name', title: this.localePipe.transform("EntityCode"), width: '5' }, { field: 'description', title: this.localePipe.transform("EntityName"), width: '5' }, { field: 'type', title: this.localePipe.transform("EntityType"), width: '2' }, { title: this.localePipe.transform("InsertType"), width: '3', align: 'center', halign: 'center', template: this.operCell } ]; this.searchFields = [ { label: this.localePipe.transform("EntityCode"), value: "name" }, { label: this.localePipe.transform("EntityName"), value: "description" } ] this.allColumnsTitle = this.localePipe.transform("EntityAllColumn"); if (this.newSchemaMap && this.newSchemaMap.size > 0) { this.treedata = SchemaToStructUtils.onInitNewSchema(this.newSchemaMap, this.injectedEntities, this.EntitySet, this.i18nTypes); } else if (this.schema && this.schema.size > 0) { this.treedata = SchemaToStructUtils.OnInitSchema(this.schema, this.injectedEntities, this.EntitySet); } this.treedata = [...this.treedata]; } selectRowChange($event) { this.currentNode = new CurrentNode; this.currentNode.id = $event.node.data.id; this.currentNode.name = $event.node.data.name; this.currentNode.parentName = this.selectParentString($event.node); this.currentParent = this.selectParentString($event.node); this.currentNode.schema = $event.node.data.schema; this.currentNode.nodeType = $event.node.data.nodeType; this.currentNode.description = $event.node.data.description; this.selectentitychange.emit(this.currentNode); } dblClick($event) { if (this.currentParent) { this.dbclickInsert.emit(this.currentParent + "." + $event.data.name); } else { this.dbclickInsert.emit($event.data.name); } } ngOnChanges(): void { //资源i18n this.EntitySet = this.localePipe.transform("EntitySet") this.i18nTypes = { String: this.localePipe.transform("NewDataTypeString"), Byte: this.localePipe.transform("NewDataTypeByte"), Boolean: this.localePipe.transform("NewDataTypeBoolean"), Date: this.localePipe.transform("NewDataTypeDate"), DateTime: this.localePipe.transform("NewDataTypeDateTime"), Decimal: this.localePipe.transform("NewDataTypeDecimal"), Integer: this.localePipe.transform("NewDataTypeInteger") }; if (this.newSchemaMap && this.newSchemaMap.size > 0) { this.treedata = SchemaToStructUtils.onInitNewSchema(this.newSchemaMap, this.injectedEntities, this.EntitySet, this.i18nTypes); } else if (this.schema && this.schema.size > 0) { this.treedata = SchemaToStructUtils.OnInitSchema(this.schema, this.injectedEntities, this.EntitySet); } this.treedata = [...this.treedata]; } //递归父节点名 selectParentString(node: any) { if (node.parent) { if (this.selectParentString(node.parent)) { if (this.strContain(node.parent.data.type) && this.showChildSymbol) return this.selectParentString(node.parent) + "." + node.parent.data.name + "[0]"; else return this.selectParentString(node.parent) + "." + node.parent.data.name; } else if (this.strContain(node.parent.data.type) && this.showChildSymbol) { return node.parent.data.name + "[0]"; } else { return node.parent.data.name; } } else { return ""; } } //"按结构"按钮 insertByStructure(node) { this.currentParent = this.selectParentString(node); if (this.currentParent && this.currentParent != "") { this.dbclickInsert.emit(this.currentParent + "." + node.data.name); } else { this.dbclickInsert.emit(node.data.name); } } //"按属性"按钮 insertByProperty(node) { this.dbclickInsert.emit(node.data.name); } private strContain(strr: any): boolean { let temp = strr + ""; if (temp.indexOf("子表") != -1 || temp.indexOf("ChildTable") != -1) return true; else return false; } //过滤 filter($event) { //通过farris-treetable的方法过滤 this.tt.searchHandle.search($event.field, $event.value, 'client') } }