From e99822cf2855a907b34d093664e077afabc4671d Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Fri, 13 Jun 2025 16:47:47 -0500 Subject: [PATCH] Removed some methods that aren't needed anymore. --- .../all-series/all-series.component.ts | 4 +- .../bookmarks/bookmarks.component.ts | 4 +- .../collection-detail.component.ts | 4 +- .../_components/dashboard.component.ts | 8 +- .../library-detail.component.ts | 2 +- .../nav-header/nav-header.component.ts | 5 +- .../person-detail/person-detail.component.ts | 6 +- .../_services/filter-utilities.service.ts | 78 ++++++++----------- .../want-to-read/want-to-read.component.ts | 2 +- 9 files changed, 54 insertions(+), 59 deletions(-) diff --git a/UI/Web/src/app/all-series/_components/all-series/all-series.component.ts b/UI/Web/src/app/all-series/_components/all-series/all-series.component.ts index 979781878..d4b2b451d 100644 --- a/UI/Web/src/app/all-series/_components/all-series/all-series.component.ts +++ b/UI/Web/src/app/all-series/_components/all-series/all-series.component.ts @@ -169,8 +169,8 @@ export class AllSeriesComponent implements OnInit { } - this.filterActiveCheck = this.filterUtilityService.createSeriesV2Filter(); - this.filterActiveCheck!.statements.push(this.filterUtilityService.createSeriesV2DefaultStatement()); + this.filterActiveCheck = this.metadataService.createDefaultFilterDto('series'); + this.filterActiveCheck.statements.push(this.metadataService.createDefaultFilterStatement('series') as FilterStatement); this.filterSettings.presetsV2 = this.filter; this.cdRef.markForCheck(); diff --git a/UI/Web/src/app/bookmark/_components/bookmarks/bookmarks.component.ts b/UI/Web/src/app/bookmark/_components/bookmarks/bookmarks.component.ts index 985515bb6..200766135 100644 --- a/UI/Web/src/app/bookmark/_components/bookmarks/bookmarks.component.ts +++ b/UI/Web/src/app/bookmark/_components/bookmarks/bookmarks.component.ts @@ -96,8 +96,8 @@ export class BookmarksComponent implements OnInit { this.filter.statements.push(this.metadataService.createDefaultFilterStatement('series') as FilterStatement); } - this.filterActiveCheck = this.filterUtilityService.createSeriesV2Filter(); - this.filterActiveCheck!.statements.push(this.filterUtilityService.createSeriesV2DefaultStatement()); + this.filterActiveCheck = this.metadataService.createDefaultFilterDto('series'); + this.filterActiveCheck.statements.push(this.metadataService.createDefaultFilterStatement('series') as FilterStatement); this.filterSettings.presetsV2 = this.filter; this.filterSettings.statementLimit = 1; diff --git a/UI/Web/src/app/collections/_components/collection-detail/collection-detail.component.ts b/UI/Web/src/app/collections/_components/collection-detail/collection-detail.component.ts index 214806b5c..8cc6b4c26 100644 --- a/UI/Web/src/app/collections/_components/collection-detail/collection-detail.component.ts +++ b/UI/Web/src/app/collections/_components/collection-detail/collection-detail.component.ts @@ -193,7 +193,7 @@ export class CollectionDetailComponent implements OnInit, AfterContentChecked { this.route.data.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(data => { this.filter = data['filter'] as FilterV2; - + const defaultStmt = {field: FilterField.CollectionTags, value: tagId + '', comparison: FilterComparison.Equal}; if (this.filter == null) { @@ -205,7 +205,7 @@ export class CollectionDetailComponent implements OnInit, AfterContentChecked { this.filter!.statements.push(defaultStmt); } - this.filterActiveCheck = this.filterUtilityService.createSeriesV2Filter(); + this.filterActiveCheck = this.metadataService.createDefaultFilterDto('series'); this.filterActiveCheck!.statements.push(defaultStmt); this.filterSettings.presetsV2 = this.filter; diff --git a/UI/Web/src/app/dashboard/_components/dashboard.component.ts b/UI/Web/src/app/dashboard/_components/dashboard.component.ts index 73fd10e89..12f763313 100644 --- a/UI/Web/src/app/dashboard/_components/dashboard.component.ts +++ b/UI/Web/src/app/dashboard/_components/dashboard.component.ts @@ -219,7 +219,7 @@ export class DashboardComponent implements OnInit { const params: any = {}; params['page'] = 1; params['title'] = translate('dashboard.recently-updated-title'); - const filter = this.filterUtilityService.createSeriesV2Filter(); + const filter = this.metadataService.createDefaultFilterDto('series'); if (filter.sortOptions) { filter.sortOptions.sortField = SortField.LastChapterAdded; filter.sortOptions.isAscending = false; @@ -230,7 +230,7 @@ export class DashboardComponent implements OnInit { params['page'] = 1; params['title'] = translate('dashboard.on-deck-title'); - const filter = this.filterUtilityService.createSeriesV2Filter(); + const filter = this.metadataService.createDefaultFilterDto('series'); filter.statements.push({field: FilterField.ReadProgress, comparison: FilterComparison.GreaterThan, value: '0'}); filter.statements.push({field: FilterField.ReadProgress, comparison: FilterComparison.NotEqual, value: '100'}); if (filter.sortOptions) { @@ -242,7 +242,7 @@ export class DashboardComponent implements OnInit { const params: any = {}; params['page'] = 1; params['title'] = translate('dashboard.recently-added-title'); - const filter = this.filterUtilityService.createSeriesV2Filter(); + const filter = this.metadataService.createDefaultFilterDto('series'); if (filter.sortOptions) { filter.sortOptions.sortField = SortField.Created; filter.sortOptions.isAscending = false; @@ -252,7 +252,7 @@ export class DashboardComponent implements OnInit { const params: any = {}; params['page'] = 1; params['title'] = translate('dashboard.more-in-genre-title', {genre: this.genre?.title}); - const filter = this.filterUtilityService.createSeriesV2Filter(); + const filter = this.metadataService.createDefaultFilterDto('series'); filter.statements.push({field: FilterField.Genres, value: this.genre?.id + '', comparison: FilterComparison.MustContains}); this.filterUtilityService.applyFilterWithParams(['all-series'], filter, params).subscribe(); } diff --git a/UI/Web/src/app/library-detail/library-detail.component.ts b/UI/Web/src/app/library-detail/library-detail.component.ts index 68dcfcd34..365d5455c 100644 --- a/UI/Web/src/app/library-detail/library-detail.component.ts +++ b/UI/Web/src/app/library-detail/library-detail.component.ts @@ -197,7 +197,7 @@ export class LibraryDetailComponent implements OnInit { } - this.filterActiveCheck = this.filterUtilityService.createSeriesV2Filter(); + this.filterActiveCheck = this.metadataService.createDefaultFilterDto('series'); this.filterActiveCheck!.statements.push(defaultStmt); this.filterSettings.presetsV2 = this.filter; diff --git a/UI/Web/src/app/nav/_components/nav-header/nav-header.component.ts b/UI/Web/src/app/nav/_components/nav-header/nav-header.component.ts index 27bfefd85..fd4af01f0 100644 --- a/UI/Web/src/app/nav/_components/nav-header/nav-header.component.ts +++ b/UI/Web/src/app/nav/_components/nav-header/nav-header.component.ts @@ -47,6 +47,7 @@ import {SettingsTabId} from "../../../sidenav/preference-nav/preference-nav.comp import {Breakpoint, UtilityService} from "../../../shared/_services/utility.service"; import {WikiLink} from "../../../_models/wiki"; import {NavLinkModalComponent} from "../nav-link-modal/nav-link-modal.component"; +import {MetadataService} from "../../../_services/metadata.service"; @Component({ selector: 'app-nav-header', @@ -70,6 +71,8 @@ export class NavHeaderComponent implements OnInit { protected readonly imageService = inject(ImageService); protected readonly utilityService = inject(UtilityService); protected readonly modalService = inject(NgbModal); + protected readonly metadataService = inject(MetadataService); + protected readonly FilterField = FilterField; protected readonly WikiLink = WikiLink; @@ -161,7 +164,7 @@ export class NavHeaderComponent implements OnInit { goTo(statement: FilterStatement) { let params: any = {}; - const filter = this.filterUtilityService.createSeriesV2Filter(); + const filter = this.metadataService.createDefaultFilterDto('series'); filter.statements = [statement]; params['page'] = 1; this.clearSearch(); diff --git a/UI/Web/src/app/person-detail/person-detail.component.ts b/UI/Web/src/app/person-detail/person-detail.component.ts index 524be9de4..ab3c486bd 100644 --- a/UI/Web/src/app/person-detail/person-detail.component.ts +++ b/UI/Web/src/app/person-detail/person-detail.component.ts @@ -44,6 +44,7 @@ import {SafeUrlPipe} from "../_pipes/safe-url.pipe"; import {MergePersonModalComponent} from "./_modal/merge-person-modal/merge-person-modal.component"; import {EVENTS, MessageHubService} from "../_services/message-hub.service"; import {BadgeExpanderComponent} from "../shared/badge-expander/badge-expander.component"; +import {MetadataService} from "../_services/metadata.service"; interface PersonMergeEvent { srcId: number, @@ -87,6 +88,7 @@ export class PersonDetailComponent implements OnInit { private readonly themeService = inject(ThemeService); private readonly toastr = inject(ToastrService); private readonly messageHubService = inject(MessageHubService) + private readonly metadataService = inject(MetadataService) protected readonly FilterField = FilterField; @@ -181,7 +183,7 @@ export class PersonDetailComponent implements OnInit { } createFilter(roles: PersonRole[]) { - const filter = this.filterUtilityService.createSeriesV2Filter(); + const filter = this.metadataService.createDefaultFilterDto('series'); filter.combination = FilterCombination.Or; filter.limitTo = 20; @@ -217,7 +219,7 @@ export class PersonDetailComponent implements OnInit { params['page'] = 1; params['title'] = translate('person-detail.browse-person-by-role-title', {name: this.person!.name, role: personPipe.transform(role)}); - const searchFilter = this.filterUtilityService.createSeriesV2Filter(); + const searchFilter = this.metadataService.createDefaultFilterDto('series'); searchFilter.limitTo = 0; searchFilter.combination = FilterCombination.Or; diff --git a/UI/Web/src/app/shared/_services/filter-utilities.service.ts b/UI/Web/src/app/shared/_services/filter-utilities.service.ts index d5ca3a211..559a70ab1 100644 --- a/UI/Web/src/app/shared/_services/filter-utilities.service.ts +++ b/UI/Web/src/app/shared/_services/filter-utilities.service.ts @@ -1,9 +1,8 @@ import {inject, Injectable} from '@angular/core'; -import {ActivatedRouteSnapshot, Params, Router} from '@angular/router'; +import {Params, Router} from '@angular/router'; import {allSeriesSortFields, SortField} from 'src/app/_models/metadata/series-filter'; import {MetadataService} from "../../_services/metadata.service"; import {FilterV2} from "../../_models/metadata/v2/filter-v2"; -import {FilterStatement} from "../../_models/metadata/v2/filter-statement"; import {FilterCombination} from "../../_models/metadata/v2/filter-combination"; import {allSeriesFilterFields, FilterField} from "../../_models/metadata/v2/filter-field"; import {FilterComparison} from "../../_models/metadata/v2/filter-comparison"; @@ -11,7 +10,7 @@ import {HttpClient} from "@angular/common/http"; import {TextResonse} from "../../_types/text-response"; import {environment} from "../../../environments/environment"; import {map, tap} from "rxjs/operators"; -import {Observable, of, switchMap} from "rxjs"; +import {switchMap} from "rxjs"; import {allPersonFilterFields, PersonFilterField} from "../../_models/metadata/v2/person-filter-field"; import {allPersonSortFields} from "../../_models/metadata/v2/person-sort-field"; import { @@ -40,44 +39,40 @@ export class FilterUtilitiesService { private readonly apiUrl = environment.apiUrl; - encodeFilter(filter: FilterV2 | undefined) { + encodeFilter(filter: FilterV2 | undefined) { return this.http.post(this.apiUrl + 'filter/encode', filter, TextResonse); } decodeFilter(encodedFilter: string) { - return this.http.post>(this.apiUrl + 'filter/decode', {encodedFilter}).pipe(map(filter => { + return this.http.post(this.apiUrl + 'filter/decode', {encodedFilter}).pipe(map(filter => { if (filter == null) { filter = this.metadataService.createDefaultFilterDto('series'); - filter.statements.push(this.createSeriesV2DefaultStatement()); + filter.statements.push(this.metadataService.createDefaultFilterStatement('series')); } return filter; })) } - updateUrlFromFilter(filter: FilterV2 | undefined) { + /** + * Encodes the filter and patches into the url + * @param filter + */ + updateUrlFromFilter(filter: FilterV2 | undefined) { return this.encodeFilter(filter).pipe(tap(encodedFilter => { window.history.replaceState(window.location.href, '', window.location.href.split('?')[0]+ '?' + encodedFilter); })); } - filterPresetsFromUrl(snapshot: ActivatedRouteSnapshot, entityType: ValidFilterEntity, defaultStatement: FilterStatement | null = null): Observable> { - const filter = this.metadataService.createDefaultFilterDto(entityType); - filter.statements.push(defaultStatement ?? this.createSeriesV2DefaultStatement()); - if (!window.location.href.includes('?')) return of(filter); - - return this.decodeFilter(window.location.href.split('?')[1]); - } - /** - * Applies and redirects to the passed page with the filter encoded + * Applies and redirects to the passed page with the filter encoded (Series only) * @param page * @param filter * @param comparison * @param value */ applyFilter(page: Array, filter: FilterField, comparison: FilterComparison, value: string) { - const dto = this.createSeriesV2Filter(); + const dto = this.metadataService.createDefaultFilterDto('series'); dto.statements.push(this.metadataService.createFilterStatement(filter, comparison, value + '')); return this.encodeFilter(dto).pipe(switchMap(encodedFilter => { @@ -85,6 +80,12 @@ export class FilterUtilitiesService { })); } + /** + * (Series only) + * @param page + * @param filter + * @param extraParams + */ applyFilterWithParams(page: Array, filter: FilterV2, extraParams: Params) { return this.encodeFilter(filter).pipe(switchMap(encodedFilter => { let url = page.join('/') + '?' + encodedFilter; @@ -94,25 +95,6 @@ export class FilterUtilitiesService { })); } - createSeriesV2Filter(): FilterV2 { - return { - combination: FilterCombination.And, - statements: [], - limitTo: 0, - sortOptions: { - isAscending: true, - sortField: SortField.SortName - }, - }; - } - - createSeriesV2DefaultStatement(): FilterStatement { - return { - comparison: FilterComparison.Equal, - value: '', - field: FilterField.SeriesName - } - } createPersonV2Filter(): FilterV2 { return { @@ -126,14 +108,10 @@ export class FilterUtilitiesService { }; } - createPersonV2DefaultStatement(): FilterStatement { - return { - comparison: FilterComparison.Equal, - value: '', - field: PersonFilterField.Name - } - } - + /** + * Returns the Sort Fields for the Metadata filter based on the entity. + * @param type + */ getSortFields(type: ValidFilterEntity) { switch (type) { case 'series': @@ -149,6 +127,10 @@ export class FilterUtilitiesService { } } + /** + * Returns the Filter Fields for the Metadata filter based on the entity. + * @param type + */ getFilterFields(type: ValidFilterEntity): {title: string, value: T}[] { switch (type) { case 'series': @@ -164,6 +146,10 @@ export class FilterUtilitiesService { } } + /** + * Returns the default field for the Series or Person entity aka what should be there if there are no statements + * @param type + */ getDefaultFilterField(type: ValidFilterEntity) { switch (type) { case 'series': @@ -196,6 +182,10 @@ export class FilterUtilitiesService { } } + /** + * Returns the applicable String fields + * @param type + */ getStringFields(type: ValidFilterEntity) { switch (type) { case 'series': diff --git a/UI/Web/src/app/want-to-read/_components/want-to-read/want-to-read.component.ts b/UI/Web/src/app/want-to-read/_components/want-to-read/want-to-read.component.ts index 3ffbd7a7d..c7d940b7a 100644 --- a/UI/Web/src/app/want-to-read/_components/want-to-read/want-to-read.component.ts +++ b/UI/Web/src/app/want-to-read/_components/want-to-read/want-to-read.component.ts @@ -124,7 +124,7 @@ export class WantToReadComponent implements OnInit, AfterContentChecked { } - this.filterActiveCheck = this.filterUtilityService.createSeriesV2Filter(); + this.filterActiveCheck = this.metadataService.createDefaultFilterDto('series'); this.filterActiveCheck!.statements.push(defaultStmt); this.filterSettings.presetsV2 = this.filter;