ESPResult.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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/data/ObjectStore",
  19. "hpcc/WsWorkunits",
  20. "hpcc/ESPBase"
  21. ], function (declare, ObjectStore, WsWorkunits, ESPBase) {
  22. return declare(ESPBase, {
  23. store: null,
  24. Total: "-1",
  25. constructor: function (args) {
  26. declare.safeMixin(this, args);
  27. this.store = new WsWorkunits.WUResult({
  28. wuid: this.wuid,
  29. sequence: this.Sequence,
  30. isComplete: this.isComplete()
  31. });
  32. },
  33. getName: function () {
  34. return this.Name;
  35. },
  36. isComplete: function () {
  37. return this.Total != "-1";
  38. },
  39. getStructure: function () {
  40. var retVal = [];
  41. retVal.push({
  42. name: "##",
  43. field: this.store.idProperty,
  44. width: "40px"
  45. });
  46. for (var i = 0; i < this.ECLSchemas.length; ++i) {
  47. retVal.push({
  48. name: this.ECLSchemas[i].ColumnName,
  49. field: this.ECLSchemas[i].ColumnName,
  50. width: this.extractWidth(this.ECLSchemas[i].ColumnType, this.ECLSchemas[i].ColumnName)
  51. });
  52. }
  53. return retVal;
  54. },
  55. extractWidth: function (type, name) {
  56. var numStr = "0123456789";
  57. var retVal = -1;
  58. var i = type.length;
  59. while (i >= 0) {
  60. if (numStr.indexOf(type.charAt(--i)) == -1)
  61. break;
  62. }
  63. if (i > 0)
  64. retVal = parseInt(type.substring(i + 1, type.length));
  65. if (retVal < name.length)
  66. retVal = name.length;
  67. return Math.round(retVal * 2 / 3);
  68. },
  69. getObjectStore: function () {
  70. return ObjectStore({
  71. objectStore: this.store
  72. });
  73. },
  74. getECLRecord: function () {
  75. var retVal = "RECORD\n";
  76. for (var i = 0; i < this.ECLSchemas.length; ++i) {
  77. retVal += "\t" + this.ECLSchemas[i].ColumnType + "\t" + this.ECLSchemas[i].ColumnName + ";\n";
  78. }
  79. retVal += "END;\n";
  80. return retVal;
  81. }
  82. });
  83. });