ESPDFUWorkunit.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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/lang",
  19. "dojo/_base/xhr",
  20. "hpcc/ESPResult",
  21. "hpcc/ESPBase"
  22. ], function (declare, lang, xhr, ESPResult, ESPBase) {
  23. return declare(ESPBase, {
  24. Wuid: "",
  25. stateID: 0,
  26. state: "",
  27. text: "",
  28. resultCount: 0,
  29. results: [],
  30. graphs: [],
  31. exceptions: [],
  32. timers: [],
  33. onCreate: function () {
  34. },
  35. onUpdate: function () {
  36. },
  37. onSubmit: function () {
  38. },
  39. constructor: function (args) {
  40. declare.safeMixin(this, args);
  41. },
  42. isComplete: function () {
  43. switch (this.stateID) {
  44. case 6: //DFUStateFinished:
  45. return true;
  46. }
  47. return false;
  48. },
  49. monitor: function (callback, monitorDuration) {
  50. if (!monitorDuration)
  51. monitorDuration = 0;
  52. var request = {
  53. wuid: this.Wuid
  54. };
  55. // request['rawxml_'] = "1";
  56. var context = this;
  57. xhr.post({
  58. url: this.getBaseURL("FileSpray") + "/GetDFUWorkunit.json",
  59. handleAs: "json",
  60. content: request,
  61. load: function (response) {
  62. var workunit = response.GetDFUWorkunitResponse.result;
  63. context.stateID = workunit.State;
  64. context.state = workunit.StateMessage;
  65. if (callback) {
  66. callback(workunit);
  67. }
  68. if (!context.isComplete()) {
  69. var timeout = 30; // Seconds
  70. if (monitorDuration < 5) {
  71. timeout = 1;
  72. } else if (monitorDuration < 10) {
  73. timeout = 2;
  74. } else if (monitorDuration < 30) {
  75. timeout = 5;
  76. } else if (monitorDuration < 60) {
  77. timeout = 10;
  78. } else if (monitorDuration < 120) {
  79. timeout = 20;
  80. }
  81. setTimeout(function () {
  82. context.monitor(callback, monitorDuration + timeout);
  83. }, timeout * 1000);
  84. }
  85. },
  86. error: function () {
  87. done = true;
  88. }
  89. });
  90. },
  91. fetchStructure: function (format, onFetchStructure) {
  92. var request = {
  93. Name: this.logicalName,
  94. Format: format,
  95. rawxml_: true
  96. };
  97. var context = this;
  98. xhr.post({
  99. url: this.getBaseURL("FileSpray") + "/DFUWUFile",
  100. handleAs: "text",
  101. content: request,
  102. load: function (response) {
  103. onFetchStructure(response);
  104. },
  105. error: function (e) {
  106. }
  107. });
  108. },
  109. fetchDEF: function (onFetchXML) {
  110. this.fetchStructure("def", onFetchXML);
  111. },
  112. fetchXML: function (onFetchXML) {
  113. var request = {
  114. Wuid: this.Wuid
  115. };
  116. var context = this;
  117. xhr.post({
  118. url: this.getBaseURL("FileSpray") + "/DFUWUFile",
  119. handleAs: "text",
  120. content: request,
  121. load: function (response) {
  122. onFetchXML(response);
  123. },
  124. error: function (e) {
  125. var d = 0;
  126. }
  127. });
  128. },
  129. create: function (ecl) {
  130. },
  131. update: function (request, appData, callback) {
  132. },
  133. submit: function (target) {
  134. },
  135. _resubmit: function (clone, resetWorkflow, callback) {
  136. },
  137. clone: function (callback) {
  138. this._resubmit(true, false, callback);
  139. },
  140. resubmit: function (callback) {
  141. this._resubmit(false, false, callback);
  142. },
  143. restart: function (callback) {
  144. this._resubmit(false, true, callback);
  145. },
  146. _action: function (action, callback) {
  147. },
  148. abort: function (callback) {
  149. this._action("Abort", callback);
  150. },
  151. doDelete: function (callback) {
  152. this._action("Delete", callback);
  153. },
  154. getInfo: function (args) {
  155. var request = {
  156. wuid: this.Wuid
  157. };
  158. var context = this;
  159. xhr.post({
  160. url: this.getBaseURL("FileSpray") + "/GetDFUWorkunit.json",
  161. handleAs: "json",
  162. content: request,
  163. load: function (response) {
  164. var workunit = response.GetDFUWorkunitResponse.result;
  165. context.GetDFUWorkunitResponse = workunit;
  166. if (args.onGetAll) {
  167. args.onGetAll(workunit);
  168. }
  169. },
  170. error: function (e) {
  171. }
  172. });
  173. },
  174. getState: function () {
  175. return this.state;
  176. },
  177. getProtectedImage: function () {
  178. if (this.protected) {
  179. return "img/locked.png"
  180. }
  181. return "img/unlocked.png"
  182. },
  183. getStateImage: function () {
  184. switch (this.stateID) {
  185. case 6:
  186. return "img/workunit_completed.png";
  187. }
  188. return "img/workunit.png";
  189. }
  190. });
  191. });