QuerySetDetailsWidget.js 9.5 KB

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