123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- /*##############################################################################
- # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- ############################################################################## */
- define([
- "dojo/_base/declare",
- "dojo/data/ObjectStore",
- "dojo/dom-construct",
- "dojox/xml/parser",
- "dojox/xml/DomParser",
- "hpcc/WsWorkunits",
- "hpcc/ESPBase"
- ], function (declare, ObjectStore, domConstruct,
- parser, DomParser,
- WsWorkunits, ESPBase) {
- return declare(ESPBase, {
- store: null,
- hasChildDataset: false,
- Total: "-1",
- constructor: function (args) {
- declare.safeMixin(this, args);
- this.store = new WsWorkunits.WUResult({
- wuid: this.wuid,
- sequence: this.Sequence,
- isComplete: this.isComplete()
- });
- },
- getName: function () {
- return this.Name;
- },
- isComplete: function () {
- return this.Total != "-1";
- },
- getFirstSchemaNode: function (node, name) {
- if (node && node.attributes) {
- if ((node.localName && node.localName == name) || (node.hasAttributes() && node.getAttribute("name") == name)) {
- return node;
- }
- }
- for (var i = 0; i < node.childNodes.length; ++i) {
- var retVal = this.getFirstSchemaNode(node.childNodes[i], name);
- if (retVal) {
- return retVal;
- }
- }
- return null;
- },
- getFirstSequenceNode: function (schemaNode) {
- var row = this.getFirstSchemaNode(schemaNode, "Row");
- if (!row)
- return null;
- var complexType = this.getFirstSchemaNode(row, "complexType");
- if (!complexType)
- return null;
- return this.getFirstSchemaNode(complexType, "sequence");
- },
- rowToTable: function (cell) {
- var table = domConstruct.create("table", { border: 1, cellspacing: 0, width: "100%" });
- if (cell && cell.Row) {
- if (!cell.Row.length) {
- cell.Row = [cell.Row];
- }
- for (i = 0; i < cell.Row.length; ++i) {
- if (i == 0) {
- var tr = domConstruct.create("tr", null, table);
- for (key in cell.Row[i]) {
- var th = domConstruct.create("th", { innerHTML: key }, tr);
- }
- }
- var tr = domConstruct.create("tr", null, table);
- for (key in cell.Row[i]) {
- if (cell.Row[i][key].Row) {
- var td = domConstruct.create("td", null, tr);
- td.appendChild(this.rowToTable(cell.Row[i][key]));
- } else {
- var td = domConstruct.create("td", { innerHTML: cell.Row[i][key] }, tr);
- }
- }
- }
- }
- return table;
- },
- getRowStructure: function (parentNode) {
- var retVal = [];
- var sequence = this.getFirstSequenceNode(parentNode, "sequence");
- if (!sequence)
- return retVal;
- for (var i = 0; i < sequence.childNodes.length; ++i) {
- var node = sequence.childNodes[i];
- if (node.hasAttributes()) {
- var name = node.getAttribute("name");
- var type = node.getAttribute("type");
- if (name && type) {
- retVal.push({
- name: name,
- field: name,
- width: this.extractWidth(type, name),
- classes: "resultGridCell"
- });
- }
- if (node.hasChildNodes()) {
- this.hasChildDataset = true;
- var context = this;
- retVal.push({
- name: name,
- field: name,
- formatter: function (cell, row, grid) {
- var div = document.createElement("div");
- div.appendChild(context.rowToTable(cell));
- return div.innerHTML;
- },
- width: this.getRowWidth(node),
- classes: "resultGridCell"
- });
- }
- }
- }
- return retVal;
- },
- getStructure: function () {
- var structure = [
- {
- cells: [
- [
- {
- name: "##", field: this.store.idProperty, width: "40px", classes: "resultGridCell"
- }
- ]
- ]
- }
- ];
- var dom = parser.parse(this.XmlSchema);
- var dataset = this.getFirstSchemaNode(dom, "Dataset");
- var innerStruct = this.getRowStructure(dataset);
- for (var i = 0; i < innerStruct.length; ++i) {
- structure[0].cells[structure[0].cells.length - 1].push(innerStruct[i]);
- }
- return structure;
- },
- getRowWidth: function (parentNode) {
- var retVal = 0;
- var sequence = this.getFirstSequenceNode(parentNode, "sequence");
- if (!sequence)
- return retVal;
- for (var i = 0; i < sequence.childNodes.length; ++i) {
- var node = sequence.childNodes[i];
- if (node.hasAttributes()) {
- var name = node.getAttribute("name");
- var type = node.getAttribute("type");
- if (name && type) {
- retVal += this.extractWidth(type, name);
- } else if (node.hasChildNodes()) {
- retVal += this.getRowWidth(node);
- }
- }
- }
- return retVal;
- },
- extractWidth: function (type, name) {
- var retVal = -1;
- switch (type) {
- case "xs:boolean":
- retVal = 5;
- break;
- case "xs:integer":
- retVal = 8;
- break;
- case "xs:nonNegativeInteger":
- retVal = 8;
- break;
- case "xs:double":
- retVal = 8;
- break;
- default:
- var numStr = "0123456789";
- var underbarPos = type.lastIndexOf("_");
- var i = underbarPos > 0 ? underbarPos : type.length;
- while (i >= 0) {
- if (numStr.indexOf(type.charAt(--i)) == -1)
- break;
- }
- if (i > 0 && i + 1 < type.length) {
- retVal = parseInt(type.substring(i + 1, type.length));
- }
- if (type.indexOf("data") == 0) {
- retVal *= 2;
- }
- break;
- }
- if (retVal < name.length)
- retVal = name.length;
- return retVal;
- },
- getObjectStore: function () {
- return ObjectStore({
- objectStore: this.store
- });
- },
- getECLRecord: function () {
- var retVal = "RECORD\n";
- for (var i = 0; i < this.ECLSchemas.length; ++i) {
- retVal += "\t" + this.ECLSchemas[i].ColumnType + "\t" + this.ECLSchemas[i].ColumnName + ";\n";
- }
- retVal += "END;\n";
- return retVal;
- }
- });
- });
|