Made the sorting and sorting direction on the request lists stick

pull/3528/head
tidusjar 4 years ago
parent e080afe05a
commit 942a4c5ae2

@ -10,8 +10,8 @@
</mat-select>
</mat-form-field>
<table mat-table [dataSource]="dataSource" class="table" matSort matSortActive="requestedDate"
matSortDisableClear matSortDirection="desc">
<table mat-table [dataSource]="dataSource" class="table" matSort [matSortActive]="defaultSort"
matSortDisableClear [matSortDirection]="defaultOrder">
<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 { MatPaginator, MatSort } from "@angular/material";
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 { AuthService } from "../../../auth/auth.service";
import { StorageService } from "../../../shared/storage/storage-service";
@Component({
templateUrl: "./movies-grid.component.html",
selector: "movies-grid",
styleUrls: ["../requests-list.component.scss"]
})
export class MoviesGridComponent implements AfterViewInit {
export class MoviesGridComponent implements OnInit, AfterViewInit {
public dataSource: IMovieRequests[] = [];
public resultsLength: number;
public isLoadingResults = true;
@ -20,6 +21,11 @@ export class MoviesGridComponent implements AfterViewInit {
public gridCount: string = "15";
public showUnavailableRequests: 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 }>();
@ -27,9 +33,20 @@ export class MoviesGridComponent implements AfterViewInit {
@ViewChild(MatSort, { static: false }) sort: MatSort;
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() {
// 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)
.pipe(
startWith({}),
switchMap(() => {
switchMap((value: any) => {
this.isLoadingResults = true;
// eturn this.exampleDatabase!.getRepoIssues(
// this.sort.active, this.sort.direction, this.paginator.pageIndex);
if (value.active || value.direction) {
this.storageService.save(this.storageKey, value.active);
this.storageService.save(this.storageKeyOrder, value.direction);
}
return this.loadData();
}),
map((data: IRequestsViewModel<IMovieRequests>) => {

@ -11,7 +11,7 @@
</ng-template>
</mat-tab>
<mat-tab label="Albums">
<h1>Some more tab content</h1>
<h1>Coming soon</h1>
<p>...</p>
</mat-tab>
</mat-tab-group>

@ -11,8 +11,8 @@
</mat-select>
</mat-form-field>
<table mat-table [dataSource]="dataSource" class="table" matSort matSortActive="title" matSortDisableClear
matSortDirection="desc">
<table mat-table [dataSource]="dataSource" class="table" matSort [matSortActive]="defaultSort" matSortDisableClear
[matSortDirection]="defaultOrder">
<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 { MatPaginator, MatSort } from "@angular/material";
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 { AuthService } from "../../../auth/auth.service";
import { StorageService } from "../../../shared/storage/storage-service";
@Component({
templateUrl: "./tv-grid.component.html",
selector: "tv-grid",
styleUrls: ["../requests-list.component.scss"]
})
export class TvGridComponent implements AfterViewInit {
export class TvGridComponent implements OnInit, AfterViewInit {
public dataSource: IChildRequests[] = [];
public resultsLength: number;
public isLoadingResults = true;
@ -20,6 +21,11 @@ export class TvGridComponent implements AfterViewInit {
public gridCount: string = "15";
public showUnavailableRequests: 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}>();
@ -27,8 +33,19 @@ export class TvGridComponent implements AfterViewInit {
@ViewChild(MatSort, {static: false}) sort: MatSort;
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() {
@ -40,8 +57,13 @@ export class TvGridComponent implements AfterViewInit {
merge(this.sort.sortChange, this.paginator.page)
.pipe(
startWith({}),
switchMap(() => {
switchMap((value: any) => {
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();
}),
map((data: IRequestsViewModel<IChildRequests>) => {

Loading…
Cancel
Save