Linking the new filter pannel with the back

This commit is contained in:
Zoe Roux 2020-09-20 23:06:50 +02:00
parent 24399d84f9
commit e789e735fb
6 changed files with 94 additions and 26 deletions

View File

@ -18,9 +18,7 @@
<!--suppress AngularInvalidExpressionResultType ('default' color is valid for mat-chip)--> <!--suppress AngularInvalidExpressionResultType ('default' color is valid for mat-chip)-->
<mat-chip *ngFor="let genre of this.genres" <mat-chip *ngFor="let genre of this.genres"
[color]="this.filters.genres.includes(genre) ? 'accent' : 'default'" selected [color]="this.filters.genres.includes(genre) ? 'accent' : 'default'" selected
(click)="this.filters.genres.includes(genre) (click)="this.addFilter('genres', genre)">
? this.filters.genres.splice(this.filters.genres.indexOf(genre), 1)
: this.filters.genres.push(genre)">
{{genre.name}} {{genre.name}}
</mat-chip> </mat-chip>
</mat-chip-list> </mat-chip-list>
@ -30,11 +28,9 @@
<mat-chip-list> <mat-chip-list>
<!--suppress AngularInvalidExpressionResultType ('default' color is valid for mat-chip)--> <!--suppress AngularInvalidExpressionResultType ('default' color is valid for mat-chip)-->
<mat-chip *ngFor="let studio of this.studios" <mat-chip *ngFor="let studio of this.studios"
[color]="this.filters.studios.includes(studio) ? 'accent' : 'default'" selected [color]="this.filters.studio == studio ? 'accent' : 'default'" selected
(click)="this.filters.studios.includes(studio) (click)="this.addFilter('studio', studio, false)">
? this.filters.studios.splice(this.filters.studios.indexOf(studio), 1) {{studio.name}}
: this.filters.studios.push(studio)">
{{studio.name}}
</mat-chip> </mat-chip>
</mat-chip-list> </mat-chip-list>
</mat-menu> </mat-menu>

View File

@ -1,14 +1,15 @@
import {Component, Input} from '@angular/core'; import { Component, Input, OnInit } from "@angular/core";
import {ActivatedRoute} from '@angular/router'; import { ActivatedRoute } from "@angular/router";
import {DomSanitizer} from '@angular/platform-browser'; import { DomSanitizer } from '@angular/platform-browser';
import { Genre } from "../../../models/resources/genre"; import { Genre } from "../../../models/resources/genre";
import {LibraryItem} from "../../../models/resources/library-item"; import { LibraryItem } from "../../../models/resources/library-item";
import {Page} from "../../../models/page"; import { Page } from "../../../models/page";
import {HttpClient} from "@angular/common/http"; import { HttpClient } from "@angular/common/http";
import {Show, ShowRole} from "../../../models/resources/show"; import { IResource } from "../../../models/resources/resource";
import {Collection} from "../../../models/resources/collection"; import { Show, ShowRole } from "../../../models/resources/show";
import { Collection } from "../../../models/resources/collection";
import { Studio } from "../../../models/resources/studio"; import { Studio } from "../../../models/resources/studio";
import {ItemsUtils} from "../../misc/items-utils"; import { ItemsUtils } from "../../misc/items-utils";
import { PreLoaderService } from "../../services/pre-loader.service"; import { PreLoaderService } from "../../services/pre-loader.service";
@Component({ @Component({
@ -16,14 +17,19 @@ import { PreLoaderService } from "../../services/pre-loader.service";
templateUrl: './items-grid.component.html', templateUrl: './items-grid.component.html',
styleUrls: ['./items-grid.component.scss'] styleUrls: ['./items-grid.component.scss']
}) })
export class ItemsGridComponent export class ItemsGridComponent implements OnInit
{ {
@Input() page: Page<LibraryItem | Show | ShowRole | Collection>; @Input() page: Page<LibraryItem | Show | ShowRole | Collection>;
@Input() sortEnabled: boolean = true; @Input() sortEnabled: boolean = true;
complexFiltersEnabled: boolean;
defaultType: string;
sortType: string = "title"; sortType: string = "title";
sortKeys: string[] = ["title", "start year", "end year"] sortKeys: string[] = ["title", "start year", "end year"]
sortUp: boolean = true; sortUp: boolean = true;
filters: {genres: Genre[], studios: Studio[]} = {genres: [], studios: []};
filters: {genres: Genre[], studio: Studio} = {genres: [], studio: null};
genres: Genre[] = []; genres: Genre[] = [];
studios: Studio[] = []; studios: Studio[] = [];
@ -46,9 +52,69 @@ export class ItemsGridComponent
}); });
} }
ngOnInit()
{
this.defaultType = this.page.this.match(/\/(\w*)($|\?)/)[1];
this.complexFiltersEnabled = this.defaultType == "shows" || this.defaultType == "items";
}
getFilterCount() getFilterCount()
{ {
return this.filters.genres.length + this.filters.studios.length; let count: number = this.filters.genres.length;
if (this.filters.studio != null)
count++;
return count;
}
addFilter(category: string, filter: IResource, isArray: boolean = true, isShowOnly: boolean = true)
{
if (!this.complexFiltersEnabled)
return;
let useShow: boolean;
if (isArray)
{
if (this.filters[category].includes(filter))
{
this.filters[category].splice(this.filters[category].indexOf(filter), 1);
useShow = this.getFilterCount() != 0;
}
else
{
this.filters[category].push(filter);
useShow = true;
}
}
else
{
if (this.filters[category] == filter)
{
this.filters[category] = null;
useShow = false;
}
else
{
this.filters[category] = filter;
useShow = filter != null;
}
}
let url: URL = new URL(this.page.first);
if (isShowOnly)
{
url = useShow
? new URL(this.page.changeType("shows"))
: new URL(this.page.changeType(this.defaultType));
}
if (isArray && this.filters[category].length > 0)
url.searchParams.set(category, `ctn:${this.filters[category].map(x => x.slug).join(',')}`);
else if (!isArray && this.filters[category] != null)
url.searchParams.set(category, filter.slug)
else
url.searchParams.delete(category)
this.client.get<Page<Show>>(url.toString())
.subscribe(x => this.page = Object.assign(new Page<Show>(), x));
} }
getThumb(slug: string) getThumb(slug: string)

View File

@ -93,7 +93,7 @@ export class MetadataEditComponent
{ {
const input = event.input; const input = event.input;
const value = event.value; const value = event.value;
let genre: Genre = {slug: null, name: value}; let genre: Genre = {id: 0, slug: null, name: value};
this.show.genres.push(genre); this.show.genres.push(genre);
if (input) if (input)

View File

@ -26,4 +26,8 @@ export class Page<T>
this.this = x.this; this.this = x.this;
}); });
} }
changeType(type: string)
{
return this.first.replace(/\/\w*($|\?)/, `/${type}$1`)
}
} }

View File

@ -1,5 +1,6 @@
export interface Genre import { IResource } from "./resource";
export interface Genre extends IResource
{ {
slug: string;
name: string; name: string;
} }

View File

@ -1,5 +1,6 @@
export interface Studio import { IResource } from "./resource";
export interface Studio extends IResource
{ {
slug: string;
name: string; name: string;
} }