QuerySetDetailsWidget.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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/dom",
  20. "dojo/dom-attr",
  21. "dojo/dom-class",
  22. "dojo/query",
  23. "dojo/store/Memory",
  24. "dojo/store/Observable",
  25. "dojo/promise/all",
  26. "dijit/registry",
  27. "dgrid/OnDemandGrid",
  28. "dgrid/Keyboard",
  29. "dgrid/Selection",
  30. "dgrid/selector",
  31. "dgrid/extensions/ColumnResizer",
  32. "dgrid/extensions/DijitRegistry",
  33. "hpcc/ESPWorkunit",
  34. "hpcc/ESPQuery",
  35. "hpcc/WsWorkunits",
  36. "hpcc/WsTopology",
  37. "hpcc/_TabContainerWidget",
  38. "hpcc/QuerySetLogicalFilesWidget",
  39. "hpcc/QuerySetErrorsWidget",
  40. "hpcc/QueryTestWidget",
  41. "dojo/text!../templates/QuerySetDetailsWidget.html",
  42. "dijit/layout/BorderContainer",
  43. "dijit/layout/TabContainer",
  44. "dijit/layout/ContentPane",
  45. "dijit/form/Textarea",
  46. "dijit/form/Button",
  47. "dijit/form/CheckBox",
  48. "dijit/Toolbar",
  49. "dijit/ToolbarSeparator",
  50. "dijit/TooltipDialog",
  51. "dijit/TitlePane",
  52. "hpcc/WUDetailsWidget"
  53. ], function (declare, lang, dom, domAttr, domClass, query, Memory, Observable, all,
  54. registry,
  55. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  56. ESPWorkunit, ESPQuery, WsWorkunits, WsTopology, _TabContainerWidget, QuerySetLogicalFilesWidget, QuerySetErrorsWidget, QueryTestWidget,
  57. template) {
  58. return declare("QuerySetDetailsWidget", [_TabContainerWidget], {
  59. templateString: template,
  60. baseClass: "QuerySetDetailsWidget",
  61. query: null,
  62. initalized: false,
  63. summaryTab: null,
  64. summaryTabLoaded:false,
  65. errorsTab: null,
  66. errorsTabLoaded: false,
  67. graphsTab: null,
  68. graphsTabLoaded: false,
  69. logicalFilesTab: null,
  70. logicalFilesTabLoaded: false,
  71. superFilesTab: false,
  72. superFilesTabLoaded: null,
  73. workunitsTab: null,
  74. workunitsTabLoaded: false,
  75. testPagesTab: null,
  76. testPagesLoaded: false,
  77. loaded: false,
  78. postCreate: function (args) {
  79. this.inherited(arguments);
  80. this.summaryTab = registry.byId(this.id + "_Summary");
  81. this.errorsTab = registry.byId(this.id + "_Errors");
  82. this.graphsTab = registry.byId(this.id + "_Graphs");
  83. this.logicalFilesTab = registry.byId(this.id + "_QuerySetLogicalFiles");
  84. this.superFilesTab = registry.byId(this.id + "_QuerySetSuperFiles");
  85. this.workunitsTab = registry.byId(this.id + "_Workunit");
  86. this.testPagesTab = registry.byId(this.id + "_TestPages");
  87. },
  88. // Hitched actions ---
  89. _onSave: function (event) {
  90. var suspended = registry.byId(this.id + "Suspended").get("value");
  91. var activated = registry.byId(this.id + "Activated").get("value");
  92. var context = this;
  93. all({
  94. suspend: this.query.setSuspended(suspended),
  95. activate: this.query.setActivated(activated)
  96. });
  97. },
  98. _onDelete: function (event) {
  99. if (confirm('Delete selected workunits?')) {
  100. this.query.doDelete();
  101. }
  102. },
  103. _onRefresh: function () {
  104. this.query.refresh();
  105. },
  106. // Implementation ---
  107. init: function (params) {
  108. if (this.inherited(arguments))
  109. return;
  110. this.query = ESPQuery.Get(params.Id);
  111. var context = this;
  112. var data = this.query.getData();
  113. for (var key in data) {
  114. this.updateInput(key, null, data[key]);
  115. }
  116. this.query.watch(function (name, oldValue, newValue) {
  117. context.updateInput(name, oldValue, newValue);
  118. });
  119. this.query.refresh();
  120. this.selectChild(this.summaryWidget, true);
  121. },
  122. initTab: function () {
  123. var currSel = this.getSelectedChild();
  124. if (currSel.id == this.summaryTab.id && !this.summaryTabLoaded) {
  125. this.summaryTabLoaded = true;
  126. } else if (currSel.id == this.workunitsTab.id && !this.workunitsTabLoaded) {
  127. this.workunitsTabLoaded = true;
  128. this.workunitsTab.init({
  129. Wuid: this.query.Wuid
  130. });
  131. } else if (currSel.id == this.errorsTab.id && !this.errorsTabLoaded) {
  132. this.errorsTabLoaded = true;
  133. this.errorsTab.init({
  134. Query: this.query
  135. });
  136. } else if (currSel.id == this.graphsTab.id && !this.graphsTabLoaded) {
  137. this.graphsTabLoaded = true;
  138. this.graphsTab.init({
  139. Query: this.query
  140. });
  141. } else if (currSel.id == this.logicalFilesTab.id && !this.logicalFilesTabLoaded) {
  142. this.logicalFilesTabLoaded = true;
  143. this.logicalFilesTab.init({
  144. QueryId: this.query.Id,
  145. QuerySet: this.query.QuerySet,
  146. Query: this.query
  147. });
  148. } else if (currSel.id == this.testPagesTab.id && !this.testPagesTabLoaded) {
  149. this.testPagesTabLoaded = true;
  150. this.testPagesTab.init({
  151. QueryId: this.query.Id,
  152. QuerySet: this.query.QuerySet,
  153. Query: this.query
  154. });
  155. }
  156. },
  157. updateInput: function (name, oldValue, newValue) {
  158. var registryNode = registry.byId(this.id + name);
  159. if (registryNode) {
  160. registryNode.set("value", newValue);
  161. } else {
  162. var domElem = dom.byId(this.id + name);
  163. if (domElem) {
  164. switch (domElem.tagName) {
  165. case "SPAN":
  166. case "DIV":
  167. domAttr.set(this.id + name, "innerHTML", newValue);
  168. break;
  169. case "INPUT":
  170. case "TEXTAREA":
  171. domAttr.set(this.id + name, "value", newValue);
  172. break;
  173. default:
  174. alert(domElem.tagName);
  175. break;
  176. }
  177. }
  178. }
  179. if (name === "Wuid") {
  180. this.workunitsTab.set("title", newValue);
  181. }
  182. if (name === "Suspended") {
  183. dom.byId(this.id + "SuspendImg").src = newValue ? "img/suspended.png" : "img/unsuspended.png";
  184. }
  185. if (name === "Activated") {
  186. dom.byId(this.id + "ActiveImg").src = newValue ? "img/active.png" : "img/inactive.png";
  187. }
  188. else if (name === "CountGraphs" && newValue) {
  189. this.graphsTab.set("title", "Graphs " + "(" + newValue + ")");
  190. } else if (name === "graphs") {
  191. this.graphsTab.set("title", "Graphs " + "(" + newValue.length + ")");
  192. var tooltip = "";
  193. for (var i = 0; i < newValue.length; ++i) {
  194. if (tooltip != "")
  195. tooltip += "\n";
  196. tooltip += newValue[i].Name;
  197. if (newValue[i].Time)
  198. tooltip += " " + newValue[i].Time;
  199. }
  200. this.graphsTab.set("tooltip", tooltip);
  201. }
  202. else if (name === "LogicalFiles") {
  203. if (lang.exists("Item.length", newValue)) {
  204. this.logicalFilesTab.set("title", "Logical Files " + "(" + newValue.Item.length + ")");
  205. var tooltip = "";
  206. for (var i = 0; i < newValue.Item.length; ++i) {
  207. if (tooltip != "")
  208. tooltip += "\n";
  209. tooltip += newValue.Item[i];
  210. }
  211. this.logicalFilesTab.set("tooltip", tooltip);
  212. }
  213. }
  214. else if (name === "Clusters") {
  215. if (lang.exists("ClusterQueryState.length", newValue)) {
  216. this.errorsTab.set("title", "Errors / Status " + "(" + newValue.ClusterQueryState.length + ")");
  217. var tooltip = "";
  218. for (var i = 0; i < newValue.ClusterQueryState.length; ++i) {
  219. if (tooltip != "")
  220. tooltip += "\n";
  221. tooltip += newValue.ClusterQueryState[i].Cluster + " (" + newValue.ClusterQueryState[i].State + ")";
  222. }
  223. this.errorsTab.set("tooltip", tooltip);
  224. }
  225. }
  226. }
  227. });
  228. });