{"version":3,"sources":["../LuV.LUMAS.Services/scripts/controls/searchAggregationController.ts"],"names":["SearchAggregationController","prototype","config","options","this","listTitle","searchBoxPlaceholder","hideSearchBox","rowLimit","queryTemplate","selectProperties","concatWithoutDuplicates","sortProperties","templateUrl","templateHelperService","getTemplateUrl","itemTemplateUrl","pagingAt","showOverviewLink","passthrough","preRepeatFunction","webAbsoluteUrl","_lumasContext","search","defaultSearchTerm","forcedSearchTerm","_this","self","searchTerm","cleanSearchTerm","isError","showPaging","searchOptions","spSearchOptions_1","SearchOptions","setRowLimit","setSelectPropertiesMap","Object","keys","forEach","key","setSort","resultItems","length","isLoading","setRequestDigest","document","getElementById","getAttribute","searchService","then","result","rows","numberOfPages","Math","ceil","arrayOfPages","Array","err","$log","error","finally","log","getGlobalVariable","variableName","$window","arr1","arr2","angular","isArray","concat","filter","a","some","b","defaultTerm","trim","replace","$inject","$http","$scope","name","fileName","url","modified","Title","helpers","items","currentPage","vm","exports","_super","InternalDocumentsAggregationController","__extends","init","materialSapId","window","PortalConfig","changeDate","fileType","Filename","tableHeads","call"],"mappings":"wgBAsBA,IAAAA,GAoCCA,EAAAC,UAAAC,OAAA,SAAOC,GACNC,KAAKD,QAAQE,UAAYF,EAAQE,WAAaD,KAAKD,QAAQE,UAC3DD,KAAKD,QAAQG,qBAAuBH,EAAQG,sBAAwBF,KAAKD,QAAQG,qBACjFF,KAAKD,QAAQI,cAAgBJ,EAAQI,eAAiBH,KAAKD,QAAQI,cACnEH,KAAKD,QAAQK,SAAWL,EAAQK,UAAYJ,KAAKD,QAAQK,SACzDJ,KAAKD,QAAQM,cAAgBN,EAAQM,eAAiBL,KAAKD,QAAQM,cACnEL,KAAKD,QAAQO,iBAAmBV,EAA4BW,wBAAwBP,KAAKD,QAAQO,iBAAkBP,EAAQO,kBAC3HN,KAAKD,QAAQS,eAAiBT,EAAQS,gBAAkBR,KAAKD,QAAQS,eACrER,KAAKD,QAAQU,YAAcT,KAAKU,sBAAsBC,eAAeZ,EAA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AOA,IAG9CnF,KAAAwB,WAAqB,GACrBxB,KAAAsC,YAAqB,GACrBtC,KAAAwC,WAAqB,EACrBxC,KAAA0B,SAAmB,EACnB1B,KAAAoF,YAAsB,EACtBpF,KAAA2B,YAAsB,EACtB3B,KAAAoD,aAAsB,GACtBpD,KAAAiB,eAAyB,GAERjB,KAAAoB,kBAAoB,IAIpCwD,EAAOS,GAAKrF,KAjCDsF,EAAA1F,4BAAAA,EA+Gb,IAAA2F,EAAAC,gBAA4DC,UAAAD,EAA5DD,EAA4D3F,GAC3D4F,EAAA3F,UAAA6F,KAAA,SAAKC,GACJ,IAAItF,EAAgBuF,OAAW,GAAEC,aAAa,yCAAyCpB,QAAQ,kBAAmBkB,GAClH3F,KAAKF,OAAO,CACXG,UAAW,qBACXI,cAAeA,EACfC,iBAAkB,CAAC,CAAEuE,KAAQ,WAAYiB,WAAc,mBAAoBC,SAAY,WAAYhB,IAAO,SAC1GvE,eAAgB,CAAEwF,UAAY,GAC9BvF,YAAa,8BACbG,gBAAiB,mCACjBG,YAAa,CAAEkF,WAAY,CAAC,YAAa,YAAa,mBAIxDT,EAAA3F,UAAAC,OAAA,SAAOC,GACNwF,EAAA1F,UAAMC,OAAMoG,KAAAlG,KAACD,IAEfyF,GAjBA,SAAAA,mDAAaF,EAAAE,uCAAAA","file":"searchAggregationController.js","sourcesContent":["import * as angular from 'angular';\r\nimport { SearchOptions } from '../spext/services/spSearchOptions';\r\nimport { SearchService } from '../spext/services/spSearchService';\r\nimport { TemplateHelperService } from '../helpers/templateHelperService';\r\n\r\ninterface ISearchAggregationConfig {\r\n\tlistTitle: string;\r\n\thideSearchBox: boolean;\r\n\tsearchBoxPlaceholder: string;\r\n\trowLimit: number;\r\n\tqueryTemplate: string;\r\n\tselectProperties: [{ [key: string]: string }];\r\n\tsortProperties: { [key: string]: boolean };\r\n\titemTemplateUrl: string;\r\n\tpagingAt: number;\r\n\tshowOverviewLink: boolean;\r\n\ttemplateUrl: string,\r\n\tpassthrough: any,\r\n\thelpers: any,\r\n\tpreRepeatFunction: any\r\n}\r\n\r\nexport class SearchAggregationController {\r\n\r\n\tpublic options = {\r\n\t\thideSearchBox: true,\r\n\t\tlistTitle: ``,\r\n\t\tsearchBoxPlaceholder: ``,\r\n\t\trowLimit: 9999,\r\n\t\tqueryTemplate: `{searchTerms}`,\r\n\t\tselectProperties: [{ 'name': 'Title' }, { 'fileName': 'FileName' }, { 'url': 'Path' }, { 'modified': 'LastModifiedTime' }] as any,\r\n\t\tsortProperties: { 'Title': false },\r\n\t\titemTemplateUrl: ``,\r\n\t\tpagingAt: 9999,\r\n\t\tshowOverviewLink: false,\r\n\t\ttemplateUrl: ``,\r\n\t\tpassthrough: {},\r\n\t\thelpers: {},\r\n\t\t//helpers: { 'customerProjects': new CustomerProjectsAggregationHelper() },\r\n\t\tpreRepeatFunction: function (items) { return items; }\r\n\t} as ISearchAggregationConfig;\r\n\r\n\tsearchTerm: string = ``;\r\n\tresultItems: any[] = [];\r\n\tisLoading: boolean = false;\r\n\tisError: boolean = false;\r\n\tcurrentPage: number = 0;\r\n\tshowPaging: boolean = false;\r\n\tarrayOfPages: any[] = [];\r\n\twebAbsoluteUrl: string = '';\r\n\r\n\tprivate readonly defaultSearchTerm = `*`;\r\n\r\n\tstatic $inject = ['$http', '$log', '$scope', '$window', '_lumasContext', 'searchService', 'templateHelperService'];\r\n\tconstructor(private $http, private $log, private $scope: any, private $window: any, private _lumasContext: any, private searchService: SearchService, private templateHelperService: TemplateHelperService) {\r\n\t\t$scope.vm = this;\r\n\t}\r\n\r\n\tconfig(options: ISearchAggregationConfig) {\r\n\t\tthis.options.listTitle = options.listTitle || this.options.listTitle;\r\n\t\tthis.options.searchBoxPlaceholder = options.searchBoxPlaceholder || this.options.searchBoxPlaceholder;\r\n\t\tthis.options.hideSearchBox = options.hideSearchBox || this.options.hideSearchBox;\r\n\t\tthis.options.rowLimit = options.rowLimit || this.options.rowLimit;\r\n\t\tthis.options.queryTemplate = options.queryTemplate || this.options.queryTemplate;\r\n\t\tthis.options.selectProperties = SearchAggregationController.concatWithoutDuplicates(this.options.selectProperties, options.selectProperties) as [{ [key: string]: string }];\r\n\t\tthis.options.sortProperties = options.sortProperties || this.options.sortProperties;\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.pagingAt = options.pagingAt || this.options.pagingAt;\r\n\t\tthis.options.showOverviewLink = options.showOverviewLink || this.options.showOverviewLink;\r\n\t\tthis.options.passthrough = options.passthrough;\r\n\t\tthis.options.preRepeatFunction = options.preRepeatFunction;\r\n\t\tthis.webAbsoluteUrl = this._lumasContext.webAbsoluteUrl;\r\n\r\n\t\tthis.search(this.defaultSearchTerm);\r\n\t}\r\n\r\n\tsearch(forcedSearchTerm?: string) {\r\n\t\tvar self = this;\r\n\t\t// TODO do not search on pressing ctrl etc.\r\n\t\tconst searchTerm = SearchAggregationController.cleanSearchTerm(forcedSearchTerm || this.searchTerm, this.defaultSearchTerm);\r\n\t\tthis.isError = false;\r\n\t\tthis.showPaging = false;\r\n\r\n\t\t//const searchService = new SearchService(this.$http, this.$log);\r\n\t\tconst searchOptions = new SearchOptions();\r\n\t\t//searchOptions.setQueryTemplate(this.options.queryTemplate); // doesn't work in sp 2013\r\n\t\tsearchOptions.setRowLimit(this.options.rowLimit);\r\n\r\n\t\tsearchOptions.setSelectPropertiesMap(this.options.selectProperties);\r\n\t\tObject.keys(this.options.sortProperties).forEach(key => searchOptions.setSort(key, this.options.sortProperties[key]));\r\n\t\tif (this.resultItems.length == 0) {\r\n\t\t\tthis.isLoading = true;\r\n\t\t}\r\n\r\n\t\tsearchOptions.setRequestDigest(document.getElementById('__REQUESTDIGEST').getAttribute('value'));\r\n\r\n\t\tthis.searchService.search(this.options.queryTemplate, searchOptions).then(result => {\r\n\t\t\tthis.resultItems = result.rows;\r\n\t\t\tif (self.options.pagingAt != 9999 && self.options.pagingAt < result.rows.length) {\r\n\t\t\t\tself.showPaging = true;\r\n\t\t\t\tvar numberOfPages = Math.ceil(result.rows.length / self.options.pagingAt);\r\n\t\t\t\tself.arrayOfPages = new Array(numberOfPages);\r\n\t\t\t}\r\n\t\t}, err => {\r\n\t\t\tthis.isError = true;\r\n\t\t\tthis.$log.error(`[searchAggregation]`, err);\r\n\t\t}).finally(() => {\r\n\t\t\tthis.isLoading = false;\r\n\t\t});\r\n\r\n\t\tthis.$log.log(`[searchAggregation] searching: ${searchTerm}`);\r\n\t}\r\n\r\n\tgetGlobalVariable(variableName: string) {\r\n\t\treturn this.$window[variableName];\r\n\t}\r\n\r\n\tprivate static concatWithoutDuplicates(arr1: any[], arr2: any[]) {\r\n\t\tif (!angular.isArray(arr1) || !angular.isArray(arr2)) {\r\n\t\t\treturn arr1 || arr2;\r\n\t\t}\r\n\t\treturn arr1.concat(arr2.filter((a) => {\r\n\t\t\treturn !arr1.some((b) => { return a === b; })\r\n\t\t}));\r\n\t}\r\n\r\n\tprivate static cleanSearchTerm(searchTerm: string, defaultTerm: string) {\r\n\t\treturn ((searchTerm || ``).trim() || defaultTerm).replace(/[*\\s]*$/, `*`);\r\n\t}\r\n}\r\n\r\n\r\nexport class InternalDocumentsAggregationController extends SearchAggregationController {\r\n\tinit(materialSapId: string) {\r\n\t\tlet queryTemplate = window['Ll'].PortalConfig['LUMAS internal documents search query'].replace('{materialSapId}', materialSapId);\r\n\t\tthis.config({\r\n\t\t\tlistTitle: 'internal documents',\r\n\t\t\tqueryTemplate: queryTemplate,\r\n\t\t\tselectProperties: [{ 'name': 'Filename', 'changeDate': 'LastModifiedTime', 'fileType': 'FileType', 'url': 'path' }] as [{ [key: string]: string }],\r\n\t\t\tsortProperties: { 'Filename': false } as { [key: string]: boolean },\r\n\t\t\ttemplateUrl: 'searchAggregationTable.html',\r\n\t\t\titemTemplateUrl: 'searchItemInternalDocuments.html',\r\n\t\t\tpassthrough: { tableHeads: ['file name', 'file type', 'change date'] }\r\n\t\t} as ISearchAggregationConfig);\r\n\t}\r\n\r\n\tconfig(options: ISearchAggregationConfig) {\r\n\t\tsuper.config(options);\r\n\t}\r\n}"]}