diff --git a/mediarepo-ui/angular.json b/mediarepo-ui/angular.json index 7f6b32a..bb6c9a2 100644 --- a/mediarepo-ui/angular.json +++ b/mediarepo-ui/angular.json @@ -11,7 +11,8 @@ "projectType": "application", "schematics": { "@schematics/angular:component": { - "style": "scss" + "style": "scss", + "changeDetection": "OnPush" }, "@schematics/angular:application": { "strict": true diff --git a/mediarepo-ui/src-tauri/Cargo.lock b/mediarepo-ui/src-tauri/Cargo.lock index 31ff851..98e2cf1 100644 --- a/mediarepo-ui/src-tauri/Cargo.lock +++ b/mediarepo-ui/src-tauri/Cargo.lock @@ -40,7 +40,7 @@ checksum = "84450d0b4a8bd1ba4144ce8ce718fbc5d071358b1e5384bace6536b3d1f2d5b3" [[package]] name = "app" -version = "0.12.0" +version = "0.13.0" dependencies = [ "mediarepo-api", "serde", diff --git a/mediarepo-ui/src/app/components/shared/app-common/app-common.module.ts b/mediarepo-ui/src/app/components/shared/app-common/app-common.module.ts index 822cbe0..abdf5e2 100644 --- a/mediarepo-ui/src/app/components/shared/app-common/app-common.module.ts +++ b/mediarepo-ui/src/app/components/shared/app-common/app-common.module.ts @@ -14,6 +14,7 @@ import {MetadataEntryComponent} from "./metadata-entry/metadata-entry.component" import {BusyDialogComponent} from "./busy-dialog/busy-dialog.component"; import {SelectableComponent} from "./selectable/selectable.component"; import {MatProgressBarModule} from "@angular/material/progress-bar"; +import {HasPropertyPipe} from "./pipes/has-property.pipe"; @NgModule({ @@ -26,6 +27,7 @@ import {MatProgressBarModule} from "@angular/material/progress-bar"; MetadataEntryComponent, BusyDialogComponent, SelectableComponent, + HasPropertyPipe, ], exports: [ ConfirmDialogComponent, @@ -35,6 +37,7 @@ import {MatProgressBarModule} from "@angular/material/progress-bar"; InputReceiverDirective, MetadataEntryComponent, SelectableComponent, + HasPropertyPipe, ], imports: [ CommonModule, diff --git a/mediarepo-ui/src/app/components/shared/app-common/pipes/has-property.pipe.spec.ts b/mediarepo-ui/src/app/components/shared/app-common/pipes/has-property.pipe.spec.ts new file mode 100644 index 0000000..4107bcc --- /dev/null +++ b/mediarepo-ui/src/app/components/shared/app-common/pipes/has-property.pipe.spec.ts @@ -0,0 +1,8 @@ +import { HasPropertyPipe } from './has-property.pipe'; + +describe('HasPropertyPipe', () => { + it('create an instance', () => { + const pipe = new HasPropertyPipe(); + expect(pipe).toBeTruthy(); + }); +}); diff --git a/mediarepo-ui/src/app/components/shared/app-common/pipes/has-property.pipe.ts b/mediarepo-ui/src/app/components/shared/app-common/pipes/has-property.pipe.ts new file mode 100644 index 0000000..11a4cf3 --- /dev/null +++ b/mediarepo-ui/src/app/components/shared/app-common/pipes/has-property.pipe.ts @@ -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; + } +} diff --git a/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-dialog/filter-expression-list-item/filter-expression-list-item.component.html b/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-dialog/filter-expression-list-item/filter-expression-list-item.component.html index 44c4af4..1f1ae8f 100644 --- a/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-dialog/filter-expression-list-item/filter-expression-list-item.component.html +++ b/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-dialog/filter-expression-list-item/filter-expression-list-item.component.html @@ -7,10 +7,10 @@ - - + + @@ -19,9 +19,9 @@ - - + + diff --git a/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-dialog/filter-expression-list-item/filter-expression-list-item.component.ts b/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-dialog/filter-expression-list-item/filter-expression-list-item.component.ts index e2ea659..1619375 100644 --- a/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-dialog/filter-expression-list-item/filter-expression-list-item.component.ts +++ b/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-dialog/filter-expression-list-item/filter-expression-list-item.component.ts @@ -1,16 +1,12 @@ -import {Component, EventEmitter, Input, OnChanges, Output, SimpleChanges} from "@angular/core"; -import { - FilterExpression, - FilterQuery, - FilterQueryProperty, - FilterQueryTag -} from "../../../../../../../api/api-types/files"; +import {ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Output, SimpleChanges} from "@angular/core"; +import {FilterExpression, FilterQuery} from "../../../../../../../api/api-types/files"; import {enumerate} from "../../../../../../utils/list-utils"; @Component({ selector: "app-filter-expression-list-item", 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 { @@ -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() { if (this.filter && "OrExpression" in this.filter) { this.orExpression = enumerate(this.filter.OrExpression); diff --git a/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-expression-item/filter-expression-item.component.html b/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-expression-item/filter-expression-item.component.html index eb73324..a71228a 100644 --- a/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-expression-item/filter-expression-item.component.html +++ b/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-expression-item/filter-expression-item.component.html @@ -1,15 +1,15 @@ - - - - + + + + OR - - - + + + diff --git a/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-expression-item/filter-expression-item.component.ts b/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-expression-item/filter-expression-item.component.ts index 3356495..51dbbea 100644 --- a/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-expression-item/filter-expression-item.component.ts +++ b/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-expression-item/filter-expression-item.component.ts @@ -1,47 +1,35 @@ -import {Component, Input} from "@angular/core"; -import { - FilterExpression, - FilterExpressionOrExpression, - FilterExpressionQuery, - FilterQuery, - FilterQueryProperty, - FilterQueryTag -} from "../../../../../../api/api-types/files"; +import {ChangeDetectionStrategy, Component, Input, OnChanges, OnInit, SimpleChanges} from "@angular/core"; +import {FilterExpression, FilterQuery} from "../../../../../../api/api-types/files"; @Component({ selector: "app-filter-expression-item", 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; + public orExpression?: FilterQuery[]; + public query?: FilterQuery; constructor() { } - public is(key: "OrExpression" | "Query"): boolean { - return key in this.filter; - } - - 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 ngOnInit(): void { + this.parseQuery(); } - public propertyQuery(query: FilterQuery): FilterQueryProperty { - return query as FilterQueryProperty; + public ngOnChanges(changes: SimpleChanges): void { + if (changes["filter"]) { + this.parseQuery(); + } } - public tagQuery(query: FilterQuery): FilterQueryTag { - return query as FilterQueryTag; + private parseQuery() { + if ("Query" in this.filter) { + this.query = this.filter.Query; + } else { + this.orExpression = this.filter.OrExpression; + } } } diff --git a/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-pipes/get-property-query.pipe.spec.ts b/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-pipes/get-property-query.pipe.spec.ts new file mode 100644 index 0000000..a76d56f --- /dev/null +++ b/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-pipes/get-property-query.pipe.spec.ts @@ -0,0 +1,8 @@ +import { GetPropertyQueryPipe } from './get-property-query.pipe'; + +describe('GetPropertyQueryPipe', () => { + it('create an instance', () => { + const pipe = new GetPropertyQueryPipe(); + expect(pipe).toBeTruthy(); + }); +}); diff --git a/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-pipes/get-property-query.pipe.ts b/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-pipes/get-property-query.pipe.ts new file mode 100644 index 0000000..879c019 --- /dev/null +++ b/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-pipes/get-property-query.pipe.ts @@ -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; + } + +} diff --git a/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-pipes/get-tag-query.pipe.spec.ts b/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-pipes/get-tag-query.pipe.spec.ts new file mode 100644 index 0000000..ba39149 --- /dev/null +++ b/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-pipes/get-tag-query.pipe.spec.ts @@ -0,0 +1,8 @@ +import { GetTagQueryPipe } from './get-tag-query.pipe'; + +describe('GetTagQueryPipe', () => { + it('create an instance', () => { + const pipe = new GetTagQueryPipe(); + expect(pipe).toBeTruthy(); + }); +}); diff --git a/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-pipes/get-tag-query.pipe.ts b/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-pipes/get-tag-query.pipe.ts new file mode 100644 index 0000000..96f518e --- /dev/null +++ b/mediarepo-ui/src/app/components/shared/sidebar/file-search/filter-pipes/get-tag-query.pipe.ts @@ -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; + } +} diff --git a/mediarepo-ui/src/app/components/shared/sidebar/sidebar.module.ts b/mediarepo-ui/src/app/components/shared/sidebar/sidebar.module.ts index 7e8b843..980d6ca 100644 --- a/mediarepo-ui/src/app/components/shared/sidebar/sidebar.module.ts +++ b/mediarepo-ui/src/app/components/shared/sidebar/sidebar.module.ts @@ -46,6 +46,8 @@ import { import { FilterExpressionListItemComponent } 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({ @@ -62,6 +64,8 @@ import { TagQueryItemComponent, PropertyQueryItemComponent, FilterExpressionListItemComponent, + GetTagQueryPipe, + GetPropertyQueryPipe, ], exports: [ TagEditComponent,