exportBundle.js 6.1 KB

1
  1. function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}define("storytelling/glass/controllers/ExportAsStory",["baglass/core-client/js/core-client/errors/BaseError","baglass/core-client/js/core-client/utils/ClassFactory","underscore","gemini/app/util/ErrorUtils","gemini/app/ui/dialogs/GenericViewDialog","react","react-dom"],function(e,t,o,r,n,s,a){var i=function(e){var t=null;return e.appController.getCurrentContentView?t=e.appController.getCurrentContentView():e.appController.currentAppView.currentContentView&&(t=e.appController.currentAppView.currentContentView),t};return function(){function o(){_classCallCheck(this,o),this._contributionId="com.ibm.bi.storytelling"}return o.prototype.isItemVisible=function(e){return e.target.itemId===this._contributionId+".exportAsStory"&&(this._isBoardTypeSupported(e)&&r.hasCapability(e.glassContext,"canAuthorDashboard"))},o.prototype.onSelectItem=function(e){if(this._contributionId+".exportAsStory"===e.target.itemId){var t={type:"Exported Object"};return i(e.glassContext).getDashboardApi().getFeature("segment").track("exportedToStory",function(){return t}),this._convertToStory(e)}return Promise.resolve()},o.prototype.exportAsStory=function(e,t,o,r,n){return this._sendRequest({context:e.context,url:t.url,name:o,overwrite:r}).then(this._onExportSuccess.bind(this,e.context,n)).catch(this._onExportError.bind(this)).finally(this._exportDialog.hide.bind(this._exportDialog))},o.prototype._convertToStory=function(e){return this._openStoryTypeSelectionDialog(e).then(this._openSaveAsDialog.bind(this))},o.prototype._openStoryTypeSelectionDialog=function(e){var o=this;return Promise.all([t.loadModule("storytelling/glass/StoryLayoutPickerView"),t.loadModule("storytelling/nls/StringResources")]).then(function(t){var r=t[0],s=t[1];return new Promise(function(t){document.createElement("div").classList.add("templatePickerDialog");var a={action:function(){this._templateSelectDialog.hide(),this._templateSelectDialog.view.getSelectedLayoutSpec().then(function(o){var r=o.layout;t({context:e,navModel:r.layout.type})})}.bind(o)};o._templateSelectDialog=new n({id:"selectTemplateTitle",title:s.get("selectTemplateLabel"),viewClass:r,viewOptions:a,okCallback:a.action,cancelCallback:function(){t({cancelled:!0})},buttons:[{text:s.get("selectLabel"),handler:a.action,type:"primary",defaultId:"select_button"},"cancel"],showCloseX:!0,width:"760px"}),o._templateSelectDialog.open()})})},o.prototype._openSaveAsDialog=function(e){var o=this;if(e.cancelled&&!0===e.cancelled)return Promise.resolve();var r=e.context,n=e.navModel,s=r.glassContext,a=i(s),l=a.getDashboardApi();return Promise.all([t.loadModule("storytelling/glass/ExportToStoryDialog"),t.loadModule("storytelling/nls/StringResources"),t.loadModule("storytelling-ui/storytelling-ui.min"),this._createStory(l,a,n),this._getAncestors(r,a.getBoardId())]).then(function(e){var t=e[0],r=e[1],n=e[2],i=e[3],l=e[4],c=i.model;o._exportDialog=new t({glassContext:s,defaultFileName:r.get("newDefaultStoryName",{modelName:a.boardModel.name}),service:{context:{glassContext:s,boardModel:c},export:o.exportAsStory.bind(o)},ancestors:l,onHide:o._clearToast.bind(o)}),o._exportDialog.open(),i.status.hasOutOfBoundsWidget?o._showToast(n,r.get("outOfBoundsWarningMessage")):i.status.hasEmptyExploreCards&&o._showToast(n,r.get("emptyExploreCardsWarningMessage"))})},o.prototype._createStory=function(e,o,r){var n=this;return Promise.all([t.loadModule("storytelling/StoryService")]).then(function(t){return new(0,t[0])({dashboardApi:e}).createStory({boardModel:o.boardModel,layoutController:o.boardController.layoutController,targetInfo:{type:r,transition:"none"},sourceType:n.sourceType})})},o.prototype._showToast=function(e,t){var o=s.createElement(e.Toast,{contentString:t,statusType:"warning",className:"db-st-export-toast"});a.render(o,this._exportDialog.$el[0])},o.prototype._clearToast=function(){this._exportDialog&&a.unmountComponentAtNode(this._exportDialog.$el[0])},o.prototype._getAncestors=function(e,t){return function(t){return t?e.glassContext.getSvc(".Content").then(function(e){var o=e.getBaseObjectsURL()+"/"+t;return e.get(o,{data:{fields:"ancestors"}})}):Promise.resolve(null)}(t).then(function(e){return e?e.data[0].ancestors||null:null})},o.prototype._onExportSuccess=function(e,o,r){var n=e.glassContext.appController;if(!o)return t.loadModule("storytelling/nls/StringResources").then(function(t){var o=i(e.glassContext).perspective;n.showToast(t.get(o+"_export_success"))});n.openAppView("story",{perspective:"story",content:{perspective:"story",objectUrl:r.jqXHR.getResponseHeader("location"),isAuthoringMode:n.getCurrentContentView().isAuthoringMode}})},o.prototype._onExportError=function(t){return"cmDuplicateName"===r.getErrorCode(t.saveRequest)?Promise.reject(new e("duplicate",{isDuplicate:!0})):(r.showError(t.glassContext,t.saveRequest,t.cmSpec),Promise.resolve())},o.prototype._sendRequest=function(t){var o=t.context,r=t.url,n=t.name,s=t.overwrite,a=o.glassContext.getCoreSvc(".Ajax"),i=o.boardModel;n&&(i.name=n);var l=this._getCMSpec({spec:i,context:o});return r+=s?"?updateAction=replace":"",a.ajax({type:"post",url:r,contentType:"application/json",processData:!1,dataType:"text",data:JSON.stringify(l)}).catch(function(t){return Promise.reject(new e("saving story error",{cmSpec:l,glassContext:o.glassContext,saveRequest:t.jqXHR}))})},o.prototype._getCMSpec=function(e){var t=e.spec,o=e.context;return{defaultName:t.name,type:this._getAssetType(o),specification:JSON.stringify(t),deploymentReferences:i(o.glassContext).dashboardApi.getFeature("dataSources.deprecated").getDeploymentReferences(),iconURI:"#common-catalog",defaultScreenTip:"story",tags:["story"]}},o.prototype._getAssetType=function(e){var t="exploration",o=i(e.glassContext).getContent();if(o.options&&o.options.config){var r=o.options.config;r.hasOwnProperty("assetType")&&(t=r.assetType)}return t},o.prototype._isBoardTypeSupported=function(e){var t=i(e.glassContext);return this.sourceType=t.getDashboardApi&&t.getDashboardApi().getType(),"dashboard"===this.sourceType?"tab"===t.boardModel.layout.type:"explore"===this.sourceType},o}()}),define("storytelling/exportBundle",function(){});