JobPane.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. *
  5. * IBM Cognos Products: ADMIN
  6. *
  7. * Copyright IBM Corp. 2017, 2022
  8. *
  9. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  10. */
  11. define(['jquery', 'underscore', 'bi/glass/app/ContentView', 'bi/admin/nls/StringResource', 'react', 'react-dom', 'ba-react-admin/ba-react-admin.min', 'bacontentnav/ui/dialogs/OpenDialog', 'bi/admin/account/slideout/SecurityObjectSelectorPane', 'bi/content_apps/PromptValuesView'], function ($, _, ContentView, StringResource, React, ReactDOM, AdminReact, OpenDialog, SecurityObjectSelectorPane, PromptValuesView) {
  12. var view = ContentView.extend({
  13. selectableItems: _.keys(AdminReact.JobStepObjects),
  14. init: function init(options) {
  15. view.inherited('init', this, arguments);
  16. this.objectInfo = {};
  17. if (this.objRef) {
  18. this.objectInfo.id = this.objRef;
  19. }
  20. $.extend(this, options);
  21. },
  22. updateContent: function updateContent(options) {
  23. if (AdminReact.JobUIStore.isOpen) {
  24. if (options) {
  25. AdminReact.JobObjectStore.updateWithNewContent(this.glassContext, options);
  26. if (options.objectInfo && options.objectInfo.id) {
  27. this.objectInfo.id = options.objectInfo.id;
  28. }
  29. this.trigger("change:state");
  30. }
  31. }
  32. },
  33. deactivate: function deactivate() {
  34. return Promise.resolve();
  35. },
  36. activate: function activate(options) {
  37. if (options.setFocus) {
  38. return Promise.resolve();
  39. }
  40. AdminReact.JobObjectStore.updateWithNewContent(this.glassContext, options);
  41. if (options.objectInfo && options.objectInfo.id) {
  42. this.objectInfo.id = options.objectInfo.id;
  43. }
  44. this.trigger("change:state");
  45. return Promise.resolve();
  46. },
  47. getTitle: function getTitle() {
  48. var jobStore = AdminReact.JobObjectStore;
  49. if (jobStore.isNew) {
  50. return StringResource.get("newJob");
  51. } else {
  52. return jobStore.defaultName;
  53. }
  54. },
  55. getContent: function getContent() {
  56. if (AdminReact.JobObjectStore.isNew) {
  57. return {
  58. objRef: ""
  59. };
  60. }
  61. if (this.objectInfo && this.objectInfo.id) {
  62. return {
  63. objRef: this.objectInfo.id
  64. };
  65. }
  66. },
  67. isDirty: function isDirty() {
  68. var jobStore = AdminReact.JobObjectStore;
  69. if (jobStore.isNew) {
  70. return true;
  71. } else {
  72. return jobStore.isDirty;
  73. }
  74. },
  75. getIcon: function getIcon() {
  76. return 'common-open-tab';
  77. },
  78. setTitle: function setTitle() {
  79. this.trigger("change:title", {
  80. value: this.getTitle()
  81. });
  82. },
  83. updateAfterSave: function updateAfterSave() {
  84. this.setTitle();
  85. this.trigger("change:dirty");
  86. this.objectInfo.id = AdminReact.JobObjectStore.id;
  87. this.trigger("change:state");
  88. },
  89. renderAccountSelector: function renderAccountSelector(rootEl) {
  90. var anEl = $(rootEl);
  91. var defaultTypes = ['account'];
  92. var aPane = new SecurityObjectSelectorPane({
  93. glassContext: this.glassContext,
  94. 'parentView': this,
  95. 'objectInfo': [{}],
  96. 'allowedSelectionTypes': defaultTypes,
  97. 'targetType': [],
  98. '$el': anEl
  99. });
  100. aPane.renderBody(anEl);
  101. },
  102. _openScheduleSlideout: function _openScheduleSlideout(objectInformation) {
  103. var objIn = JSON.parse(JSON.stringify(objectInformation));
  104. this.glassContext.appController.showSlideOut({
  105. content: {
  106. module: 'bi/schedule/views/SchedulesView',
  107. glassContext: this.glassContext,
  108. objectInfo: objIn
  109. },
  110. width: '390px',
  111. enableTabLooping: true,
  112. label: "Schedule",
  113. position: 'left'
  114. });
  115. },
  116. _showOptionsSlideout: function _showOptionsSlideout(objectInformation, selectedStep) {
  117. this.glassContext.appController.showSlideOut({
  118. content: {
  119. module: 'bi/admin/job/RunOptionsView',
  120. glassContext: this.glassContext,
  121. objectInformation: objectInformation,
  122. selectedStep: selectedStep
  123. },
  124. width: '390px',
  125. enableTabLooping: true,
  126. label: StringResource.get("options"),
  127. position: 'left',
  128. onHide: function onHide() {
  129. this.contentView.onHide();
  130. }
  131. });
  132. },
  133. openRelinkDialog: function openRelinkDialog() {
  134. var dialog = new OpenDialog({
  135. glassContext: this.glassContext,
  136. typesToOpen: this.selectableItems,
  137. multiSelect: false,
  138. primaryBtnText: StringResource.get('ok'),
  139. onOpenCallback: AdminReact.JobUIStore.relinkDialogClosed.bind(AdminReact.JobUIStore, this.glassContext),
  140. dataManipulationCallback: this._filterOutNoExecute.bind(this),
  141. extraUrlParameters: ['options']
  142. });
  143. dialog.title = StringResource.get('relinkAsset');
  144. dialog.primaryBtnText = StringResource.get('ok');
  145. dialog.open();
  146. },
  147. openOptionsSlideout: function openOptionsSlideout(selectedStep, descriptor) {
  148. var runnable = selectedStep;
  149. if (selectedStep.stepObject && selectedStep.stepObject.length > 0) {
  150. runnable = selectedStep.stepObject[0];
  151. }
  152. if (runnable.type === 'reportView') {
  153. AdminReact.JobAccess.getPropertiesForReportView(this.glassContext, runnable.id).then(function (result) {
  154. var objectInformation = result.data.data[0];
  155. objectInformation.descriptor = descriptor;
  156. this._showOptionsSlideout(objectInformation, selectedStep);
  157. }.bind(this));
  158. } else {
  159. this._showOptionsSlideout({
  160. id: runnable.id,
  161. type: runnable.type,
  162. canBurst: selectedStep.canBurst,
  163. descriptor: descriptor
  164. }, selectedStep);
  165. }
  166. },
  167. openDeploymentSelection: function openDeploymentSelection(addFunction) {
  168. var jobAccess = AdminReact.JobAccess;
  169. jobAccess.getAdminFolderID(this.glassContext).then(function (adminFolderID) {
  170. var rootObject = {
  171. id: adminFolderID,
  172. defaultName: 'Directory',
  173. type: 'adminFolder',
  174. _meta: {
  175. links: {
  176. items: {
  177. mimeType: 'application/json',
  178. url: 'v1/objects/' + adminFolderID + '/items'
  179. },
  180. self: {
  181. mimeType: 'application/json',
  182. url: 'v1/objects/' + adminFolderID
  183. }
  184. }
  185. }
  186. };
  187. var dialog = new OpenDialog({
  188. glassContext: this.glassContext,
  189. typesToOpen: ['importDeployment', 'exportDeployment'],
  190. multiSelect: true,
  191. ancestors: [rootObject],
  192. rootObjects: [rootObject],
  193. onOpenCallback: addFunction,
  194. extraUrlParameters: ['options']
  195. });
  196. dialog.title = StringResource.get("addJobSteps");
  197. dialog.primaryBtnText = StringResource.get("jobStepsToAdd");
  198. dialog.open();
  199. }.bind(this));
  200. },
  201. renderPromptSelector: function renderPromptSelector(rootEl, obj) {
  202. var anEl = $(rootEl);
  203. this.objectInfo = {
  204. id: obj.stepObject[0].id,
  205. type: obj.type
  206. };
  207. var anEl = $(rootEl);
  208. var defaultTypes = ['account'];
  209. var aPane = new PromptValuesView({
  210. glassContext: this.glassContext,
  211. 'parentView': this,
  212. 'promptDisplayValues': [],
  213. 'parameters': [],
  214. 'objectInformation': {
  215. id: obj.id,
  216. type: obj.type
  217. },
  218. 'hasPermission': true,
  219. 'clearCallback': function clearCallback() {
  220. console.log('weeeeee');
  221. },
  222. 'editCallback': function editCallback() {
  223. console.log('weeeeee');
  224. },
  225. '$el': anEl,
  226. slideout: this
  227. });
  228. aPane.render();
  229. },
  230. _filterOutNoExecute: function _filterOutNoExecute(response) {
  231. response.data = _.filter(response.data, function (result) {
  232. if (this.selectableItems.indexOf(result.type) === -1) {
  233. return true;
  234. }
  235. return result.permissions.indexOf("execute") !== -1;
  236. }.bind(this));
  237. },
  238. openContentSelection: function openContentSelection(addFunction) {
  239. var dialog = new OpenDialog({
  240. glassContext: this.glassContext,
  241. typesToOpen: this.selectableItems,
  242. multiSelect: true,
  243. primaryBtnText: StringResource.get("addJobSteps"),
  244. filesToOpenTitle: StringResource.get("jobStepsToAdd"),
  245. onOpenCallback: addFunction,
  246. dataManipulationCallback: this._filterOutNoExecute.bind(this),
  247. extraUrlParameters: ['options']
  248. });
  249. dialog.title = StringResource.get("addJobSteps");
  250. dialog.primaryBtnText = StringResource.get("jobStepsToAdd");
  251. dialog.open();
  252. },
  253. remove: function remove() {
  254. AdminReact.JobUIStore.setIsOpen(false);
  255. view.inherited('remove', this, arguments);
  256. ReactDOM.unmountComponentAtNode(this.$el[0]);
  257. },
  258. render: function render() {
  259. AdminReact.JobUIStore.setIsOpen(true);
  260. this.$el.addClass("jobmgt");
  261. this.$el.css("width", "100%");
  262. this.$el.css("height", "100%");
  263. ReactDOM.unmountComponentAtNode(this.$el[0]);
  264. var jobPane = React.createElement(AdminReact.JobPane, {
  265. glassContext: this.glassContext,
  266. StringResource: StringResource,
  267. objectInfo: this.objectInfo,
  268. dialog: this,
  269. selectedJobSteps: this.selectedSteps
  270. });
  271. AdminReact.JobObjectStore.setOptionDefault(this.glassContext);
  272. ReactDOM.render(jobPane, this.$el[0]);
  273. return Promise.resolve();
  274. }
  275. });
  276. view.openJobPane = function (glassContext, content) {
  277. var perspective = glassContext.appController.currentAppView.perspective;
  278. var context = {
  279. id: "123",
  280. content: content
  281. };
  282. if (perspective === 'job_mgt' && content.setFocus) return;
  283. if (content.addToJob === true) {
  284. glassContext.appController.openAppView('job_mgt', context);
  285. return;
  286. }
  287. glassContext.appController.closeAppView('job_mgt', '123').then(function () {
  288. setTimeout(function () {
  289. glassContext.appController.openAppView('job_mgt', context);
  290. }, 1);
  291. });
  292. };
  293. return view;
  294. });