Improve filter query display performance

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/3/head
trivernis 3 years ago
parent 96c44d1fbc
commit 83f820e8ea
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -11,7 +11,8 @@
"projectType": "application", "projectType": "application",
"schematics": { "schematics": {
"@schematics/angular:component": { "@schematics/angular:component": {
"style": "scss" "style": "scss",
"changeDetection": "OnPush"
}, },
"@schematics/angular:application": { "@schematics/angular:application": {
"strict": true "strict": true

@ -40,7 +40,7 @@ checksum = "84450d0b4a8bd1ba4144ce8ce718fbc5d071358b1e5384bace6536b3d1f2d5b3"
[[package]] [[package]]
name = "app" name = "app"
version = "0.12.0" version = "0.13.0"
dependencies = [ dependencies = [
"mediarepo-api", "mediarepo-api",
"serde", "serde",

@ -14,6 +14,7 @@ import {MetadataEntryComponent} from "./metadata-entry/metadata-entry.component"
import {BusyDialogComponent} from "./busy-dialog/busy-dialog.component"; import {BusyDialogComponent} from "./busy-dialog/busy-dialog.component";
import {SelectableComponent} from "./selectable/selectable.component"; import {SelectableComponent} from "./selectable/selectable.component";
import {MatProgressBarModule} from "@angular/material/progress-bar"; import {MatProgressBarModule} from "@angular/material/progress-bar";
import {HasPropertyPipe} from "./pipes/has-property.pipe";
@NgModule({ @NgModule({
@ -26,6 +27,7 @@ import {MatProgressBarModule} from "@angular/material/progress-bar";
MetadataEntryComponent, MetadataEntryComponent,
BusyDialogComponent, BusyDialogComponent,
SelectableComponent, SelectableComponent,
HasPropertyPipe,
], ],
exports: [ exports: [
ConfirmDialogComponent, ConfirmDialogComponent,
@ -35,6 +37,7 @@ import {MatProgressBarModule} from "@angular/material/progress-bar";
InputReceiverDirective, InputReceiverDirective,
MetadataEntryComponent, MetadataEntryComponent,
SelectableComponent, SelectableComponent,
HasPropertyPipe,
], ],
imports: [ imports: [
CommonModule, CommonModule,

@ -0,0 +1,8 @@
import { HasPropertyPipe } from './has-property.pipe';
describe('HasPropertyPipe', () => {
it('create an instance', () => {
const pipe = new HasPropertyPipe();
expect(pipe).toBeTruthy();
});
});

@ -0,0 +1,11 @@
import {Pipe, PipeTransform} from "@angular/core";
@Pipe({
name: "hasProperty"
})
export class HasPropertyPipe implements PipeTransform {
transform(value: any, propertyName: string): unknown {
return propertyName in value;
}
}

@ -7,10 +7,10 @@
<app-selectable #componentSelectable <app-selectable #componentSelectable
(appSelect)="this.entrySelect.emit(entry)" (appSelect)="this.entrySelect.emit(entry)"
(appUnselect)="this.entryUnselect.emit(entry)"> (appUnselect)="this.entryUnselect.emit(entry)">
<app-property-query-item *ngIf="this.queryIs(entry[1], 'Property')" <app-property-query-item *ngIf="entry[1] | hasProperty: 'Property'"
[propertyQuery]="this.propertyQuery(entry[1]).Property"></app-property-query-item> [propertyQuery]="entry[1] | getPropertyQuery"></app-property-query-item>
<app-tag-query-item *ngIf="this.queryIs(entry[1], 'Tag')" <app-tag-query-item *ngIf="entry[1] | hasProperty: 'Tag'"
[tagQuery]="this.tagQuery(entry[1]).Tag"></app-tag-query-item> [tagQuery]="entry[1] | getTagQuery"></app-tag-query-item>
</app-selectable> </app-selectable>
</mat-list-item> </mat-list-item>
</mat-list> </mat-list>
@ -19,9 +19,9 @@
<app-selectable #singleSelectable <app-selectable #singleSelectable
(appSelect)="this.appSelect.emit(this.query)" (appSelect)="this.appSelect.emit(this.query)"
(appUnselect)="this.appUnselect.emit(this.query)"> (appUnselect)="this.appUnselect.emit(this.query)">
<app-property-query-item *ngIf="this.queryIs(this.query, 'Property')" <app-property-query-item *ngIf="this.query | hasProperty: 'Property'"
[propertyQuery]="this.propertyQuery(this.query).Property"></app-property-query-item> [propertyQuery]="this.query | getPropertyQuery"></app-property-query-item>
<app-tag-query-item *ngIf="this.queryIs(this.query, 'Tag')" <app-tag-query-item *ngIf="this.query | hasProperty: 'Tag'"
[tagQuery]="this.tagQuery(this.query).Tag"></app-tag-query-item> [tagQuery]="this.query | getTagQuery"></app-tag-query-item>
</app-selectable> </app-selectable>
</span> </span>

@ -1,16 +1,12 @@
import {Component, EventEmitter, Input, OnChanges, Output, SimpleChanges} from "@angular/core"; import {ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Output, SimpleChanges} from "@angular/core";
import { import {FilterExpression, FilterQuery} from "../../../../../../../api/api-types/files";
FilterExpression,
FilterQuery,
FilterQueryProperty,
FilterQueryTag
} from "../../../../../../../api/api-types/files";
import {enumerate} from "../../../../../../utils/list-utils"; import {enumerate} from "../../../../../../utils/list-utils";
@Component({ @Component({
selector: "app-filter-expression-list-item", selector: "app-filter-expression-list-item",
templateUrl: "./filter-expression-list-item.component.html", templateUrl: "./filter-expression-list-item.component.html",
styleUrls: ["./filter-expression-list-item.component.scss"] styleUrls: ["./filter-expression-list-item.component.scss"],
changeDetection: ChangeDetectionStrategy.OnPush,
}) })
export class FilterExpressionListItemComponent implements OnChanges { export class FilterExpressionListItemComponent implements OnChanges {
@ -35,18 +31,6 @@ export class FilterExpressionListItemComponent implements OnChanges {
} }
} }
public queryIs(query: FilterQuery, key: "Property" | "Tag"): boolean {
return key in query;
}
public propertyQuery(query: FilterQuery): FilterQueryProperty {
return query as FilterQueryProperty;
}
public tagQuery(query: FilterQuery): FilterQueryTag {
return query as FilterQueryTag;
}
private parseFilter() { private parseFilter() {
if (this.filter && "OrExpression" in this.filter) { if (this.filter && "OrExpression" in this.filter) {
this.orExpression = enumerate(this.filter.OrExpression); this.orExpression = enumerate(this.filter.OrExpression);

@ -1,15 +1,15 @@
<span *ngIf="is('OrExpression')" class="or-expression"> <span *ngIf="this.orExpression" class="or-expression">
<ng-container *ngFor="let query of this.orExpression().OrExpression"> <ng-container *ngFor="let query of this.orExpression">
<app-property-query-item *ngIf="this.queryIs(query, 'Property')" <app-property-query-item *ngIf="query | hasProperty: 'Property'"
[propertyQuery]="this.propertyQuery(query).Property"></app-property-query-item> [propertyQuery]="query | getPropertyQuery"></app-property-query-item>
<app-tag-query-item *ngIf="this.queryIs(query, 'Tag')" <app-tag-query-item *ngIf="query | hasProperty: 'Tag'"
[tagQuery]="this.tagQuery(query).Tag"></app-tag-query-item> [tagQuery]="query | getTagQuery"></app-tag-query-item>
<span class="or-combinator"> OR </span> <span class="or-combinator"> OR </span>
</ng-container> </ng-container>
</span> </span>
<span *ngIf="is('Query')" class="query"> <span *ngIf="this.query" class="query">
<app-property-query-item *ngIf="this.queryIs(this.query().Query, 'Property')" <app-property-query-item *ngIf="this.query | hasProperty: 'Property'"
[propertyQuery]="this.propertyQuery(this.query().Query).Property"></app-property-query-item> [propertyQuery]="this.query | getPropertyQuery"></app-property-query-item>
<app-tag-query-item *ngIf="this.queryIs(this.query().Query, 'Tag')" <app-tag-query-item *ngIf="this.query | hasProperty: 'Tag'"
[tagQuery]="this.tagQuery(this.query().Query).Tag"></app-tag-query-item> [tagQuery]="this.query | getTagQuery"></app-tag-query-item>
</span> </span>

@ -1,47 +1,35 @@
import {Component, Input} from "@angular/core"; import {ChangeDetectionStrategy, Component, Input, OnChanges, OnInit, SimpleChanges} from "@angular/core";
import { import {FilterExpression, FilterQuery} from "../../../../../../api/api-types/files";
FilterExpression,
FilterExpressionOrExpression,
FilterExpressionQuery,
FilterQuery,
FilterQueryProperty,
FilterQueryTag
} from "../../../../../../api/api-types/files";
@Component({ @Component({
selector: "app-filter-expression-item", selector: "app-filter-expression-item",
templateUrl: "./filter-expression-item.component.html", templateUrl: "./filter-expression-item.component.html",
styleUrls: ["./filter-expression-item.component.scss"] styleUrls: ["./filter-expression-item.component.scss"],
changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class FilterExpressionItemComponent { export class FilterExpressionItemComponent implements OnInit, OnChanges {
@Input() filter!: FilterExpression; @Input() filter!: FilterExpression;
public orExpression?: FilterQuery[];
public query?: FilterQuery;
constructor() { constructor() {
} }
public is(key: "OrExpression" | "Query"): boolean { public ngOnInit(): void {
return key in this.filter; this.parseQuery();
}
public orExpression(): FilterExpressionOrExpression {
return this.filter as FilterExpressionOrExpression;
}
public query(): FilterExpressionQuery {
return this.filter as FilterExpressionQuery;
}
public queryIs(query: FilterQuery, key: "Property" | "Tag"): boolean {
return key in query;
} }
public propertyQuery(query: FilterQuery): FilterQueryProperty { public ngOnChanges(changes: SimpleChanges): void {
return query as FilterQueryProperty; if (changes["filter"]) {
this.parseQuery();
}
} }
public tagQuery(query: FilterQuery): FilterQueryTag { private parseQuery() {
return query as FilterQueryTag; if ("Query" in this.filter) {
this.query = this.filter.Query;
} else {
this.orExpression = this.filter.OrExpression;
}
} }
} }

@ -0,0 +1,8 @@
import { GetPropertyQueryPipe } from './get-property-query.pipe';
describe('GetPropertyQueryPipe', () => {
it('create an instance', () => {
const pipe = new GetPropertyQueryPipe();
expect(pipe).toBeTruthy();
});
});

@ -0,0 +1,13 @@
import {Pipe, PipeTransform} from "@angular/core";
import {FilterQuery, FilterQueryProperty, PropertyQuery} from "../../../../../../api/api-types/files";
@Pipe({
name: "getPropertyQuery"
})
export class GetPropertyQueryPipe implements PipeTransform {
transform(value: FilterQuery): PropertyQuery {
return (value as FilterQueryProperty).Property;
}
}

@ -0,0 +1,8 @@
import { GetTagQueryPipe } from './get-tag-query.pipe';
describe('GetTagQueryPipe', () => {
it('create an instance', () => {
const pipe = new GetTagQueryPipe();
expect(pipe).toBeTruthy();
});
});

@ -0,0 +1,12 @@
import {Pipe, PipeTransform} from "@angular/core";
import {FilterQuery, FilterQueryTag, TagQuery} from "../../../../../../api/api-types/files";
@Pipe({
name: "getTagQuery"
})
export class GetTagQueryPipe implements PipeTransform {
transform(value: FilterQuery): TagQuery {
return (value as FilterQueryTag).Tag;
}
}

@ -46,6 +46,8 @@ import {
import { import {
FilterExpressionListItemComponent FilterExpressionListItemComponent
} from "./file-search/filter-dialog/filter-expression-list-item/filter-expression-list-item.component"; } from "./file-search/filter-dialog/filter-expression-list-item/filter-expression-list-item.component";
import { GetTagQueryPipe } from './file-search/filter-pipes/get-tag-query.pipe';
import { GetPropertyQueryPipe } from './file-search/filter-pipes/get-property-query.pipe';
@NgModule({ @NgModule({
@ -62,6 +64,8 @@ import {
TagQueryItemComponent, TagQueryItemComponent,
PropertyQueryItemComponent, PropertyQueryItemComponent,
FilterExpressionListItemComponent, FilterExpressionListItemComponent,
GetTagQueryPipe,
GetPropertyQueryPipe,
], ],
exports: [ exports: [
TagEditComponent, TagEditComponent,

Loading…
Cancel
Save