{"version":3,"sources":["../../src/app/components/dataview/dataview.ts"],"names":["DataView","el","cd","filterService","this","layout","pageLinks","paginatorPosition","alwaysShowPaginator","paginatorDropdownScrollHeight","currentPageReportTemplate","showFirstLastIcon","showPageLinks","emptyMessage","onLazyLoad","EventEmitter","trackBy","index","item","loadingIcon","first","onPage","onSort","onChangeLayout","prototype","ngOnInit","lazy","emit","createLazyLoadMetadata","initialized","ngOnChanges","simpleChanges","value","_value","currentValue","updateTotalRecords","hasFilter","filter","filterValue","sortField","sortOrder","sort","ngAfterContentInit","_this","templates","forEach","getType","listItemTemplate","template","gridItemTemplate","paginatorLeftTemplate","paginatorRightTemplate","paginatorDropdownItemTemplate","headerTemplate","footerTemplate","updateItemTemplate","itemTemplate","changeLayout","markForCheck","totalRecords","length","paginate","event","rows","data1","data2","value1","ObjectUtils","resolveFieldData","value2","result","localeCompare","isEmpty","data","filteredValue","getBlockableElement","nativeElement","children","filterMatchMode","searchFields","filterBy","split","filterLocale","paginator","trim","Component","args","selector","changeDetection","ChangeDetectionStrategy","OnPush","encapsulation","ViewEncapsulation","None","ElementRef","ChangeDetectorRef","FilterService","Input","Output","ContentChild","Header","Footer","ContentChildren","PrimeTemplate","DataViewLayoutOptions","dv","preventDefault","NgModule","imports","CommonModule","SharedModule","PaginatorModule","exports","declarations"],"mappings":"6lBAgJI,SAAAA,EAAmBC,EAAuBC,EAA8BC,GAArDC,KAAAH,GAAAA,EAAuBG,KAAAF,GAAAA,EAA8BE,KAAAD,cAAAA,EA9F/DC,KAAAC,OAAiB,OAQjBD,KAAAE,UAAoB,EAIpBF,KAAAG,kBAA4B,SAE5BH,KAAAI,qBAA+B,EAI/BJ,KAAAK,8BAAwC,QAExCL,KAAAM,0BAAoC,gCAMpCN,KAAAO,mBAA6B,EAE7BP,KAAAQ,eAAyB,EAIzBR,KAAAS,aAAuB,mBAEtBT,KAAAU,WAAgC,IAAIC,EAAAA,aAMrCX,KAAAY,QAAoB,SAACC,EAAeC,GAAc,OAAAA,G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AAA,sCAEAA,EAAAA,iCAEAA,EAAAA,6BAEAA,EAAAA,oBAEAA,EAAAA,4BAEAA,EAAAA,0BAEAC,EAAAA,sBAEAD,EAAAA,0BAEAA,EAAAA,uBAEAA,EAAAA,wBAEAA,EAAAA,4BAEAA,EAAAA,uBAEAA,EAAAA,2BAEAA,EAAAA,qBAEAA,EAAAA,yBAEAA,EAAAA,yBAEAA,EAAAA,qBAEAA,EAAAA,sBAEAC,EAAAA,uBAEAA,EAAAA,+BAEAA,EAAAA,uBAEAC,EAAAA,aAAYb,KAAA,CAACc,EAAAA,wBAEbD,EAAAA,aAAYb,KAAA,CAACe,EAAAA,2BAEbC,EAAAA,gBAAehB,KAAA,CAACiB,EAAAA,mCAoOjB,SAAAC,EAAmBC,GAAArG,KAAAqG,GAAAA,SAEnBD,EAAAhF,UAAAiC,aAAA,SAAaK,EAAczD,GACvBD,KAAKqG,GAAGhD,aAAapD,GACrByD,EAAM4C,2CAvBbrB,EAAAA,UAASC,KAAA,CAAC,CACPC,SAAU,0BACVvC,SAAU,gsBASV2C,cAAeC,EAAAA,kBAAkBC,kDAQV7F,oCAJtBiG,EAAAA,0BAEAA,EAAAA,eAcL,iCALCU,EAAAA,SAAQrB,KAAA,CAAC,CACNsB,QAAS,CAACC,EAAAA,aAAaC,EAAAA,aAAaC,EAAAA,iBACpCC,QAAS,CAAChH,EAAS8G,EAAAA,aAAaN,GAChCS,aAAc,CAACjH,EAASwG","sourcesContent":["import {NgModule,Component,ElementRef,OnInit,AfterContentInit,Input,Output,EventEmitter,ContentChild,ContentChildren,QueryList,TemplateRef,OnChanges,SimpleChanges,ChangeDetectionStrategy,ChangeDetectorRef, ViewEncapsulation} from '@angular/core';\nimport {CommonModule} from '@angular/common';\nimport {ObjectUtils} from 'primeng/utils';\nimport {Header,Footer,PrimeTemplate,SharedModule,FilterService} from 'primeng/api';\nimport {PaginatorModule} from 'primeng/paginator';\nimport {BlockableUI} from 'primeng/api';\n\n@Component({\n selector: 'p-dataView',\n template: `\n
\n
\n
\n \n
\n
\n
\n \n \n
\n \n
\n
\n \n \n \n
\n
{{emptyMessage}}
\n
\n
\n
\n \n
\n \n \n
\n
\n `,\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n styleUrls: ['./dataview.css']\n})\nexport class DataView implements OnInit,AfterContentInit,BlockableUI,OnChanges {\n\n @Input() layout: string = 'list';\n\n @Input() paginator: boolean;\n\n @Input() rows: number;\n\n @Input() totalRecords: number;\n\n @Input() pageLinks: number = 5;\n\n @Input() rowsPerPageOptions: any[];\n\n @Input() paginatorPosition: string = 'bottom';\n\n @Input() alwaysShowPaginator: boolean = true;\n\n @Input() paginatorDropdownAppendTo: any;\n\n @Input() paginatorDropdownScrollHeight: string = '200px';\n\n @Input() currentPageReportTemplate: string = '{currentPage} of {totalPages}';\n\n @Input() showCurrentPageReport: boolean;\n\n @Input() showJumpToPageDropdown: boolean;\n\n @Input() showFirstLastIcon: boolean = true;\n\n @Input() showPageLinks: boolean = true;\n\n @Input() lazy: boolean;\n\n @Input() emptyMessage: string = 'No records found';\n\n @Output() onLazyLoad: EventEmitter = new EventEmitter();\n\n @Input() style: any;\n\n @Input() styleClass: string;\n\n @Input() trackBy: Function = (index: number, item: any) => item;\n\n @Input() filterBy: string;\n\n @Input() filterLocale: string;\n\n @Input() loading: boolean;\n\n @Input() loadingIcon: string = 'pi pi-spinner';\n\n @Input() first: number = 0;\n\n @Input() sortField: string;\n\n @Input() sortOrder: number;\n\n @Input() value: any[];\n\n @Output() onPage: EventEmitter = new EventEmitter();\n\n @Output() onSort: EventEmitter = new EventEmitter();\n\n @Output() onChangeLayout: EventEmitter = new EventEmitter();\n\n @ContentChild(Header) header;\n\n @ContentChild(Footer) footer;\n\n @ContentChildren(PrimeTemplate) templates: QueryList;\n\n _value: any[];\n\n listItemTemplate: TemplateRef;\n\n gridItemTemplate: TemplateRef;\n\n itemTemplate: TemplateRef;\n\n headerTemplate: TemplateRef;\n\n footerTemplate: TemplateRef;\n\n paginatorLeftTemplate: TemplateRef;\n\n paginatorRightTemplate: TemplateRef;\n\n paginatorDropdownItemTemplate: TemplateRef;\n\n filteredValue: any[];\n\n filterValue: string;\n\n initialized: boolean;\n\n constructor(public el: ElementRef, public cd: ChangeDetectorRef, public filterService: FilterService) {}\n\n ngOnInit() {\n if (this.lazy) {\n this.onLazyLoad.emit(this.createLazyLoadMetadata());\n }\n this.initialized = true;\n }\n\n ngOnChanges(simpleChanges: SimpleChanges) {\n if (simpleChanges.value) {\n this._value = simpleChanges.value.currentValue;\n this.updateTotalRecords();\n\n if (!this.lazy && this.hasFilter()) {\n this.filter(this.filterValue);\n }\n }\n\n if (simpleChanges.sortField || simpleChanges.sortOrder) {\n //avoid triggering lazy load prior to lazy initialization at onInit\n if (!this.lazy || this.initialized) {\n this.sort();\n }\n }\n }\n\n ngAfterContentInit() {\n this.templates.forEach((item) => {\n switch(item.getType()) {\n case 'listItem':\n this.listItemTemplate = item.template;\n break;\n\n case 'gridItem':\n this.gridItemTemplate = item.template;\n break;\n\n case 'paginatorleft':\n this.paginatorLeftTemplate = item.template;\n break;\n\n case 'paginatorright':\n this.paginatorRightTemplate = item.template;\n break;\n\n case 'paginatordropdownitem':\n this.paginatorDropdownItemTemplate = item.template;\n break;\n\n case 'header':\n this.headerTemplate = item.template;\n break;\n\n case 'footer':\n this.footerTemplate = item.template;\n break;\n }\n });\n\n this.updateItemTemplate();\n }\n\n updateItemTemplate() {\n switch(this.layout) {\n case 'list':\n this.itemTemplate = this.listItemTemplate;\n break;\n\n case 'grid':\n this.itemTemplate = this.gridItemTemplate;\n break;\n }\n }\n\n changeLayout(layout: string) {\n this.layout = layout;\n this.onChangeLayout.emit({\n layout: this.layout\n });\n this.updateItemTemplate();\n\n this.cd.markForCheck();\n }\n\n updateTotalRecords() {\n this.totalRecords = this.lazy ? this.totalRecords : (this._value ? this._value.length : 0);\n }\n\n paginate(event) {\n this.first = event.first;\n this.rows = event.rows;\n\n if (this.lazy) {\n this.onLazyLoad.emit(this.createLazyLoadMetadata());\n }\n\n this.onPage.emit({\n first: this.first,\n rows: this.rows\n });\n }\n\n sort() {\n this.first = 0;\n\n if (this.lazy) {\n this.onLazyLoad.emit(this.createLazyLoadMetadata());\n }\n else if (this.value) {\n this.value.sort((data1, data2) => {\n let value1 = ObjectUtils.resolveFieldData(data1, this.sortField);\n let value2 = ObjectUtils.resolveFieldData(data2, this.sortField);\n let result = null;\n\n if (value1 == null && value2 != null)\n result = -1;\n else if (value1 != null && value2 == null)\n result = 1;\n else if (value1 == null && value2 == null)\n result = 0;\n else if (typeof value1 === 'string' && typeof value2 === 'string')\n result = value1.localeCompare(value2);\n else\n result = (value1 < value2) ? -1 : (value1 > value2) ? 1 : 0;\n\n return (this.sortOrder * result);\n });\n\n if (this.hasFilter()) {\n this.filter(this.filterValue);\n }\n }\n\n this.onSort.emit({\n sortField: this.sortField,\n sortOrder: this.sortOrder\n });\n }\n\n isEmpty() {\n let data = this.filteredValue||this.value;\n return data == null || data.length == 0;\n }\n\n createLazyLoadMetadata(): any {\n return {\n first: this.first,\n rows: this.rows,\n sortField: this.sortField,\n sortOrder: this.sortOrder\n };\n }\n\n getBlockableElement(): HTMLElement {\n return this.el.nativeElement.children[0];\n }\n\n filter(filter: string, filterMatchMode:string =\"contains\") {\n this.filterValue = filter;\n\n if (this.value && this.value.length) {\n let searchFields = this.filterBy.split(',');\n this.filteredValue = this.filterService.filter(this.value, searchFields, filter, filterMatchMode, this.filterLocale);\n\n if (this.filteredValue.length === this.value.length ) {\n this.filteredValue = null;\n }\n\n if (this.paginator) {\n this.first = 0;\n this.totalRecords = this.filteredValue ? this.filteredValue.length : this.value ? this.value.length : 0;\n }\n\n this.cd.markForCheck();\n }\n }\n\n hasFilter() {\n return this.filterValue && this.filterValue.trim().length > 0;\n }\n}\n\n@Component({\n selector: 'p-dataViewLayoutOptions',\n template: `\n
\n \n
\n `,\n encapsulation: ViewEncapsulation.None\n})\nexport class DataViewLayoutOptions {\n\n @Input() style: any;\n\n @Input() styleClass: string;\n\n constructor(public dv: DataView) {}\n\n changeLayout(event: Event, layout: string) {\n this.dv.changeLayout(layout);\n event.preventDefault();\n }\n}\n@NgModule({\n imports: [CommonModule,SharedModule,PaginatorModule],\n exports: [DataView,SharedModule,DataViewLayoutOptions],\n declarations: [DataView,DataViewLayoutOptions]\n})\nexport class DataViewModule { }\n"]}