smartsDashboardGenerator.min.js 14 KB

12
  1. !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("polyglot"));else if("function"==typeof define&&define.amd)define(["polyglot"],t);else{var n="object"==typeof exports?t(require("polyglot")):t(e.polyglot);for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(window,function(e){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/install/webcontent/bi/js/smarts-js",n(n.s=12)}([,,,function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(e){return e&&e.__esModule?e:{default:e}}(n(4));var a=n(5),i=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.polyglot=new a({phrases:o.default})}return r(e,[{key:"get",value:function(e,t){return this.polyglot.t(e,t)}}]),e}();t.default=new i},function(e,t){var n={__root:{errorNotADashbaord:"Not a dashboard",errorDashboardCannotBeModified:"Dashboard cannot be modified",errorDashboardNotTabbed:"Dashboard is not tabbed",errorMissingModuleId:"The moduleId parameter is missing",errorUnableToLoadMetadata:"Unable to download the metadata. Verify that the provided module ID is correct",errorMissingModuleIdMetadataParameters:"The Missing moduleId and/or metadata parameters are missing",errorModuleNotYetLoaded:"No loaded Metadata found. Make sure that the Metadata is loaded before calling this function"},init:function(e){e||(e=window._i18n&&window._i18n.locale?window._i18n.locale:document.documentElement.lang?document.documentElement.lang:"root");var t=this["__"+e]||this.__root;if(t)for(var n in t)this[n]=t[n];for(var n in this.__root)void 0===this[n]&&(this[n]=this.__root[n])}};n.init(),e.exports=n},function(t,n){t.exports=e},function(e,t,n){"use strict";function r(e,t){var n=[],r={version:"1.0",sources:[{shaping:{embeddedModuleUpToDate:!0}}]},o={},a=[],i={id:e,boardSpec:{name:"New dashboard",theme:"defaultTheme",version:t,layout:{id:e+"_layout",items:n,style:{height:"100%"},type:"tab",pageSize:{width:1280,height:720},layoutPositioning:"relative"},dataSources:r,widgets:o,eventGroups:a},isAuthoringMode:!0};function u(e){var t=e.modelRefId,n=e.sourceType,o=e.sourceId;Object.assign(r.sources[0],{assetId:o,type:n,id:t})}function s(t,n,r){var a=[{id:e+"_templateIndicator_"+n,style:{top:"0%",left:"0%",right:"0%",bottom:"0%"},type:"templateIndicator"}],i={id:e+"_container_"+n,items:[{id:e+"_genericPage_"+n,css:"templateBox aspectRatio_default",items:a,type:"genericPage",layoutPositioning:"relative"}],type:"container",title:{translationTable:{Default:t||"Tab "+n}},templateName:"Template9"},u=[];return r.forEach(function(e,t){var r=e.chart,i=e.spec,s=e.style,c="widget_"+n+t+Date.now();i.id=c,a.push(function(e,t,n){return{id:e,style:t,type:"widget",name:n}}(c,s,r.label)),o[c]=i,u.push(c)}),{containerSpec:i,widgetIds:u}}function c(e,t,r){var o=s(e,t,r);n.push(o.containerSpec),function(e,t){var n={id:e+":1",widgetIds:t};a.push(n)}(o.containerSpec.id,o.widgetIds)}return{build:function(e,t){return e.forEach(function(e,t){c(e.tabLabel,t,e.chartInfoList)}),u(t),i},buildTabContents:function(e,t){return e.map(function(e,n){var a=e.chartInfoList,i=e.tabLabel;o={};var c=s(i,n,a);return u(t),{widgets:o,layout:c.containerSpec,dataSources:r}})}}}Object.defineProperty(t,"__esModule",{value:!0});var o={isAuthoringMode:!0,boardSpec:{name:"New dashboard",layout:{id:"page0_"+Date.now(),items:[{id:"container_1",items:[],type:"container",title:{translationTable:{Default:"Tab 1"}},templateName:"Template9"}],style:{height:"100%"},type:"tab",showGrid:!0,snapGrid:!0,snapObjects:!0,pageSize:{width:1280,height:720},layoutPositioning:"relative"},theme:"defaultTheme",pageContext:[],dataSources:{version:"1.0",sources:[]},widgets:{}}},a={SUM:"sum",COUNT_DISTINCT:"countdistinct",COUNT:"count",AVERAGE:"avg",NONE:"none",MINIMUM:"min",MAXIMUM:"max"};t.default={build:function(e,t,n,o){return r(e,o).build(t,n)},buildTabContents:function(e,t,n){return r(e).buildTabContents(t,n)},getNewDashboardSpec:function(){return o.id="dashboard_"+Date.now(),o},fixupLiveWidgetSpec:function(e,t,n){var r=this;e=this._addProperties(e);var o={},a={},i=n.filters,u=n.autoGroupingMap,s=n.columns,c="INCLUSION_EXCLUSION",d="TOP_BOTTOM",l="NUMERIC";(s&&s.forEach(function(e){e.aggregation&&e.id.forEach(function(t){return o[t]=e.aggregation})}),i&&i.forEach(function(t){switch(t.type){case c:e.localFilters.push(r._addInclusionExclusionFilter(t));break;case d:a[t.columnId]=t;break;case l:e.localFilters.push(r._addNumericFilter(t))}}),e.data)&&e.data.dataViews.forEach(function(e){var n=e.dataItems;e.modelRef=t,delete e.model,n.forEach(function(e){var t=e,n=t.itemId,i=t.id,s=t.itemLabel;o[n]&&(e=r._addAggregateSpec(e,o[n])),u&&u[n]&&u[n].groupSize&&(e=r._addAutoBinningSpec(e,i,s,u[n].groupSize)),a&&a[n]&&(e=r._addTopBottomSpec(e,a[n]))})});return e},_addAggregateSpec:function(e,t){return e.aggregate=a[t],e},_addAutoBinningSpec:function(e,t,n,r){return e.binningDefinition={id:t,binning:{auto:{numberOfBins:r,maxDecPlaces:2}},label:n+" groups"},e},_addNumericFilter:function(e){return{id:e.columnId,columnId:e.columnId,values:[{d:e.value,u:e.value}],excludedValues:[],operator:{GREATER_THAN:"gt",LESS_THAN:"lt"}[e.operator],preOrPost:"pre"}},_addInclusionExclusionFilter:function(e){var t=e.inclusionValues,n=e.exclusionValues,r=e.label,o=e.filterCondition,a=t&&!!t.length;if(o)return this._addInclusionExclusionFilterWithCondition(e);e.invertFlag&&((a=!a)?t=n:n=t);var i=a?t:n,u={id:e.columnId,columnId:e.columnId,values:i.map(function(e){return{d:e.displayValue,u:e.uniqueValue}}),operator:a?"in":"notin",binsLabel:r};return a&&(u.excludedValues=[]),u},_addInclusionExclusionFilterWithCondition:function(e){var t=e.columnId,n=e.filterCondition,r=e.invertFlag,o={operator:{CONTAINS:"containsignorecase",EQUALS:"in",BEGINS_WITH:"beginswith",ENDS_WITH:"endswith"}[n.condition],itemId:t,ignoreCase:!0,values:n.values,valueType:"display"};if(n.values&&n.values.length>1){var a={or:[]};n.values.forEach(function(e){var t=Object.assign({},o);t.values=[e],a.or.push(t)}),o=a}return{id:t,columnId:t,values:[],excludedValues:[],operator:"in",conditions:r?{not:o}:o}},_addTopBottomSpec:function(e,t){var n=t.topBottomType,r=t.method;if(!(n=n.toLowerCase()))return e;var o={operation:"keep",topBottom:{type:n+("count"===(r=r.toLowerCase())?"count":"percent"),value:t.domainSize}};if(t.byColumn){var i={itemId:t.byColumn},u=t.byAggregate;u&&(i.aggregate=a[u]),o.context=[i]}return e.selection=[o],e},_addProperties:function(e){return e.showTitle=!("summary"===e.visId),e.borderColor="color2",e.type=e.type?e.type:"live",e.localFilters=[],e.properties=[{id:"widget.legend.position",value:"bottom"}],"com.ibm.vis.rave2marimekko"===e.visId&&e.properties.push({id:"stacked.percent",value:!1}),e}}},,,,,,function(e,t,n){"use strict";var r,o=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=s(n(13)),i=s(n(6)),u=s(n(3));function s(e){return e&&e.__esModule?e:{default:e}}void 0===(r=function(){function e(e,t){var n=function(e){var t=e.sourceModuleId,n=e.sourceType,r=e.analysisType,o=e.includePredictiveCharts,a=e.supportedCharts,i={sourceModuleId:t,sourceType:n,includePredictiveCharts:o||!0,analysisType:(r||"SIMPLE").toUpperCase()};if(a&&a.length>0){var u={ContentType:"CHART",instances:a};Object.assign(i,{includedArtifacts:[u]})}return i}(t);return e.getSvc(".SmartsService").then(function(e){return e.getContentRecommendation(n)}).then(function(e){return e.containers})}return function(){function t(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t)}return o(t,[{key:"initialize",value:function(e){var t=this;return Promise.resolve().then(function(){t._glassContext=e})}},{key:"generate",value:function(t){var n=this;e(this._glassContext,t).then(function(e){return t.content=e,n.createNewDashboard(t)})}},{key:"createNewDashboard",value:function(e){var t=this,n=e.sourceId,r=e.sourceType,o=e.content;return Promise.resolve().then(function(){return t._glassContext.openAppView("dashboard",{content:i.default.getNewDashboardSpec()})}).then(function(){return t._glassContext.getCurrentContentView().dashboardApi}).then(function(e){return t.addToTabbedDashboard({sourceId:n,sourceType:r,content:o,dashboardApi:e})})}},{key:"addToTabbedDashboard",value:function(e){var t=this,n=e.sourceId,r=e.sourceType,o=e.content,i=e.dashboardApi;if("dashboard"!==i.getType())return Promise.reject(Error(u.default.get("errorNotADashbaord")));if(i.getMode()===i.MODES.VIEW)return Promise.reject(Error(u.default.get("errorDashboardCannotBeModified")));if(this._canvas=i.getCanvas(),!(this._canvas.getContent().getType().indexOf("tab")>-1))return Promise.reject(Error(u.default.get("errorDashboardNotTabbed")));var s=this._canvas.findContent({type:"container"}),c=i.getFeature("Transaction"),d=c.startTransaction(),l=i.getFeature("DataSources").addDataSource({assetId:n,type:r}),f=this._canvas.findContent({type:"tab"})[0].getId();return a.default.processSmartsContent(this._glassContext,{sourceId:n,sourceType:r,content:o,modelRefId:l}).then(function(e){return e.reverse().reduce(function(e,n){var r=n.chartInfoList,o=n.tabLabel;return e.then(function(){return t._addPage(f,r,o,d,0)})},Promise.resolve())}).catch(Promise.reject).finally(function(){s.forEach(function(e){return t._canvas.removeContent(e.getId())}),c.endTransaction(d)})}},{key:"_addPage",value:function(e,t,n,r,o){var a=this;return this._createPage(e,n,r,o).then(function(e){return a._addWidgetsToPage(e,t,r)})}},{key:"_createPage",value:function(e,t,n,r){return this._canvas.addContent({containerId:e,type:"page",properties:{title:t},position:r},n).then(function(e){var t=e.getFeature("state");return t.whenStatusChanges(t.STATUS.RENDERED).then(function(){return e.getId()})})}},{key:"_addWidgetsToPage",value:function(e,t,n){var r=this;return Promise.all(t.map(function(t){var o=t.spec,a=t.style;return r._canvas.addContent({containerId:e,spec:o,properties:a},n)})).then(function(){return e})}}]),t}()}.apply(t,[]))||(e.exports=r)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(e){return e&&e.__esModule?e:{default:e}}(n(6));t.default={convertToTabContents:function(e,t){this.glassContext=e;var n="dashboard_"+Date.now(),o=t.sourceId,a=t.sourceType,i={modelRefId:t.modelRefId,sourceId:o,sourceType:a};return this.processSmartsContent(e,t).then(function(e){return r.default.buildTabContents(n,e,i)})},processSmartsContent:function(e,t){var n=this,r=t.sourceId,o=t.sourceType,a=t.content,i=t.modelRefId;return this.glassContext=e,Promise.all(a.map(function(e){return n._processContainer(e,r,o,i)}))},_processContainer:function(e,t,n,r){var o=this,a=e.groups,i=e.predictive,u=e.label;return Promise.all(a.map(function(e,a){var u=e.contents;return o._processGroup(t,n,r,u,0==a,i)})).then(function(e){return{chartInfoList:e.reduce(function(e,t){return e.concat(t)},[]),tabLabel:u}})},_processGroup:function(e,t,n,o,a,i){var u=this;return Promise.all(o.map(function(o){var a=o.chart;return u._convertToLiveWidgetSpec(e,t,a,n).then(function(e){return e.length?(r.default.fixupLiveWidgetSpec(e[0],n,a),e[0]):Promise.reject(Error("Unable to create dashboard due to unsupported chart type: "+a.chartType))}).then(function(e){return{spec:e,chart:a}})})).then(function(e){return e=e.filter(function(e){return!!e.spec}),u._addLayoutInfo(e,i,a),e})},_addLayoutInfo:function(e,t,n){if(n)return this._addStyleForPrimaryGroup(e,t);var r=75/e.length-1;return e.forEach(function(e,t){var n=t*r+1*(t+1);e.style={left:"56%",width:"43%",height:r+"%",top:n+"%"}}),e},_addStyleForPrimaryGroup:function(e,t){var n={vizOnly:{viz:{top:"1%",height:"74%",left:"1%",width:"54%"}},withText:{viz:{top:"1%",height:"57%",left:"1%",width:"54%"},text:{top:"60%",height:"15%",left:"1%",width:"54%"}},withPredict:{viz:{top:"1%",height:"56%",left:"1%",width:"54%"},predict:{top:"58%",height:"17%",left:"1%",width:"54%"}},withBoth:{predict:{top:"1%",height:"18%",left:"1%",width:"54%"},viz:{top:"20%",height:"35%",left:"1%",width:"54%"},text:{top:"65%",height:"10%",left:"1%",width:"54%"}}},r={};return r=1===e.length?n.vizOnly:2===e.length?t?n.withPredict:n.withText:n.withBoth,e.forEach(function(e){switch(e.chart.chartType){case"Spiral":case"DecisionTree":case"DriverAnalysis":case"Sunburst":e.style=r.predict;break;default:e.style=r.viz}}),e},_convertToLiveWidgetSpec:function(e,t,n){if(n)return this.glassContext.getSvc(".LiveWidgetService").then(function(r){return r.transformRecommendationsToLiveWidgetSpecs([n],{assetId:e,type:t})})}}}])});
  2. //# sourceMappingURL=smartsDashboardGenerator.min.js.map