HPCCPlatformWidget.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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/array",
  20. "dojo/dom",
  21. "dojo/dom-style",
  22. "dijit/registry",
  23. "dijit/Tooltip",
  24. "dojox/widget/UpgradeBar",
  25. "hpcc/_TabContainerWidget",
  26. "hpcc/ESPRequest",
  27. "hpcc/WsAccount",
  28. "hpcc/ws_access",
  29. "hpcc/WsSMC",
  30. "hpcc/GraphWidget",
  31. "dojo/text!../templates/HPCCPlatformWidget.html",
  32. "dijit/layout/BorderContainer",
  33. "dijit/layout/TabContainer",
  34. "dijit/layout/StackContainer",
  35. "dijit/layout/StackController",
  36. "dijit/layout/ContentPane",
  37. "dijit/form/DropDownButton",
  38. "dijit/form/ComboButton",
  39. "dijit/form/TextBox",
  40. "dijit/Menu",
  41. "dijit/MenuSeparator",
  42. "dijit/Toolbar",
  43. "dijit/TooltipDialog",
  44. "hpcc/HPCCPlatformMainWidget",
  45. "hpcc/HPCCPlatformECLWidget",
  46. "hpcc/HPCCPlatformFilesWidget",
  47. "hpcc/HPCCPlatformRoxieWidget",
  48. "hpcc/HPCCPlatformOpsWidget"
  49. ], function (declare, lang, arrayUtil, dom, domStyle,
  50. registry, Tooltip,
  51. UpgradeBar,
  52. _TabContainerWidget, ESPRequest, WsAccount, WsAccess, WsSMC, GraphWidget,
  53. template) {
  54. return declare("HPCCPlatformWidget", [_TabContainerWidget], {
  55. templateString: template,
  56. baseClass: "HPCCPlatformWidget",
  57. banner: "",
  58. upgradeBar: null,
  59. postCreate: function (args) {
  60. this.inherited(arguments);
  61. this.searchText = registry.byId(this.id + "FindText");
  62. this.aboutDialog = registry.byId(this.id + "AboutDialog");
  63. this.setBannerDialog = registry.byId(this.id + "SetBannerDialog");
  64. this.searchPage = registry.byId(this.id + "_Main" + "_Search");
  65. this.stackContainer = registry.byId(this.id + "TabContainer");
  66. this.mainPage = registry.byId(this.id + "_Main");
  67. this.errWarnPage = registry.byId(this.id + "_ErrWarn");
  68. this.mainStackContainer = registry.byId(this.mainPage.id + "TabContainer");
  69. this.searchPage = registry.byId(this.id + "_Main" + "_Search");
  70. this.upgradeBar = new UpgradeBar({
  71. notifications: [],
  72. noRemindButton: ""
  73. });
  74. },
  75. startup: function (args) {
  76. this.inherited(arguments);
  77. domStyle.set(dom.byId(this.id + "StackController_stub_ErrWarn").parentNode.parentNode, {
  78. visibility: "hidden"
  79. });
  80. },
  81. // Implementation ---
  82. parseBuildString: function (build) {
  83. this.build = {};
  84. this.build.orig = build;
  85. this.build.prefix = "";
  86. this.build.postfix = "";
  87. var verArray = build.split("[");
  88. if (verArray.length > 1) {
  89. this.build.postfix = verArray[1].split("]")[0];
  90. }
  91. verArray = verArray[0].split("_");
  92. if (verArray.length > 1) {
  93. this.build.prefix = verArray[0];
  94. verArray.splice(0, 1);
  95. }
  96. this.build.version = verArray.join("_");
  97. },
  98. refreshActivityResponse: function(response) {
  99. if (lang.exists("ActivityResponse.Build", response)) {
  100. this.parseBuildString(response.ActivityResponse.Build);
  101. this.banner = lang.exists("ActivityResponse.BannerContent", response) ? response.ActivityResponse.BannerContent : "";
  102. if (this.banner) {
  103. this.upgradeBar.notify("<div style='text-align:center'><b>" + this.banner + "</b></div>");
  104. this.upgradeBar.show();
  105. }
  106. }
  107. },
  108. init: function (params) {
  109. if (this.inherited(arguments))
  110. return;
  111. var context = this;
  112. registry.byId(context.id + "SetBanner").set("disabled", true);
  113. WsAccount.MyAccount({
  114. }).then(function (response) {
  115. if (lang.exists("MyAccountResponse.username", response)) {
  116. dom.byId(context.id + "UserID").innerHTML = response.MyAccountResponse.username;
  117. context.checkIfAdmin(response.MyAccountResponse.username);
  118. }
  119. });
  120. WsSMC.Activity({
  121. }).then(function (response) {
  122. context.refreshActivityResponse(response);
  123. });
  124. this.createStackControllerTooltip(this.id + "_ECL", "ECL");
  125. this.createStackControllerTooltip(this.id + "_Files", "Files");
  126. this.createStackControllerTooltip(this.id + "_Queries", "Published Queries");
  127. this.createStackControllerTooltip(this.id + "_OPS", "Operations");
  128. this.initTab();
  129. },
  130. initTab: function () {
  131. var currSel = this.getSelectedChild();
  132. if (currSel && !currSel.initalized) {
  133. if (currSel.init) {
  134. currSel.init({});
  135. }
  136. }
  137. },
  138. getTitle: function () {
  139. return "HPCC Platform";
  140. },
  141. checkIfAdmin: function (user) {
  142. var context = this;
  143. if(user == null){
  144. registry.byId(context.id + "SetBanner").set("disabled", false);
  145. }else{
  146. WsAccess.UserEdit({
  147. request: {
  148. username: user
  149. }
  150. }).then(function (response) {
  151. if (lang.exists("UserEditResponse.Groups.Group", response)) {
  152. arrayUtil.forEach(response.UserEditResponse.Groups.Group, function (item, idx) {
  153. if(item.name == "Administrators"){
  154. registry.byId(context.id + "SetBanner").set("disabled", false);
  155. return true;
  156. }
  157. });
  158. }
  159. });
  160. }
  161. },
  162. // Hitched actions ---
  163. _onFind: function (evt) {
  164. this.stackContainer.selectChild(this.mainPage);
  165. this.mainStackContainer.selectChild(this.searchPage);
  166. this.searchPage.doSearch(this.searchText.get("value"));
  167. },
  168. _onOpenLegacy: function (evt) {
  169. var win = window.open("\\", "_blank");
  170. win.focus();
  171. },
  172. _onOpenReleaseNotes: function (evt) {
  173. var win = window.open("http://hpccsystems.com/download/free-community-edition-known-limitations#" + this.build.version, "_blank");
  174. win.focus();
  175. },
  176. _onOpenErrWarn: function (evt) {
  177. this.stackContainer.selectChild(this.errWarnPage);
  178. },
  179. _onAboutLoaded: false,
  180. _onAbout: function (evt) {
  181. if (!this._onAboutLoaded) {
  182. this._onAboutLoaded = true;
  183. dom.byId(this.id + "ServerVersion").value = this.build.version;
  184. var gc = registry.byId(this.id + "GraphControl");
  185. dom.byId(this.id + "GraphControlVersion").value = gc.getVersion();
  186. }
  187. this.aboutDialog.show();
  188. },
  189. _onAboutClose: function (evt) {
  190. this.aboutDialog.hide();
  191. },
  192. _onSetBanner: function (evt) {
  193. dom.byId(this.id + "BannerText").value = this.banner;
  194. this.setBannerDialog.show();
  195. },
  196. _onSetBannerOk: function (evt) {
  197. var context = this;
  198. WsSMC.Activity({
  199. request: {
  200. FromSubmitBtn: true,
  201. BannerAction: dom.byId(this.id + "BannerText").value != "",
  202. EnableChatURL: 0,
  203. BannerContent: dom.byId(this.id + "BannerText").value,
  204. BannerColor: "red",
  205. BannerSize: 4,
  206. BannerScroll: 2
  207. }
  208. }).then(function (response) {
  209. context.refreshActivityResponse(response);
  210. });
  211. this.setBannerDialog.hide();
  212. },
  213. _onSetBannerCancel: function (evt) {
  214. this.setBannerDialog.hide();
  215. },
  216. createStackControllerTooltip: function (widgetID, text) {
  217. return new Tooltip({
  218. connectId: [this.id + "StackController_" + widgetID],
  219. label: text,
  220. showDelay: 1,
  221. position: ["below"]
  222. });
  223. }
  224. });
  225. });