ESPResult.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "dojo/_base/declare",
  18. "dojo/_base/Deferred",
  19. "dojo/data/ObjectStore",
  20. "hpcc/WsWorkunits",
  21. "hpcc/ESPBase"
  22. ], function (declare, Deferred, ObjectStore, WsWorkunits, ESPBase) {
  23. return declare(ESPBase, {
  24. store: null,
  25. Total: "-1",
  26. constructor: function (args) {
  27. declare.safeMixin(this, args);
  28. if (this.Sequence != null) {
  29. this.store = new WsWorkunits.WUResult({
  30. wuid: this.wuid,
  31. sequence: this.Sequence,
  32. isComplete: this.isComplete()
  33. });
  34. } else {
  35. this.store = new WsWorkunits.WUResult({
  36. wuid: this.wuid,
  37. name: this.Name,
  38. isComplete: true
  39. });
  40. }
  41. },
  42. getName: function () {
  43. return this.Name;
  44. },
  45. getID: function () {
  46. if (this.Sequence != null) {
  47. return this.Sequence;
  48. }
  49. return this.Name;
  50. },
  51. isComplete: function () {
  52. return this.Total != "-1";
  53. },
  54. getStructure: function () {
  55. var retVal = [];
  56. retVal.push({
  57. name: "##",
  58. field: this.store.idProperty,
  59. width: "40px"
  60. });
  61. if (this.ECLSchemas) {
  62. for (var i = 0; i < this.ECLSchemas.ECLSchemaItem.length; ++i) {
  63. retVal.push({
  64. name: this.ECLSchemas.ECLSchemaItem[i].ColumnName,
  65. field: this.ECLSchemas.ECLSchemaItem[i].ColumnName,
  66. width: this.extractWidth(this.ECLSchemas.ECLSchemaItem[i].ColumnType, this.ECLSchemas.ECLSchemaItem[i].ColumnName)
  67. });
  68. }
  69. } else {
  70. var context = this;
  71. Deferred.when(this.store.query("*", {
  72. start: 0,
  73. count: 1,
  74. sync: true
  75. }), function (rows) {
  76. if (rows.length) {
  77. for (var key in rows[0]) {
  78. if (key != "myInjectedRowNum") {
  79. retVal.push({
  80. name: key,
  81. field: key,
  82. width: context.extractWidth("string12", key)
  83. });
  84. }
  85. }
  86. }
  87. });
  88. }
  89. return retVal;
  90. },
  91. extractWidth: function (type, name) {
  92. var numStr = "0123456789";
  93. var retVal = -1;
  94. var i = type.length;
  95. while (i >= 0) {
  96. if (numStr.indexOf(type.charAt(--i)) == -1)
  97. break;
  98. }
  99. if (i > 0)
  100. retVal = parseInt(type.substring(i + 1, type.length));
  101. if (retVal < name.length)
  102. retVal = name.length;
  103. return Math.round(retVal * 2 / 3);
  104. },
  105. getObjectStore: function () {
  106. return ObjectStore({
  107. objectStore: this.store
  108. });
  109. },
  110. getECLRecord: function () {
  111. var retVal = "RECORD\n";
  112. for (var i = 0; i < this.ECLSchemas.ECLSchemaItem.length; ++i) {
  113. retVal += "\t" + this.ECLSchemas.ECLSchemaItem[i].ColumnType + "\t" + this.ECLSchemas.ECLSchemaItem[i].ColumnName + ";\n";
  114. }
  115. retVal += "END;\n";
  116. return retVal;
  117. }
  118. });
  119. });