{"version":3,"sources":["../LuV.LUMAS.Services/scripts/controls/publishedDocumentsAggregationController.ts"],"names":["PublishedDocumentsAggregationController","prototype","config","options","this","productCode","productName","productLines","hideSearchBox","templateUrl","templateHelperService","getTemplateUrl","itemTemplateUrl","passthrough","origin","window","location","protocol","hostname","port","cpmIntranetUrl","PortalConfig","publishedDocumentsQueryTemplate","query","webAbsoluteUrl","$lumasContext","listTitle","showList","linkTitle","linkUrl","search","_this","isError","errorMessage","resultItems","length","isLoading","headers","content-type","accept","X-RequestDigest","document","getElementById","getAttribute","replace","$window","encodeURIComponent","ID","Name","productLineNameMatches","match","_i","productLineNameMatches_1","productLineNameMatch","productLineFieldName","substring","productLineQueries","_a","productLines_1","productLine","push","join","productLineIdMatches","_b","productLineIdMatches_1","productLineIdMatch","_c","productLines_2","$http","method","url","then","data","parsePublishedDocumentItems","d","results","err","status","fileIconCalls","resultItem","fileIconCall","fileName","$q","all","fileIcons","i","fileIcon","fileIconSrc","MapToIcon","finally","$log","log","items","parsedResults","_","forEach","item","FileRef","substr","lastIndexOf","fileType","toLowerCase","title","Title","language","Language","documentType","Type","published","Date","Modified","format","$inject","$scope","preRepeatFunction","arrayOfPages","vm","exports"],"mappings":"mIAwBA,IAAAA,GAuBCA,EAAAC,UAAAC,OAAA,SAAOC,GACNC,KAAKD,QAAQE,YAAcF,EAAQE,YACnCD,KAAKD,QAAQG,YAAcH,EAAQG,YACnCF,KAAKD,QAAQI,aAAeJ,EAAQI,aACpCH,KAAKD,QAAQK,eAAgB,EAC7BJ,KAAKD,QAAQM,YAAcL,KAAKM,sBAAsBC,eAAeR,EAAQM,aAAeL,KAAKD,QAAQM,aACzGL,KAAKD,QAAQS,gBAAkBR,KAAKM,sBAAsBC,eAAeR,EAAQS,iBAAmBR,KAAKD,QAAQS,iBACjHR,KAAKD,QAAQU,YAAcV,EAAQU,YACnC,IAAIC,EAASC,OAAOC,SAASF,OAASC,OAAOC,SAASF,OACpDC,OAAOC,SAASC,SAAW,KAAOF,O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AAM,sBAAAA,EAjBpHN,KAAAD,QAAU,CAChBS,gBAAiB,GACjBH,YAAa,GACbI,YAAa,GACbqG,kBAAmB,SAAUtB,GAAS,OAAOA,GAC7ClE,UAAW,GACXC,UAAU,GAGXvB,KAAA8B,YAAqB,GACrB9B,KAAAgC,WAAqB,EACrBhC,KAAA4B,SAAmB,EAEnB5B,KAAA+G,aAAsB,GAKrBF,EAAOG,GAAKhH,KApBDiH,EAAArH,wCAAAA","file":"publishedDocumentsAggregationController.js","sourcesContent":["import * as _ from 'lodash';\r\nimport * as angular from 'angular';\r\nimport '../polyfills';\r\nimport { TemplateHelperService } from 'helpers/templateHelperService';\r\n\r\ninterface IPublishedDocumentsAggregationConfig {\r\n\tproductCode: string,\r\n\tproductName: string,\r\n\tproductLines: any[],\r\n\thideSearchBox: boolean,\r\n\titemTemplateUrl: string,\r\n\ttemplateUrl: string,\r\n\tpassthrough: any,\r\n\thelpers: any,\r\n\tpreRepeatFunction: any,\r\n\tcpmIntranetUrl: string,\r\n\tpublishedDocumentsQueryTemplate: string,\r\n\tquery: string,\r\n\tlistTitle: string,\r\n\tshowList: boolean,\r\n\tlinkUrl: string,\r\n\tlinkTitle: string\r\n}\r\n\r\nexport class PublishedDocumentsAggregationController {\r\n\r\n\tpublic options = {\r\n\t\titemTemplateUrl: ``,\r\n\t\ttemplateUrl: ``,\r\n\t\tpassthrough: {},\r\n\t\tpreRepeatFunction: function (items) { return items; },\r\n\t\tlistTitle: ``,\r\n\t\tshowList: false\r\n\t} as IPublishedDocumentsAggregationConfig;\r\n\r\n\tresultItems: any[] = [];\r\n\tisLoading: boolean = false;\r\n\tisError: boolean = false;\r\n\terrorMessage: string;\r\n\tarrayOfPages: any[] = [];\r\n\twebAbsoluteUrl: string;\r\n\r\n\tstatic $inject = ['$http', '$log', '$scope', '$window', '$q', 'templateHelperService'];\r\n\tconstructor(private $http, private $log, private $scope: any, private $window: any, private $q: angular.IQService, private templateHelperService: TemplateHelperService) {\r\n\t\t$scope.vm = this;\r\n\t}\r\n\r\n\tconfig(options: IPublishedDocumentsAggregationConfig) {\r\n\t\tthis.options.productCode = options.productCode;\r\n\t\tthis.options.productName = options.productName;\r\n\t\tthis.options.productLines = options.productLines;\r\n\t\tthis.options.hideSearchBox = true;\r\n\t\tthis.options.templateUrl = this.templateHelperService.getTemplateUrl(options.templateUrl || this.options.templateUrl);\r\n\t\tthis.options.itemTemplateUrl = this.templateHelperService.getTemplateUrl(options.itemTemplateUrl || this.options.itemTemplateUrl);\r\n\t\tthis.options.passthrough = options.passthrough;\r\n\t\tvar origin = window.location.origin ? window.location.origin :\r\n\t\t\t(window.location.protocol + \"//\" + window.location.hostname + (window.location.port ? ':' + window.location.port : ''));\r\n\t\tthis.options.cpmIntranetUrl = origin + window['Ll'].PortalConfig['CPM Intranet Url'];\r\n\t\tthis.options.publishedDocumentsQueryTemplate = window['Ll'].PortalConfig['CPM Intranet published documents query'];\r\n\t\tthis.options.query = this.options.cpmIntranetUrl + this.options.publishedDocumentsQueryTemplate;\r\n\t\tthis.webAbsoluteUrl = window.$lumasContext.webAbsoluteUrl;\r\n\t\tthis.options.listTitle = options.listTitle;\r\n\t\tthis.options.showList = options.showList;\r\n\t\tthis.options.linkTitle = 'brochures & presentations';\r\n\t\tthis.options.linkUrl = window['Ll'].PortalConfig['CPM Intranet published documents link URL']\r\n\t\tthis.search();\r\n\t}\r\n\r\n\tsearch() {\r\n\t\tvar self = this;\r\n\r\n\t\tif (window['usernotauthorizedforcpmintranet']) {\r\n\t\t\tthis.isError = true;\r\n\t\t\tthis.errorMessage = 'Sorry, you don\\'t have permissions to read CPM intranet';\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tthis.isError = false;\r\n\t\tif (this.resultItems.length == 0) {\r\n\t\t\tthis.isLoading = true;\r\n\t\t}\r\n\r\n\t\tvar headers = {\r\n\t\t\t'content-type': 'application/json;odata=verbose',\r\n\t\t\t'accept': 'application/json;odata=verbose',\r\n\t\t\t'X-RequestDigest': document.getElementById('__REQUESTDIGEST').getAttribute('value')\r\n\t\t};\r\n\r\n\t\tvar query = this.options.query\r\n\t\t\t.replace(/{cpmIntranetUrl}/gi, this.options.cpmIntranetUrl)\r\n\t\t\t.replace(/{materialSapId}/gi, this.options.productCode)\r\n\t\t\t.replace(/{materialName}/gi, this.$window.encodeURIComponent(this.options.productName))\r\n\r\n\t\tlet productLines = this.options.productLines.length > 0 ? this.options.productLines : [{ID:0,Name:''}];\r\n\t\tlet productLineNameMatches = query.match(/{productLineName:[^}]*}/gi);\r\n\t\tif (productLineNameMatches) {\r\n\t\t\tfor (let productLineNameMatch of productLineNameMatches) {\r\n\t\t\t\tlet productLineFieldName = productLineNameMatch.substring(17, productLineNameMatch.length - 1);\r\n\t\t\t\tlet productLineQueries = [];\r\n\r\n\t\t\t\tfor (let productLine of productLines) {\r\n\t\t\t\t\tproductLineQueries.push(`substringof('${this.$window.encodeURIComponent(productLine.Name)}',${productLineFieldName})`);\r\n\t\t\t\t}\r\n\t\t\t\tquery = query.replace(productLineNameMatch, productLineQueries.join(' or '));\r\n\t\t\t}\r\n\t\t}\r\n\t\tlet productLineIdMatches = query.match(/{productLineId:[^}]*}/gi);\r\n\t\tif (productLineIdMatches) {\r\n\t\t\tfor (let productLineIdMatch of productLineIdMatches) {\r\n\t\t\t\tlet productLineFieldName = productLineIdMatch.substring(15, productLineIdMatch.length - 1);\r\n\t\t\t\tlet productLineQueries = [];\r\n\r\n\t\t\t\tfor (let productLine of productLines) {\r\n\t\t\t\t\tproductLineQueries.push(`substringof('${this.$window.encodeURIComponent(productLine.ID)}',${productLineFieldName})`);\r\n\t\t\t\t}\r\n\t\t\t\tquery = query.replace(productLineIdMatch, productLineQueries.join(' or '));\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tthis.$http({\r\n\t\t\tmethod: 'GET',\r\n\t\t\turl: query,\r\n\t\t\theaders: headers\r\n\t\t})\r\n\t\t\t.then((data) => {\r\n\t\t\t\tthis.resultItems = PublishedDocumentsAggregationController.parsePublishedDocumentItems(data.data.d.results);\r\n\t\t\t\treturn this.resultItems;\r\n\t\t\t}, err => {\r\n\t\t\t\tthis.isError = true;\r\n\t\t\t\tif (err.status == 401) {\r\n\t\t\t\t\tthis.errorMessage = 'Sorry, you don\\'t have permissions to read CPM intranet';\r\n\t\t\t\t\twindow['usernotauthorizedforcpmintranet'] = true;\r\n\t\t\t\t}\r\n\r\n\t\t\t\treturn null;\r\n\t\t\t})\r\n\t\t\t.then(() => {\r\n\t\t\t\tvar fileIconCalls = [];\r\n\t\t\t\tfor (var resultItem of this.resultItems) {\r\n\t\t\t\t\tvar fileIconCall = this.$http({\r\n\t\t\t\t\t\tmethod: 'GET',\r\n\t\t\t\t\t\turl: window.$lumasContext.webAbsoluteUrl + \"/_api/web/maptoicon(filename='\" + resultItem.fileName + \"', progid='', size=0)\",\r\n\t\t\t\t\t\theaders: headers\r\n\t\t\t\t\t});\r\n\t\t\t\t\tfileIconCalls.push(fileIconCall);\r\n\t\t\t\t}\r\n\t\t\t\treturn this.$q.all(fileIconCalls);\r\n\t\t\t})\r\n\t\t\t.then((fileIcons) => {\r\n\t\t\t\tfor (var i in fileIcons) {\r\n\t\t\t\t\tvar fileIcon = fileIcons[i];\r\n\t\t\t\t\tif (fileIcon != null && fileIcon.data.d) {\r\n\t\t\t\t\t\tvar fileIconSrc = fileIcon.data.d.MapToIcon;\r\n\t\t\t\t\t\tthis.resultItems[i].fileIconSrc = fileIconSrc;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t})\r\n\t\t\t.finally(() => {\r\n\t\t\t\tthis.isLoading = false;\r\n\t\t\t});;\r\n\r\n\t\tthis.$log.log(`[listAggregation] getting: ${this.options.query}`);\r\n\t}\r\n\r\n\tprivate static parsePublishedDocumentItems(items: any[]) {\r\n\t\tvar parsedResults = [];\r\n\t\tif (items != null && items.length > 0) {\r\n\t\t\t_.forEach(items, (item) => {\r\n\t\t\t\tlet fileName = item.FileRef.substr(item.FileRef.lastIndexOf('/') + 1);\r\n\t\t\t\tlet fileType = fileName.lastIndexOf('.') > -1 ? fileName.substr(fileName.lastIndexOf('.') + 1).toLowerCase() : '';\r\n\t\t\t\tparsedResults.push({\r\n\t\t\t\t\turl: item.FileRef,\r\n\t\t\t\t\tfileName: fileName,\r\n\t\t\t\t\ttitle: item.Title ? item.Title : fileName,\r\n\t\t\t\t\tfileType: fileType,\r\n\t\t\t\t\tlanguage: item.Language,\r\n\t\t\t\t\tdocumentType: item.Type,\r\n\t\t\t\t\tpublished: new Date(item.Modified).format('dd.MM.yyyy')\r\n\t\t\t\t})\r\n\t\t\t});\r\n\t\t}\r\n\t\treturn parsedResults;\r\n\t}\r\n}"]}