ESPResult.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*##############################################################################
  2. # Copyright (C) 2011 HPCC Systems.
  3. #
  4. # All rights reserved. This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ############################################################################## */
  17. define([
  18. "dojo/_base/declare",
  19. "dojo/data/ObjectStore",
  20. "hpcc/WUResultStore",
  21. "hpcc/ESPBase"
  22. ], function (declare, ObjectStore, WUResultStore, ESPBase) {
  23. return declare(ESPBase, {
  24. store: null,
  25. Total: "-1",
  26. constructor: function (args) {
  27. declare.safeMixin(this, args);
  28. this.store = new WUResultStore({
  29. wuid: this.wuid,
  30. sequence: this.Sequence,
  31. isComplete: this.isComplete()
  32. });
  33. },
  34. getName: function () {
  35. return this.Name;
  36. },
  37. isComplete: function () {
  38. return this.Total != "-1";
  39. },
  40. getStructure: function () {
  41. var retVal = [];
  42. retVal.push({
  43. name: "##",
  44. field: this.store.idProperty,
  45. width: "40px"
  46. });
  47. for (var i = 0; i < this.ECLSchemas.length; ++i) {
  48. retVal.push({
  49. name: this.ECLSchemas[i].ColumnName,
  50. field: this.ECLSchemas[i].ColumnName,
  51. width: this.extractWidth(this.ECLSchemas[i].ColumnType, this.ECLSchemas[i].ColumnName)
  52. });
  53. }
  54. return retVal;
  55. },
  56. extractWidth: function (type, name) {
  57. var numStr = "0123456789";
  58. var retVal = -1;
  59. var i = type.length;
  60. while (i >= 0) {
  61. if (numStr.indexOf(type.charAt(--i)) == -1)
  62. break;
  63. }
  64. if (i > 0)
  65. retVal = parseInt(type.substring(i + 1, type.length));
  66. if (retVal < name.length)
  67. retVal = name.length;
  68. return Math.round(retVal * 2 / 3);
  69. },
  70. getObjectStore: function () {
  71. return ObjectStore({
  72. objectStore: this.store
  73. });
  74. },
  75. getECLRecord: function () {
  76. var retVal = "RECORD\n";
  77. for (var i = 0; i < this.ECLSchemas.length; ++i) {
  78. retVal += "\t" + this.ECLSchemas[i].ColumnType + "\t" + this.ECLSchemas[i].ColumnName + ";\n";
  79. }
  80. retVal += "END;\n";
  81. return retVal;
  82. }
  83. });
  84. });