12 |
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("dashboard-analytics/visualizations/recommender/VisRecommenderUtils"));else if("function"==typeof define&&define.amd)define(["dashboard-analytics/visualizations/recommender/VisRecommenderUtils"],t);else{var n="object"==typeof exports?t(require("dashboard-analytics/visualizations/recommender/VisRecommenderUtils")):t(e["dashboard-analytics/visualizations/recommender/VisRecommenderUtils"]);for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(window,function(e){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},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 i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},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="",n(n.s=169)}({169:function(e,t,n){"use strict";var i,r=function(e){return e&&e.__esModule?e:{default:e}}(n(170));void 0===(i=function(){return function(e){function t(e){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,r.default),t}()}.apply(t,[]))||(e.exports=i)},170:function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],i=!0,r=!1,s=void 0;try{for(var o,a=e[Symbol.iterator]();!(i=(o=a.next()).done)&&(n.push(o.value),!t||n.length!==t);i=!0);}catch(e){r=!0,s=e}finally{try{!i&&a.return&&a.return()}finally{if(r)throw s}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),r=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),s=n(171),o=n(172);var a=function(){function e(){var t=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.setServiceExtensionConfig=function(){return t.glassContext.findCollection("com.ibm.bi.assistant.service").then(function(e){if(e&&e.length){var n=e[0].params,i=n.widgetSpecType,r=n.url;i&&(t.widgetSpecType=i),r&&(t.conversationServiceUrl=r)}})},this.conversationServiceUrl="v1/smarts/conversation",this.messages=[],this.context={},this.chatContext={},this.click_intent=[],this.chatQueue=[],this.sentenceActive=!1,this.initializing=!1,this.pendingReset=!1,this.recallBuffer=[],this.singleAction={},this.activeMessageId=null}return r(e,[{key:"initialize",value:function(e){return this.glassContext=e,this.logger=this.glassContext.getCoreSvc(".Logger"),this.events=this.glassContext.getCoreSvc(".Events"),this.setServiceExtensionConfig().then(this.resetConversation.bind(this))}},{key:"resetConversation",value:function(){var e=this;if(!this.initializing)return this.messages=[],this.context={},this.chatContext={},this.click_intent=[],this.chatQueue=[],this.sentenceActive=!1,this.pendingReset=!1,this.initializing=!0,this.askQuestion({sentence:"hello",showSentence:!1}).finally(function(){e.initializing=!1})}},{key:"refresh",value:function(e){this.events.trigger("conversation:refresh",e)}},{key:"getMessages",value:function(){return this.messages}},{key:"updateExistingMessage",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=null!==n?n:this.findExistingMessageIndex(e);if(null!==i){var r=Object.assign({},this.messages[i],{timestamp:this.genTimestamp()},t);this.messages[i]=r,this.refresh({actionId:r.response&&r.response.action&&r.response.action.id})}else this.logger.error("Could not find chat with id "+this.activeMessageId,this.messages)}},{key:"findExistingMessageIndex",value:function(e){var t=null;return this.messages.find(function(n,i){return n.id===e&&(t=i,!0)}),t}},{key:"appendResponse",value:function(e,t){if(!t.action||"listen"!=t.action.id&&"clear"!=t.action.id&&"end_of_scenario"!=t.action.id){var n=this.findExistingMessageIndex(e),i={currentSource:this.getCurrentSource(),response:t};if(n>0)this.messages[n-1].currentSource.name!==i.currentSource.name&&(i.showSourceSeparator=!0);else i.currentSource.name&&(i.showSourceSeparator=!0);this.updateExistingMessage(e,i,n)}}},{key:"getAgent",value:function(){return"Cognos"}},{key:"getUser",value:function(){return this.getUserContext().displayName}},{key:"genTimestamp",value:function(){return(new Date).toJSON()}},{key:"getRecallBuffer",value:function(){return this.recallBuffer}},{key:"getUserContext",value:function(){var e=this.glassContext.profile.account;return{defaultName:e.defaultName,displayName:e.displayName,givenName:e.givenName,surname:e.surname,email:e.email}}},{key:"getChatContext",value:function(){var e=this;return this.glassContext.findCollection("com.ibm.bi.assistant.chatContext").then(function(t){var n=Object.assign({},e.chatContext);if(e.click_intent&&e.click_intent.length&&(n.click_intent=e.click_intent,e.click_intent=[]),t){var i={};t.forEach(function(e){i[e.label]=e.value}),n.capability_override=i}return n})}},{key:"getAppMode",value:function(){var e=this.glassContext.currentAppView,t=e.context.perspective;return"dashboard"===t&&e.context.content.mode&&"story"==e.context.content.mode&&(t="story"),t}},{key:"getDashboardSupportedCharts",value:function(e){return this.glassContext.getSvc(".SmartsService").then(function(t){return t.getSupportedChartTypes(e)})}},{key:"getAppContext",value:function(){var e=this;return Promise.resolve().then(function(){var t=e.getAppMode(),n=e.glassContext.currentAppView,i=n.currentContentView,r=n.context.content,s=e.glassContext.isDevInstall(),a={};switch(t){case"home":a={mode:t,title:i.getTitle(),content:{module:r.module,version:i.labels.version,welcome:i.labels.welcome}};break;case"dashboard":case"explore":case"story":var c=e.glassContext.getCurrentContentView().dashboardApi,u=o.VisRecommenderUtils.buildChartTypes(c.getFeature("VisDefinitions").getList());return Promise.all([e.getDashboardSupportedCharts(u),c.getSources()]).spread(function(e,o){var a={mode:t,title:i.getTitle(),isHomepage:n.context.isHomepage,id:n.id,includedCharts:e,content:{boardId:r.boardId,isAuthoringMode:r.isAuthoringMode,isStoryMode:r.isStoryMode,mode:r.mode,module:r.module},isDevInstall:s||!1};return o&&o.length>0&&(o=o.map(function(e){return{id:e.assetId,label:e.name,type:e.type,active:!!e.active}}),a.sources=o),a});case"authoring":a={mode:t,title:i.getTitle(),isHomepage:n.context.isHomepage,content:{UIProfile:r.UIProfile,id:r.id,isDataSet:r.isDataSet,isNewDataSetFromModule:n.content.isNewDataSetFromModule,isNewDataSetFromPackage:r.isNewDataSetFromPackage,isNewFromModule:r.isNewFromModule,isNewFromPackage:r.isNewFromPackage,isTemplate:r.isTemplate,isViewer:r.isViewer,module:r.module,cmSearchPath:r.application.cmSearchPath,isModified:r.application.isModified,reportName:r.application.reportName,storeID:r.application.storeID,type:r.application.type}};break;case"ca-modeler":a={mode:t,title:i.getTitle(),isHomepage:n.context.isHomepage,content:{id:r.id,module:r.module,objRef:r.objRef}};break;default:a={mode:"UNKNOWN"}}return a})}},{key:"convertRecommendations",value:function(e,t,n,i,r){return this.glassContext.getSvc(".LiveWidgetService").then(function(o){return o.transformRecommendationsToLiveWidgetSpecs(n,{assetId:e,type:t}).then(function(e){if(i){var t=(0,s.transWidgetModifier)(i);e.forEach(function(e){e.data.dataViews.forEach(function(e){e.dataItems.forEach(function(e){t.forEach(function(t){e.itemId===t.id&&(e.selection=t.selection,e.aggregate=t.aggregate)})})})})}if(r){var n=(0,s.transWidgetFilter)(r);e.forEach(function(e){e.localFilters=n})}return e})})}},{key:"requestSourcesInScope",value:function(){var e=this.glassContext.getCurrentContentView();return e.dashboardApi?e.dashboardApi.getSources():[]}},{key:"requestMRU",value:function(){return this.glassContext.getSvc(".Content").then(function(e){return e.getMRUList()}).catch(function(){return[]})}},{key:"sortSourcesList",value:function(e,t,n){var i=t.map(function(e){return e.assetId}),r=function(e){return i.indexOf(e.id)>-1},s=function(e){return t.filter(function(t){return e.id===t.assetId})[0].active},o=n&&n.length>0,a=void 0,c=void 0,u=void 0;o&&(a=n.map(function(e){return e.id}),c=function(e){return a.indexOf(e.id)},u=function(e){return c(e)>-1});return[].concat(function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}(e)).sort(function(e,t){var n=function(e,t){if(r(e)&&r(t)){if(s(e)&&!s(t))return-1;if(!s(e)&&s(t))return 1}return r(e)&&!r(t)?-1:!r(e)&&r(t)?1:0}(e,t);return 0===n&&(o&&(n=function(e,t){return u(e)&&u(t)?c(e)>c(t)?1:c(e)<c(t)?-1:0:u(e)&&!u(t)?-1:!u(e)&&u(t)?1:0}(e,t)),0===n&&(n=function(e,t){return e.label.toUpperCase()>t.label.toUpperCase()?1:e.label.toUpperCase()<t.label.toUpperCase()?-1:0}(e,t))),n})}},{key:"sortSources",value:function(e){var t=this;return e&&e.length?Promise.all([this.requestSourcesInScope(),this.requestMRU()]).spread(function(n,i){return t.sortSourcesList(e,n,i)}):Promise.resolve([])}},{key:"performAction",value:function(e){var t=this,n=e.action,i=n.sections||[],r=[];return"clear"===n.id?Promise.resolve().then(function(){t.pendingReset=!0}):(i.forEach(function(e){if("charts"===e.id){var n=e.module_id,i=e.module_type,s=e.vis_recommendations,o=e.vis_modifiers,a=e.vis_filters;"live"===t.widgetSpecType?e.widgetSpecs=s:r.push(t.convertRecommendations(n,i,s,o,a).then(function(t){t&&(e.widgetSpecs=t)}))}else"source_list"===e.id&&e.items&&r.push(t.sortSources(e.items).then(function(t){e.items=t}))}),Promise.all(r).then(function(){t.appendResponse(t.activeMessageId,e)}))}},{key:"request",value:function(e,t){return this.glassContext.getCoreSvc(".Ajax").ajax({type:"POST",url:e,contentType:"application/json",data:JSON.stringify(t),xhrFields:{withCredentials:!0}})}},{key:"requestError",value:function(e){this.logger.error("requestError: ",e);var t="";t=404===e.code?"Conversation Service not found":"Conversation Service returned "+e.code,this.appendResponse(this.activeMessageId,{error:t})}},{key:"createInitialMessage",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=this.genTimestamp();return this.messages.push({id:n,actor:this.getUser(),user:this.getUserContext(),timestamp:this.genTimestamp(),showSentence:t,sentence:{value:e}}),this.refresh({actionId:null}),n}},{key:"askQuestion",value:function(e){var t=e.sentence,n=e.clickIntent,i=void 0===n?[]:n,r=e.chatContext,s=e.showSentence,o=e.followup_action,a=void 0===o?null:o;this.clearFollowupSections();var c=this.createInitialMessage(t,s);return a?(this.activeMessageId=c,this.askResponse({action:a,context:this.context})):this.askChatService(t,i,r,c)}},{key:"clearFollowupSections",value:function(){if(0!==this.messages.length){var e=this.messages.length-1,t=this.messages[e];if(t.response){var n=t.response.action&&t.response.action.sections;if(n){var i=n.filter(function(e){return!e.ui_hints||!e.ui_hints.followup});n.length!==i.length&&(t.response.action.sections=i,this.updateExistingMessage(t.id,{response:t.response},e))}}}}},{key:"askChatService",value:function(e,t,n,i){var r=this;return e!==this.recallBuffer.slice(-1)[0]&&this.recallBuffer.push(e),this.sentenceActive?Promise.resolve().then(function(){r.chatQueue.push({sentence:e,clickIntent:t,chatContext:n,messageId:i})}):(this.sentenceActive=!0,n&&(this.chatContext=n),this.click_intent=t,this.activeMessageId=i,this.askSentence(e).then(function(){return r.sentenceActive=!1,r.activeMessageId=null,r.processChatQueue()}).catch(function(e){r.logger.error("ask error: ",e),r.appendResponse(r.activeMessageId,{error:"Conversation Service error."}),r.sentenceActive=!1,r.chatQueue=[]}))}},{key:"processChatQueue",value:function(){if(this.chatQueue.length){var e=this.chatQueue.shift(),t=e.sentence,n=e.clickIntent,i=e.chatContext,r=e.messageId;return this.askChatService(t,n,i,r)}return Promise.resolve()}},{key:"askSentence",value:function(e,t){var n=this;t=t||this.context;var r=this.conversationServiceUrl+"/sentence";return Promise.all([this.getChatContext(),this.getAppContext()]).then(function(s){var o=i(s,2),a=o[0],c=o[1];return n.request(r,{sentence:e,context:t,userContext:n.getUserContext(),appContext:c,chatContext:a}).then(function(e){return n.askResponse(e.data)}).catch(function(e){return n.requestError(e)})})}},{key:"getCurrentSource",value:function(){var e={};return this.context&&this.context.name&&this.context.type&&(e={name:this.context.name,type:this.context.type}),this.context.cognos&&this.context.cognos.name&&this.context.cognos.type&&(e={name:this.context.cognos.name,type:this.context.cognos.type}),e}},{key:"askResponse",value:function(e){var t=this,n=e.action,i=e.context;return Promise.resolve().then(function(){return t.context=i,t.performAction({action:n})}).then(function(){if(t.pendingReset)return t.resetConversation()}).catch(function(e){t.logger.error("askResponse Error: ",e),t.appendResponse(t.activeMessageId,{error:"Conversation Service error"})})}}]),e}();t.default=a},171:function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.transWidgetModifier=function(e){return e.map(function(e){var t=e.id,n=e.aggregate,i=e.type,r=e.value,s=e.by,o=e.by_aggregate,a={id:t};return n&&(a.aggregate=n),i&&r&&s?(Object.assign(a,{selection:[{operation:"keep",topBottom:{type:i,value:r},context:[{itemId:s}]}]}),o&&(a.selection[0].context[0].aggregate=o)):i&&r&&Object.assign(a,{selection:[{operation:"keep",topBottom:{type:i,value:r}}]}),a})},t.transWidgetFilter=function(e){return e.map(function(e){var t={id:e.id,columnId:e.id,values:[],excludedValues:[],operator:"in",type:null};switch(e.condition){case"notcontains":return 1===e.values.length?Object.assign(t,{conditions:{not:{operator:"containsignorecase",itemId:e.id,ignoreCase:!0,values:e.values,valueType:"display"}}}):Object.assign(t,{conditions:{and:e.values.map(function(t){return{not:{operator:"containsignorecase",itemId:e.id,ignoreCase:!0,values:[t],valueType:"display"}}})}});case"notbeginswith":return Object.assign(t,{conditions:{not:{operator:"beginswith",itemId:e.id,ignoreCase:!0,values:e.values,valueType:"display"}}});case"contains":return Object.assign(t,{conditions:{operator:"containsignorecase",itemId:e.id,ignoreCase:!0,values:e.values,valueType:"display"}});case"orcontains":return Object.assign(t,{conditions:{or:e.values.map(function(t){return{operator:"containsignorecase",itemId:e.id,ignoreCase:!0,values:[t],valueType:"display"}})}});case"greaterthan":return Object.assign(t,{operator:"gt",preOrPost:"pre",values:[{d:e.values[0],u:e.values[0]}]});case"lessthan":return Object.assign(t,{operator:"lt",preOrPost:"pre",values:[{d:e.values[0],u:e.values[0]}]});case"between":return Object.assign(t,{operator:"between",preOrPost:"pre",values:[{d:e.values[0],u:e.values[0]},{d:e.values[1],u:e.values[1]}]});case"in":return Object.assign(t,{operator:"in",ignoreCase:!0,values:e.values,valueType:"display"});default:return{error:"undefined"}}})}},172:function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.VisRecommenderUtils=n(173)},173:function(t,n){t.exports=e}})});
- //# sourceMappingURL=conversationServiceBundle.min.js.map
|