| /******************************************************************************** |
| * Copyright (c) 2015-2018 Contributors to the Eclipse Foundation |
| * |
| * See the NOTICE file(s) distributed with this work for additional |
| * information regarding copyright ownership. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| ********************************************************************************/ |
| |
| |
| import { Component, OnInit, ViewChild, Input, OnDestroy, Output, EventEmitter } from '@angular/core'; |
| import { FormGroup, FormControl, FormBuilder, FormArray, Validators } from '@angular/forms'; |
| import { ActivatedRoute } from '@angular/router'; |
| import { TranslateService } from '@ngx-translate/core'; |
| import { DropdownModule } from 'primeng/dropdown'; |
| import { TreeTableModule } from 'primeng/treetable'; |
| import { TreeNode, MenuItem, SelectItem } from 'primeng/api'; |
| import { ContextMenuModule } from 'primeng/contextmenu'; |
| import { TreeTable, TreeTableToggler, DataTable } from 'primeng/primeng'; |
| import { DialogModule } from 'primeng/dialog'; |
| import { Observable, BehaviorSubject } from 'rxjs'; |
| import 'rxjs/add/operator/toPromise'; |
| |
| import { MDMNotificationService } from '../core/mdm-notification.service'; |
| import { ExtSystemService } from './extsystem.service'; |
| import { Node, Attribute, Relation } from '../navigator/node'; |
| import { plainToClass } from 'class-transformer'; |
| import { CatalogService } from './catalog.service'; |
| |
| @Component( { |
| selector: 'mdm-extsystem-editor', |
| templateUrl: './extsystem-editor.component.html', |
| styleUrls: ['./extsystem.component.css'] |
| }) |
| export class ExtSystemEditorComponent implements OnInit, OnDestroy { |
| |
| // passed down from parent |
| @Input() extSystems: Node[]; |
| @Input() selectedEnvironment: Node; |
| @Input() selectedES: string; |
| |
| @Output() editMode = new EventEmitter<boolean>(); |
| |
| // table selection |
| selectedExtSystem: Node; |
| selectedExtSystemAttr: Node; |
| selectedExtSystemMDMAttr: Node; |
| tableExtSystems: Node[] = new Array(); |
| |
| // dropdown for edit dialog |
| mdmCompTypes: SelectItem[]; |
| mdmCompNames: Node[]; |
| mdmAttrNames: Node[]; |
| |
| // external system attributes |
| extSystemAttrs: Node[]; |
| bsExtSystemAttrs: BehaviorSubject<Node[]> = new BehaviorSubject<Node[]>(undefined); |
| |
| // contextmenu mappings |
| menuItemsExtSystemAttr: MenuItem[]; |
| menuItemsExtSystemMDMAttr: MenuItem[]; |
| |
| // dialog and loading states |
| dialogExtSystemAttr: boolean = false; |
| dialogExtSystemMDMAttr: boolean = false; |
| loadingExtSystemAttr: boolean = false; |
| |
| dialogLoadingExtSystemComps: boolean = false; |
| dialogLoadingExtSystemAttrs: boolean = false; |
| |
| // for edit dialogs |
| tmpExtSystemAttr: Node; |
| tmpExtSystemMDMAttr: Node; |
| tmpNode: Node; |
| tmpCatalogComps: string[]; |
| tmpAttributeComps: string[]; |
| |
| loadedTemplateRoots: any[][] = []; |
| loadedCatalogComps: any[][] = []; |
| loadedAttributeComps: Node[] = new Array(); |
| |
| constructor(private extSystemService: ExtSystemService, |
| private notificationService: MDMNotificationService, |
| private translateService: TranslateService, |
| private catalogService: CatalogService) { |
| |
| this.bsExtSystemAttrs.subscribe(value => { |
| this.extSystemAttrs = value; |
| }); |
| |
| this.mdmCompTypes = [ |
| { label: this.translateService.instant('administration.extsystem.dropdown-please-select'), value: '' }, |
| { label: this.translateService.instant('administration.extsystem.unit-under-test'), value: 'UnitUnderTest' }, |
| { label: this.translateService.instant('administration.extsystem.test-equipment'), value: 'TestEquipment' }, |
| { label: this.translateService.instant('administration.extsystem.test-sequence'), value: 'TestSequence' }, |
| { label: this.translateService.instant('administration.extsystem.sensor'), value: 'Sensor' } |
| ]; |
| } |
| |
| ngOnInit() { |
| for (let i in this.extSystems) { |
| if (this.extSystems[i].type === 'ExtSystem' && this.extSystems[i].id === this.selectedES) { |
| this.selectedExtSystem = this.extSystems[i]; |
| this.tableExtSystems.push(this.selectedExtSystem); |
| break; |
| } |
| } |
| |
| this.loadingExtSystemAttr = true; |
| this.extSystemService.getExtSystemAttributesForScope(this.selectedEnvironment.sourceName, this.selectedExtSystem.id).subscribe(attrs => { |
| this.bsExtSystemAttrs.next(attrs); |
| this.loadingExtSystemAttr = false; |
| }); |
| |
| this.menuItemsExtSystemAttr = [ |
| { |
| label: this.translateService.instant('administration.extsystem.btn-edit'), icon: 'fa fa-pencil-square-o', command: (event) => this.editExtSystemAttr(this.selectedExtSystemAttr) |
| }, |
| { label: this.translateService.instant('administration.extsystem.btn-del'), icon: 'fa fa-times', command: (event) => this.removeExtSystemAttr(this.selectedExtSystemAttr) } |
| ]; |
| |
| this.menuItemsExtSystemMDMAttr = [ |
| { |
| label: this.translateService.instant('administration.extsystem.btn-edit'), icon: 'fa fa-pencil-square-o', command: (event) => this.editExtSystemMDMAttr(this.selectedExtSystemMDMAttr) |
| }, |
| { label: this.translateService.instant('administration.extsystem.btn-del'), icon: 'fa fa-times', command: (event) => this.removeExtSystemMDMAttr(this.selectedExtSystemMDMAttr) } |
| ]; |
| } |
| |
| ngOnDestroy() { |
| } |
| |
| getExternalSystemAttributes() { |
| let data = new Array(); |
| for (let i in this.extSystemAttrs) { |
| if (this.extSystemAttrs[i].type === 'ExtSystemAttribute') { |
| data.push(this.extSystemAttrs[i]); |
| } |
| } |
| return data; |
| } |
| getMDMAttributes() { |
| let ids = new Array(); |
| for (let i in this.selectedExtSystemAttr.relations) { |
| if (this.selectedExtSystemAttr.relations[i].entityType === 'MDMAttribute') { |
| for (let j in this.selectedExtSystemAttr.relations[i].ids) { |
| ids.push(this.selectedExtSystemAttr.relations[i].ids[j]); |
| } |
| } |
| } |
| let data = new Array(); |
| for (let i in this.extSystemAttrs) { |
| if (this.extSystemAttrs[i].type === 'MDMAttribute' && ids.find(el => el === this.extSystemAttrs[i].id)) { |
| data.push(this.extSystemAttrs[i]); |
| } |
| } |
| return data; |
| } |
| |
| getAttributeValueFromNode(node: Node, attribute: string) { |
| if (node.attributes !== undefined) { |
| for (let i in node.attributes) { |
| if (node.attributes[i].name === attribute) { |
| return node.attributes[i].value; |
| } |
| } |
| } |
| return ''; |
| } |
| |
| getAttributeFromNode(node: Node, attribute: string) { |
| if (node.attributes !== undefined) { |
| for (let i in node.attributes) { |
| if (node.attributes[i].name === attribute) { |
| return node.attributes[i]; |
| } |
| } |
| } |
| return undefined; |
| } |
| |
| getNextTemporaryId() { |
| let id: number = -1; |
| for (let i in this.extSystems) { |
| if (parseInt(this.extSystems[i].id) < id) { |
| id = parseInt(this.extSystems[i].id); |
| } |
| } |
| return --id; |
| } |
| |
| createAttribute(name: string, value?: string) { |
| let attr = new Attribute(); |
| attr.dataType = 'STRING'; |
| attr.unit = ''; |
| attr.value = value !== undefined ? value : ''; |
| attr.name = name; |
| return attr; |
| } |
| |
| getIndicesForIds(ids: string[]) { |
| let indices = new Array(); |
| for (let id in ids) { |
| for (let i in this.extSystems) { |
| if (this.extSystems[i].id === ids[id]) { |
| indices.push(this.extSystems.indexOf(this.extSystems[i])); |
| } |
| } |
| } |
| return indices; |
| } |
| |
| addExtSystemAttr() { |
| this.tmpExtSystemAttr = new Node(); |
| this.tmpExtSystemAttr.type = 'ExtSystemAttribute'; |
| this.tmpExtSystemAttr.sourceType = 'ExtSystemAttr'; |
| this.tmpExtSystemAttr.sourceName = this.selectedEnvironment.sourceName; |
| this.tmpExtSystemAttr.attributes = new Array(); |
| this.tmpExtSystemAttr.attributes.push(this.createAttribute('Description')); |
| this.tmpExtSystemAttr.attributes.push(this.createAttribute('Name')); |
| this.tmpExtSystemAttr.attributes.push(this.createAttribute('ConverterClassname')); |
| this.tmpExtSystemAttr.attributes.push(this.createAttribute('ConverterParameter')); |
| this.tmpExtSystemAttr.attributes.push(this.createAttribute('MimeType', 'application/x-asam.aoany.extsystemattr')); |
| this.dialogExtSystemAttr = true; |
| } |
| |
| editExtSystemAttr(extSystemAttr?: Node) { |
| if (extSystemAttr != undefined) { |
| this.tmpNode = JSON.parse(JSON.stringify(extSystemAttr)); |
| this.tmpExtSystemAttr = extSystemAttr; |
| this.dialogExtSystemAttr = true; |
| } |
| } |
| |
| removeExtSystemAttr(extSystemAttr?: Node) { |
| if (extSystemAttr != undefined) { |
| |
| if (extSystemAttr.id !== undefined && parseInt(extSystemAttr.id) > 0 && this.extSystemAttrs.indexOf(extSystemAttr) !== -1) { |
| this.extSystemService.deleteExtSystemAttr(this.selectedEnvironment.sourceName, extSystemAttr.id).subscribe(); |
| let idxES: number = this.extSystemAttrs.indexOf(extSystemAttr); |
| if (idxES !== -1) { |
| this.extSystemAttrs.splice(idxES, 1); |
| if (extSystemAttr.relations !== undefined && extSystemAttr.relations.length > 0) { |
| // remove all children |
| let indices = new Array<number>(); |
| for (let h in extSystemAttr.relations) { |
| // the mdm attributes |
| indices = indices.concat(this.getIndicesForIds(extSystemAttr.relations[h].ids)); |
| } |
| indices.sort((a, b) => b - a); |
| for (let i in indices) { |
| this.extSystemAttrs.splice(indices[i], 1); |
| } |
| } |
| } |
| } |
| } |
| this.selectedExtSystemAttr = undefined; |
| } |
| |
| saveExtSystem() { |
| this.getAttributeFromNode(this.selectedExtSystem, 'Name').value = this.selectedExtSystem.name; |
| this.extSystemService.saveExtSystem(this.selectedEnvironment.sourceName, this.selectedExtSystem) |
| .subscribe( |
| response => { /* discard */ }, |
| error => this.notificationService.notifyError( |
| this.translateService.instant('administration.extsystem.err-cannot-update-ext-system'), error) |
| ); |
| } |
| |
| patchResponseAttr(nodes: Node[]) { |
| for (let i in nodes) { |
| if (nodes[i].name === this.tmpExtSystemAttr.name) { |
| if (this.tmpExtSystemAttr.id === undefined) { |
| this.extSystemAttrs.push(this.tmpExtSystemAttr); |
| } |
| this.tmpExtSystemAttr.id = nodes[i].id; |
| } |
| } |
| this.tmpExtSystemAttr = undefined; |
| this.tmpNode = undefined; |
| } |
| |
| saveDialogExtSystemAttr() { |
| if (this.tmpExtSystemAttr.id === undefined) { |
| // add relation |
| if (this.selectedExtSystem.relations === undefined || this.selectedExtSystem.relations.length == 0) { |
| this.selectedExtSystem.relations = new Array(); |
| let relation = new Relation(); |
| relation.entityType = 'ExtSystemAttribute'; |
| relation.type = 'CHILDREN'; |
| relation.ids = new Array(); |
| this.selectedExtSystem.relations.push(relation); |
| } |
| if (this.selectedExtSystem.relations[0].ids === undefined) { |
| this.selectedExtSystem.relations[0].ids = new Array(); |
| } |
| this.tmpExtSystemAttr.id = undefined; |
| } |
| // update the name attribute |
| this.getAttributeFromNode(this.tmpExtSystemAttr, 'Name').value = this.tmpExtSystemAttr.name; |
| this.extSystemService.saveExtSystemAttr(this.selectedEnvironment.sourceName, this.tmpExtSystemAttr, this.selectedExtSystem) |
| .subscribe( |
| response => this.patchResponseAttr(plainToClass(Node, response.json().data)), |
| error => { |
| this.notificationService.notifyError( |
| this.translateService.instant('administration.extsystem.err-cannot-save-ext-system-attr'), error); |
| // restore values |
| this.getAttributeFromNode(this.tmpExtSystemAttr, 'Name').value = this.getAttributeValueFromNode(this.tmpNode, 'Name'); |
| this.getAttributeFromNode(this.tmpExtSystemAttr, 'Description').value = <string> this.getAttributeValueFromNode(this.tmpNode, 'Description'); |
| this.tmpExtSystemAttr.name = <string> this.getAttributeValueFromNode(this.tmpExtSystemAttr, 'Name'); |
| this.tmpNode = undefined; |
| } |
| ); |
| |
| this.dialogExtSystemAttr = false; |
| } |
| |
| cancelDialogExtSystemAttr() { |
| this.dialogExtSystemAttr = false; |
| this.getAttributeFromNode(this.tmpExtSystemAttr, 'Name').value = this.getAttributeValueFromNode(this.tmpNode, 'Name'); |
| this.getAttributeFromNode(this.tmpExtSystemAttr, 'Description').value = this.getAttributeValueFromNode(this.tmpNode, 'Description'); |
| this.tmpExtSystemAttr.name = <string> this.getAttributeValueFromNode(this.tmpExtSystemAttr, 'Name'); |
| this.tmpExtSystemAttr = undefined; |
| } |
| |
| addExtSystemMDMAttr() { |
| this.tmpExtSystemMDMAttr = new Node(); |
| this.tmpExtSystemMDMAttr.type = 'MDMAttribute'; |
| this.tmpExtSystemMDMAttr.sourceType = 'MDMAttr'; |
| this.tmpExtSystemMDMAttr.sourceName = this.selectedEnvironment.sourceName; |
| this.tmpExtSystemMDMAttr.attributes = new Array(); |
| this.tmpExtSystemMDMAttr.attributes.push(this.createAttribute('AttrName')); |
| this.tmpExtSystemMDMAttr.attributes.push(this.createAttribute('CompName')); |
| this.tmpExtSystemMDMAttr.attributes.push(this.createAttribute('CompType')); |
| this.tmpExtSystemMDMAttr.attributes.push(this.createAttribute('MimeType', 'application/x-asam.aoany.mdmattr')); |
| // the name is the hierarchy from the parent elements appended with the name, set in save method |
| this.tmpExtSystemMDMAttr.attributes.push(this.createAttribute('Name')); |
| this.dialogExtSystemMDMAttr = true; |
| } |
| |
| editExtSystemMDMAttr(extSystemMDMAttr?: Node) { |
| if (extSystemMDMAttr != undefined) { |
| this.tmpNode = JSON.parse(JSON.stringify(extSystemMDMAttr)); |
| this.tmpExtSystemMDMAttr = extSystemMDMAttr; |
| // trigger data reload |
| this.tmpAttributeComps = []; |
| this.loadedAttributeComps = new Array(); |
| this.dialogExtSystemMDMAttr = true; |
| this.getAttributeComponentStr(); |
| } |
| } |
| |
| removeExtSystemMDMAttr(extSystemMDMAttr?: Node) { |
| if (extSystemMDMAttr != undefined) { |
| if (this.extSystemAttrs.indexOf(extSystemMDMAttr) !== -1) { |
| if (extSystemMDMAttr.id !== undefined && parseInt(extSystemMDMAttr.id) > 0) { |
| this.extSystemService.deleteExtSystemMDMAttr(this.selectedEnvironment.sourceName, extSystemMDMAttr.id).subscribe(); |
| this.extSystemAttrs.splice(this.extSystemAttrs.indexOf(extSystemMDMAttr), 1); |
| } |
| } |
| } |
| this.selectedExtSystemMDMAttr = undefined; |
| } |
| |
| patchResponseMDMAttr(nodes: Node[]) { |
| for (let i in nodes) { |
| if (nodes[i].name === this.tmpExtSystemMDMAttr.name) { |
| if (this.tmpExtSystemMDMAttr.id === undefined) { |
| this.extSystemAttrs.push(this.tmpExtSystemMDMAttr); |
| } |
| this.tmpExtSystemMDMAttr.id = nodes[i].id; |
| for (let j in this.selectedExtSystemAttr.relations) { |
| if (this.selectedExtSystemAttr.relations[j].entityType === 'MDMAttribute') { |
| if (this.selectedExtSystemAttr.relations[j].ids === undefined) { |
| this.selectedExtSystemAttr.relations[j].ids = new Array(); |
| }; |
| this.selectedExtSystemAttr.relations[j].ids.push(nodes[i].id); |
| } |
| } |
| } |
| } |
| this.tmpExtSystemMDMAttr = undefined; |
| this.tmpNode = undefined; |
| } |
| |
| saveDialogExtSystemMDMAttr() { |
| if (this.tmpExtSystemMDMAttr.id === undefined) { |
| // add relation |
| if (this.selectedExtSystemAttr.relations === undefined || this.selectedExtSystemAttr.relations.length == 0) { |
| this.selectedExtSystemAttr.relations = new Array(); |
| let relation = new Relation(); |
| relation.entityType = 'MDMAttribute'; |
| relation.type = 'CHILDREN'; |
| relation.ids = new Array(); |
| this.selectedExtSystemAttr.relations.push(relation); |
| } |
| if (this.selectedExtSystemAttr.relations[0].ids === undefined) { |
| this.selectedExtSystemAttr.relations[0].ids = new Array(); |
| } |
| this.tmpExtSystemMDMAttr.id = undefined; |
| } |
| // update the name attribute with the hierarchy |
| this.tmpExtSystemMDMAttr.name = this.getAttributeValueFromNode(this.tmpExtSystemMDMAttr, 'CompType') + '.' + this.getAttributeValueFromNode(this.tmpExtSystemMDMAttr, 'CompName') + '.' + this.getAttributeValueFromNode(this.tmpExtSystemMDMAttr, 'AttrName'); |
| this.getAttributeFromNode(this.tmpExtSystemMDMAttr, 'Name').value = this.tmpExtSystemMDMAttr.name; |
| this.extSystemService.saveExtSystemMDMAttr(this.selectedEnvironment.sourceName, this.tmpExtSystemMDMAttr, this.selectedExtSystemAttr) |
| .subscribe( |
| response => this.patchResponseMDMAttr(plainToClass(Node, response.json().data)), |
| error => { |
| this.notificationService.notifyError( |
| this.translateService.instant('administration.extsystem.err-cannot-save-ext-mdm-attr'), error); |
| // restore values |
| this.getAttributeFromNode(this.tmpExtSystemMDMAttr, 'Name').value = this.getAttributeValueFromNode(this.tmpNode, 'Name'); |
| this.getAttributeFromNode(this.tmpExtSystemMDMAttr, 'CompType').value = this.getAttributeValueFromNode(this.tmpNode, 'CompType'); |
| this.getAttributeFromNode(this.tmpExtSystemMDMAttr, 'CompName').value = this.getAttributeValueFromNode(this.tmpNode, 'CompName'); |
| this.getAttributeFromNode(this.tmpExtSystemMDMAttr, 'AttrName').value = this.getAttributeValueFromNode(this.tmpNode, 'AttrName'); |
| this.tmpExtSystemMDMAttr.name = <string> this.getAttributeValueFromNode(this.tmpExtSystemMDMAttr, 'Name'); |
| this.tmpNode = undefined; |
| } |
| ); |
| |
| this.dialogExtSystemMDMAttr = false; |
| } |
| |
| cancelDialogExtSystemMDMAttr() { |
| this.dialogExtSystemMDMAttr = false; |
| this.getAttributeFromNode(this.tmpExtSystemMDMAttr, 'Name').value = this.getAttributeValueFromNode(this.tmpNode, 'Name'); |
| this.getAttributeFromNode(this.tmpExtSystemMDMAttr, 'CompType').value = this.getAttributeValueFromNode(this.tmpNode, 'CompType'); |
| this.getAttributeFromNode(this.tmpExtSystemMDMAttr, 'CompName').value = this.getAttributeValueFromNode(this.tmpNode, 'CompName'); |
| this.getAttributeFromNode(this.tmpExtSystemMDMAttr, 'AttrName').value = this.getAttributeValueFromNode(this.tmpNode, 'AttrName'); |
| this.tmpExtSystemMDMAttr = undefined; |
| } |
| |
| async loadCatalogComps(type: string) { |
| if (type !== undefined && type != null && type.length > 0) { |
| this.tmpCatalogComps = []; |
| this.tmpAttributeComps = []; |
| this.loadedCatalogComps[type] = []; |
| this.loadedAttributeComps = new Array(); |
| |
| if (this.loadedTemplateRoots[type] === undefined) { |
| await this.catalogService.getTplRootsForType(this.selectedEnvironment.sourceName, type) |
| .subscribe( |
| response => this.loadedTemplateRoots[type] = response, |
| error => this.notificationService.notifyError( |
| this.translateService.instant('administration.extsystem.err-cannot-load-comp-types'), error) |
| ); |
| } |
| |
| if (this.loadedTemplateRoots[type] !== undefined) { |
| let tmpIds = ''; |
| for (let i = 0; i < this.loadedTemplateRoots[type].length; i++) { |
| tmpIds = tmpIds + this.loadedTemplateRoots[type][i].id; |
| if (i + 1 < this.loadedTemplateRoots[type].length) tmpIds = tmpIds + ','; |
| } |
| this.dialogLoadingExtSystemComps = true; |
| await this.catalogService.getTplCompForRoot(this.selectedEnvironment.sourceName, type, tmpIds) |
| .subscribe( |
| response => { |
| for(let t in response) this.loadedCatalogComps[type].push(response[t]) |
| this.dialogLoadingExtSystemComps = false; |
| }, |
| error => { |
| this.notificationService.notifyError( |
| this.translateService.instant('administration.extsystem.err-cannot-load-comp-types'), error); |
| this.dialogLoadingExtSystemComps = false; |
| } |
| ); |
| return true; |
| } |
| } |
| return false; |
| } |
| |
| async loadAttributeComps(type: string, comp: string) { |
| if (type !== undefined && type != null && type.length > 0 && comp !== undefined && comp != null && comp.length > 0) { |
| this.loadedAttributeComps = new Array(); |
| this.tmpAttributeComps = []; |
| let compId: string = ''; |
| let rootId: string = '0'; |
| for (let i in this.loadedCatalogComps[type]) { |
| if (this.loadedCatalogComps[type][i].name === comp) { |
| compId = this.loadedCatalogComps[type][i].id; |
| break; |
| } |
| } |
| for (let i in this.loadedTemplateRoots[type]) { |
| if (this.loadedTemplateRoots[type][i].relations !== undefined) { |
| for (let j in this.loadedTemplateRoots[type][i].relations) { |
| if (this.loadedTemplateRoots[type][i].relations[j].entityType === 'TemplateComponent' && this.loadedTemplateRoots[type][i].relations[j].ids !== undefined) { |
| for (let k in this.loadedTemplateRoots[type][i].relations[j].ids) { |
| if (this.loadedTemplateRoots[type][i].relations[j].ids[k] === compId) { |
| rootId = this.loadedTemplateRoots[type][i].id; |
| break; |
| } |
| } |
| if (rootId !== '0') break; |
| } |
| } |
| if (rootId !== '0') break; |
| } |
| } |
| this.dialogLoadingExtSystemAttrs = true; |
| if (rootId !== '0' && compId !== '') { |
| await this.catalogService.getTplAttrsForComp(this.selectedEnvironment.sourceName, type, rootId, compId) |
| .subscribe( |
| response => { |
| this.loadedAttributeComps = response; |
| this.dialogLoadingExtSystemAttrs = false; |
| }, |
| error => { |
| this.notificationService.notifyError( |
| this.translateService.instant('administration.extsystem.err-cannot-load-comp-types'), error); |
| this.dialogLoadingExtSystemAttrs = false; |
| } |
| ); |
| return true; |
| } |
| this.dialogLoadingExtSystemAttrs = false; |
| } else { |
| return false; |
| } |
| } |
| |
| getCatalogComponentStr() { |
| let type: string = <string> this.getAttributeValueFromNode(this.tmpExtSystemMDMAttr, 'CompType'); |
| let data: string[] = new Array(); |
| // sensor does not have catalog elements |
| if (type !== undefined && type !== 'Sensor') { |
| let components = this.getCatalogComponents(type); |
| for (let component of components) { |
| data.push(component.name); |
| } |
| } |
| return data; |
| } |
| |
| getAttributeComponentStr() { |
| let type: string = <string> this.getAttributeValueFromNode(this.tmpExtSystemMDMAttr, 'CompType'); |
| let comp: string = <string> this.getAttributeValueFromNode(this.tmpExtSystemMDMAttr, 'CompName'); |
| let data: string[] = new Array(); |
| if (type !== undefined && comp !== undefined) { |
| let components = this.getAttributeComponents(type, comp); |
| for (let component of components) { |
| data.push(component.name); |
| } |
| } |
| return data; |
| } |
| |
| getCatalogComponents(type: string) { |
| let data: Node[] = this.loadedCatalogComps[type]; |
| if (data === undefined || data == null || data.length == 0) { |
| if (this.loadCatalogComps(type)) { |
| data = this.loadedCatalogComps[type]; |
| } |
| } |
| return data; |
| } |
| |
| getAttributeComponents(type: string, comp: string) { |
| let data: Node[] = this.loadedAttributeComps; |
| if (data === undefined || data == null || data.length == 0) { |
| if (this.loadAttributeComps(type, comp)) { |
| data = this.loadedAttributeComps; |
| } |
| } |
| return data; |
| } |
| |
| searchCatalogComps(event) { |
| this.tmpCatalogComps = []; |
| for (let i = 0; i < this.getCatalogComponentStr().length; i++) { |
| let item = this.getCatalogComponentStr()[i]; |
| if (item !== undefined && item.toLowerCase().indexOf(event.query.toLowerCase()) == 0) { |
| this.tmpCatalogComps.push(item); |
| } |
| } |
| } |
| |
| searchAttributeComps(event) { |
| this.tmpAttributeComps = []; |
| for (let i = 0; i < this.getAttributeComponentStr().length; i++) { |
| let item = this.getAttributeComponentStr()[i]; |
| if (item !== undefined && item.toLowerCase().indexOf(event.query.toLowerCase()) == 0) { |
| this.tmpAttributeComps.push(item); |
| } |
| } |
| } |
| |
| handleCompTypeSelect(event) { |
| this.tmpAttributeComps = []; |
| this.tmpCatalogComps = []; |
| this.loadedAttributeComps = new Array(); |
| this.getAttributeFromNode(this.tmpExtSystemMDMAttr, 'CompName').value = ''; |
| this.getAttributeFromNode(this.tmpExtSystemMDMAttr, 'AttrName').value = ''; |
| this.getCatalogComponentStr(); |
| } |
| |
| handleCompSelect(event) { |
| this.tmpAttributeComps = []; |
| this.loadedAttributeComps = new Array(); |
| this.getAttributeFromNode(this.tmpExtSystemMDMAttr, 'AttrName').value = ''; |
| this.getAttributeComponentStr(); |
| } |
| |
| } |