UNPKG

igniteui-webcomponents-datasources

Version:

Reference custom data providers for the Ignite UI Web Components data source.

66 lines (65 loc) 2.17 kB
import { EntityProperty } from "./EntityProperty"; import { XName } from "igniteui-webcomponents-core"; import { toArray } from './util'; export class Entity { constructor(name, entityNode) { this._properties = null; this._primaryKey = null; this._name = null; this.name = name; this.loadProperties(entityNode); this.loadPrimaryKey(entityNode); } get name() { return this._name; } set name(value) { this._name = value; } get properties() { if (null == this._properties) { this._properties = new Map(); } return this._properties; } get primaryKey() { if (null == this._primaryKey) { this._primaryKey = []; } return this._primaryKey; } loadProperties(entityNode) { let children = toArray(entityNode.elements()); let elementCount = children.length; let nameAttr = XName.get("Name", ""); let typeAttr = XName.get("Type", ""); for (let i = 0; i < elementCount; i++) { let node = children[i]; if (node.name.localName == "Property") { let name = node.attribute(nameAttr).value; let type = node.attribute(typeAttr).value; this.properties.set(name, new EntityProperty(name, type)); } } ; } loadPrimaryKey(entityNode) { let children = toArray(entityNode.elements()); let elementCount = children.length; let nameAttr = XName.get("Name", ""); for (let i = 0; i < elementCount; i++) { let node = children[i]; if (node.name.localName == "Key") { let subChildren = toArray(node.elements()); let keyNodeCOunt = subChildren.length; for (let j = 0; j < keyNodeCOunt; j++) { let keyNode = subChildren[j]; if (keyNode.name.localName == "PropertyRef") { this.primaryKey.push(keyNode.attribute(nameAttr).value); } } } } ; } }