HPCCPlatformWidget.js 9.8 KB

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