QuerySetDetailsWidget.js 8.8 KB

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