1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

replacing mergeMap to switchMap in filter and sorting #287

This commit is contained in:
Patrik J. Braun 2022-02-18 22:56:14 +01:00
parent fda3168486
commit 44e7445e0f
4 changed files with 83 additions and 82 deletions

View File

@ -2,7 +2,7 @@ import {Injectable} from '@angular/core';
import {BehaviorSubject, Observable} from 'rxjs';
import {PhotoDTO} from '../../../../../common/entities/PhotoDTO';
import {DirectoryContent} from '../content.service';
import {map, mergeMap} from 'rxjs/operators';
import {map, switchMap} from 'rxjs/operators';
export enum FilterRenderType {
enum = 1, range = 2
@ -90,18 +90,21 @@ export class FilterService {
}
public applyFilters(directoryContent: Observable<DirectoryContent>): Observable<DirectoryContent> {
return directoryContent.pipe(mergeMap((dirContent: DirectoryContent) => {
return directoryContent.pipe(switchMap((dirContent: DirectoryContent) => {
return this.selectedFilters.pipe(map((filters: SelectedFilter[]) => {
if (!dirContent || !dirContent.media || !this.filtersVisible) {
return dirContent;
}
// clone, so the original won't get overwritten
const c = {
media: dirContent.media,
directories: dirContent.directories,
metaFile: dirContent.metaFile
};
for (const f of filters) {
// get options

View File

@ -1,29 +1,29 @@
<nav class="nav-container" aria-label="breadcrumb">
<ol *ngIf="isDirectory | async" id="directory-path" class="breadcrumb">
<li *ngFor="let path of Routes | async" class="breadcrumb-item">
<ol *ngIf="isDirectory" id="directory-path" class="breadcrumb">
<li *ngFor="let path of Routes" class="breadcrumb-item">
<a *ngIf="path.route" [routerLink]="['/gallery',path.route]"
[queryParams]="queryService.getParams()">{{path.name}}</a>
<ng-container *ngIf="!path.route">{{path.name}}</ng-container>
</li>
</ol>
<ol *ngIf="!(isDirectory | async)" class="breadcrumb">
<ol *ngIf="!isDirectory" class="breadcrumb">
<li class="active">
<ng-container i18n>Searching for:</ng-container>
<strong> {{(wrappedContent | async)?.searchResult?.searchQuery | searchQuery}}</strong>
<strong> {{galleryService.content.value?.searchResult?.searchQuery | searchQuery}}</strong>
</li>
</ol>
<div class="right-side">
<ng-container *ngIf="(ItemCount | async) > 0 && config.Client.Other.NavBar.showItemCount">
<ng-container *ngIf="ItemCount> 0 && config.Client.Other.NavBar.showItemCount">
<div class="photos-count">
{{ItemCount | async}} <span i18n>items</span>
{{ItemCount}} <span i18n>items</span>
</div>
<div class="divider">&nbsp;</div>
</ng-container>
<ng-container *ngIf="config.Client.Other.enableDownloadZip && (isDirectory | async) && (ItemCount | async) > 0">
<a [href]="getDownloadZipLink() | async"
<ng-container *ngIf="config.Client.Other.enableDownloadZip && isDirectory && ItemCount > 0">
<a [href]="getDownloadZipLink()"
class="btn btn-navbar">
<span class="oi oi-data-transfer-download"
title="download" i18n-title></span>
@ -31,9 +31,9 @@
<div class="divider">&nbsp;</div>
</ng-container>
<ng-container *ngIf="config.Client.Other.enableDirectoryFlattening && (isDirectory | async)">
<ng-container *ngIf="config.Client.Other.enableDirectoryFlattening && isDirectory">
<a
[routerLink]="['/search', getDirectoryFlattenSearchQuery() | async]"
[routerLink]="['/search', getDirectoryFlattenSearchQuery()]"
class="btn btn-navbar">
<span class="oi oi-fork"
title="Flatten directory" i18n-title></span>
@ -50,7 +50,7 @@
<div class="btn-group" dropdown placement="bottom right">
<button id="button-alignment" dropdownToggle type="button"
class="btn btn-secondary dropdown-toggle"
[ngClass]="{'btn-secondary':sortingService.sorting.value !== (DefaultSorting | async)}"
[ngClass]="{'btn-secondary':sortingService.sorting.value !== DefaultSorting}"
aria-controls="dropdown-alignment"
[innerHTML]="sortingService.sorting.value | iconizeSorting">
</button>

View File

@ -40,16 +40,18 @@ export class GalleryNavigatorComponent {
this.directoryContent = this.wrappedContent.pipe(map(c => c.directory ? c.directory : c.searchResult));
}
get isDirectory(): Observable<boolean> {
return this.wrappedContent.pipe(map(c => !!c.directory));
get isDirectory(): boolean {
return !!this.galleryService.content.value.directory;
}
get ItemCount(): Observable<number> {
return this.wrappedContent.pipe(map(c => c.directory ? c.directory.mediaCount : (c.searchResult ? c.searchResult.media.length : 0)));
get ItemCount(): number {
const c = this.galleryService.content.value;
return c.directory ? c.directory.mediaCount : (c.searchResult ? c.searchResult.media.length : 0);
}
get Routes(): Observable<NavigatorPath[]> {
return this.wrappedContent.pipe(map((c) => {
get Routes(): NavigatorPath[] {
const c = this.galleryService.content.value;
if (!c.directory) {
return [];
}
@ -88,21 +90,19 @@ export class GalleryNavigatorComponent {
});
return arr;
}));
}
get DefaultSorting(): Observable<SortingMethods> {
return this.wrappedContent.pipe(map(c =>
this.sortingService.getDefaultSorting(c.directory)
));
get DefaultSorting(): SortingMethods {
return this.sortingService.getDefaultSorting(this.galleryService.content.value.directory);
}
setSorting(sorting: SortingMethods): void {
this.sortingService.setSorting(sorting);
}
getDownloadZipLink(): Observable<string> {
return this.wrappedContent.pipe(map((c) => {
getDownloadZipLink(): string {
const c = this.galleryService.content.value;
if (!c.directory) {
return null;
}
@ -113,12 +113,10 @@ export class GalleryNavigatorComponent {
return Utils.concatUrls(Config.Client.urlBase,
'/api/gallery/zip/',
c.directory.path, c.directory.name, '?' + queryParams);
}));
}
getDirectoryFlattenSearchQuery(): Observable<string> {
return this.wrappedContent.pipe(map((c) => {
getDirectoryFlattenSearchQuery(): string {
const c = this.galleryService.content.value;
if (!c.directory) {
return null;
}
@ -127,7 +125,7 @@ export class GalleryNavigatorComponent {
matchType: TextSearchQueryMatchTypes.like,
text: Utils.concatUrls('./', c.directory.path, c.directory.name)
} as TextSearch);
}));
}
}

View File

@ -6,9 +6,9 @@ import {BehaviorSubject, Observable} from 'rxjs';
import {Config} from '../../../../../common/config/public/Config';
import {SortingMethods} from '../../../../../common/entities/SortingMethods';
import {PG2ConfMap} from '../../../../../common/PG2ConfMap';
import {DirectoryContent, ContentService} from '../content.service';
import {ContentService, DirectoryContent} from '../content.service';
import {PhotoDTO} from '../../../../../common/entities/PhotoDTO';
import {map, mergeMap} from 'rxjs/operators';
import {map, switchMap} from 'rxjs/operators';
import {SeededRandomService} from '../../../model/seededRandom.service';
@ -57,7 +57,7 @@ export class GallerySortingService {
}
public applySorting(directoryContent: Observable<DirectoryContent>): Observable<DirectoryContent> {
return directoryContent.pipe(mergeMap((dirContent) => {
return directoryContent.pipe(switchMap((dirContent) => {
return this.sorting.pipe(map((sorting: SortingMethods) => {
if (!dirContent) {
return dirContent;