HPCCPlatformWidget.js 8.8 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/common",
  21. "dojo/i18n!./nls/HPCCPlatformWidget",
  22. "dojo/_base/array",
  23. "dojo/dom",
  24. "dojo/dom-style",
  25. "dijit/registry",
  26. "dijit/Tooltip",
  27. "dojox/widget/UpgradeBar",
  28. "hpcc/_TabContainerWidget",
  29. "hpcc/ESPActivity",
  30. "hpcc/ws_account",
  31. "hpcc/ws_access",
  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, nlsCommon, nlsSpecific, arrayUtil, dom, domStyle,
  53. registry, Tooltip,
  54. UpgradeBar,
  55. _TabContainerWidget, ESPActivity, WsAccount, WsAccess, WsSMC, GraphWidget,
  56. template) {
  57. return declare("HPCCPlatformWidget", [_TabContainerWidget], {
  58. templateString: template,
  59. baseClass: "HPCCPlatformWidget",
  60. i18n: lang.mixin(nlsCommon, nlsSpecific),
  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. init: function (params) {
  113. if (this.inherited(arguments))
  114. return;
  115. var context = this;
  116. registry.byId(context.id + "SetBanner").set("disabled", true);
  117. WsAccount.MyAccount({
  118. }).then(function (response) {
  119. if (lang.exists("MyAccountResponse.username", response)) {
  120. dom.byId(context.id + "UserID").innerHTML = response.MyAccountResponse.username;
  121. context.checkIfAdmin(response.MyAccountResponse.username);
  122. }
  123. });
  124. this.activity = ESPActivity.Get();
  125. this.activity.watch("Build", function (name, oldValue, newValue) {
  126. context.parseBuildString(newValue);
  127. });
  128. this.activity.watch("BannerContent", function (name, oldValue, newValue) {
  129. context.refreshBanner(newValue);
  130. });
  131. this.createStackControllerTooltip(this.id + "_ECL", this.i18n.ECL);
  132. this.createStackControllerTooltip(this.id + "_Files", this.i18n.files);
  133. this.createStackControllerTooltip(this.id + "_RoxieQueries", this.i18n.publishedQueries);
  134. this.createStackControllerTooltip(this.id + "_OPS", this.i18n.operations);
  135. this.initTab();
  136. },
  137. initTab: function () {
  138. var currSel = this.getSelectedChild();
  139. if (currSel && !currSel.initalized) {
  140. if (currSel.init) {
  141. currSel.init({});
  142. }
  143. }
  144. },
  145. getTitle: function () {
  146. return "HPCC Platform";
  147. },
  148. checkIfAdmin: function (user) {
  149. var context = this;
  150. if(user == null){
  151. registry.byId(context.id + "SetBanner").set("disabled", false);
  152. }else{
  153. WsAccess.UserEdit({
  154. request: {
  155. username: user
  156. }
  157. }).then(function (response) {
  158. if (lang.exists("UserEditResponse.Groups.Group", response)) {
  159. arrayUtil.forEach(response.UserEditResponse.Groups.Group, function (item, idx) {
  160. if(item.name == "Administrators"){
  161. registry.byId(context.id + "SetBanner").set("disabled", false);
  162. return true;
  163. }
  164. });
  165. }
  166. });
  167. }
  168. },
  169. // Hitched actions ---
  170. _onFind: function (evt) {
  171. this.stackContainer.selectChild(this.mainPage);
  172. this.mainStackContainer.selectChild(this.searchPage);
  173. this.searchPage.doSearch(this.searchText.get("value"));
  174. },
  175. _onOpenLegacy: function (evt) {
  176. var win = window.open("/?legacy", "_blank");
  177. win.focus();
  178. },
  179. _onOpenReleaseNotes: function (evt) {
  180. var win = window.open("http://hpccsystems.com/download/free-community-edition-known-limitations#" + this.build.version, "_blank");
  181. win.focus();
  182. },
  183. _onOpenErrWarn: function (evt) {
  184. this.stackContainer.selectChild(this.errWarnPage);
  185. },
  186. _onAboutLoaded: false,
  187. _onAbout: function (evt) {
  188. if (!this._onAboutLoaded) {
  189. this._onAboutLoaded = true;
  190. dom.byId(this.id + "ServerVersion").value = this.build.version;
  191. var gc = registry.byId(this.id + "GraphControl");
  192. dom.byId(this.id + "GraphControlVersion").value = gc.getVersion();
  193. }
  194. this.aboutDialog.show();
  195. },
  196. _onAboutClose: function (evt) {
  197. this.aboutDialog.hide();
  198. },
  199. _onSetBanner: function (evt) {
  200. dom.byId(this.id + "BannerText").value = this.banner;
  201. this.setBannerDialog.show();
  202. },
  203. _onSetBannerOk: function (evt) {
  204. this.activity.setBanner(dom.byId(this.id + "BannerText").value);
  205. this.setBannerDialog.hide();
  206. },
  207. _onSetBannerCancel: function (evt) {
  208. this.setBannerDialog.hide();
  209. },
  210. createStackControllerTooltip: function (widgetID, text) {
  211. return new Tooltip({
  212. connectId: [this.id + "StackController_" + widgetID],
  213. label: text,
  214. showDelay: 1,
  215. position: ["below"]
  216. });
  217. }
  218. });
  219. });