123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469 |
- /*
- * Licensed Materials - Property of IBM
- *
- * IBM Cognos Products: SHARE
- *
- * (C) Copyright IBM Corp. 2015, 2020
- *
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define([
- 'react',
- 'react-dom',
- 'ba-react-admin/ba-react-admin.min',
- 'bi/commons/ui/View',
- 'jquery',
- 'bi/sharecommon/utils/translator',
- 'q',
- 'underscore',
- 'bi/sharecommon/utils/simpledoT',
- 'bi/commons/utils/Utils',
- 'text!bi/schedule/templates/SchedulesView.html',
- 'bi/schedule/utils/CadenceLabelGenerator',
- 'bi/commons/ui/properties/ToggleButton',
- 'bi/schedule/app/appControler',
- 'text!bi/notifications/templates/emptyMessageList.html',
- 'bi/commons/ui/dialogs/ConfirmationDialog'
- ],
- function (React, ReactDOM, AdminReact, View, $, t, Q, _, dot, Utils, template, cadence, ToggleButton, controller, emptySchTemplate, ConfirmationDialog) {
- 'use strict';
- var schedulesView = View.extend({
- schedule: {},
- /**
- * @constructor
- */
- init: function (options) {
- schedulesView.inherited('init', this, arguments);
- // defaults
- this.stateToggler = null;
- this.hasPermission = {
- execute: true,
- read: true,
- setPolicy: true,
- traverse: true,
- write: true
- };
- $.extend(this, options);
- this.timezone = this.glassContext.services.userProfile.preferences.timeZoneID;
- this.productLocale = this.glassContext.services.userProfile.preferences.productLocale || 'en-us';
- if (typeof (this.objectInfo.descriptor) == 'undefined') {
- this.hasPermission = {
- execute: $.inArray('execute', this.objectInfo.permissions) != -1,
- read: $.inArray('read', this.objectInfo.permissions) != -1,
- setPolicy: $.inArray('setPolicy', this.objectInfo.permissions) != -1,
- traverse: $.inArray('traverse', this.objectInfo.permissions) != -1,
- write: $.inArray('write', this.objectInfo.permissions) != -1
- };
- }
- },
- /**
- * Render the schedule view within the flyout panel
- *
- */
- renderOld: function () {
- var deferred = Q.defer();
-
- this.updateScheduleList().then(function() {
- controller.getSchedule(this.objectInfo.id, this.glassContext).then(function (schedule) {
- if (!((this.glassContext.isDevInstall) && (this.glassContext.isDevInstall()))) {
- this.$el.append("<div class='newSchedPane'/>");
- var $newPane = this.$el.find('.newSchedPane');
- var scheduleDialog = React.createElement(AdminReact.SchedulesListView, { glassContext: this.glassContext, StringResource: t, runnable: this.objectInfo, shareAppController: controller, schedule: schedule, deleteFunction: this._deleteFunction.bind(this) });
- ReactDOM.render(scheduleDialog, $newPane[0]);
- }
- deferred.resolve(this);
- }.bind(this));
- }.bind(this));
- return deferred.promise;
- },
- renderNew: function () {
- var deferred = Q.defer();
- controller.getSchedule(this.objectInfo.id, this.glassContext).then(function (schedule) {
- this.$el.append("<div class='newSchedPane'/>");
- var $newPane = this.$el.find('.newSchedPane');
- var runnableObj = JSON.parse(JSON.stringify(this.objectInfo));
- var schedulesListView = React.createElement(AdminReact.SchedulesListView, { glassContext: this.glassContext, StringResource: t, runnable: runnableObj, shareAppController: controller, schedule: schedule, deleteRequest : controller.deleteSchedule });
- ReactDOM.render(schedulesListView, $newPane[0]);
- deferred.resolve(this);
- }.bind(this));
- if (this.slideout.contentView) {
- this.slideout.contentView.canHide = this._canHide.bind(this);
- }
- return deferred.promise;
- },
- _canHide: function() {
- return !AdminReact.ScheduleUIStore.isDialogOpen;
- },
- render: function() {
- if ((this.glassContext.isDevInstall) && (this.glassContext.isDevInstall())) {
- return this.renderOld();
- } else {
- return this.renderNew();
- }
- },
- _supportsFormats: function () {
- var objWithNoFormats = ['agentDefinition', 'agentDefinitionView', 'jobDefinition', 'jupyterNotebook'];
- return objWithNoFormats.indexOf(this.objectInfo.type) === -1;
- },
- /*update schedule list based on object Info*/
- updateScheduleList: function () {
- var deferred = Q.defer();
- var showCreate = true;
- var scheduleType = null;
- controller.getSchedule(this.objectInfo.id, this.glassContext).then(function (schedule) {
- var cadenceLabel = cadence.getLabelFor(schedule.scheduleInfo, this.timezone, this.productLocale);
- var outputFormats = [];
- var showFormats = this._supportsFormats();
- this.schedule = schedule;
- if (schedule && schedule.scheduleInfo) {
- // schedule exists, hide create button
- showCreate = false;
- scheduleType = t.translate(this._getScheduleType() + '_label');
- var numberOfFormats = (schedule.options && schedule.options.outputFormat) ? schedule.options.outputFormat.length : 0;
- for (var i = 0; i < numberOfFormats; i++) {
- var newFormat = { format: schedule.options.outputFormat[i] };
- switch (newFormat.format) {
- case 'HTML':
- newFormat['icon'] = 'html_icon';
- newFormat['displayName'] = t.translate('schedule_format_web');
- break;
- case 'PDF':
- newFormat['icon'] = 'pdf_icon';
- newFormat['displayName'] = t.translate('schedule_format_pdf');
- break;
- case 'spreadsheetML':
- newFormat['icon'] = 'excel_icon';
- newFormat['displayName'] = t.translate('schedule_format_xlsx');
- break;
- case 'xlsxData':
- newFormat['icon'] = 'excel_icon';
- newFormat['displayName'] = t.translate('schedule_format_xlsx_data');
- break;
- case 'XLWA':
- newFormat['icon'] = 'unsupportedformat_icon';
- newFormat['displayName'] = t.translate('schedule_format_unsupported');
- break;
- case 'CSV':
- newFormat['icon'] = 'csv_icon';
- newFormat['displayName'] = t.translate('schedule_format_csv');
- break;
- case 'XML':
- newFormat['icon'] = 'xml_icon';
- newFormat['displayName'] = t.translate('schedule_format_xml');
- break;
- case 'dataSet':
- newFormat['icon'] = 'dataset';
- newFormat['displayName'] = t.translate('schedule_format_dataset');
- break;
- default: // unknown, skip
- continue;
- }
- outputFormats.push(newFormat);
- }
- // no format defined? default to HTML
- if (outputFormats.length === 0) {
- outputFormats.push({
- format: 'HTML',
- icon: 'html_icon',
- displayName: t.translate('schedule_format_web')
- });
- }
- }
- var attributes = {
- schedule_toolbar_label: t.translate('schedule_toolbar_label'),
- schedule_new_label: t.translate('schedule_new_label'),
- schedule_delete_label: t.translate('schedule_delete_label'),
- schedule_update_label: t.translate('schedule_update_label'),
- schedule_toggle_label: t.translate('schedule_enable_label'),
- schedule_new_btn_label: t.translate('schedule_new_btn_label'),
- report_id: schedule.reportId,
- schedule_type: scheduleType,
- schedule_cadence_label: cadenceLabel || '',
- show_create: showCreate,
- show_formats: showFormats,
- outputFormat: outputFormats
- };
- this._loadTemplates(attributes, showCreate);
- if (!showCreate) {
- this._renderToggleButton();
- }
- // Disable based on permissions
- if (!this.hasPermission.write && showCreate) {
- // Remove new
- this.$el.find('.schedule_create_new').remove();
- }
- if (!this.hasPermission.write && !showCreate) {
- // Remove Toolbar
- this.$el.find('.schedule_toolbar').remove();
- if (!this.hasPermission.read) {
- // No read permission disable Forward
- this.$el.find('.schedule_expand').prop('disabled', true);
- }
- }
- if (this.schedule.id) {
- return controller.getRawSchedule(this.schedule.id, this.glassContext);
- } else {
- return Promise.resolve({ data: [{ options: [] }] });
- }
- }.bind(this)).then(function(result) {
- if (this.schedule.id) {
- this.objectInfo.rawOptions = result.data[0].options;
- } else if (this.schedule.reportId) {
- this.objectInfo.rawOptions = result.data[0].options;
- }
- console.log("raw result is", result);
- deferred.resolve();
- }.bind(this));
- return deferred.promise;
- },
- _getScheduleType: function () {
- switch (this.schedule.scheduleInfo.type) {
- case 'daily':
- case 'dailyWithIntradayRecurrence':
- return 'daily';
- case 'monthlyRelative':
- case 'monthlyAbsolute':
- case 'monthlyRelativeWithIntradayRecurrence':
- case 'monthlyAbsoluteWithIntradayRecurrence':
- return 'monthly';
- case 'yearlyRelative':
- case 'yearlyAbsolute':
- case 'yearlyRelativeWithIntradayRecurrence':
- case 'yearlyAbsoluteWithIntradayRecurrence':
- return 'yearly';
- case 'trigger':
- return 'trigger';
- default:
- return 'weekly';
- }
- },
- _loadTemplates: function (attributes, showCreate) {
- var htmlGenerator = dot.simpleTemplate(template);
- this.$el.html(htmlGenerator(attributes));
- if (showCreate) {
- var sHtml = dot.template(emptySchTemplate)({
- 'text': t.translate('no_schedule_label', { type: t.translate(this.objectInfo.type + '_type') })
- });
- this.$el.find('.schedule_no_schedule_container').append(sHtml);
- }
- this._setIcons();
- this._setEvents();
- },
- _renderToggleButton: function () {
- var reportState = false;
- if (this.schedule && this.schedule.scheduleInfo) {
- reportState = this.schedule.scheduleInfo.active;
- }
- this.stateToggler = new ToggleButton({
- id: 'schedule_toggler_' + this.schedule.reportId,
- el: this.$el.find('.schedule_toggle_button_container'),
- name: 'schedule_status_toggler',
- ariaLabel: t.translate('schedule_toggle_label'),
- checked: reportState,
- onChange: this._handleToggler.bind(this)
- });
- this.stateToggler.doRender();
- },
- _handleToggler: function (name, value) {
- if (name === 'schedule_status_toggler') {
- var newDescriptor = this.schedule;
- newDescriptor.scheduleInfo.active = value;
- delete newDescriptor.name; //Need to delete the name property before making CM call
- controller.updateSchedule(newDescriptor, this.glassContext).then(function (data) {
- this.schedule = data;
- }.bind(this));
- }
- },
- /**
- * Open a slideout with the schedule view in it
- *
- * @param isUpdating {boolean} - Default false; Set true if opening an existing schedule to view/edit.
- */
- _openScheduleView: function (isUpdating) {
- var _self = this;
- if (typeof (isUpdating) !== 'boolean') {
- isUpdating = false;
- }
- this.glassContext.getSvc('.Content').then(function (contentSvc) {
- var server_URL = contentSvc.getBaseObjectsURL() + '/' + _self.schedule.reportId + '?fields=canBurst';
- contentSvc.get(server_URL, {}).done(function (data, textStatus, jqXHR) {
- if (isUpdating) {
- _self.objectInfo.descriptor = _self.schedule;
- }
- _self.objectInfo.hasPermission = _self.hasPermission;
- var module = _self._getScheduleModule();
- _self.glassContext.appController.showSlideOut({
- 'parent': _self.slideout,
- 'overlay': true,
- 'enableTabLooping': true,
- 'label': t.translate('schedule_report_properties_name'),
- 'content': {
- 'module': module,
- 'objectInformation': _self.objectInfo,
- 'onCreateOrUpdateCallback': _self.updateScheduleList.bind(_self),
- 'canBurst': data.data[0].canBurst,
- 'glassContext': _self.glassContext,
- 'slideoutparent': _self.slideout
- }
- });
- });
- });
- },
- remove: function() {
- var $newPane = this.$el.find('.newSchedPane');
- if (($newPane) && ($newPane.length === 1)) {
- ReactDOM.unmountComponentAtNode($newPane[0]);
- } else {
- this.glassContext.getCoreSvc('.Logger').log('could not remove schedule react element');
- }
- },
- _getScheduleModule: function () {
- if (this.objectInfo.type === 'dataSet2') {
- return 'bi/schedule/views/DatasetScheduleView';
- } else if (this.objectInfo.type === 'jobDefinition') {
- return 'bi/schedule/views/JobScheduleView';
- }
- return 'bi/schedule/views/ScheduleView';
- },
- _getOutputFormat: function(options) {
- var outputFormat = '';
- try {
- for (var i = 0; i < options.length; i++) {
- if (options[i].name === 'outputFormat') {
- // expect output format option value to be a MobX ObservableArray
- outputFormat = options[i].value.join(',');
- break;
- }
- }
- } catch(e) {
- // return outputFormat as empty string
- }
- return outputFormat;
- },
- _deleteFunction: function() {
- var deleteDialog = new ConfirmationDialog('warning', t.translate('delete_confirm'),
- t.translate('delete_schedule_confirm_message'));
- deleteDialog.confirm(function () {
- controller.deleteSchedule(this.objectInfo.id, this.glassContext).done(function () {
- var trackingOpts = {
- type: 'Deleted Object',
- objectType: this.objectInfo.type,
- object: this.objectInfo.id,
- action: 'scheduleDeleted',
- milestoneName: 'scheduleDeleted_' + this.objectInfo.type,
- 'custom.outputFormat': this._getOutputFormat(this.schedule.options.outputFormat)
- };
- var instrumentor = this.glassContext.getCoreSvc('.Instrumentation');
- if ((instrumentor) && (instrumentor.track)) {
- instrumentor.track(trackingOpts);
- }
- if (this.objectInfo && this.objectInfo.descriptor) {
- delete this.objectInfo.descriptor;
- }
- this.updateScheduleList();
- }.bind(this));
- }.bind(this));
- },
- _setEvents: function () {
- this.$el.find('.schedule_create_new button').on('clicktap', function () {
- this._openScheduleView(false);
- return false;
- }.bind(this));
- this.$el.find('.schedule_expand').on('clicktap', function () {
- this._openScheduleView(true);
- return false;
- }.bind(this));
- this.$el.find('.schedule_delete_button').on('clicktap', function () {
- var deleteDialog = new ConfirmationDialog('warning', t.translate('delete_confirm'),
- t.translate('delete_schedule_confirm_message'));
- deleteDialog.confirm(function () {
- controller.deleteSchedule(this.objectInfo.id, this.glassContext).done(function () {
- var trackingOpts = {
- type: 'Deleted Object',
- objectType: this.objectInfo.type,
- object: this.objectInfo.id,
- action: 'scheduleDeleted',
- milestoneName: 'scheduleDeleted_' + this.objectInfo.type,
- 'custom.outputFormat': this._getOutputFormat(this.schedule.options.outputFormat)
- };
- var instrumentor = this.glassContext.getCoreSvc('.Instrumentation');
- if ((instrumentor) && (instrumentor.track)) {
- instrumentor.track(trackingOpts);
- }
- if (this.objectInfo && this.objectInfo.descriptor) {
- delete this.objectInfo.descriptor;
- }
- this.updateScheduleList();
- }.bind(this));
- }.bind(this));
- }.bind(this));
- },
- _setIcons: function () {
- var icons = this.$el.find('.schedule_common_icon');
- for (var k = 0; k < icons.length; k++) {
- var $icon = $(icons[k]);
- var display = icons[k].dataset.displayName;
- Utils.setIcon($icon, 'common-' + icons[k].dataset.icon, display ? display : icons[k].dataset.icon);
- }
- }
- });
- return schedulesView;
- });
|