increase table cache and other updates

This commit is contained in:
Dan Percic 2021-11-17 01:26:25 +02:00
parent 9dcc58d57d
commit 9759e0477e
4 changed files with 17 additions and 28 deletions

View File

@ -1,12 +1,12 @@
import { Directive, Injector, OnDestroy, TemplateRef, ViewChild } from '@angular/core'; import { Directive, Injector, OnDestroy, TemplateRef, ViewChild } from '@angular/core';
import { BehaviorSubject, combineLatest, Observable } from 'rxjs'; import { combineLatest, Observable } from 'rxjs';
import { map, switchMapTo } from 'rxjs/operators'; import { map, switchMapTo } from 'rxjs/operators';
import { FilterService } from '../filtering'; import { FilterService } from '../filtering';
import { SortingService } from '../sorting'; import { SortingService } from '../sorting';
import { AutoUnsubscribe, shareDistinctLast } from '../utils'; import { AutoUnsubscribe, shareDistinctLast } from '../utils';
import { SearchService } from '../search'; import { SearchService } from '../search';
import { EntitiesService, ListingService } from './services'; import { EntitiesService, ListingService } from './services';
import { IListable, ListingMode, ListingModes, TableColumnConfig } from './models'; import { IListable, TableColumnConfig } from './models';
export const DefaultListingServicesTmp = [FilterService, SearchService, SortingService, ListingService] as const; export const DefaultListingServicesTmp = [FilterService, SearchService, SortingService, ListingService] as const;
export const DefaultListingServices = [...DefaultListingServicesTmp, EntitiesService] as const; export const DefaultListingServices = [...DefaultListingServicesTmp, EntitiesService] as const;
@ -29,8 +29,6 @@ export abstract class ListingComponent<T extends IListable> extends AutoUnsubscr
@ViewChild('tableItemTemplate') readonly tableItemTemplate?: TemplateRef<unknown>; @ViewChild('tableItemTemplate') readonly tableItemTemplate?: TemplateRef<unknown>;
@ViewChild('workflowItemTemplate') readonly workflowItemTemplate?: TemplateRef<unknown>; @ViewChild('workflowItemTemplate') readonly workflowItemTemplate?: TemplateRef<unknown>;
private readonly _listingMode$ = new BehaviorSubject<ListingMode>(ListingModes.table);
protected constructor(protected readonly _injector: Injector) { protected constructor(protected readonly _injector: Injector) {
super(); super();
} }

View File

@ -5,27 +5,21 @@
[minBufferPx]="300" [minBufferPx]="300"
iqserHasScrollbar iqserHasScrollbar
> >
<ng-container *ngIf="listingComponent.sortedDisplayedEntities$ | async as entities"> <ng-container *cdkVirtualFor="let entity of listingComponent.sortedDisplayedEntities$; trackBy: trackBy; templateCacheSize: 60">
<!-- mouseenter and mouseleave triggers change detection event if itemMouse functions are undefined --> <!-- mouseenter and mouseleave triggers change detection event if itemMouse functions are undefined -->
<!-- this little hack below ensures that change detection won't be triggered if functions are undefined --> <!-- this little hack below ensures that change detection won't be triggered if functions are undefined -->
<ng-container *ngIf="itemMouseEnterFn || itemMouseLeaveFn; else withoutMouseEvents"> <div
<div (mouseenter)="itemMouseEnterFn && itemMouseEnterFn(entity)"
(mouseenter)="itemMouseEnterFn && itemMouseEnterFn(entity)" (mouseleave)="itemMouseLeaveFn && itemMouseLeaveFn(entity)"
(mouseleave)="itemMouseLeaveFn && itemMouseLeaveFn(entity)" *ngIf="itemMouseEnterFn || itemMouseLeaveFn; else withoutMouseEvents"
*cdkVirtualFor="let entity of entities; trackBy: trackById" [ngClass]="getTableItemClasses(entity)"
[ngClass]="getTableItemClasses(entity)" [routerLink]="entity.routerLink"
[routerLink]="entity.routerLink" >
> <ng-container *ngTemplateOutlet="tableItem; context: { entity: entity }"></ng-container>
<ng-container *ngTemplateOutlet="tableItem; context: { entity: entity }"></ng-container> </div>
</div>
</ng-container>
<ng-template #withoutMouseEvents> <ng-template #withoutMouseEvents>
<div <div [ngClass]="getTableItemClasses(entity)" [routerLink]="entity.routerLink">
*cdkVirtualFor="let entity of entities; trackBy: trackById"
[ngClass]="getTableItemClasses(entity)"
[routerLink]="entity.routerLink"
>
<ng-container *ngTemplateOutlet="tableItem; context: { entity: entity }"></ng-container> <ng-container *ngTemplateOutlet="tableItem; context: { entity: entity }"></ng-container>
</div> </div>
</ng-template> </ng-template>

View File

@ -1,7 +1,7 @@
import { AfterViewInit, ChangeDetectionStrategy, Component, forwardRef, Inject, Input, OnDestroy, ViewChild } from '@angular/core'; import { AfterViewInit, ChangeDetectionStrategy, Component, forwardRef, Inject, Input, OnDestroy, ViewChild } from '@angular/core';
import { CdkVirtualScrollViewport } from '@angular/cdk/scrolling'; import { CdkVirtualScrollViewport } from '@angular/cdk/scrolling';
import { tap } from 'rxjs/operators'; import { tap } from 'rxjs/operators';
import { AutoUnsubscribe } from '../../utils'; import { AutoUnsubscribe, trackBy } from '../../utils';
import { IListable } from '../models'; import { IListable } from '../models';
import { ListingComponent, ListingService } from '../index'; import { ListingComponent, ListingService } from '../index';
import { HasScrollbarDirective } from '../../scrollbar'; import { HasScrollbarDirective } from '../../scrollbar';
@ -18,6 +18,7 @@ export class TableContentComponent<T extends IListable> extends AutoUnsubscribe
@Input() itemMouseLeaveFn?: (entity: T) => void; @Input() itemMouseLeaveFn?: (entity: T) => void;
@Input() tableItemClasses?: Record<string, (e: T) => boolean>; @Input() tableItemClasses?: Record<string, (e: T) => boolean>;
@Input() selectionEnabled!: boolean; @Input() selectionEnabled!: boolean;
readonly trackBy = trackBy<T>();
@ViewChild(CdkVirtualScrollViewport, { static: true }) readonly scrollViewport!: CdkVirtualScrollViewport; @ViewChild(CdkVirtualScrollViewport, { static: true }) readonly scrollViewport!: CdkVirtualScrollViewport;
@ViewChild(HasScrollbarDirective, { static: true }) readonly hasScrollbarDirective!: HasScrollbarDirective; @ViewChild(HasScrollbarDirective, { static: true }) readonly hasScrollbarDirective!: HasScrollbarDirective;
@ -49,10 +50,6 @@ export class TableContentComponent<T extends IListable> extends AutoUnsubscribe
this.scrollViewport.scrollToIndex(this._lastScrolledIndex, 'smooth'); this.scrollViewport.scrollToIndex(this._lastScrolledIndex, 'smooth');
} }
trackById(index: number, entity: T): string {
return entity.id;
}
getTableItemClasses(entity: T): Record<string, boolean> { getTableItemClasses(entity: T): Record<string, boolean> {
const classes: Record<string, boolean> = { const classes: Record<string, boolean> = {
'table-item': true, 'table-item': true,

View File

@ -27,6 +27,6 @@ export function toNumber(str: string): number {
} }
} }
export function trackBy() { export function trackBy<T extends ITrackable>() {
return <T extends ITrackable>(index: number, item: T): string => item.id; return (index: number, item: T): string => item.id;
} }