optimize show filter
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
<mat-form-field appearance="outline">
|
<mat-form-field appearance="outline">
|
||||||
<mat-label>Ersteller</mat-label>
|
<mat-label>Ersteller</mat-label>
|
||||||
<mat-select formControlName="owner">
|
<mat-select formControlName="owner">
|
||||||
|
<mat-option [value]="null">Alle</mat-option>
|
||||||
<mat-option *ngFor="let owner of owners" [value]="owner.key">{{
|
<mat-option *ngFor="let owner of owners" [value]="owner.key">{{
|
||||||
owner.value
|
owner.value
|
||||||
}}
|
}}
|
||||||
@@ -24,6 +25,7 @@
|
|||||||
<mat-form-field appearance="outline">
|
<mat-form-field appearance="outline">
|
||||||
<mat-label>Art der Veranstaltung</mat-label>
|
<mat-label>Art der Veranstaltung</mat-label>
|
||||||
<mat-select formControlName="showType">
|
<mat-select formControlName="showType">
|
||||||
|
<mat-option [value]="null">Alle</mat-option>
|
||||||
<mat-optgroup label="öffentlich">
|
<mat-optgroup label="öffentlich">
|
||||||
<mat-option *ngFor="let key of showTypePublic" [value]="key">{{
|
<mat-option *ngFor="let key of showTypePublic" [value]="key">{{
|
||||||
key | showType
|
key | showType
|
||||||
@@ -41,5 +43,5 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<i>Anzahl der Suchergebnisse: {{ shows.length }}</i>
|
<i>Anzahl der Suchergebnisse: {{ shows?.length ?? 0 }}</i>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ export class FilterComponent {
|
|||||||
activatedRoute.queryParams.subscribe(params => {
|
activatedRoute.queryParams.subscribe(params => {
|
||||||
const filterValues = params as FilterValues;
|
const filterValues = params as FilterValues;
|
||||||
if (filterValues.time) this.filterFormGroup.controls.time.setValue(+filterValues.time);
|
if (filterValues.time) this.filterFormGroup.controls.time.setValue(+filterValues.time);
|
||||||
|
this.filterFormGroup.controls.owner.setValue(filterValues.owner ?? null, {emitEvent: false});
|
||||||
|
this.filterFormGroup.controls.showType.setValue(filterValues.showType ?? null, {emitEvent: false});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.filterFormGroup.controls.time.valueChanges.subscribe(_ => void this.filerValueChanged('time', _ as number));
|
this.filterFormGroup.controls.time.valueChanges.subscribe(_ => void this.filerValueChanged('time', _ as number));
|
||||||
@@ -87,7 +89,7 @@ export class FilterComponent {
|
|||||||
|
|
||||||
private async filerValueChanged<T>(key: string, value: T): Promise<void> {
|
private async filerValueChanged<T>(key: string, value: T): Promise<void> {
|
||||||
const route = this.router.createUrlTree([this.route], {
|
const route = this.router.createUrlTree([this.route], {
|
||||||
queryParams: {[key]: value},
|
queryParams: {[key]: value || null},
|
||||||
queryParamsHandling: 'merge',
|
queryParamsHandling: 'merge',
|
||||||
});
|
});
|
||||||
await this.router.navigateByUrl(route);
|
await this.router.navigateByUrl(route);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {fade} from '../../../animations';
|
|||||||
import {ShowService} from '../services/show.service';
|
import {ShowService} from '../services/show.service';
|
||||||
import {FilterValues} from './filter/filter-values';
|
import {FilterValues} from './filter/filter-values';
|
||||||
import {ActivatedRoute, RouterLink} from '@angular/router';
|
import {ActivatedRoute, RouterLink} from '@angular/router';
|
||||||
import {map} from 'rxjs/operators';
|
import {map, switchMap} from 'rxjs/operators';
|
||||||
import {RoleDirective} from '../../../services/user/role.directive';
|
import {RoleDirective} from '../../../services/user/role.directive';
|
||||||
import {ListHeaderComponent} from '../../../widget-modules/components/list-header/list-header.component';
|
import {ListHeaderComponent} from '../../../widget-modules/components/list-header/list-header.component';
|
||||||
import {AsyncPipe, NgFor, NgIf} from '@angular/common';
|
import {AsyncPipe, NgFor, NgIf} from '@angular/common';
|
||||||
@@ -43,18 +43,26 @@ export class ListComponent {
|
|||||||
return filterValues?.showType;
|
return filterValues?.showType;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
public queriedPublicShows$ = this.lastMonths$.pipe(switchMap(lastMonths => this.showService.listPublicSince$(lastMonths)));
|
||||||
|
|
||||||
public publicShows$ = combineLatest([this.shows$, this.lastMonths$, this.owner$, this.showType$]).pipe(
|
public fallbackPublicShows$ = combineLatest([this.shows$, this.lastMonths$]).pipe(
|
||||||
map(([shows, lastMonths, owner, showType]) =>
|
map(([shows, lastMonths]) => {
|
||||||
shows
|
const startDate = new Date();
|
||||||
.filter(f => {
|
startDate.setHours(0, 0, 0, 0);
|
||||||
const d = new Date();
|
startDate.setDate(startDate.getDate() - lastMonths * 30);
|
||||||
d.setMonth(d.getMonth() - lastMonths);
|
|
||||||
return f.published && f.date.toDate() >= d;
|
return shows.filter(show => show.published && !show.archived && show.date.toDate() >= startDate);
|
||||||
})
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
public publicShows$ = combineLatest([this.queriedPublicShows$, this.fallbackPublicShows$, this.owner$, this.showType$]).pipe(
|
||||||
|
map(([queriedShows, fallbackShows, owner, showType]) => {
|
||||||
|
const shows = queriedShows.length > 0 || fallbackShows.length === 0 ? queriedShows : fallbackShows;
|
||||||
|
|
||||||
|
return shows
|
||||||
.filter(show => !owner || show.owner === owner)
|
.filter(show => !owner || show.owner === owner)
|
||||||
.filter(show => !showType || show.showType === showType)
|
.filter(show => !showType || show.showType === showType);
|
||||||
)
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import {Observable} from 'rxjs';
|
|||||||
import {DbService} from '../../../services/db.service';
|
import {DbService} from '../../../services/db.service';
|
||||||
import {Show} from './show';
|
import {Show} from './show';
|
||||||
import {map, shareReplay} from 'rxjs/operators';
|
import {map, shareReplay} from 'rxjs/operators';
|
||||||
|
import {QueryFn} from '@angular/fire/compat/firestore/interfaces';
|
||||||
|
import firebase from 'firebase/compat/app';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
@@ -22,6 +24,23 @@ export class ShowDataService {
|
|||||||
|
|
||||||
public listRaw$ = () => this.dbService.col$<Show>(this.collection);
|
public listRaw$ = () => this.dbService.col$<Show>(this.collection);
|
||||||
|
|
||||||
|
public listPublicSince$(lastMonths: number): Observable<Show[]> {
|
||||||
|
const startDate = new Date();
|
||||||
|
startDate.setHours(0, 0, 0, 0);
|
||||||
|
startDate.setDate(startDate.getDate() - lastMonths * 30);
|
||||||
|
const startTimestamp = firebase.firestore.Timestamp.fromDate(startDate);
|
||||||
|
|
||||||
|
const queryFn: QueryFn = ref => ref.where('published', '==', true).where('date', '>=', startTimestamp).orderBy('date', 'desc');
|
||||||
|
|
||||||
|
return this.dbService.col$<Show>(this.collection, queryFn).pipe(
|
||||||
|
map(shows => shows.filter(show => !show.archived)),
|
||||||
|
shareReplay({
|
||||||
|
bufferSize: 1,
|
||||||
|
refCount: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public read$ = (showId: string): Observable<Show | null> => this.dbService.doc$(`${this.collection}/${showId}`);
|
public read$ = (showId: string): Observable<Show | null> => this.dbService.doc$(`${this.collection}/${showId}`);
|
||||||
|
|
||||||
public update = async (showId: string, data: Partial<Show>): Promise<void> => await this.dbService.doc(`${this.collection}/${showId}`).update(data);
|
public update = async (showId: string, data: Partial<Show>): Promise<void> => await this.dbService.doc(`${this.collection}/${showId}`).update(data);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ export class ShowService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public read$ = (showId: string): Observable<Show | null> => this.showDataService.read$(showId);
|
public read$ = (showId: string): Observable<Show | null> => this.showDataService.read$(showId);
|
||||||
|
public listPublicSince$ = (lastMonths: number): Observable<Show[]> => this.showDataService.listPublicSince$(lastMonths);
|
||||||
|
|
||||||
public list$(publishedOnly = false): Observable<Show[]> {
|
public list$(publishedOnly = false): Observable<Show[]> {
|
||||||
return this.userService.user$.pipe(
|
return this.userService.user$.pipe(
|
||||||
|
|||||||
Reference in New Issue
Block a user