mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
Made the sorting and sorting direction on the request lists stick
This commit is contained in:
parent
e080afe05a
commit
942a4c5ae2
5 changed files with 56 additions and 15 deletions
|
@ -10,8 +10,8 @@
|
||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
|
||||||
<table mat-table [dataSource]="dataSource" class="table" matSort matSortActive="requestedDate"
|
<table mat-table [dataSource]="dataSource" class="table" matSort [matSortActive]="defaultSort"
|
||||||
matSortDisableClear matSortDirection="desc">
|
matSortDisableClear [matSortDirection]="defaultOrder">
|
||||||
|
|
||||||
|
|
||||||
<ng-container matColumnDef="requestedUser.requestedBy">
|
<ng-container matColumnDef="requestedUser.requestedBy">
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Component, AfterViewInit, ViewChild, EventEmitter, Output, ChangeDetectorRef } from "@angular/core";
|
import { Component, AfterViewInit, ViewChild, EventEmitter, Output, ChangeDetectorRef, OnInit } from "@angular/core";
|
||||||
import { IMovieRequests, IRequestsViewModel } from "../../../interfaces";
|
import { IMovieRequests, IRequestsViewModel } from "../../../interfaces";
|
||||||
import { MatPaginator, MatSort } from "@angular/material";
|
import { MatPaginator, MatSort } from "@angular/material";
|
||||||
import { merge, Observable, of as observableOf } from 'rxjs';
|
import { merge, Observable, of as observableOf } from 'rxjs';
|
||||||
|
@ -6,13 +6,14 @@ import { catchError, map, startWith, switchMap } from 'rxjs/operators';
|
||||||
|
|
||||||
import { RequestServiceV2 } from "../../../services/requestV2.service";
|
import { RequestServiceV2 } from "../../../services/requestV2.service";
|
||||||
import { AuthService } from "../../../auth/auth.service";
|
import { AuthService } from "../../../auth/auth.service";
|
||||||
|
import { StorageService } from "../../../shared/storage/storage-service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
templateUrl: "./movies-grid.component.html",
|
templateUrl: "./movies-grid.component.html",
|
||||||
selector: "movies-grid",
|
selector: "movies-grid",
|
||||||
styleUrls: ["../requests-list.component.scss"]
|
styleUrls: ["../requests-list.component.scss"]
|
||||||
})
|
})
|
||||||
export class MoviesGridComponent implements AfterViewInit {
|
export class MoviesGridComponent implements OnInit, AfterViewInit {
|
||||||
public dataSource: IMovieRequests[] = [];
|
public dataSource: IMovieRequests[] = [];
|
||||||
public resultsLength: number;
|
public resultsLength: number;
|
||||||
public isLoadingResults = true;
|
public isLoadingResults = true;
|
||||||
|
@ -20,6 +21,11 @@ export class MoviesGridComponent implements AfterViewInit {
|
||||||
public gridCount: string = "15";
|
public gridCount: string = "15";
|
||||||
public showUnavailableRequests: boolean;
|
public showUnavailableRequests: boolean;
|
||||||
public isAdmin: boolean;
|
public isAdmin: boolean;
|
||||||
|
public defaultSort: string = "requestedDate";
|
||||||
|
public defaultOrder: string = "desc";
|
||||||
|
|
||||||
|
private storageKey = "Movie_DefaultRequestListSort";
|
||||||
|
private storageKeyOrder = "Movie_DefaultRequestListSortOrder";
|
||||||
|
|
||||||
@Output() public onOpenOptions = new EventEmitter<{ request: any, filter: any, onChange: any }>();
|
@Output() public onOpenOptions = new EventEmitter<{ request: any, filter: any, onChange: any }>();
|
||||||
|
|
||||||
|
@ -27,9 +33,20 @@ export class MoviesGridComponent implements AfterViewInit {
|
||||||
@ViewChild(MatSort, { static: false }) sort: MatSort;
|
@ViewChild(MatSort, { static: false }) sort: MatSort;
|
||||||
|
|
||||||
constructor(private requestService: RequestServiceV2, private ref: ChangeDetectorRef,
|
constructor(private requestService: RequestServiceV2, private ref: ChangeDetectorRef,
|
||||||
private auth: AuthService) {
|
private auth: AuthService, private storageService: StorageService) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ngOnInit() {
|
||||||
|
const defaultSort = this.storageService.get(this.storageKey);
|
||||||
|
const defaultOrder = this.storageService.get(this.storageKeyOrder);
|
||||||
|
if (defaultSort) {
|
||||||
|
this.defaultSort = defaultSort;
|
||||||
|
}
|
||||||
|
if (defaultOrder) {
|
||||||
|
this.defaultOrder = defaultOrder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async ngAfterViewInit() {
|
public async ngAfterViewInit() {
|
||||||
// const results = await this.requestService.getMovieRequests(this.gridCount, 0, OrderType.RequestedDateDesc,
|
// const results = await this.requestService.getMovieRequests(this.gridCount, 0, OrderType.RequestedDateDesc,
|
||||||
|
@ -45,10 +62,12 @@ export class MoviesGridComponent implements AfterViewInit {
|
||||||
merge(this.sort.sortChange, this.paginator.page)
|
merge(this.sort.sortChange, this.paginator.page)
|
||||||
.pipe(
|
.pipe(
|
||||||
startWith({}),
|
startWith({}),
|
||||||
switchMap(() => {
|
switchMap((value: any) => {
|
||||||
this.isLoadingResults = true;
|
this.isLoadingResults = true;
|
||||||
// eturn this.exampleDatabase!.getRepoIssues(
|
if (value.active || value.direction) {
|
||||||
// this.sort.active, this.sort.direction, this.paginator.pageIndex);
|
this.storageService.save(this.storageKey, value.active);
|
||||||
|
this.storageService.save(this.storageKeyOrder, value.direction);
|
||||||
|
}
|
||||||
return this.loadData();
|
return this.loadData();
|
||||||
}),
|
}),
|
||||||
map((data: IRequestsViewModel<IMovieRequests>) => {
|
map((data: IRequestsViewModel<IMovieRequests>) => {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</mat-tab>
|
</mat-tab>
|
||||||
<mat-tab label="Albums">
|
<mat-tab label="Albums">
|
||||||
<h1>Some more tab content</h1>
|
<h1>Coming soon</h1>
|
||||||
<p>...</p>
|
<p>...</p>
|
||||||
</mat-tab>
|
</mat-tab>
|
||||||
</mat-tab-group>
|
</mat-tab-group>
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
|
||||||
<table mat-table [dataSource]="dataSource" class="table" matSort matSortActive="title" matSortDisableClear
|
<table mat-table [dataSource]="dataSource" class="table" matSort [matSortActive]="defaultSort" matSortDisableClear
|
||||||
matSortDirection="desc">
|
[matSortDirection]="defaultOrder">
|
||||||
|
|
||||||
|
|
||||||
<ng-container matColumnDef="series">
|
<ng-container matColumnDef="series">
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Component, AfterViewInit, ViewChild, Output, EventEmitter, ChangeDetectorRef } from "@angular/core";
|
import { Component, AfterViewInit, ViewChild, Output, EventEmitter, ChangeDetectorRef, OnInit } from "@angular/core";
|
||||||
import { IRequestsViewModel, IChildRequests } from "../../../interfaces";
|
import { IRequestsViewModel, IChildRequests } from "../../../interfaces";
|
||||||
import { MatPaginator, MatSort } from "@angular/material";
|
import { MatPaginator, MatSort } from "@angular/material";
|
||||||
import { merge, of as observableOf, Observable } from 'rxjs';
|
import { merge, of as observableOf, Observable } from 'rxjs';
|
||||||
|
@ -6,13 +6,14 @@ import { catchError, map, startWith, switchMap } from 'rxjs/operators';
|
||||||
|
|
||||||
import { RequestServiceV2 } from "../../../services/requestV2.service";
|
import { RequestServiceV2 } from "../../../services/requestV2.service";
|
||||||
import { AuthService } from "../../../auth/auth.service";
|
import { AuthService } from "../../../auth/auth.service";
|
||||||
|
import { StorageService } from "../../../shared/storage/storage-service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
templateUrl: "./tv-grid.component.html",
|
templateUrl: "./tv-grid.component.html",
|
||||||
selector: "tv-grid",
|
selector: "tv-grid",
|
||||||
styleUrls: ["../requests-list.component.scss"]
|
styleUrls: ["../requests-list.component.scss"]
|
||||||
})
|
})
|
||||||
export class TvGridComponent implements AfterViewInit {
|
export class TvGridComponent implements OnInit, AfterViewInit {
|
||||||
public dataSource: IChildRequests[] = [];
|
public dataSource: IChildRequests[] = [];
|
||||||
public resultsLength: number;
|
public resultsLength: number;
|
||||||
public isLoadingResults = true;
|
public isLoadingResults = true;
|
||||||
|
@ -20,6 +21,11 @@ export class TvGridComponent implements AfterViewInit {
|
||||||
public gridCount: string = "15";
|
public gridCount: string = "15";
|
||||||
public showUnavailableRequests: boolean;
|
public showUnavailableRequests: boolean;
|
||||||
public isAdmin: boolean;
|
public isAdmin: boolean;
|
||||||
|
public defaultSort: string = "requestedDate";
|
||||||
|
public defaultOrder: string = "desc";
|
||||||
|
|
||||||
|
private storageKey = "Tv_DefaultRequestListSort";
|
||||||
|
private storageKeyOrder = "Tv_DefaultRequestListSortOrder";
|
||||||
|
|
||||||
@Output() public onOpenOptions = new EventEmitter<{request: any, filter: any, onChange: any}>();
|
@Output() public onOpenOptions = new EventEmitter<{request: any, filter: any, onChange: any}>();
|
||||||
|
|
||||||
|
@ -27,10 +33,21 @@ export class TvGridComponent implements AfterViewInit {
|
||||||
@ViewChild(MatSort, {static: false}) sort: MatSort;
|
@ViewChild(MatSort, {static: false}) sort: MatSort;
|
||||||
|
|
||||||
constructor(private requestService: RequestServiceV2, private auth: AuthService,
|
constructor(private requestService: RequestServiceV2, private auth: AuthService,
|
||||||
private ref: ChangeDetectorRef) {
|
private ref: ChangeDetectorRef, private storageService: StorageService) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ngOnInit() {
|
||||||
|
const defaultSort = this.storageService.get(this.storageKey);
|
||||||
|
const defaultOrder = this.storageService.get(this.storageKeyOrder);
|
||||||
|
if (defaultSort) {
|
||||||
|
this.defaultSort = defaultSort;
|
||||||
|
}
|
||||||
|
if (defaultOrder) {
|
||||||
|
this.defaultOrder = defaultOrder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async ngAfterViewInit() {
|
public async ngAfterViewInit() {
|
||||||
|
|
||||||
this.isAdmin = this.auth.hasRole("admin") || this.auth.hasRole("poweruser");
|
this.isAdmin = this.auth.hasRole("admin") || this.auth.hasRole("poweruser");
|
||||||
|
@ -40,8 +57,13 @@ export class TvGridComponent implements AfterViewInit {
|
||||||
merge(this.sort.sortChange, this.paginator.page)
|
merge(this.sort.sortChange, this.paginator.page)
|
||||||
.pipe(
|
.pipe(
|
||||||
startWith({}),
|
startWith({}),
|
||||||
switchMap(() => {
|
switchMap((value: any) => {
|
||||||
this.isLoadingResults = true;
|
this.isLoadingResults = true;
|
||||||
|
|
||||||
|
if (value.active || value.direction) {
|
||||||
|
this.storageService.save(this.storageKey, value.active);
|
||||||
|
this.storageService.save(this.storageKeyOrder, value.direction);
|
||||||
|
}
|
||||||
return this.loadData();
|
return this.loadData();
|
||||||
}),
|
}),
|
||||||
map((data: IRequestsViewModel<IChildRequests>) => {
|
map((data: IRequestsViewModel<IChildRequests>) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue