|
|
|
@ -7,6 +7,7 @@ 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";
|
|
|
|
|
import { RequestFilterType } from "../../models/RequestFilterType";
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
templateUrl: "./movies-grid.component.html",
|
|
|
|
@ -19,14 +20,19 @@ export class MoviesGridComponent implements OnInit, AfterViewInit {
|
|
|
|
|
public isLoadingResults = true;
|
|
|
|
|
public displayedColumns: string[] = ['requestedUser.requestedBy', 'title', 'requestedDate', 'status', 'requestStatus', 'actions'];
|
|
|
|
|
public gridCount: string = "15";
|
|
|
|
|
public showUnavailableRequests: boolean;
|
|
|
|
|
public isAdmin: boolean;
|
|
|
|
|
public defaultSort: string = "requestedDate";
|
|
|
|
|
public defaultOrder: string = "desc";
|
|
|
|
|
|
|
|
|
|
public RequestFilter = RequestFilterType;
|
|
|
|
|
|
|
|
|
|
private currentFilter: RequestFilterType = RequestFilterType.All;
|
|
|
|
|
|
|
|
|
|
private storageKey = "Movie_DefaultRequestListSort";
|
|
|
|
|
private storageKeyOrder = "Movie_DefaultRequestListSortOrder";
|
|
|
|
|
private storageKeyGridCount = "Movie_DefaultGridCount";
|
|
|
|
|
private storageKeyCurrentFilter = "Movie_DefaultFilter";
|
|
|
|
|
private $data: Observable<any>;
|
|
|
|
|
|
|
|
|
|
@Output() public onOpenOptions = new EventEmitter<{ request: any, filter: any, onChange: any }>();
|
|
|
|
|
|
|
|
|
@ -39,9 +45,12 @@ export class MoviesGridComponent implements OnInit, AfterViewInit {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ngOnInit() {
|
|
|
|
|
this.isAdmin = this.auth.hasRole("admin") || this.auth.hasRole("poweruser");
|
|
|
|
|
|
|
|
|
|
const defaultCount = this.storageService.get(this.storageKeyGridCount);
|
|
|
|
|
const defaultSort = this.storageService.get(this.storageKey);
|
|
|
|
|
const defaultOrder = this.storageService.get(this.storageKeyOrder);
|
|
|
|
|
const defaultFilter = +this.storageService.get(this.storageKeyCurrentFilter);
|
|
|
|
|
if (defaultSort) {
|
|
|
|
|
this.defaultSort = defaultSort;
|
|
|
|
|
}
|
|
|
|
@ -51,6 +60,9 @@ export class MoviesGridComponent implements OnInit, AfterViewInit {
|
|
|
|
|
if (defaultCount) {
|
|
|
|
|
this.gridCount = defaultCount;
|
|
|
|
|
}
|
|
|
|
|
if (defaultFilter) {
|
|
|
|
|
this.currentFilter = defaultFilter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async ngAfterViewInit() {
|
|
|
|
@ -60,13 +72,12 @@ export class MoviesGridComponent implements OnInit, AfterViewInit {
|
|
|
|
|
// this.resultsLength = results.total;
|
|
|
|
|
|
|
|
|
|
this.storageService.save(this.storageKeyGridCount, this.gridCount);
|
|
|
|
|
|
|
|
|
|
this.isAdmin = this.auth.hasRole("admin") || this.auth.hasRole("poweruser");
|
|
|
|
|
this.storageService.save(this.storageKeyCurrentFilter, (+this.currentFilter).toString());
|
|
|
|
|
|
|
|
|
|
// If the user changes the sort order, reset back to the first page.
|
|
|
|
|
this.sort.sortChange.subscribe(() => this.paginator.pageIndex = 0);
|
|
|
|
|
|
|
|
|
|
merge(this.sort.sortChange, this.paginator.page)
|
|
|
|
|
merge(this.sort.sortChange, this.paginator.page, this.currentFilter)
|
|
|
|
|
.pipe(
|
|
|
|
|
startWith({}),
|
|
|
|
|
switchMap((value: any) => {
|
|
|
|
@ -92,11 +103,19 @@ export class MoviesGridComponent implements OnInit, AfterViewInit {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public loadData(): Observable<IRequestsViewModel<IMovieRequests>> {
|
|
|
|
|
if (this.showUnavailableRequests) {
|
|
|
|
|
return this.requestService.getMovieUnavailableRequests(+this.gridCount, this.paginator.pageIndex * +this.gridCount, this.sort.active, this.sort.direction);
|
|
|
|
|
} else {
|
|
|
|
|
switch(RequestFilterType[RequestFilterType[this.currentFilter]]) {
|
|
|
|
|
case RequestFilterType.All:
|
|
|
|
|
return this.requestService.getMovieRequests(+this.gridCount, this.paginator.pageIndex * +this.gridCount, this.sort.active, this.sort.direction);
|
|
|
|
|
case RequestFilterType.Pending:
|
|
|
|
|
return this.requestService.getMoviePendingRequests(+this.gridCount, this.paginator.pageIndex * +this.gridCount, this.sort.active, this.sort.direction);
|
|
|
|
|
case RequestFilterType.Available:
|
|
|
|
|
return this.requestService.getMovieAvailableRequests(+this.gridCount, this.paginator.pageIndex * +this.gridCount, this.sort.active, this.sort.direction);
|
|
|
|
|
case RequestFilterType.Processing:
|
|
|
|
|
return this.requestService.getMovieProcessingRequests(+this.gridCount, this.paginator.pageIndex * +this.gridCount, this.sort.active, this.sort.direction);
|
|
|
|
|
case RequestFilterType.Denied:
|
|
|
|
|
return this.requestService.getMovieDeniedRequests(+this.gridCount, this.paginator.pageIndex * +this.gridCount, this.sort.active, this.sort.direction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public openOptions(request: IMovieRequests) {
|
|
|
|
@ -112,4 +131,9 @@ export class MoviesGridComponent implements OnInit, AfterViewInit {
|
|
|
|
|
|
|
|
|
|
this.onOpenOptions.emit({ request: request, filter: filter, onChange: onChange });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public switchFilter(type: RequestFilterType) {
|
|
|
|
|
this.currentFilter = type;
|
|
|
|
|
this.ngAfterViewInit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|