QuerySetDetailsWidget.js 9.6 KB

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