@politie/ngx-list-service
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -319,7 +319,8 @@ (function (global, factory) { | ||
this.filterFunction$ = new rxjs.BehaviorSubject(null); | ||
this.sortOptions$ = new rxjs.BehaviorSubject({ key: null, order: 'asc' }); | ||
this.sortOptions$ = new rxjs.BehaviorSubject(null); | ||
this.currentIndex$ = new rxjs.BehaviorSubject(0); | ||
this.originalList$ = new rxjs.Subject(); | ||
this.config = { | ||
data: [], | ||
sort: { key: null, order: 'asc' }, | ||
list: [], | ||
filterFunction: null, | ||
@@ -351,7 +352,10 @@ sortFunction: null, | ||
} | ||
if (rxjs.isObservable(this.config.data)) { | ||
this.config.data.subscribe(function (r) { return _this.update(r); }); | ||
if (this.config.sort) { | ||
this.sortOptions$.next(this.config.sort); | ||
} | ||
if (rxjs.isObservable(this.config.list)) { | ||
this.config.list.subscribe(function (r) { return _this.update(r); }); | ||
} | ||
else { | ||
this.update(this.config.data); | ||
this.update(this.config.list); | ||
} | ||
@@ -385,5 +389,6 @@ }; | ||
ListService.prototype.sort = function (key) { | ||
var _a, _b; | ||
var order; | ||
if (key === this.sortOptions$.getValue().key) { | ||
order = this.sortOptions$.getValue().order === 'asc' ? 'desc' : 'asc'; | ||
if (key === ((_a = this.sortOptions$.getValue()) === null || _a === void 0 ? void 0 : _a.key)) { | ||
order = ((_b = this.sortOptions$.getValue()) === null || _b === void 0 ? void 0 : _b.order) === 'asc' ? 'desc' : 'asc'; | ||
} | ||
@@ -404,4 +409,4 @@ else { | ||
this.filterFunction$ | ||
]).pipe(operators.map(function (_a) { | ||
var _b = __read(_a, 2), list = _b[0], filterFunction = _b[1]; | ||
]).pipe(operators.map(function (_c) { | ||
var _d = __read(_c, 2), list = _d[0], filterFunction = _d[1]; | ||
if (filterFunction) { | ||
@@ -423,5 +428,5 @@ return list.filter(filterFunction); | ||
this.filteredList$, | ||
this.sortOptions$ | ||
]).pipe(operators.map(function (_a) { | ||
var _b = __read(_a, 2), filteredList = _b[0], sorting = _b[1]; | ||
this.sortOptions$.pipe(operators.filter(function (i) { return i !== null; })) | ||
]).pipe(operators.map(function (_c) { | ||
var _d = __read(_c, 2), filteredList = _d[0], sorting = _d[1]; | ||
var list; | ||
@@ -466,4 +471,4 @@ if (sorting.key) { | ||
var _this = this; | ||
this.list$ = this.currentIndex$.pipe(operators.skip(1), operators.withLatestFrom(this.sortedList$), operators.map(function (_a) { | ||
var _b = __read(_a, 2), requestedIndex = _b[0], _c = _b[1], list = _c.list, sorting = _c.sorting; | ||
this.result$ = this.currentIndex$.pipe(operators.skip(1), operators.withLatestFrom(this.sortedList$), operators.map(function (_c) { | ||
var _d = __read(_c, 2), requestedIndex = _d[0], _e = _d[1], list = _e.list, sorting = _e.sorting; | ||
/** | ||
@@ -478,5 +483,6 @@ * Check the amount of pages that is needed for the given list | ||
/** | ||
* Create a slice based on the index and the pageSize | ||
* Create a page based on the index and the pageSize | ||
*/ | ||
var slice = totalPages === 0 ? list : list.slice((index * _this.config.pageSize), ((index * _this.config.pageSize) + _this.config.pageSize)); | ||
var sliceStart = index * _this.config.pageSize; | ||
var page = (totalPages === 0) ? list.slice() : list.slice(sliceStart, (sliceStart + _this.config.pageSize)); | ||
/** | ||
@@ -486,3 +492,3 @@ * Return the payload to the view, with the list, sorting and pagination options | ||
return { | ||
list: slice, | ||
page: page, | ||
sorting: sorting, | ||
@@ -493,3 +499,3 @@ pagination: { | ||
current: index + 1, | ||
size: slice.length, | ||
size: page.length, | ||
total: Math.max(totalPages, 1) | ||
@@ -496,0 +502,0 @@ }, |
@@ -15,3 +15,3 @@ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("rxjs"),require("rxjs/operators"),require("@angular/core")):"function"==typeof define&&define.amd?define("@politie/ngx-list-service",["exports","rxjs","rxjs/operators","@angular/core"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).politie=t.politie||{},t.politie["ngx-list-service"]={}),t.rxjs,t.rxjs.operators,t.ng.core)}(this,(function(t,e,i,n){"use strict"; | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */Object.create;function r(t,e){var i="function"==typeof Symbol&&t[Symbol.iterator];if(!i)return t;var n,r,o=i.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(t){r={error:t}}finally{try{n&&!n.done&&(i=o.return)&&i.call(o)}finally{if(r)throw r.error}}return s}Object.create;var o=function(){function t(){this.filterFunction$=new e.BehaviorSubject(null),this.sortOptions$=new e.BehaviorSubject({key:null,order:"asc"}),this.currentIndex$=new e.BehaviorSubject(0),this.originalList$=new e.Subject,this.config={data:[],filterFunction:null,sortFunction:null,pageSize:0,resetToFirstPageOnUpdate:!0},this.createFilteredList$(),this.createSortedList$(),this.createList$()}return t.prototype.create=function(t){var i=this;this.config=Object.assign(Object.assign({},this.config),t),this.config.filterFunction&&this.filterFunction$.next(this.config.filterFunction),e.isObservable(this.config.data)?this.config.data.subscribe((function(t){return i.update(t)})):this.update(this.config.data)},t.prototype.update=function(t){this.originalList$.next(t.slice()),this.currentIndex$.next(0)},t.prototype.filter=function(t){this.filterFunction$.next(null!=t?t:this.config.filterFunction),this.currentIndex$.next(0)},t.prototype.sort=function(t){var e;e=t===this.sortOptions$.getValue().key&&"asc"===this.sortOptions$.getValue().order?"desc":"asc",this.sortOptions$.next({order:e,key:t}),this.currentIndex$.next(0)},t.prototype.createFilteredList$=function(){this.filteredList$=e.combineLatest([this.originalList$,this.filterFunction$]).pipe(i.map((function(t){var e=r(t,2),i=e[0],n=e[1];return n?i.filter(n):i})))},t.prototype.createSortedList$=function(){var t=this;this.sortedList$=e.combineLatest([this.filteredList$,this.sortOptions$]).pipe(i.map((function(e){var i=r(e,2),n=i[0],o=i[1];return{list:o.key?n.sort((function(e,i){var n,r;return t.config.sortFunction?(n=t.config.sortFunction(e,o.key),r=t.config.sortFunction(i,o.key)):(n=e[o.key],r=i[o.key]),"asc"===o.order?n<r?-1:n>r?1:0:"desc"===o.order?r<n?-1:r>n?1:0:0})):n,sorting:o}})))},t.prototype.createList$=function(){var t=this;this.list$=this.currentIndex$.pipe(i.skip(1),i.withLatestFrom(this.sortedList$),i.map((function(e){var i=r(e,2),n=i[0],o=i[1],s=o.list,c=o.sorting,a=0===t.config.pageSize?0:Math.ceil(s.length/t.config.pageSize),u=Math.max(0,Math.min(n,a-1)),l=0===a?s:s.slice(u*t.config.pageSize,u*t.config.pageSize+t.config.pageSize);return{list:l,sorting:c,pagination:{listSize:s.length,page:{current:u+1,size:l.length,total:Math.max(a,1)},pages:Array.from({length:Math.max(a,1)},(function(t,e){return e+1})),disabled:{prev:0===u,next:u===Math.max(a-1,0)}}}})))},t.prototype.goToPage=function(t){this.currentIndex$.next(t-1)},t.prototype.nextPage=function(){this.currentIndex$.next(this.currentIndex$.getValue()+1)},t.prototype.prevPage=function(){this.currentIndex$.next(this.currentIndex$.getValue()-1)},t}();o.decorators=[{type:n.Injectable}],o.ctorParameters=function(){return[]},t.ListService=o,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
***************************************************************************** */Object.create;function r(t,e){var i="function"==typeof Symbol&&t[Symbol.iterator];if(!i)return t;var n,r,o=i.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(t){r={error:t}}finally{try{n&&!n.done&&(i=o.return)&&i.call(o)}finally{if(r)throw r.error}}return s}Object.create;var o=function(){function t(){this.filterFunction$=new e.BehaviorSubject(null),this.sortOptions$=new e.BehaviorSubject(null),this.currentIndex$=new e.BehaviorSubject(0),this.originalList$=new e.Subject,this.config={sort:{key:null,order:"asc"},list:[],filterFunction:null,sortFunction:null,pageSize:0,resetToFirstPageOnUpdate:!0},this.createFilteredList$(),this.createSortedList$(),this.createList$()}return t.prototype.create=function(t){var i=this;this.config=Object.assign(Object.assign({},this.config),t),this.config.filterFunction&&this.filterFunction$.next(this.config.filterFunction),this.config.sort&&this.sortOptions$.next(this.config.sort),e.isObservable(this.config.list)?this.config.list.subscribe((function(t){return i.update(t)})):this.update(this.config.list)},t.prototype.update=function(t){this.originalList$.next(t.slice()),this.currentIndex$.next(0)},t.prototype.filter=function(t){this.filterFunction$.next(null!=t?t:this.config.filterFunction),this.currentIndex$.next(0)},t.prototype.sort=function(t){var e,i,n;n=t===(null===(e=this.sortOptions$.getValue())||void 0===e?void 0:e.key)&&"asc"===(null===(i=this.sortOptions$.getValue())||void 0===i?void 0:i.order)?"desc":"asc",this.sortOptions$.next({order:n,key:t}),this.currentIndex$.next(0)},t.prototype.createFilteredList$=function(){this.filteredList$=e.combineLatest([this.originalList$,this.filterFunction$]).pipe(i.map((function(t){var e=r(t,2),i=e[0],n=e[1];return n?i.filter(n):i})))},t.prototype.createSortedList$=function(){var t=this;this.sortedList$=e.combineLatest([this.filteredList$,this.sortOptions$.pipe(i.filter((function(t){return null!==t})))]).pipe(i.map((function(e){var i=r(e,2),n=i[0],o=i[1];return{list:o.key?n.sort((function(e,i){var n,r;return t.config.sortFunction?(n=t.config.sortFunction(e,o.key),r=t.config.sortFunction(i,o.key)):(n=e[o.key],r=i[o.key]),"asc"===o.order?n<r?-1:n>r?1:0:"desc"===o.order?r<n?-1:r>n?1:0:0})):n,sorting:o}})))},t.prototype.createList$=function(){var t=this;this.result$=this.currentIndex$.pipe(i.skip(1),i.withLatestFrom(this.sortedList$),i.map((function(e){var i=r(e,2),n=i[0],o=i[1],s=o.list,c=o.sorting,a=0===t.config.pageSize?0:Math.ceil(s.length/t.config.pageSize),u=Math.max(0,Math.min(n,a-1)),l=u*t.config.pageSize,f=0===a?s.slice():s.slice(l,l+t.config.pageSize);return{page:f,sorting:c,pagination:{listSize:s.length,page:{current:u+1,size:f.length,total:Math.max(a,1)},pages:Array.from({length:Math.max(a,1)},(function(t,e){return e+1})),disabled:{prev:0===u,next:u===Math.max(a-1,0)}}}})))},t.prototype.goToPage=function(t){this.currentIndex$.next(t-1)},t.prototype.nextPage=function(){this.currentIndex$.next(this.currentIndex$.getValue()+1)},t.prototype.prevPage=function(){this.currentIndex$.next(this.currentIndex$.getValue()-1)},t}();o.decorators=[{type:n.Injectable}],o.ctorParameters=function(){return[]},t.ListService=o,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=politie-ngx-list-service.umd.min.js.map |
export {}; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlzdC5tb2RlbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3Byb2plY3RzL25neC1saXN0LXNlcnZpY2Uvc3JjL2xpYi9tb2RlbHMvbGlzdC5tb2RlbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgT2JzZXJ2YWJsZSB9IGZyb20gJ3J4anMnO1xuXG4vKipcbiAqIFNvcnRpbmcgcGF5bG9hZFxuICovXG5leHBvcnQgdHlwZSBMaXN0U29ydGluZzxUPiA9IHtcbiAgLyoqXG4gICAqIEtleSB0byBzb3J0IGJ5LCBhcyBrZXlvZiBvZiB0aGUgcHJvdmlkZWQgZ2VuZXJpYyB0eXBlIFRcbiAgICovXG4gIGtleTogKEV4dHJhY3Q8a2V5b2YgVCwgc3RyaW5nPikgfCBudWxsO1xuXG4gIC8qKlxuICAgKiBPcmRlciwgY2FuIGJlICdhc2MnIG9yICdkZXNjJ1xuICAgKi9cbiAgb3JkZXI6ICdhc2MnIHwgJ2Rlc2MnO1xufTtcblxuLyoqXG4gKiBMaXN0IHBhZ2luYXRpb24gcGF5bG9hZFxuICovXG5leHBvcnQgdHlwZSBMaXN0UGFnaW5hdGlvbiA9IHtcbiAgLyoqXG4gICAqIFNpemUgb2YgdGhlIGN1cnJlbnQgc29ydGVkIGxpc3RcbiAgICovXG4gIGxpc3RTaXplOiBudW1iZXI7XG5cbiAgcGFnZToge1xuICAgIC8qKlxuICAgICAqIFRoZSBjdXJyZW50IHBhZ2UgKDEtYmFz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PiBhbnkpO1xufVxuIl19 |
import { BehaviorSubject, combineLatest, isObservable, Subject } from 'rxjs'; | ||
import { map, skip, withLatestFrom } from 'rxjs/operators'; | ||
import { filter, map, skip, withLatestFrom } from 'rxjs/operators'; | ||
import { Injectable } from '@angular/core'; | ||
@@ -7,7 +7,8 @@ export class ListService { | ||
this.filterFunction$ = new BehaviorSubject(null); | ||
this.sortOptions$ = new BehaviorSubject({ key: null, order: 'asc' }); | ||
this.sortOptions$ = new BehaviorSubject(null); | ||
this.currentIndex$ = new BehaviorSubject(0); | ||
this.originalList$ = new Subject(); | ||
this.config = { | ||
data: [], | ||
sort: { key: null, order: 'asc' }, | ||
list: [], | ||
filterFunction: null, | ||
@@ -38,7 +39,10 @@ sortFunction: null, | ||
} | ||
if (isObservable(this.config.data)) { | ||
this.config.data.subscribe(r => this.update(r)); | ||
if (this.config.sort) { | ||
this.sortOptions$.next(this.config.sort); | ||
} | ||
if (isObservable(this.config.list)) { | ||
this.config.list.subscribe(r => this.update(r)); | ||
} | ||
else { | ||
this.update(this.config.data); | ||
this.update(this.config.list); | ||
} | ||
@@ -72,5 +76,6 @@ } | ||
sort(key) { | ||
var _a, _b; | ||
let order; | ||
if (key === this.sortOptions$.getValue().key) { | ||
order = this.sortOptions$.getValue().order === 'asc' ? 'desc' : 'asc'; | ||
if (key === ((_a = this.sortOptions$.getValue()) === null || _a === void 0 ? void 0 : _a.key)) { | ||
order = ((_b = this.sortOptions$.getValue()) === null || _b === void 0 ? void 0 : _b.order) === 'asc' ? 'desc' : 'asc'; | ||
} | ||
@@ -107,3 +112,3 @@ else { | ||
this.filteredList$, | ||
this.sortOptions$ | ||
this.sortOptions$.pipe(filter((i) => i !== null)) | ||
]).pipe(map(([filteredList, sorting]) => { | ||
@@ -148,3 +153,3 @@ let list; | ||
createList$() { | ||
this.list$ = this.currentIndex$.pipe(skip(1), withLatestFrom(this.sortedList$), map(([requestedIndex, { list, sorting }]) => { | ||
this.result$ = this.currentIndex$.pipe(skip(1), withLatestFrom(this.sortedList$), map(([requestedIndex, { list, sorting }]) => { | ||
/** | ||
@@ -159,5 +164,6 @@ * Check the amount of pages that is needed for the given list | ||
/** | ||
* Create a slice based on the index and the pageSize | ||
* Create a page based on the index and the pageSize | ||
*/ | ||
const slice = totalPages === 0 ? list : list.slice((index * this.config.pageSize), ((index * this.config.pageSize) + this.config.pageSize)); | ||
const sliceStart = index * this.config.pageSize; | ||
const page = (totalPages === 0) ? list.slice() : list.slice(sliceStart, (sliceStart + this.config.pageSize)); | ||
/** | ||
@@ -167,3 +173,3 @@ * Return the payload to the view, with the list, sorting and pagination options | ||
return { | ||
list: slice, | ||
page, | ||
sorting, | ||
@@ -174,3 +180,3 @@ pagination: { | ||
current: index + 1, | ||
size: slice.length, | ||
size: page.length, | ||
total: Math.max(totalPages, 1) | ||
@@ -213,2 +219,2 @@ }, | ||
ListService.ctorParameters = () => []; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlzdC5zZXJ2aWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vcHJvamVjdHMvbmd4LWxpc3Qtc2VydmljZS9zcmMvbGliL3NlcnZpY2UvbGlzdC5zZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxlQUFlLEVBQUUsYUFBYSxFQUFFLFlBQVksRUFBYyxPQUFPLEVBQUUsTUFBTSxNQUFNLENBQUM7QUFDekYsT0FBTyxFQUFFLEdBQUcsRUFBRSxJQUFJLEVBQUUsY0FBYyxFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFDM0QsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLGVBQWUsQ0FBQztBQUkzQyxNQUFNLE9BQU8sV0FBVztJQW1CdEI7UUFoQlEsb0JBQWUsR0FBbUQsSUFBSSxlQUFlLENBQWdDLElBQUksQ0FBQyxDQUF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0ID0gZmlsdGVyZWRMaXN0LnNvcnQoKGEsIGIpOiBudW1iZXIgPT4ge1xuICAgICAgICAgICAgbGV0IHJlc3VsdEE6IGFueTtcbiAgICAgICAgICAgIGxldCByZXN1bHRCOiBhbnk7XG5cbiAgICAgICAgICAgIGlmICh0aGlzLmNvbmZpZy5zb3J0RnVuY3Rpb24pIHtcbiAgICAgICAgICAgICAgcmVzdWx0QSA9IHRoaXMuY29uZmlnLnNvcnRGdW5jdGlvbihhLCBzb3J0aW5nLmtleSBhcyBzdHJpbmcpO1xuICAgICAgICAgICAgICByZXN1bHRCID0gdGhpcy5jb25maWcuc29ydEZ1bmN0aW9uKGIsIHNvcnRpbmcua2V5IGFzIHN0cmluZyk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICByZXN1bHRBID0gYVsoc29ydGluZy5rZXkgYXMgRXh0cmFjdDxrZXlvZiBULCBzdHJpbmc+KV07XG4gICAgICAgICAgICAgIHJlc3VsdEIgPSBiWyhzb3J0aW5nLmtleSBhcyBFeHRyYWN0PGtleW9mIFQsIHN0cmluZz4pXTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHNvcnRpbmcub3JkZXIgPT09ICdhc2MnKSB7XG4gICAgICAgICAgICAgIHJldHVybiByZXN1bHRBIDwgcmVzdWx0QiA/IC0xIDogcmVzdWx0QSA+IHJlc3VsdEIgPyAxIDogMDtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoc29ydGluZy5vcmRlciA9PT0gJ2Rlc2MnKSB7XG4gICAgICAgICAgICAgIHJldHVybiByZXN1bHRCIDwgcmVzdWx0QSA/IC0xIDogcmVzdWx0QiA+IHJlc3VsdEEgPyAxIDogMDtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIHJldHVybiAwO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0pO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGxpc3QgPSBmaWx0ZXJ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IHRoZSByZXF1ZXN0ZWQgaW5kZXggaXMgaW4gYm91bmRzIG9mIHRoZSBsaXN0IHNpemUuXG4gICAgICAgICAqL1xuICAgICAgICBjb25zdCBpbmRleCA9IE1hdGgubWF4KDAsIE1hdGgubWluKHJlcXVlc3RlZEluZGV4LCB0b3RhbFBhZ2VzIC0gMSkpO1xuXG4gICAgICAgIC8qKlxuICAgICAgICAgKiBDcmVhdGUgYSBzbGljZSBiYXNlZCBvbiB0aGUgaW5kZXggYW5kIHRoZSBwYWdlU2l6ZVxuICAgICAgICAgKi9cbiAgICAgICAgY29uc3Qgc2xpY2UgPSB0b3RhbFBhZ2VzID09PSAwID8gbGlzdCA6IGxpc3Quc2xpY2UoKGluZGV4ICogdGhpcy5jb25maWcucGFnZVNpemUpLCAoKGluZGV4ICogdGhpcy5jb25maWcucGFnZVNpemUpICsgdGhpcy5jb25maWcucGFnZVNpemUpKTtcblxuICAgICAgICAvKipcbiAgICAgICAgICogUmV0dXJuIHRoZSBwYXlsb2FkIHRvIHRoZSB2aWV3LCB3aXRoIHRoZSBsaXN0LCBzb3J0aW5nIGFuZCBwYWdpbmF0aW9uIG9wdGlvbnNcbiAgICAgICAgICovXG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgbGlzdDogc2xpY2UsXG4gICAgICAgICAgc29ydGluZyxcbiAgICAgICAgICBwYWdpbmF0aW9uOiB7XG4gICAgICAgICAgICBsaXN0U2l6ZTogbGlzdC5sZW5ndGgsXG4gICAgICAgICAgICBwYWdlOiB7XG4gICAgICAgICAgICAgIGN1cnJlbnQ6IGluZGV4ICsgMSxcbiAgICAgICAgICAgICAgc2l6ZTogc2xpY2UubGVuZ3RoLFxuICAgICAgICAgICAgICB0b3RhbDogTWF0aC5tYXgodG90YWxQYWdlcywgMSlcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgICBwYWdlczogQXJyYXkuZnJvbSh7bGVuZ3RoOiBNYXRoLm1heCh0b3RhbFBhZ2VzLCAxKX0sIChfLCBpKSA9PiBpICsgMSksXG4gICAgICAgICAgICBkaXNhYmxlZDoge1xuICAgICAgICAgICAgICBwcmV2OiAoaW5kZXggPT09IDApLFxuICAgICAgICAgICAgICBuZXh0OiAoaW5kZXggPT09IE1hdGgubWF4KHRvdGFsUGFnZXMgLSAxLCAwKSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgICB9KVxuICAgICk7XG4gIH1cblxuICAvKipcbiAgICogR28gdG8gYSBzcGVjaWZpYyBwYWdlIGluIHRoZSBzZXRcbiAgICogVGhpcyB3aWxsIGJlIHRyYW5zZm9ybWVkIHRvIGEgemVybyBiYXNlZCBpbmRleFxuICAgKlxuICAgKiBAcGFyYW0gcGFnZSB0aGUgcGFnZSBudW1iZXIgdG8gZ28gdG9cbiAgICovXG4gIGdvVG9QYWdlKHBhZ2U6IG51bWJlcikge1xuICAgIHRoaXMuY3VycmVudEluZGV4JC5uZXh0KHBhZ2UgLSAxKTtcbiAgfVxuXG4gIC8qKlxuICAgKiBHbyB0byB0aGUgbmV4dCBwYWdlXG4gICAqL1xuICBuZXh0UGFnZSgpIHtcbiAgICB0aGlzLmN1cnJlbnRJbmRleCQubmV4dCh0aGlzLmN1cnJlbnRJbmRleCQuZ2V0VmFsdWUoKSArIDEpO1xuICB9XG5cbiAgLyoqXG4gICAqIEdvIHRvIHRoZSBwcmV2aW91cyBwYWdlXG4gICAqL1xuICBwcmV2UGFnZSgpIHtcbiAgICB0aGlzLmN1cnJlbnRJbmRleCQubmV4dCh0aGlzLmN1cnJlbnRJbmRleCQuZ2V0VmFsdWUoKSAtIDEpO1xuICB9XG59XG4iXX0= | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlzdC5zZXJ2aWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vcHJvamVjdHMvbmd4LWxpc3Qtc2VydmljZS9zcmMvbGli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AgbGV0IHJlc3VsdEE6IGFueTtcbiAgICAgICAgICAgIGxldCByZXN1bHRCOiBhbnk7XG5cbiAgICAgICAgICAgIGlmICh0aGlzLmNvbmZpZy5zb3J0RnVuY3Rpb24pIHtcbiAgICAgICAgICAgICAgcmVzdWx0QSA9IHRoaXMuY29uZmlnLnNvcnRGdW5jdGlvbihhLCBzb3J0aW5nLmtleSBhcyBzdHJpbmcpO1xuICAgICAgICAgICAgICByZXN1bHRCID0gdGhpcy5jb25maWcuc29ydEZ1bmN0aW9uKGIsIHNvcnRpbmcua2V5IGFzIHN0cmluZyk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICByZXN1bHRBID0gYVsoc29ydGluZy5rZXkgYXMgRXh0cmFjdDxrZXlvZiBULCBzdHJpbmc+KV07XG4gICAgICAgICAgICAgIHJlc3VsdEIgPSBiWyhzb3J0aW5nLmtleSBhcyBFeHRyYWN0PGtleW9mIFQsIHN0cmluZz4pXTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHNvcnRpbmcub3JkZXIgPT09ICdhc2MnKSB7XG4gICAgICAgICAgICAgIHJldHVybiByZXN1bHRBIDwgcmVzdWx0QiA/IC0xIDogcmVzdWx0QSA+IHJlc3VsdEIgPyAxIDogMDtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoc29ydGluZy5vcmRlciA9PT0gJ2Rlc2MnKSB7XG4gICAgICAgICAgICAgIHJldHVybiByZXN1bHRCIDwgcmVzdWx0QSA/IC0xIDogcmVzdWx0QiA+IHJlc3VsdEEgPyAxIDogMDtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIHJldHVybiAwO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0pO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIGxpc3QgPSBmaWx0ZXJlZExpc3Q7XG4gICAgICAgIH1cblxuICAgICAgICAvKipcbiAgICAgICAgICogUmV0dXJuIGEgb2Jq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ICBkaXNhYmxlZDoge1xuICAgICAgICAgICAgICBwcmV2OiAoaW5kZXggPT09IDApLFxuICAgICAgICAgICAgICBuZXh0OiAoaW5kZXggPT09IE1hdGgubWF4KHRvdGFsUGFnZXMgLSAxLCAwKSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgICB9KVxuICAgICk7XG4gIH1cblxuICAvKipcbiAgICogR28gdG8gYSBzcGVjaWZpYyBwYWdlIGluIHRoZSBzZXRcbiAgICogVGhpcyB3aWxsIGJlIHRyYW5zZm9ybWVkIHRvIGEgemVybyBiYXNlZCBpbmRleFxuICAgKlxuICAgKiBAcGFyYW0gcGFnZSB0aGUgcGFnZSBudW1iZXIgdG8gZ28gdG9cbiAgICovXG4gIGdvVG9QYWdlKHBhZ2U6IG51bWJlcikge1xuICAgIHRoaXMuY3VycmVudEluZGV4JC5uZXh0KHBhZ2UgLSAxKTtcbiAgfVxuXG4gIC8qKlxuICAgKiBHbyB0byB0aGUgbmV4dCBwYWdlXG4gICAqL1xuICBuZXh0UGFnZSgpIHtcbiAgICB0aGlzLmN1cnJlbnRJbmRleCQubmV4dCh0aGlzLmN1cnJlbnRJbmRleCQuZ2V0VmFsdWUoKSArIDEpO1xuICB9XG5cbiAgLyoqXG4gICAqIEdvIHRvIHRoZSBwcmV2aW91cyBwYWdlXG4gICAqL1xuICBwcmV2UGFnZSgpIHtcbiAgICB0aGlzLmN1cnJlbnRJbmRleCQubmV4dCh0aGlzLmN1cnJlbnRJbmRleCQuZ2V0VmFsdWUoKSAtIDEpO1xuICB9XG59XG4iXX0= |
import { BehaviorSubject, Subject, isObservable, combineLatest } from 'rxjs'; | ||
import { map, skip, withLatestFrom } from 'rxjs/operators'; | ||
import { map, filter, skip, withLatestFrom } from 'rxjs/operators'; | ||
import { Injectable } from '@angular/core'; | ||
@@ -8,7 +8,8 @@ | ||
this.filterFunction$ = new BehaviorSubject(null); | ||
this.sortOptions$ = new BehaviorSubject({ key: null, order: 'asc' }); | ||
this.sortOptions$ = new BehaviorSubject(null); | ||
this.currentIndex$ = new BehaviorSubject(0); | ||
this.originalList$ = new Subject(); | ||
this.config = { | ||
data: [], | ||
sort: { key: null, order: 'asc' }, | ||
list: [], | ||
filterFunction: null, | ||
@@ -39,7 +40,10 @@ sortFunction: null, | ||
} | ||
if (isObservable(this.config.data)) { | ||
this.config.data.subscribe(r => this.update(r)); | ||
if (this.config.sort) { | ||
this.sortOptions$.next(this.config.sort); | ||
} | ||
if (isObservable(this.config.list)) { | ||
this.config.list.subscribe(r => this.update(r)); | ||
} | ||
else { | ||
this.update(this.config.data); | ||
this.update(this.config.list); | ||
} | ||
@@ -73,5 +77,6 @@ } | ||
sort(key) { | ||
var _a, _b; | ||
let order; | ||
if (key === this.sortOptions$.getValue().key) { | ||
order = this.sortOptions$.getValue().order === 'asc' ? 'desc' : 'asc'; | ||
if (key === ((_a = this.sortOptions$.getValue()) === null || _a === void 0 ? void 0 : _a.key)) { | ||
order = ((_b = this.sortOptions$.getValue()) === null || _b === void 0 ? void 0 : _b.order) === 'asc' ? 'desc' : 'asc'; | ||
} | ||
@@ -108,3 +113,3 @@ else { | ||
this.filteredList$, | ||
this.sortOptions$ | ||
this.sortOptions$.pipe(filter((i) => i !== null)) | ||
]).pipe(map(([filteredList, sorting]) => { | ||
@@ -149,3 +154,3 @@ let list; | ||
createList$() { | ||
this.list$ = this.currentIndex$.pipe(skip(1), withLatestFrom(this.sortedList$), map(([requestedIndex, { list, sorting }]) => { | ||
this.result$ = this.currentIndex$.pipe(skip(1), withLatestFrom(this.sortedList$), map(([requestedIndex, { list, sorting }]) => { | ||
/** | ||
@@ -160,5 +165,6 @@ * Check the amount of pages that is needed for the given list | ||
/** | ||
* Create a slice based on the index and the pageSize | ||
* Create a page based on the index and the pageSize | ||
*/ | ||
const slice = totalPages === 0 ? list : list.slice((index * this.config.pageSize), ((index * this.config.pageSize) + this.config.pageSize)); | ||
const sliceStart = index * this.config.pageSize; | ||
const page = (totalPages === 0) ? list.slice() : list.slice(sliceStart, (sliceStart + this.config.pageSize)); | ||
/** | ||
@@ -168,3 +174,3 @@ * Return the payload to the view, with the list, sorting and pagination options | ||
return { | ||
list: slice, | ||
page, | ||
sorting, | ||
@@ -175,3 +181,3 @@ pagination: { | ||
current: index + 1, | ||
size: slice.length, | ||
size: page.length, | ||
total: Math.max(totalPages, 1) | ||
@@ -178,0 +184,0 @@ }, |
@@ -56,3 +56,3 @@ import { Observable } from 'rxjs'; | ||
*/ | ||
list: T[]; | ||
page: T[]; | ||
/** | ||
@@ -71,3 +71,3 @@ * The current sorting options | ||
*/ | ||
data: T[] | Observable<T[]>; | ||
list: T[] | Observable<T[]>; | ||
/** | ||
@@ -78,2 +78,6 @@ * Set to number of items per page / slice | ||
/** | ||
* Initial sorting | ||
*/ | ||
sort?: ListSorting<T>; | ||
/** | ||
* Should the pagination return to page 1 on update? | ||
@@ -80,0 +84,0 @@ * |
import { Observable } from 'rxjs'; | ||
import { ListPayload, ListResult } from '../models/list.model'; | ||
export declare class ListService<T> { | ||
list$: Observable<ListResult<T>>; | ||
result$: Observable<ListResult<T>>; | ||
private filterFunction$; | ||
@@ -6,0 +6,0 @@ private sortOptions$; |
{ | ||
"name": "@politie/ngx-list-service", | ||
"license": "Apache-2.0", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"peerDependencies": { | ||
@@ -23,2 +23,2 @@ "@angular/common": "^11.0.9", | ||
"sideEffects": false | ||
} | ||
} |
@@ -35,3 +35,3 @@ # ListService | ||
this.listService.create({ | ||
data: myData, | ||
list: myData, | ||
pageSize: 25 | ||
@@ -54,11 +54,11 @@ }); | ||
| --- | :--- | --- | --- | | ||
| data | `T[]` or `Observable<T[]>` | Array (or observable with array) of objects containing the data that should be displayed. | `[]` | | ||
| list | `T[]` or `Observable<T[]>` | Array (or observable with array) of objects containing the data that should be displayed. | `[]` | | ||
| pageSize | `number` | How many items should be returned per page? Set to `0` for no pages. | `0` | | ||
| sort | `{key: property: Extract<keyof T, string>, order: 'asc' / 'desc' `} | If you want to sort the list on initialzation, set the sort property to the key you want to sort the list to. | `{ key: null, order: 'asc' }` | | ||
| filterFunction | `(item: T) => boolean` | Define a custom filter function. See [Filtering the List](#filtering-the-list) for a example. | `null` | | ||
| sortFunction | `(item: T, property: Extract<keyof T, string>) => any)` | If you want to override the default sorting behaviour, you can do so by adding your own sortFunction. See [Sorting the List](#sorting-the-list) for a example. | `null` | | ||
### `update(payload: T[])` | ||
Update the data list with a new set. This will return a slice of the new data, based on the filtering and sorting options already set. | ||
Update the data list with a new set. This will return a chunk of the new data, based on the filtering and sorting options already set. | ||
@@ -79,7 +79,7 @@ ### `sort(key: Extract<keyof T, string>)` | ||
If pagination is active, grab the next `slice` of data and emit the result to the `result$` observable. | ||
If pagination is active, grab the next `chunk` of data and emit the result to the `result$` observable. | ||
### `prevPage()` | ||
If pagination is active, grab the previous `slice` of data and emit the result to the `result$` observable. | ||
If pagination is active, grab the previous `chunk` of data and emit the result to the `result$` observable. | ||
@@ -96,7 +96,7 @@ ### `goToPage(page: number)` | ||
The list$ observable will emit a new result whenever the ListService `update()`, `sort()` or `filter()` methods are called. The `result$` observable contains the current slice of items, the active sorting options and properties to create pagination. The object that is returned looks like this: | ||
The result$ observable will emit a new result whenever the ListService `update()`, `sort()` or `filter()` methods are called. The `result$` observable contains the current chunk of items, the active sorting options and properties to create pagination. The object that is returned from this observable looks like this: | ||
```typescript | ||
{ | ||
list: `T[]`, // The current list slice (based on pagination and pageSize) of the filtered and sorted list | ||
page: `T[]`, // The current page chunk (based on pagination and pageSize) of the filtered and sorted list | ||
sorting: { | ||
@@ -115,4 +115,4 @@ key: `Extract<keyof T, string>`, | ||
disabled: { | ||
prev: `boolean`, // Should a prev button be disabled (current slice is start of list) | ||
next: `boolean` // Should a next button be disabled (current slice is end of list) | ||
prev: `boolean`, // Should a prev button be disabled (current chunk is start of list) | ||
next: `boolean` // Should a next button be disabled (current chunk is end of list) | ||
} | ||
@@ -144,3 +144,3 @@ } | ||
const myData: User[] = [ | ||
const myList: User[] = [ | ||
{ | ||
@@ -159,3 +159,3 @@ id: 1, | ||
this.listService.create({ | ||
data: myData, | ||
list: myList, | ||
pageSize: 25, | ||
@@ -192,3 +192,3 @@ filterFunction: (item: User): boolean => { | ||
this.listService.create({ | ||
data: myData, | ||
list: myList, | ||
pageSize: 25, | ||
@@ -202,3 +202,3 @@ sortFunction: (item: User, key: string): any => { | ||
// By default, just return the value of the key to sort | ||
// By default, just return the value of the key to the sorting function inside the Service. | ||
return item[key]; | ||
@@ -205,0 +205,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
153507
1167