', {
'class': 'buttonRow'
});
this.$el.append(buttonRow);
var runButton = new UIButton({
'buttonSpec': {
'label': StringResource.get('run'),
'onSelect': this._onRun.bind(this)
}
});
runButton.render();
buttonRow.append(runButton.$el);
return Promise.resolve(true);
},
_getSeparatorSpec: function() {
return {
'type': 'Separator'
};
},
_getRunInBackgroundToggleSpec: function() {
return {
'name': RunAsOptionsView.OPTION.RUN_IN_BG,
'checked': false,
'label': StringResource.get('runInBackgroundOption'),
'type': 'ToggleButton',
'onChange': this._toggleOptionsControl.bind(this)
};
},
_toggleOptionsControl: function() {
this._runInBackgroundOptionsControl.toggleCollapsibleSection();
this._runAsOptionsControl.toggleCollapsibleSection();
this._copySelectionForRunInBackgroundToggle();
this._copyPromptForValuesOnRunInBackgroundChange();
},
_copyPromptForValuesOnRunInBackgroundChange: function() {
var modifiedProperties = this._runOptionsControl.getModifiedProperties();
var isRunInBackgroundChecked = modifiedProperties[RunAsOptionsView.OPTION.RUN_IN_BG];
// get promptForValues checkbox control for both RunAs and RunInBackground
var runAsPromptControl = this._runAsOptionsControl.getProperty(RunAsOptionsView.OPTION.PROMPT);
var runInBackgroundPromptControl = this._runInBackgroundOptionsControl.getProperty(RunAsOptionsView.OPTION.PROMPT);
// get prompt control to update, depending on how RunInBackground is toggled
var prompControlToUpdate = isRunInBackgroundChecked ? runInBackgroundPromptControl : runAsPromptControl;
var isPromptForValuesChecked = isRunInBackgroundChecked ? runAsPromptControl['checked'] : runInBackgroundPromptControl['checked'];
// Propagate promptForValues to foreground run options control
if (isPromptForValuesChecked) {
if (!prompControlToUpdate.checked) prompControlToUpdate.check();
} else {
if (prompControlToUpdate.checked) prompControlToUpdate.uncheck();
}
},
_copySelectionForRunInBackgroundToggle: function() {
var noOfFormats = this._supportedFormats.length;
if (noOfFormats === 1) {
return;
}
var modifiedProperties = this._runOptionsControl.getModifiedProperties();
if (modifiedProperties[RunAsOptionsView.OPTION.RUN_IN_BG]) {
$.each(this._supportedFormats, function(i, format) {
if (AuthoringHelper.userCanGenerateFormat(this.glassContext, format)) {
this._runOptionsControl.getProperty(format).uncheck();
}
}.bind(this));
this._runOptionsControl.getProperty(modifiedProperties[RunAsOptionsView.OPTION.RUNFORMAT] || this._outputFormat).check();
} else {
var selectedFormat = null;
// Loop through _supportedFormats to select the first supported format in order.
$.each(this._supportedFormats, function(i, format) {
if (modifiedProperties[format]) {
selectedFormat = format;
return false;
}
}.bind(this));
this._runOptionsControl.getProperty(RunAsOptionsView.OPTION.RUNFORMAT).setValue(selectedFormat || this._outputFormat);
}
},
_getRunInBackgroundOptionsSpec: function() {
return {
'type': 'CollapsibleSection',
'name': 'runInBackgroundOptions',
'hideSectionTitle': true,
'items': this._getRunInBackgroundFormatsSpec().concat(
this._getSeparatorSpec(),
this._getPromptForValuesOptionSpec(),
this._getPromptGenerationHintText(this._promptValue),
this._getAdvancedSectionSpec()
)
};
},
_getRunAsOptionsSpec: function() {
return {
'type': 'CollapsibleSection',
'name': 'runAsOptions',
'hideSectionTitle': true,
'items': [this._getRunAsFormatsSpec(),
this._getSeparatorSpec(),
this._getPromptForValuesOptionSpec(),
this._getSeparatorSpec()
],
'open': true
};
},
_getRunInBackgroundFormatsSpec: function() {
var noOfFormats = this._supportedFormats.length;
if (noOfFormats === 1) {
return [this._getSingleFormatSpec(this._supportedFormats[0])];
}
var itemsSpec = [];
this._supportedFormats.forEach(function(format) {
if (AuthoringHelper.userCanGenerateFormat(this.glassContext, format)) {
itemsSpec.push({
'type': 'CheckBox',
'name': format,
'label': StringResource.get(AuthoringHelper.FORMAT_MESSAGE_KEY_MAP[format]),
'value': format,
'controlOnLeft': true,
'checked': this._outputFormat === format,
'onChange': this._updateSelectedFormat.bind(this)
});
}
}.bind(this));
return [{
'type': 'CollapsibleSection',
'hideSectionTitle': true,
'open': true,
'name': RunAsOptionsView.OPTION.OUTPUTFORMAT,
'ariaLabel': StringResource.get('formatOptions'),
'items': itemsSpec
}];
},
_getRunAsFormatsSpec: function() {
var noOfFormats = this._supportedFormats.length;
if (noOfFormats === 1) {
return this._getSingleFormatSpec(this._supportedFormats[0]);
}
var itemsSpec = [];
this._supportedFormats.forEach(function(format) {
if (AuthoringHelper.userCanGenerateFormat(this.glassContext, format)) {
itemsSpec.push({
'name': format,
'label': StringResource.get(AuthoringHelper.FORMAT_MESSAGE_KEY_MAP[format]),
'value': format
});
}
}.bind(this));
return ({
'type': 'RadioButtonGroup',
'ariaLabel': StringResource.get('formatOptions'),
'name': RunAsOptionsView.OPTION.RUNFORMAT,
'value': this._outputFormat,
'controlOnLeft': true,
'separator': false,
'items': itemsSpec
});
},
_getSingleFormatSpec: function(format) {
return {
'type': 'SingleLineValue',
'name': format,
'label': StringResource.get(format),
'value': ''
};
},
_getPromptForValuesOptionSpec: function() {
return {
'type': 'CheckBox',
'name': RunAsOptionsView.OPTION.PROMPT,
'label': StringResource.get('promptForValues'),
'controlOnLeft': true,
'checked': ContentStoreObject.getExecutionPrompt(this.objectInformation),
'onChange': this._togglePromptValue.bind(this)
};
},
_getPromptGenerationHintText: function(isPromptMeChecked) {
return {
'type' : 'HintText',
'name' : 'promptGenerationHintText',
'label' : StringResource.get('promptGenerationHint'),
'visibility' : this._getCssVisibility(isPromptMeChecked)
};
},
_togglePromptValue: function(controlName, value) {
// Check actual value of control instead of negating previous value to avoid falling out of sync with Prompt checkbox
this._promptValue = value;
this._showHidePromptGenerationHintText(this._promptValue);
},
_showHidePromptGenerationHintText: function(isPromptMeChecked) {
// Set hintText visibility
var visibility = this._getCssVisibility(isPromptMeChecked);
var hintText = this._runOptionsControl.getProperty('promptGenerationHintText');
hintText.visibility = visibility;
// Directly write visibility to element class to ensure it is always shown/hidden immediately when RunInBackground is toggled
this.$el.find('.l_promptGenerationHintText').css('visibility', visibility);
},
_getCssVisibility: function(isVisible) {
return isVisible ? 'visible' : 'hidden';
},
_getAdvancedSectionSpec: function() {
var itemsSpec = [
this._getRunNowOrLaterOptions(),
this._getExecutionTimePicker(),
this._getBurstOptionSpec(),
this._getPDFOptionsSpec(),
this._getLanguagesOptionSpec(),
this._getDeliveryOptionsSpec()
];
//some functions can return undefined so filter it out.
var filteredItems = itemsSpec.filter(function(item) {
return !!item;
});
return {
'type': 'CollapsibleSection',
'name': 'advancedProperties',
'label': StringResource.get('advancedProperties'),
'items': filteredItems
};
},
_getRunNowOrLaterOptions: function() {
return {
'type': 'HorizontalRadioButtonGroup',
'name': RunAsOptionsView.OPTION.RUN_NOW_OR_LATER,
'value': 'now',
'controlOnLeft': true,
'ariaLabel': StringResource.get('nowOrLaterRadioOptions'),
'onChange': this._toggleDatetimePicker.bind(this),
'items': [{
'name': RunAsOptionsView.OPTION.RUN_NOW,
'value': RunAsOptionsView.OPTION.RUN_NOW,
'label': StringResource.get('now')
}, {
'label': StringResource.get('later'),
'name': RunAsOptionsView.OPTION.RUN_LATER,
'value': RunAsOptionsView.OPTION.RUN_LATER
}]
};
},
_toggleDatetimePicker: function(name, value) {
if (this._lastRunNowOrLaterOption === value) {
return;
}
//a different option is selected
if (!this._datetimePicker) {
this._datetimePicker = this._runOptionsControl.getProperty(RunAsOptionsView.OPTION.EXECUTIONTIME);
}
if (value === RunAsOptionsView.OPTION.RUN_LATER) {
this._datetimePicker.show();
} else {
this._datetimePicker.hide();
}
this._lastRunNowOrLaterOption = value;
},
_getExecutionTimePicker: function() {
return {
'module': CA_DateTimePicker,
'name': RunAsOptionsView.OPTION.EXECUTIONTIME,
'glassContext': this.glassContext
};
},
_getBurstOptionSpec: function() {
if (ContentStoreObject.canBurst(this.objectInformation) && this.glassContext.hasCapability('canUseBursting')) {
return {
'type': 'CheckBox',
'name': RunAsOptionsView.OPTION.BURST,
'label': StringResource.get('burst'),
'value': RunAsOptionsView.OPTION.BURST,
'onChange': this._updateBurstSelected.bind(this)
};
}
},
_getPDFOptionsSpec: function() {
if (this._supportedFormats.length === 1 || !AuthoringHelper.userCanGenerateFormat(this.glassContext, 'PDF')) {
return;
}
return {
'type': 'SingleLineValue',
'name': RunAsOptionsView.OPTION.ADVANCED_PDF,
'label': StringResource.get('pdf'),
'editCallback': this._showMoreOptionsPane.bind(this, this._getMorePDFOptionsSpec.bind(this)),
'hidden': true
};
},
_getLanguagesOptionSpec: function() {
return {
'type': 'SingleLineValue',
'name': RunAsOptionsView.OPTION.LANGUAGES,
'label': StringResource.get('languages'),
'editCallback': this._showMoreOptionsPane.bind(this, this._getMoreLanguageOptionsSpec.bind(this))
};
},
_getDeliveryOptionsSpec: function() {
return {
'type': 'SingleLineValue',
'name': RunAsOptionsView.OPTION.DELIVERY,
'label': StringResource.get('delivery'),
'editCallback': this._showMoreOptionsPane.bind(this, this._getMoreDeliveryOptionsSpec.bind(this))
};
},
_showMoreOptionsPane: function(getContentSpecFunc) {
if (typeof getContentSpecFunc !== 'function') {
this.logger.debug('getContentSpecFunc is not a function');
}
var parentSlideout = this.slideout;
getContentSpecFunc().then(function(spec) {
this._slideout = this._appController.showSlideOut({
'position': 'left',
'parent': parentSlideout,
'width': '400',
'enableTabLooping': true,
'overlay': (spec.overlay === undefined) ? true : spec.overlay,
'content': spec.slideoutContent,
'label': spec.slideoutLabel
});
}.bind(this));
},
_getMoreDeliveryOptionsSpec: function() {
var content = {
'module': CA_DeliveryPickerView,
'closeCallback': this._closeMoreDeliveryOptionsSlideout.bind(this),
'objectInformation': this.objectInformation,
'glassContext': this.glassContext,
'deliveryOptions': this._selections.delivery,
'burstSelected': this._selections[RunAsOptionsView.OPTION.BURST] ? true : false
};
var spec = {
'overlay': true,
'slideoutContent': content,
'slideoutLabel': StringResource.get('delivery')
};
return Promise.resolve(spec);
},
_getMoreLanguageOptionsSpec: function() {
var content = {
'module': 'bi/content_apps/common/ui/LanguagePickerView',
'closeCallback': this._closeMoreLanguageOptionsSlideout.bind(this)
};
if (this._selections.languages) {
content.enabledLanguages = this._selections.languages;
}
var spec = {
'slideoutContent': content,
'slideoutLabel': StringResource.get('languages')
};
return Promise.resolve(spec);
},
_closeMoreLanguageOptionsSlideout: function(selectedLanguages) {
this._selections.languages = selectedLanguages;
},
_closeMoreDeliveryOptionsSlideout: function(selectedOptions) {
this._selections.delivery = selectedOptions;
},
// Getting default values from report properties or previous selections
_getDefaultPDFOptionValues: function() {
if (this._selections.pdf) {
return Promise.resolve({
'pdfOptions': this._selections.pdf
});
}
if (this._defaultPDFOptionsValues) {
return Promise.resolve(this._defaultPDFOptionsValues);
}
var options = {
dataType: 'json',
type: 'GET',
url: ContentStoreObject.getSelfLink(this.objectInformation) + '?fields=options'
};
return this.glassContext.getCoreSvc('.Ajax').ajax(options)
.then(function(jsonResponse) {
var options = jsonResponse.data.data[0].options;
if (!options) {
return;
}
var defaultPDFOptions = options.filter(function(option) {
return (RunAsOptionsView.PDF_OPTIONS.indexOf(option.name) !== -1);
});
this._defaultPDFOptionsValues = {
'pdfOptions': defaultPDFOptions
};
return this._defaultPDFOptionsValues;
}.bind(this)).catch(this._handleRunError.bind(this));
},
_getMorePDFOptionsSpec: function() {
var content = {
'module': PdfOptionsView,
'closeCallback': this._closeMorePDFOptionsSlideout.bind(this)
};
return this._getDefaultPDFOptionValues()
.then(function(pdfOptions) {
if (pdfOptions) {
_.extend(content, pdfOptions);
}
var spec = {
'slideoutContent': content,
'slideoutLabel': StringResource.get('pdfOptions')
};
return spec;
});
},
_closeMorePDFOptionsSlideout: function(pdfOptions) {
this._selections.pdf = pdfOptions;
},
_onRun: function() {
_.extend(this._selections, this._runOptionsControl.getModifiedProperties());
this.logger.debug('RunAsOptionsView._onRun', this._selections);
if (this._selections[RunAsOptionsView.OPTION.RUN_IN_BG]) {
this._doRunInBackground();
} else {
this._doRunAs();
}
},
_doRunAs: function() {
this._appController.performAction(this._getActionId(), this._buildPayload());
this._appController.hideSlideOut();
},
_getSelectedFormats: function(bRunInBackgroud) {
var selectedFormats;
if (bRunInBackgroud) {
//returns an array
if (this._supportedFormats.length === 1) {
// Use the one and only supported format
selectedFormats = this._supportedFormats;
} else {
var formats = [];
for (var key in this._selections.formats) {
if (this._selections.formats.hasOwnProperty(key) &&
this._selections.formats[key]) {
formats.push(key);
}
}
selectedFormats = formats;
}
} else {
// returns a string
if (this._supportedFormats.length === 1) {
selectedFormats = this._supportedFormats[0];
} else {
selectedFormats = this._selections[RunAsOptionsView.OPTION.RUNFORMAT] || this._outputFormat;
}
}
return selectedFormats;
},
_updateBurstSelected: function(name, bValue) {
this._selections[RunAsOptionsView.OPTION.BURST] = bValue;
},
_updateSelectedFormat: function(name, value) {
this._selections.formats[name] = value;
if (name === 'PDF' && AuthoringHelper.userCanGenerateFormat(this.glassContext, name)) {
var pdfSection = this._runOptionsControl.getProperty(RunAsOptionsView.OPTION.ADVANCED_PDF);
if (value) {
pdfSection.show();
} else {
pdfSection.hide();
}
}
},
_setOutputLocaleRequestParams: function() {
if (this._selections.languages) {
// setting outputLocale will explicitly override the report language
this._requestParams.options.outputLocale = this._selections.languages;
}
},
_setDeliveryOptionsRequestParams: function() {
if (this._selections.delivery) {
this._requestParams.options.delivery = this._selections.delivery;
} else {
this._requestParams.options.delivery = {
'save': {
'notify': false
}
};
}
},
_setOutputFormatRequestParams: function() {
var selectedOutputFormats = this._getSelectedFormats(true /*bRunInBackgroud*/ );
this._requestParams.options.outputFormat = selectedOutputFormats;
},
_setSaveToCloudRequestParams: function() {
if (this._selections.delivery && (this._selections.delivery.cloudLocation) && (this._selections.delivery.cloudLocation !== '')) {
this._requestParams.options.saveToCloud = this._selections.delivery.cloudLocation;
if ((this._selections.delivery.cloudName) && (this._selections.delivery.cloudName !== '')) {
this._requestParams.options.cloudName = this._selections.delivery.cloudName;
}
}
},
_setExecutionTimeRequestParams: function() {
if (this._selections[RunAsOptionsView.OPTION.RUN_NOW_OR_LATER] === RunAsOptionsView.OPTION.RUN_LATER && this._selections.executionTime) {
if (Date.now() < Date.parse(this._selections.executionTime)) {
this._requestParams.executionTime = this._selections.executionTime;
} else {
GlassContextHelper.displayToast(this.glassContext, StringResource.get('invalidTime'));
throw 'Invalid time selected';
}
}
},
_setBurstOptionRequestParams: function() {
if (this._selections[RunAsOptionsView.OPTION.BURST]) {
this._requestParams.options.burst = true;
}
},
_setParametersRequestParams: function(parameters) {
if (parameters) {
this._requestParams.parameters = parameters;
}
},
_setPDFOptionsRequestParams: function() {
if (!this._selections || !this._selections.pdf) {
return;
}
this._requestParams.options.pdf = {};
this._selections.pdf.forEach(function(option) {
var value = option.value;
if ((option.name).indexOf('Password') !== -1 && option.value.length) {
var xmlDoc = $.parseXML(option.value);
var $pwd = $(xmlDoc).find('password');
if ($pwd.text().length) {
value = $pwd.text();
}
}
if (value) {
this._requestParams.options.pdf[option.name] = value;
}
}.bind(this));
},
_doRunInBackground: function() {
if (!this._getSelectedFormats(true /*bRunInBackground*/ ).length) {
GlassContextHelper.displayToast(this.glassContext,
StringResource.get('selectAFormat'), {
'type': 'warning'
});
throw 'No format selected';
}
if (this._promptValue) {
this._showPromptPicker();
this._appController.hideSlideOut();
return;
}
this._executeRequest();
},
_onPromptFinish: function() {
this._executeRequest();
},
_updateRunOptionsForPowerPlayPrompt: function(options) {
if (this._selections && this._selections.delivery && this._selections.delivery.email) {
options.ca_deliveryOptions = C10Utils.getPowerPlayC10DeliveryOptions(this._selections.delivery.email);
}
},
_showPromptPicker: function(openInTab) {
var toggler = $('
', {
'class': 'ca_promptpicker'
});
var options = {
'reportId': this.objectInformation.id,
'glassContext': this.glassContext,
'onFinish': this._onPromptFinish.bind(this),
'$toggler': toggler,
'deliveryOptions': this._selections.delivery,
'languageOptions': this._selections.languages
};
if (openInTab) {
options.openInTab = true;
}
if (C10Utils.isPowerPlay(this.objectInformation.type)) {
if (this._selections.runNowOrLater === 'later') {
options.executionTime = this._selections.executionTime;
}
this._updateRunOptionsForPowerPlayPrompt(options);
this._promptPickerControl = new PowerPlayPromptPickerView(options);
} else {
this._promptPickerControl = new PromptPickerView(options);
}
this._promptPickerControl.showPromptOverlay();
},
_getRequestParams: function() {
return this._appController.hideSlideOut().then(function() {
this._setOutputFormatRequestParams();
this._setSaveToCloudRequestParams();
this._setExecutionTimeRequestParams();
this._setDeliveryOptionsRequestParams();
this._setBurstOptionRequestParams();
this._setPDFOptionsRequestParams();
this._setOutputLocaleRequestParams();
if (this._promptValue) {
this._setParametersRequestParams(this._promptPickerControl.getParameterValues());
}
}.bind(this));
},
// if options is empty, don't bother send it in data
_validRequestParamsOptions: function(){
var options = this._requestParams.options;
if( options == null ){
return;
}else{
var content = [];
for (var key in options) {
if (options[key] != null) {
content.push(options[key]);
}
}
if(content.length === 0){
delete this._requestParams.options;
}
}
},
_executeRequest: function() {
this._getRequestParams().then(function() {
this._validRequestParamsOptions();
var jsonData = JSON.stringify(this._requestParams);
var options = {
'headers': {
'Content-Type': 'application/vnd.ibm.bi.platform.execution+json; charset=UTF-8',
'Accept': 'application/json'
},
'datatype': 'json',
'type': 'post',
'url': 'v1/reports/' + this.objectInformation.id + '/executions',
'data': jsonData
};
return this.glassContext.getCoreSvc('.Ajax').ajax(options)
.catch(this._handleRunError.bind(this));
}.bind(this));
},
_handleRunError: function(err) {
GlassContextHelper.showAjaxServiceError(this.glassContext, err);
},
_buildPayload: function() {
return {
'glassContext': this.glassContext,
'target': {
'objectInformation': this.objectInformation,
'itemId': this._getActionId(),
'runOptions': {
'prompt': this._promptValue,
'format': this._getSelectedFormats()
},
'activeObject': {
'oListControl': this.listControl,
'aSelectedContext': [this.objectInformation]
}
}
};
},
_getActionId: function() {
var actionId = RunAsOptionsView.ACTION_ID;
if (this.objectInformation.type.indexOf('powerPlay8Report') !== -1) {
actionId = 'com.ibm.bi.contentApps.defaultAction.' + this.objectInformation.type;
}
return actionId;
}
});
RunAsOptionsView.ACTION_ID = 'com.ibm.bi.contentApps.action.runAs';
RunAsOptionsView.SUPPORTED_FORMATS = {
'all': ['spreadsheetML', 'xlsxData', 'PDF', 'HTML', 'CSV', 'XML'],
'interactiveReport': ['HTML'],
'powerPlay8Report': ['PDF']
};
/* names used to access controls */
RunAsOptionsView.OPTION = {
PROMPT: 'promptForValues',
RUNFORMAT: 'runFormat',
OUTPUTFORMAT: 'outputFormat',
DELIVERY: 'delivery',
EXECUTIONTIME: 'executionTime',
LANGUAGES: 'languages',
RUN_IN_BG: 'runInBackgroundChecked',
RUN_LATER: 'later',
RUN_NOW: 'now',
RUN_NOW_OR_LATER: 'runNowOrLater',
BURST: 'burst',
ADVANCED_PDF: 'advancedPDF'
};
RunAsOptionsView.PDF_OPTIONS = ['outputPageDefinition',
'outputPageOrientation',
'userPassword',
'ownerPassword',
'allowPrintQuality',
'allowModifications',
'allowAnnotations',
'allowFieldCompletion',
'allowAssembly',
'allowContentCopy',
'allowAccessibilitySupport'
];
return RunAsOptionsView;
});
/*
*+------------------------------------------------------------------------+
*| Licensed Materials - Property of IBM
*| IBM Cognos Products: Content Explorer
*| (C) Copyright IBM Corp. 2015, 2018
*|
*| US Government Users Restricted Rights - Use, duplication or disclosure
*| restricted by GSA ADP Schedule Contract with IBM Corp.
*+------------------------------------------------------------------------+
*/
define('bi/content_apps/common/ui/list_actions/ViewReportAction',[
'bacontentnav/common/ui/list_actions/ListAction',
'bacontentnav/utils/ContentStoreObject',
'bi/commons/utils/Downloader',
'underscore'
], function(ListAction, ContentStoreObject, Downloader, _) {
'use strict';
var ViewReportAction = ListAction.extend({
canExecute: function(options) {
var selectedContext = options.target.activeObject.aSelectedContext;
if (!selectedContext || selectedContext.length > 1) {
return false;
}
return ContentStoreObject.hasPermissions(selectedContext[0], ['traverse', 'read']);
},
doAction: function(context) {
var selectedObjects = context.target.activeObject.aSelectedContext;
if (!selectedObjects || selectedObjects.length > 1) {
return Promise.reject(new Error('No objects selected'));
} else {
var selectedObject = selectedObjects[0];
return ContentStoreObject.getBaseObjectType(selectedObject).then(function(type) {
if (!this._isSupportedType(type)) {
return Promise.reject(new Error('Not supported type'));
} else {
var requestOptions = {
url: ContentStoreObject.getSelfLink(selectedObject),
type: 'GET',
dataType: 'json',
data: {
'fields': 'defaultOutputFormat'
}
};
return context.glassContext.getCoreSvc('.Ajax').ajax(requestOptions)
.then(function(response) {
response = response && response.data;
if (response.data[0].defaultOutputFormat) {
var outputId = context.target.activeObject.outputId;
var download = context.target.activeObject.download;
var suffix = download ? '/content?download=true' : this._getSuffix(type);
var outputHref;
// If we're passed an output ID then we want to view a specific output and not simply the latest
if (outputId) {
outputHref = 'v1/disp/repository/sid/cm/oid/' + outputId + suffix;
} else {
outputHref = 'v1/disp/repository/sid/cm/rid/' + selectedObject.id + '/oid/default' + suffix;
}
if (download) {
var downloader = this._getDownloader({
url: outputHref,
logger: context.glassContext.appController.logger
});
downloader.doDownload();
} else {
if (type.indexOf('powerPlay8Report') !== -1) {
var name = ContentStoreObject.getName(selectedObject);
outputHref = this._getPP8ReportViewerUrl(outputId, name);
}
this._openWindow(outputHref);
}
return Promise.resolve();
} else {
return Promise.reject(new Error('No saved output'));
}
}.bind(this));
}
}.bind(this));
}
},
_getDownloader: function(options) {
return new Downloader(options);
},
_openWindow: function(outputHref) {
window.open(outputHref);
},
_getSuffix: function(type) {
var suffix;
switch (type) {
case 'interactiveReport':
suffix = '/content/mht/content';
break;
case 'powerPlay8Report':
case 'powerPlay8ReportView':
suffix = '/content?cv.id=_THIS_';
break;
default:
suffix = '';
break;
}
return suffix;
},
_isSupportedType: function(type) {
var isSupported = false;
switch (type) {
case 'interactiveReport':
case 'powerPlay8Report':
case 'powerPlay8ReportView':
isSupported = true;
break;
default:
break;
}
return isSupported;
},
_getPP8ReportViewerUrl: function(outputId, name) {
var url = 'v1/disp?b_action=cognosViewer&ui.action=view&ui.format=PDF&ui.object=storeID(%22' + outputId + '%22)&ui.name=' + _.escape(name);
url = url + '&cv.header=false&ui.backURL=%2fcps4%2fportlets%2fcommon%2fclose.html';
return url;
}
});
return ViewReportAction;
});
/*
*+------------------------------------------------------------------------+
*| Licensed Materials - Property of IBM
*|
*| IBM Cognos Products: content-apps
*|
*| (C) Copyright IBM Corp. 2015, 2021
*|
*| US Government Users Restricted Rights - Use, duplication or disclosure
*| restricted by GSA ADP Schedule Contract with IBM Corp.
*+------------------------------------------------------------------------+
*/
define('bi/content_apps/VersionsTab',[
'require',
'jquery',
'bi/glass/app/ContentView',
'bi/commons/ui/Slideout',
'bi/content_apps/nls/StringResource',
'bacontentnav/utils/UIHelper',
'bacontentnav/utils/ContentStoreObject',
'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl',
'bacontentnav/utils/GlassContextHelper',
'bi/content_apps/common/ui/list_actions/ViewReportAction',
'bi/commons/ui/dialogs/ConfirmationDialog',
'bi/commons/utils/BidiUtil',
'underscore'
], function(localRequire, $, ContentView, Slideout, StringResource, UIHelper, ContentStoreObject, PropertyUIControl, GlassContextHelper, ViewReportAction, ConfirmationDialog, BidiUtil, _) {
'use strict';
var _SUPPORTED_FORMATS = {
'PDF': true,
'HTML': true,
'CSV': true,
'spreadsheetML': true,
'xlsxData': true,
'XHTML': true,
'XLWA': true,
'XML': true,
'HTMLFragment': true
};
var _FORMAT_ICONSTRING = {
'xlsxdata':'common-excel_icon',
'spreadsheetml':'common-excel_icon',
'xlwa':'common-excel_icon',
'xhtml':'common-html_icon',
'html':'common-html_icon',
'csv':'common-csv_icon',
'pdf':'common-pdf_icon',
'xml':'common-xml_icon',
'default': 'common-savedoutput_report'
};
var VersionsTab = ContentView.extend({
/**
* @param options.el {node} - container dom node
*/
init: function(options) {
VersionsTab.inherited('init', this, arguments);
_.extend(this, options);
this.noBurstKey = 'secretIBMNoBurstKey';
this.mockableViewInteractiveReportAction = ViewReportAction;
this.batchSize = Math.floor((window.innerHeight) / 18);
this.initialEndIndex = this.batchSize;
this.renderIndex = this.batchSize;
},
render: function() {
this._id = _.uniqueId('prop_');
return this._queryHistoriesVersions().then(function(res) {
if (!(res.historiesInfo || res.versionsInfo)) {
UIHelper.renderInfoMessage(this.$el, StringResource.get('noVersions'));
} else {
this.$el.addClass('versionsTab');
var mergedInfo = this._mergeVersionAndHistory(res.historiesInfo, res.versionsInfo);
mergedInfo.sort(function(a, b) {
a = new Date(ContentStoreObject.getRequestedTime(a));
b = new Date(ContentStoreObject.getRequestedTime(b));
return a > b ? -1 : a < b ? 1 : 0;
});
this.items = this._getItems(mergedInfo);
if (this.initialEndIndex > this.items.length) {
this.initialEndIndex = this.items.length;
}
this._oPropertyUIControl = new PropertyUIControl({
'el': this.$el,
'items': [{
'name': 'showAllHistory',
'label': StringResource.get('showAllHistory'),
'checked': false,
'type': 'CheckBox',
'onChange': this._showAllHistoryChange.bind(this)
}, {
'type': 'Separator'
}].concat(this.items.slice(0, this.initialEndIndex))
});
return this._oPropertyUIControl.render();
}
}.bind(this))
.then(function() {
this._showAllHistoryChange();
// Render the first page with an almost minimum number of rows and then render the subsequent pages with a size: 3 times bigger than the one for the first page.
this.batchSize *= 3;
this._scrollNode = this.$el.find('.containerUIControl');
$(this._scrollNode).on('scroll', this._onScroll.bind(this));
}.bind(this));
},
/**
* Render a batch of spec. items in [startIndex, endIndex)
* @startIndex Start index in the spec. items list
* @endIndex End index in the the spec. items list
*/
_render: function(startIndex, endIndex) {
this.renderIndex = endIndex;
return this._oPropertyUIControl.renderItems(this.items.slice(startIndex, endIndex));
},
/**
* Handle scroll event
*/
_onScroll: function(event) {
if (this._bScrollToBottom(event) === true) {
if (this.renderIndex >= this.items.length) {
return;
}
var endIndex = this.renderIndex + this.batchSize;
if (endIndex < this.items.length) {
return this._render(this.renderIndex, endIndex);
} else {
return this._render(this.renderIndex, this.items.length);
}
}
},
/**
* @return true if scrolling to the bottom of current pane
* false otherwise
*/
_bScrollToBottom: function(event) {
var $target = $(event.target);
if ($target.scrollTop() + $target.innerHeight() >= ($target[0].scrollHeight - 20)) { // If we've scrolled to the bottom
return true;
}
return false;
},
/**
* @return object
*/
_queryHistoriesVersions: function() {
var aPromises = [];
if (this.objectInfo) {
aPromises.push(ContentStoreObject.getHistories(this.objectInfo, 'output'));
aPromises.push(ContentStoreObject.getVersions(this.objectInfo, 'creationTime'));
}
return Promise.all(aPromises).then(function(results) {
return {
historiesInfo: results[0],
versionsInfo: results[1]
};
});
},
_handleGetOutputsSuccess: function(data) {
var outputs = data.data;
var index = data.index;
var outputsInfo = [];
if (outputs) {
outputs.forEach(function(output) {
if (!_SUPPORTED_FORMATS[output.format]) {
return;
}
var processedOutput = {
'id': ContentStoreObject.getObjectId(output),
'format': ContentStoreObject.getFormat(output),
'content': ContentStoreObject.getOutputContentLink(output),
'modificationTime': ContentStoreObject.getModificationTime(output, true, 'short')
};
if (processedOutput.format && processedOutput.content) {
var burstKey = ContentStoreObject.getBurstKey(output);
var locale = ContentStoreObject.getLocale(output);
if (burstKey) {
if (!outputsInfo[burstKey]) {
outputsInfo[burstKey] = [];
}
if (!outputsInfo[burstKey][locale]) {
outputsInfo[burstKey][locale] = [];
}
outputsInfo[burstKey][locale].push(processedOutput);
} else {
if (!outputsInfo[this.noBurstKey]) {
outputsInfo[this.noBurstKey] = [];
}
if (!outputsInfo[this.noBurstKey][locale]) {
outputsInfo[this.noBurstKey][locale] = [];
}
outputsInfo[this.noBurstKey][locale].push(processedOutput);
}
}
}.bind(this));
}
return { outputsInfo: outputsInfo, index: index };
},
/**
* @return array
*/
_mergeVersionAndHistory: function(historiesInfo, versionsInfo) {
historiesInfo = historiesInfo || [];
versionsInfo = versionsInfo || [];
$.each(versionsInfo, function(i, v) {
var found = false;
$.each(historiesInfo, function(i, h) {
if (h.output && h.output.id === v.id) {
found = true;
return false;
}
});
if (!found) {
v[ContentStoreObject.REQUESTED_TIME] = ContentStoreObject.getCreationDate(v);
delete v[ContentStoreObject.CREATION_TIME];
v[ContentStoreObject.STATUS] = 'succeeded';
historiesInfo.push(v);
}
});
// Remove the history output which was kept in cache
$.each(historiesInfo, function(i, h) {
if (h.output && h.output.id) {
var outputid = h.output.id;
var found = false;
$.each(versionsInfo, function(i, v) {
if (v.id === outputid) {
found = true;
return false;
}
});
if (!found) {
h.output = null;
}
}
});
return historiesInfo;
},
_getItems: function(mergedInfo) {
this.mergedInfo = mergedInfo;
var items = [];
this.mergedInfo.forEach(function(historyInfo, index) {
var requestedTime = ContentStoreObject.getRequestedTime(historyInfo, true, 'medium');
var succeeded = (ContentStoreObject.getStatus(historyInfo) === 'succeeded');
var detailsLink = ContentStoreObject.getDetailsLink(this.mergedInfo[index]);
var hasDetails = detailsLink !== null;
var outputsLink = this._getOutputsLinkFromIndex(index);
var hasOutput = outputsLink !== null;
items.push({
'type': 'SingleLineLinks',
'name': index + '_versions',
'role': 'group',
'items': [{
'align': 'left',
'items': [{
'type': 'icon',
'class': succeeded ? 'versionReport' : 'versionStatusFailed',
'svgIcon': succeeded ? hasOutput ? 'common-savedoutput_report' : 'common-savedoutput_reporthistory' : 'common-failed',
'value': succeeded ? StringResource.get('successful') : StringResource.get('failed'),
'iconTooltip': StringResource.get('report')
}, {
'type': 'text',
'value': requestedTime,
'class': 'versionText' + (hasOutput ? '' : ' hasNoOutput'),
'clickCallback': hasOutput ? this._toggleOutputsSection.bind(this, index) : null
}]
}, {
'align': 'right',
'items': [{
'type': 'icon',
'class': 'versionDetailsLinks' + (hasDetails ? '' : ' disabled'),
'svgIcon': 'common-info-moreinfo',
'clickCallback': hasDetails ? this._openDetails.bind(this, index) : null,
'iconTooltip': StringResource.get('showDetails'),
'showRightArrow': true
}]
}]
});
items.push({
'type': 'CollapsibleSection',
'name': index + '_outputs',
'label': requestedTime,
'styleAsSimpleRow': true,
'hideSectionTitle': true,
'indent': 3.3,
'items': [],
'onOpenChange': this._openOutputsSection.bind(this, index)
});
items.push({
'type': 'Separator'
});
}.bind(this));
return items;
},
_toggleOutputsSection: function(index, evt) {
/*eslint no-unused-vars: 0*/
this._getOutputSection(index).toggleCollapsibleSection();
},
_showAllHistoryRefresh: function() {
var showAllHistory = this._oPropertyUIControl.getProperty('showAllHistory').isChecked();
this._showAllHistoryChange(null, showAllHistory);
},
_showItem: function(i, elem) {
$(elem).removeClass('hidden');
},
_selectItem: function(elem) {
var selected = $(elem).closest('.propertyRow').nextUntil('.separator').addBack();
// Add the separator
selected = selected.add(selected.last().next());
return selected;
},
_hideItem: function(i, elem) {
this._selectItem(elem).addClass('hidden');
},
_removeItem: function(elem) {
this._selectItem(elem).remove();
},
_showAllHistoryChange: function(name, checked) {
if (checked) {
$('.itemContainerUIControl > div', this.$el).each(this._showItem.bind(this));
} else {
$('.itemContainerUIControl .hasNoOutput', this.$el).each(this._hideItem.bind(this));
}
},
_getOutputFromIndex: function(index) {
var obj = this.mergedInfo[index];
var oData = {};
if (_.isObject(obj.output)) {
oData[ContentStoreObject.OUTPUT] = [obj.output];
} else {
oData[ContentStoreObject.OUTPUT] = [obj];
}
return oData;
},
_getOutputsLinkFromIndex: function(index) {
var obj = this._getOutputFromIndex(index);
return ContentStoreObject.getOutputsLink(obj);
},
_getVersionLinkFromIndex: function(index) {
var obj = this._getOutputFromIndex(index);
return ContentStoreObject.getVersionLink(obj);
},
_openOutputsSection: function(index, name, open) {
if (open) {
var outputsLink = this._getOutputsLinkFromIndex(index);
this._getOutputs(outputsLink, index)
.then(this._handleGetOutputsSuccess.bind(this))
.then(this._getOutputsSectionPayload.bind(this))
.done(function(payload) {
var items = this._getItemsSpec(payload.outputsInfo, index, payload.items);
this._getOutputSection(index).refreshProperties(items);
}.bind(this));
}
},
_getVersionSection: function(index) {
var outputSectionId = index + '_versions';
return this._oPropertyUIControl.getProperty(outputSectionId);
},
_getOutputSection: function(index) {
var outputSectionId = index + '_outputs';
return this._oPropertyUIControl.getProperty(outputSectionId);
},
_openDetails: function(index) {
this._getDetails(index).then(function(details) {
var overlaySlideoutEl = $('
');
this.parentEl.append(overlaySlideoutEl);
var overlaySlideout = new Slideout({
'glassContext': this.glassContext,
'position': this.slideout.position,
'el': overlaySlideoutEl,
'width': '400',
'content': {
'module': 'bi/content_apps/VersionsDetailsView',
'parentView': this,
'objectInfo': this.objectInfo,
'historyInfo': this.mergedInfo[index],
'detailsInfo': details,
'glassContext': this.glassContext
}
});
overlaySlideout.render()
.then(overlaySlideout.show());
}.bind(this));
},
_getOutputsSectionPayload: function(data) {
var outputsInfo = data.outputsInfo;
var index = data.index;
var items = [];
if (this._canDelete()) {
items.push({
'type': 'SingleLineLinks',
'items': [{
'align': 'left',
'items': [{
'type': 'text',
'value': StringResource.get('deleteReportVersion'),
'class': 'versionText',
'clickCallback': function() {
this._onClickDelete(index);
}.bind(this)
}]
}]
});
}
return GlassContextHelper.getContentLocales(this.glassContext).then(function(contentLocales) {
if (outputsInfo && Object.keys(outputsInfo).length > 0) {
var locale;
for (var burstKey in outputsInfo) {
if (outputsInfo.hasOwnProperty(burstKey)) {
if (burstKey !== this.noBurstKey) {
items.push({
'type': 'SingleLineLinks',
'items': [{
'align': 'left',
'items': [{
'type': 'text',
'class': 'wraptext versionText',
'value': burstKey
}]
}]
});
}
for (locale in outputsInfo[burstKey]) {
if (outputsInfo[burstKey].hasOwnProperty(locale)) {
items = items.concat(this._getLocaleSectionPayload(locale, contentLocales[locale], outputsInfo[burstKey][locale]));
}
}
items.push({
'type': 'Separator'
});
}
}
} else {
items.push({
'type': 'SingleLineLinks',
'items': [{
'align': 'left',
'items': [{
'type': 'text',
'class': 'versionText',
'value': StringResource.get('noSavedOutputs')
}]
}]
});
}
return Promise.resolve({
items: items,
outputsInfo: outputsInfo
});
}.bind(this));
},
_getLocaleSectionPayload: function(locale, fullLocale, aOutputs) {
var items = [];
var outputItems = [];
outputItems.push({
'type': 'text',
'class': 'versionsLocale',
'value': locale.toUpperCase()
});
outputItems.push({
'type': 'text',
'class': 'versionsLocale',
'value': fullLocale,
'name': locale,
'hidden': true
});
aOutputs.forEach(function(output) {
outputItems.push({
'type': 'icon',
'class': 'versionsOutput',
'name': 'outputlink',
'svgIcon': this._getOutputIconString(output.format),
'clickCallback': this._openOutput.bind(this, output, false),
'iconTooltip': StringResource.get(output.format),
'ariaLabelledby': locale
});
if (this._getOutputDefaultAction(output.format) === 'interactive') {
outputItems.push({
'type': 'icon',
'class': 'versionsOutput',
'name': 'outputlink',
'svgIcon': 'common-download',
'clickCallback': this._openOutput.bind(this, output, true),
'iconTooltip': StringResource.get('download'),
'ariaLabelledby': locale
});
}
}.bind(this));
items.push({
'type': 'SingleLineLinks',
'items': [{
'align': 'left',
'items': outputItems
}]
});
return items;
},
_getOutputIconString: function(format) {
return _FORMAT_ICONSTRING[format.toLowerCase()] || _FORMAT_ICONSTRING['default'];
},
_getOutputDefaultAction: function(format) {
var value;
switch (format.toLowerCase()) {
case 'xhtml':
value = 'interactive';
break;
default:
value = 'view';
break;
}
return value;
},
_getDetails: function(index) {
if (this.mergedInfo && this.mergedInfo[index]) {
var options = {
dataType: 'json',
type: 'GET',
url: ContentStoreObject.getDetailsLink(this.mergedInfo[index])
};
return this.glassContext.getCoreSvc('.Ajax').ajax(options)
.then(function(response) {
if (response && response.data) {
return Promise.resolve(response.data.data);
} else {
return Promise.reject(new Error('No details data'));
}
});
} else {
return Promise.reject(new Error('No details'));
}
},
_getOutputs: function(outputsLink, index) {
if (outputsLink) {
var options = {
dataType: 'json',
type: 'GET',
url: outputsLink
};
return this.glassContext.getCoreSvc('.Ajax').ajax(options)
.then(function(response) {
if (response && response.data) {
return Promise.resolve({ data: response.data.data, index: index });
} else {
return Promise.reject(new Error('No outputs data'));
}
});
} else {
//resolve anyways if there are no reportVersions with this history
return Promise.resolve({});
}
},
_openOutput: function(output, download) {
// let the output handlers have the first chance
return this._handleOutput({
output: output,
report: this.objectInfo,
glassContext: this.glassContext,
download: download
})
.then(function(isHandled) {
if (!isHandled) {
// get values from options
var id = output.id;
var modificationTime = output.modificationTime;
var format = output.format;
var url = output.content;
var defaultAction = this._getOutputDefaultAction(format);
var viewAction, actionContext;
switch (defaultAction) {
case 'interactive':
// This is just a temporary solution for GA. Viewing saved output
// should use contributions
viewAction = new this.mockableViewInteractiveReportAction();
actionContext = {
'glassContext': this.glassContext,
'target': {
'activeObject': {
'aSelectedContext': [this.objectInfo],
'outputId': id,
'download': !!download
},
'itemId': 'com.ibm.bi.contentApps.defaultAction.interactiveReport'
}
};
viewAction.doAction(actionContext);
break;
case 'view':
if (this.objectInfo.type && this.objectInfo.type.indexOf('powerPlay8Report') > -1) {
viewAction = new this.mockableViewInteractiveReportAction();
actionContext = {
'glassContext': this.glassContext,
'target': {
'activeObject': {
'aSelectedContext': [this.objectInfo],
'outputId': id,
'download': !!download
},
runOptions: {
prompt: true
},
'itemId': 'com.ibm.bi.contentApps.defaultAction.powerPlay8Report'
}
};
viewAction.doAction(actionContext);
this._addToMRU(this.objectInfo);
} else {
this.glassContext.appController.openAppView('savedoutput', this._getReportPayload(id, modificationTime, format, url));
this._addToMRU(this.objectInfo);
}
break;
default:
this.glassContext.appController.openAppView('savedoutput', this._getReportPayload(id, modificationTime, format, url));
this._addToMRU(this.objectInfo);
break;
}
}
return Promise.resolve();
}.bind(this));
},
_addToMRU: function(objInfo) {
return this.glassContext.getSvc('.Content').then(function(contentSvc) {
contentSvc.addToMRU(objInfo);
});
},
_getReportPayload: function(id, modificationTime, format, url) {
var title = this.objectInfo.defaultName + ' - ' + modificationTime + ' - ' + format.toUpperCase();
return {
'content': {
'path': url,
'title': title,
'id': id,
'reportId': ContentStoreObject.getObjectId(this.objectInfo),
'type': ContentStoreObject.getType(this.objectInfo),
'permissions': ContentStoreObject.getPermissions(this.objectInfo),
'runInAdvancedViewer': ContentStoreObject.getRunInAdvancedViewer(this.objectInfo)
}
};
},
_getItemsSpec: function(outputsInfo, index, outputSectionPayload) {
if (outputsInfo && Object.keys(outputsInfo).length > 0) {
var rightItems = {
'align': 'right',
'items': [{
'type': 'SingleLineLinks',
'name': 'sectionRunHistory',
'items': []
}]
};
var items = [{
'type': 'Split',
'label': 'Split',
'name': 'Split' + this.id,
'items': [{
'align': 'left',
'items': outputSectionPayload
}, rightItems]
}];
return items;
} else {
return outputSectionPayload;
}
},
_canDelete: function() {
if (this.objectInfo && this.objectInfo.permissions) {
return ContentStoreObject.hasPermissions(this.objectInfo, ['write']);
}
return true;
},
_onClickDelete: function(index) {
var oDialog = new ConfirmationDialog('confirmDelete', StringResource.get('confirmDelete'), StringResource.get('confirmDeleteMessage'));
oDialog.confirm(function() {
this._deleteVersion(index);
this.hasReportVersion = false;
}.bind(this));
oDialog.renderContent($('
'));
oDialog._container().addClass('contentDeleteConfirmDialog');
},
_handleDeleteVersionSuccess: function(index) {
var versionSection = this._getVersionSection(index);
var versionSectionNode = versionSection.getPropertyNode();
var outputSection = this._getOutputSection(index);
$('.versionText', versionSectionNode).removeClass('clickable').addClass('hasNoOutput');
this._showAllHistoryRefresh();
if ($('.versionDetailsLinks', versionSectionNode).hasClass('disabled')) {
this._removeItem(versionSectionNode);
}
var use = $('.versionReport .svgIcon use', versionSectionNode);
use.attr('xlink:href', '#common-savedoutput_reporthistory');
outputSection.getPropertyNode().remove();
var sText = StringResource.get('toastDoneDeletingSingular', {
'nameOfItem': BidiUtil.enforceTextDirection(StringResource.get('reportOutputVersion'))
});
this.glassContext.appController.showToast(sText);
},
_deleteVersion: function(index) {
var versionLink = this._getVersionLinkFromIndex(index);
if (versionLink) {
var options = {
dataType: 'json',
type: 'DELETE',
url: versionLink + '?force=true&recursive=true'
};
return this.glassContext.getCoreSvc('.Ajax').ajax(options)
.then(this._handleDeleteVersionSuccess.bind(this, index))
.catch(function(err) { GlassContextHelper.showAjaxServiceError(this.glassContext, err); }.bind(this));
} else {
return Promise.resolve();
}
},
// consider moving to a helper/utility that can load other handlers
_initOutputHandlers: function() {
if (this._outputHandlers) {
return Promise.resolve();
} else {
return this.glassContext.appController.findCollection('com.ibm.bi.contentApps.authoring.outputHandlers')
.then(function(collectionItems) {
this._outputHandlers = [];
var outputHandlersPromises = [];
_.each(collectionItems, function(item) {
outputHandlersPromises.push(
new Promise(function(resolve) {
localRequire([item.outputHandler], function(HandlerModule) {
this._outputHandlers.push(new HandlerModule());
resolve();
}.bind(this));
}.bind(this)));
}.bind(this));
return Promise.all(outputHandlersPromises);
}.bind(this));
}
},
_handleOutput: function(options) {
return this._initOutputHandlers()
.then(function() {
if (this._getOutputDefaultAction(options.output.format) === 'interactive' && options.download) {
return Promise.resolve(false);
}
var maxPriority = -1;
var currentHandler;
_.each(this._outputHandlers || [], function(outputHandler) {
var outputHandlerPriority = outputHandler.getPriority();
if (outputHandlerPriority > maxPriority && outputHandler.canExecute(options)) {
currentHandler = outputHandler;
maxPriority = outputHandlerPriority;
}
});
if (currentHandler) {
currentHandler.execute(options);
return Promise.resolve(true);
} else {
return Promise.resolve(false);
}
}.bind(this));
}
});
return VersionsTab;
});
/*
*+------------------------------------------------------------------------+
*| Licensed Materials - Property of IBM
*| IBM Cognos Products: Content Explorer
*| (C) Copyright IBM Corp. 2015, 2018
*|
*| US Government Users Restricted Rights - Use, duplication or disclosure
*| restricted by GSA ADP Schedule Contract with IBM Corp.
*+----
*/
define('bi/content_apps/ArchivesTab',['q',
'bi/glass/app/ContentView',
'bi/content_apps/nls/StringResource',
'bi/content_apps/utils/C10Utils',
'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl',
'underscore'
], function(Q, View, StringResource, C10Utils, PropertyUIControl, _) {
'use strict';
var ArchivesTab = View.extend({
/**
@paran options.el {node} - container dom node
**/
init: function(options) {
ArchivesTab.inherited('init', this, arguments);
_.extend(this, options);
},
_viewArchivedVersion: function() {
C10Utils.openC10Morphlet(C10Utils.morphletMap.archive, this.objectInfo.type, this.objectInfo.id, [{
'output_tab': 'arch'
}, {
'm_name': this.objectInfo.defaultName
}]);
},
render: function() {
var deferred = Q.defer();
this._id = _.uniqueId('prop_');
this._oPropertyUIControl = new PropertyUIControl({
'el': this.$el,
'glassContext': this.glassContext,
'items': [{
'name': 'viewArchivedVersions',
'type': 'SingleLineLinks',
'items': [{
'align': 'left',
'items': [{
'type': 'text',
'value': StringResource.get('viewRunHistory')
}]
}, {
'align': 'right',
'items': [{
'type': 'text',
'value': StringResource.get('viewArchivedVersions'),
'clickCallback': this._viewArchivedVersion.bind(this)
}]
}]
}]
});
this._oPropertyUIControl.render().then(function() {
deferred.resolve(this);
}.bind(this));
return deferred.promise;
}
});
return ArchivesTab;
});
/*
*+------------------------------------------------------------------------+
*| Licensed Materials - Property of IBM
*| IBM Cognos Products: Content Explorer
*| (C) Copyright IBM Corp. 2015, 2018
*|
*| US Government Users Restricted Rights - Use, duplication or disclosure
*| restricted by GSA ADP Schedule Contract with IBM Corp.
*+------------------------------------------------------------------------+
*/
define('bi/content_apps/VersionsView',[
'bi/glass/app/ContentView',
'bi/content_apps/nls/StringResource',
'bacontentnav/utils/ContentStoreObject',
'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl',
'bi/content_apps/VersionsTab',
'bi/content_apps/ArchivesTab',
'underscore'
],
function(ContentView, StringResource, ContentStoreObject, PropertyUIControl, VersionsTab, ArchivesTab, _) {
'use strict';
var VersionsView = ContentView.extend({
init: function(options) {
VersionsView.inherited('init', this, arguments);
_.extend(this, options);
},
render: function() {
this._containerElement = $('
', {
'class': 'propertyUIControl versionsView'
});
this.$el.append(this._containerElement);
return this._getAdditionalInfo().then(function() {
this._oPropertyUIControl = this._getPropertyUIControl({
'el': this.$el,
'glassContext': this.glassContext,
'slideout': this.slideout,
'animatedSpinner': true,
'items': [{
'name': 'versions',
'value': StringResource.get('versions'),
'type': 'Banner'
}, {
'type': 'TabControl',
'items': [{
'name': StringResource.get('versions'),
'module': VersionsTab,
'objectInfo': this.objectInformation,
'glassContext': this.glassContext,
'slideout': this.slideout,
'parentEl': this.$el
}, {
'name': StringResource.get('archives'),
'module': ArchivesTab,
'objectInfo': this.objectInformation,
'glassContext': this.glassContext,
'slideout': this.slideout
}]
}]
});
return this._oPropertyUIControl.render();
}.bind(this));
},
_getPropertyUIControl: function(options) {
return new PropertyUIControl(options);
},
_getAdditionalInfo: function() {
return this.glassContext.getCoreSvc('.Ajax').ajax({
dataType: 'json',
type: 'GET',
url: ContentStoreObject.getSelfLink(this.objectInformation),
data: {
fields: 'permissions,' + ContentStoreObject.RUN_IN_ADVANCED_VIEWER
}
}).then(function(response) {
var data = response.data && response.data.data;
if (data) {
_.extend(this.objectInformation, data[0]);
} else {
return Promise.reject(new Error('No additional information'));
}
}.bind(this));
}
});
return VersionsView;
});
/*
*+------------------------------------------------------------------------+
*| Licensed Materials - Property of IBM
*| IBM Cognos Products: Content Explorer
*| (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('bi/content_apps/VersionsDetailsView',[
'q',
'jquery',
'bi/glass/app/ContentView',
'bi/content_apps/nls/StringResource',
'bacontentnav/utils/ContentStoreObject',
'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl',
'bacontentnav/utils/GlassContextHelper',
'bi/content_apps/utils/C10Utils',
'underscore'
],
function(Q, $, ContentView, StringResource, ContentStoreObject, PropertyUIControl, GlassContextHelper, C10Utils, _) {
'use strict';
var VersionsDetailsView = ContentView.extend({
init: function(options) {
VersionsDetailsView.inherited('init', this, arguments);
_.extend(this, options);
},
render: function() {
var deferred = Q.defer();
this._getItems().then(function(items) {
this.$el.addClass('versionsDetails');
this._oPropertyUIControl = new PropertyUIControl({
'el': this.$el,
'glassContext': this.glassContext,
'slideout': this.slideout,
'items': items
});
return this._oPropertyUIControl.render();
}.bind(this)).done(deferred.resolve);
return deferred.promise;
},
_getItems: function() {
var deferred = Q.defer();
var succeeded = (ContentStoreObject.getStatus(this.historyInfo) === 'succeeded');
var items = [{
'type': 'Banner',
'name': 'detailsBanner',
'value': ContentStoreObject.getRequestedTime(this.historyInfo, true, 'medium'),
'centerLabel': true,
'backButton': true,
'editable': false,
'readOnly': true,
'onClose': function() {
this.slideout.hide();
}.bind(this)
}, {
'type': 'Separator'
}, {
'type': 'SingleLineLinks',
'name': 'actionbar',
'items': [{
'align': 'left',
'items': [{
'type': 'icon',
'class': succeeded ? 'versionStatusSuccessful' : 'versionStatusFailed',
'svgIcon': succeeded ? 'common-successful' : 'common-failed',
'value': succeeded ? StringResource.get('successful') : StringResource.get('failed'),
'iconTooltip': succeeded ? StringResource.get('successful') : StringResource.get('failed')
}, {
'type': 'text',
'class': 'versionStatusText',
'role': 'status',
'value': succeeded ? StringResource.get('successful') : StringResource.get('failed')
}]
}]
}, {
'type': 'SingleLineLinks',
'name': 'historydetails',
'items': [{
'align': 'right',
'items': [{
'type': 'text',
'value': StringResource.get('runHistoryDetails'),
'class': 'historydetailsText',
'clickCallback': this._viewRunHistory.bind(this),
'showRightArrow': true
}]
}]
}];
if (ContentStoreObject.getMessages(this.detailsInfo)) {
items.push({
'type': 'CollapsibleSection',
'name': 'errorMessages',
'open': true,
'label': StringResource.get('errorMessages'),
'items': this._getMessageItems()
});
}
this._getOptionsItems().then(function(optionsItems) {
items = items.concat([{
'type': 'CollapsibleSection',
'name': 'runTime',
'open': true,
'label': StringResource.get('runTime'),
'items': [{
'type': 'SingleLineValue',
'name': 'requestTime',
'label': StringResource.get('requestTime'),
'value': ContentStoreObject.getRequestedTime(this.historyInfo, true, 'medium')
}, {
'type': 'Separator'
}, {
'type': 'SingleLineValue',
'name': 'startTime',
'label': StringResource.get('startTime'),
'value': ContentStoreObject.getExecutionTime(this.historyInfo, true, 'medium')
}, {
'type': 'Separator'
}, {
'type': 'SingleLineValue',
'name': 'endTime',
'label': StringResource.get('endTime'),
'value': ContentStoreObject.getCompletionTime(this.historyInfo, true, 'medium')
}]
}]);
if (this.objectInfo.type !== 'jupyterNotebook') {
items.push({
'type': 'CollapsibleSection',
'name': 'options',
'open': true,
'label': this.objectInfo.type === 'jobDefinition' ? StringResource.get('job') : StringResource.get('report'),
'items': optionsItems
});
}
var parameters = ContentStoreObject.getDetailsReportVersionParameters(this.detailsInfo);
if (parameters) {
items = items.concat([{
'type': 'CollapsibleSection',
'name': 'promptValues',
'label': StringResource.get('promptValues'),
'items': this._getPromptValuesItems(parameters)
}]);
}
deferred.resolve(items);
}.bind(this));
return deferred.promise;
},
_getMessageItems: function() {
var items = [];
var msgIconClass = 'versionMessageIcon ';
var svgIcon = '';
ContentStoreObject.getMessages(this.detailsInfo).forEach(function(msg, counter) {
var severity = ContentStoreObject.getMessageSeverity(msg);
var iconClass = '';
switch (severity) {
case 'error':
case 'fatal':
iconClass = msgIconClass + 'versionErrorIcon';
svgIcon = 'common-close-cancel-error';
break;
case 'warn':
iconClass = msgIconClass + 'versionWarningIcon';
svgIcon = 'common-warning-hollow';
break;
case 'debug':
iconClass = msgIconClass + 'versionDebugIcon';
svgIcon = 'common-debug';
break;
case 'info':
iconClass = msgIconClass + 'versionInfoIcon';
svgIcon = 'common-information';
break;
}
items.push({
'type': 'SingleLineLinks',
'name': 'messages_' + counter,
'items': [{
'align': 'left',
'items': [{
'type': 'icon',
'class': iconClass,
'svgIcon': svgIcon,
'value': StringResource.get(severity),
'iconTooltip': StringResource.get(severity)
}, {
'type': 'text',
'class': 'wraptext textSelectable',
'value': ContentStoreObject.getMessageDetail(msg)
}]
}]
});
});
return items;
},
_getOptionsItems: function() {
var options = ContentStoreObject.getDetailsReportVersionOptions(this.detailsInfo);
var deferred = Q.defer();
if (options) {
this._getReportLanguages(options).then(function(languages) {
// todo: of job type, don't push formats
var items = [];
if (this.objectInfo.type !== 'jobDefinition'){
items.push({
'type': 'TextArea',
'name': 'formats',
'label': StringResource.get('formats'),
'value': this._getReportFormats(options),
'editable': false,
'multiline': false
},{
'type': 'Separator'
});
}
items.push({
'type': 'TextArea',
'name': 'languages',
'label': StringResource.get('languages'),
'value': languages,
'editable': false,
'multiline': false
});
var location = ContentStoreObject.getLocation(this.objectInfo);
if (location) {
items = items.concat([{
'type': 'Separator'
}, {
'type': 'SingleLineValue',
'name': 'location',
'label': StringResource.get('location'),
'value': location
}]);
}
deferred.resolve(items);
}.bind(this));
} else {
deferred.resolve([{
'type': 'SingleLineLinks',
'items': [{
'align': 'left',
'items': [{
'type': 'text',
'class': 'wraptext',
'value': StringResource.get('noReportOptionsAvailable')
}]
}]
}]);
}
return deferred.promise;
},
_getReportFormats: function(options) {
var formatsArray = this._getReportVersionOption(options, 'outputFormat');
var formatsLabelArray = [];
if (formatsArray) {
if (_.isArray(formatsArray)) {
formatsArray.forEach(function(format) {
formatsLabelArray.push(StringResource.get(format));
});
} else {
formatsLabelArray.push(StringResource.get(formatsArray));
}
return this._getDelimitedStringFromArray(formatsLabelArray);
} else {
return StringResource.get('unavailable');
}
},
_getReportLanguages: function(options) {
var localeArray = this._getReportVersionOption(options, 'outputLocale');
var deferred = Q.defer();
if (localeArray) {
GlassContextHelper.getContentLocales(this.glassContext).then(function(contentLocales) {
var languages = [];
// Make sure we have an object in case getContentLocales promise returns undefined
contentLocales = contentLocales || {};
localeArray.forEach(function(locale) {
languages.push(contentLocales[locale]);
});
deferred.resolve(this._getDelimitedStringFromArray(languages));
}.bind(this));
} else {
deferred.resolve(StringResource.get('unavailable'));
}
return deferred.promise;
},
_getDelimitedStringFromArray: function(array) {
if (array) {
return array.join(', ');
}
return null;
},
_getReportVersionOption: function(options, name) {
var grepResult = $.grep(options, function(e) {
return e.name === name;
});
return grepResult.length === 1 && grepResult[0].value ? grepResult[0].value : null;
},
_getPromptValuesItems: function(parameters) {
var items = [];
var promptValues = ContentStoreObject.getPromptsDisplayValues(parameters, true);
promptValues.forEach(function(prompt) {
items.push({
'type': 'SingleLineLinks',
'items': [{
'align': 'left',
'items': [{
'type': 'text',
'class': 'promptNameText textSelectable',
'value': _.escape(prompt.name + ':')
}]
}]
}, {
'type': 'SingleLineLinks',
'items': [{
'align': 'left',
'items': [{
'type': 'text',
'class': 'wraptext textSelectable',
'value': _.escape(prompt.display)
}]
}]
}, {
'type': 'Separator'
});
});
return items;
},
_viewRunHistory: function() {
var options = [{
'm_name': this.objectInfo.defaultName
}];
C10Utils.openC10Morphlet(C10Utils.morphletMap.viewHistory, this.objectInfo.type, this.historyInfo.id, options);
}
});
return VersionsDetailsView;
});
define("js/content_apps/versionBundle", function(){});