|
|
|
@ -1,12 +1,11 @@
|
|
|
|
|
import { PlatformLocation } from "@angular/common";
|
|
|
|
|
import { Component, Input, OnInit } from "@angular/core";
|
|
|
|
|
import { DomSanitizer } from "@angular/platform-browser";
|
|
|
|
|
import { TreeNode } from "primeng/primeng";
|
|
|
|
|
import { Subject } from "rxjs";
|
|
|
|
|
import { debounceTime, distinctUntilChanged } from "rxjs/operators";
|
|
|
|
|
|
|
|
|
|
import { AuthService } from "../auth/auth.service";
|
|
|
|
|
import { IIssueCategory, IPagenator, ISonarrProfile, ISonarrRootFolder, ITvRequests } from "../interfaces";
|
|
|
|
|
import { FilterType, IIssueCategory, IPagenator, IRequestsViewModel, ISonarrProfile, ISonarrRootFolder, ITvRequests, OrderType } from "../interfaces";
|
|
|
|
|
import { NotificationService, RequestService, SonarrService } from "../services";
|
|
|
|
|
import { ImageService } from "./../services/image.service";
|
|
|
|
|
|
|
|
|
@ -17,7 +16,7 @@ import { ImageService } from "./../services/image.service";
|
|
|
|
|
})
|
|
|
|
|
export class TvRequestsComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
public tvRequests: TreeNode[];
|
|
|
|
|
public tvRequests: IRequestsViewModel<ITvRequests>;
|
|
|
|
|
public searchChanged = new Subject<string>();
|
|
|
|
|
public searchText: string;
|
|
|
|
|
public isAdmin: boolean;
|
|
|
|
@ -56,11 +55,11 @@ export class TvRequestsComponent implements OnInit {
|
|
|
|
|
this.resetSearch();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.requestService.searchTvRequestsTree(this.searchText)
|
|
|
|
|
this.requestService.searchTvRequests(this.searchText)
|
|
|
|
|
.subscribe(m => {
|
|
|
|
|
this.tvRequests = m;
|
|
|
|
|
this.tvRequests.forEach((val) => this.loadBackdrop(val));
|
|
|
|
|
this.tvRequests.forEach((val) => this.setOverride(val.data));
|
|
|
|
|
this.tvRequests.collection = m;
|
|
|
|
|
this.tvRequests.collection.forEach((val) => this.loadBackdrop(val));
|
|
|
|
|
this.tvRequests.collection.forEach((val) => this.setOverride(val));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
this.defaultPoster = "../../../images/default_tv_poster.png";
|
|
|
|
@ -70,47 +69,15 @@ export class TvRequestsComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public openClosestTab(el: any) {
|
|
|
|
|
const rowclass = "undefined ng-star-inserted";
|
|
|
|
|
el = el.toElement || el.relatedTarget || el.target || el.srcElement;
|
|
|
|
|
|
|
|
|
|
if (el.nodeName === "BUTTON") {
|
|
|
|
|
|
|
|
|
|
const isButtonAlreadyActive = el.parentElement.querySelector(".active");
|
|
|
|
|
// if a Button already has Class: .active
|
|
|
|
|
if (isButtonAlreadyActive) {
|
|
|
|
|
isButtonAlreadyActive.classList.remove("active");
|
|
|
|
|
} else {
|
|
|
|
|
el.className += " active";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (el.className !== rowclass) {
|
|
|
|
|
// Increment the loop to the parent node until we find the row we need
|
|
|
|
|
el = el.parentNode;
|
|
|
|
|
}
|
|
|
|
|
// At this point, the while loop has stopped and `el` represents the element that has
|
|
|
|
|
// the class you specified
|
|
|
|
|
|
|
|
|
|
// Then we loop through the children to find the caret which we want to click
|
|
|
|
|
const caretright = "fa-caret-right";
|
|
|
|
|
const caretdown = "fa-caret-down";
|
|
|
|
|
for (const value of el.children) {
|
|
|
|
|
// the caret from the ui has 2 class selectors depending on if expanded or not
|
|
|
|
|
// we search for both since we want to still toggle the clicking
|
|
|
|
|
if (value.className.includes(caretright) || value.className.includes(caretdown)) {
|
|
|
|
|
// Then we tell JS to click the element even though we hid it from the UI
|
|
|
|
|
value.click();
|
|
|
|
|
//Break from loop since we no longer need to continue looking
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public openClosestTab(node: ITvRequests,el: any) {
|
|
|
|
|
el.preventDefault();
|
|
|
|
|
node.open = !node.open;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ngOnInit() {
|
|
|
|
|
this.amountToLoad = 10;
|
|
|
|
|
this.currentlyLoaded = 10;
|
|
|
|
|
this.tvRequests = [];
|
|
|
|
|
this.tvRequests = {collection:[], total:0};
|
|
|
|
|
this.isAdmin = this.auth.hasRole("admin") || this.auth.hasRole("poweruser");
|
|
|
|
|
|
|
|
|
|
this.loadInit();
|
|
|
|
@ -119,7 +86,7 @@ export class TvRequestsComponent implements OnInit {
|
|
|
|
|
public paginate(event: IPagenator) {
|
|
|
|
|
const skipAmount = event.first;
|
|
|
|
|
|
|
|
|
|
this.requestService.getTvRequestsTree(this.amountToLoad, skipAmount)
|
|
|
|
|
this.requestService.getTvRequests(this.amountToLoad, skipAmount, OrderType.RequestedDateDesc, FilterType.None, FilterType.None)
|
|
|
|
|
.subscribe(x => {
|
|
|
|
|
this.tvRequests = x;
|
|
|
|
|
this.currentlyLoaded = this.currentlyLoaded + this.amountToLoad;
|
|
|
|
@ -198,13 +165,13 @@ export class TvRequestsComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
private loadInit() {
|
|
|
|
|
this.requestService.getTotalTv().subscribe(x => this.totalTv = x);
|
|
|
|
|
this.requestService.getTvRequestsTree(this.amountToLoad, 0)
|
|
|
|
|
this.requestService.getTvRequests(this.amountToLoad, 0, OrderType.RequestedDateDesc, FilterType.None, FilterType.None)
|
|
|
|
|
.subscribe(x => {
|
|
|
|
|
this.tvRequests = x;
|
|
|
|
|
this.tvRequests.forEach((val, index) => {
|
|
|
|
|
this.tvRequests.collection.forEach((val, index) => {
|
|
|
|
|
this.setDefaults(val);
|
|
|
|
|
this.loadBackdrop(val);
|
|
|
|
|
this.setOverride(val.data);
|
|
|
|
|
this.setOverride(val);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -222,20 +189,20 @@ export class TvRequestsComponent implements OnInit {
|
|
|
|
|
this.loadInit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private setDefaults(val: any) {
|
|
|
|
|
if (val.data.posterPath === null) {
|
|
|
|
|
val.data.posterPath = this.defaultPoster;
|
|
|
|
|
private setDefaults(val: ITvRequests) {
|
|
|
|
|
if (val.posterPath === null) {
|
|
|
|
|
val.posterPath = this.defaultPoster;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private loadBackdrop(val: TreeNode): void {
|
|
|
|
|
if (val.data.background != null) {
|
|
|
|
|
val.data.background = this.sanitizer.bypassSecurityTrustStyle
|
|
|
|
|
("url(https://image.tmdb.org/t/p/w1280" + val.data.background + ")");
|
|
|
|
|
private loadBackdrop(val: ITvRequests): void {
|
|
|
|
|
if (val.background != null) {
|
|
|
|
|
val.background = this.sanitizer.bypassSecurityTrustStyle
|
|
|
|
|
("url(https://image.tmdb.org/t/p/w1280" + val.background + ")");
|
|
|
|
|
} else {
|
|
|
|
|
this.imageService.getTvBanner(val.data.tvDbId).subscribe(x => {
|
|
|
|
|
this.imageService.getTvBanner(val.tvDbId).subscribe(x => {
|
|
|
|
|
if (x) {
|
|
|
|
|
val.data.background = this.sanitizer.bypassSecurityTrustStyle
|
|
|
|
|
val.background = this.sanitizer.bypassSecurityTrustStyle
|
|
|
|
|
("url(" + x + ")");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|