UNPKG

@anglr/grid

Version:
151 lines 5.06 kB
import { ChangeDetectionStrategy, Inject, Optional, ElementRef, Component } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { deserializeFromUrlQuery, serializeToUrlQuery } from '@jscrpt/common'; import { extend } from '@jscrpt/common/extend'; import { GRID_INITIALIZER_OPTIONS } from '../../../misc/tokens'; import * as i0 from "@angular/core"; import * as i1 from "@angular/router"; /** * Default options for query grid initializer */ const defaultOptions = { prefix: '' }; /** * Component used for rendering query grid initializer */ export class QueryGridInitializerComponent { /** * @inheritdoc */ get options() { return this.ɵoptions; } set options(options) { this.ɵoptions = extend(true, this.ɵoptions, options); } //######################### protected properties ######################### /** * Gets name of page in url */ get pageName() { return this.ɵoptions.prefix + 'p'; } /** * Gets name of items per page in url */ get itemsPerPageName() { return this.ɵoptions.prefix + 'ipp'; } /** * Gets name of ordering in url */ get orderingName() { return this.ɵoptions.prefix + 'o'; } //######################### constructor ######################### constructor(router, pluginElement, route, options) { this.router = router; this.pluginElement = pluginElement; this.route = route; this.ɵoptions = extend(true, {}, defaultOptions, options); } //######################### public methods - implementation of NoGridInitializer ######################### /** * @inheritdoc */ initialize(_force) { } /** * @inheritdoc */ initOptions() { } /** * @inheritdoc */ invalidateVisuals() { } /** * @inheritdoc */ getPage() { if (!this.route.snapshot.queryParamMap.has(this.pageName)) { return null; } return +this.route.snapshot.queryParamMap.get(this.pageName); } /** * @inheritdoc */ setPage(page) { const pageParam = {}; pageParam[this.pageName] = page; this.router.navigate(['.'], { relativeTo: this.route, queryParams: pageParam, queryParamsHandling: 'merge', replaceUrl: true }); } /** * @inheritdoc */ getItemsPerPage() { if (!this.route.snapshot.queryParamMap.has(this.itemsPerPageName)) { return null; } return +this.route.snapshot.queryParamMap.get(this.itemsPerPageName); } /** * @inheritdoc */ setItemsPerPage(itemsPerPage) { const pageParam = {}; pageParam[this.itemsPerPageName] = itemsPerPage; this.router.navigate(['.'], { relativeTo: this.route, queryParams: pageParam, queryParamsHandling: 'merge', replaceUrl: true }); } /** * @inheritdoc */ getOrdering() { if (!this.route.snapshot.queryParamMap.has(this.orderingName)) { return null; } return deserializeFromUrlQuery(this.route.snapshot.queryParamMap.get(this.orderingName)); } /** * @inheritdoc */ setOrdering(ordering) { const orderingParam = {}; orderingParam[this.orderingName] = serializeToUrlQuery(ordering); this.router.navigate(['.'], { relativeTo: this.route, queryParams: orderingParam, queryParamsHandling: 'merge', replaceUrl: true }); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.0", ngImport: i0, type: QueryGridInitializerComponent, deps: [{ token: i1.Router }, { token: i0.ElementRef }, { token: i1.ActivatedRoute }, { token: GRID_INITIALIZER_OPTIONS, optional: true }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.1.0", type: QueryGridInitializerComponent, isStandalone: true, selector: "ng-query-grid-initializer", ngImport: i0, template: '', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.0", ngImport: i0, type: QueryGridInitializerComponent, decorators: [{ type: Component, args: [{ selector: 'ng-query-grid-initializer', template: '', changeDetection: ChangeDetectionStrategy.OnPush }] }], ctorParameters: () => [{ type: i1.Router }, { type: i0.ElementRef }, { type: i1.ActivatedRoute }, { type: undefined, decorators: [{ type: Inject, args: [GRID_INITIALIZER_OPTIONS] }, { type: Optional }] }] }); //# sourceMappingURL=queryGridInitializer.component.js.map