|
|
@ -1,4 +1,4 @@
|
|
|
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
|
|
import { Component, OnInit, OnDestroy, ViewEncapsulation } from '@angular/core';
|
|
|
|
import { Subject } from 'rxjs/Subject';
|
|
|
|
import { Subject } from 'rxjs/Subject';
|
|
|
|
import 'rxjs/add/operator/debounceTime';
|
|
|
|
import 'rxjs/add/operator/debounceTime';
|
|
|
|
import 'rxjs/add/operator/distinctUntilChanged';
|
|
|
|
import 'rxjs/add/operator/distinctUntilChanged';
|
|
|
@ -12,11 +12,17 @@ import 'rxjs/add/operator/map';
|
|
|
|
import { RequestService } from '../services/request.service';
|
|
|
|
import { RequestService } from '../services/request.service';
|
|
|
|
import { IdentityService } from '../services/identity.service';
|
|
|
|
import { IdentityService } from '../services/identity.service';
|
|
|
|
|
|
|
|
|
|
|
|
import { ITvRequests, IChildRequests } from '../interfaces/IRequestModel';
|
|
|
|
import { ITvRequests, IChildRequests, INewSeasonRequests, IEpisodesRequests } from '../interfaces/IRequestModel';
|
|
|
|
|
|
|
|
import { TreeNode, } from "primeng/primeng";
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
@Component({
|
|
|
|
selector: 'tv-requests',
|
|
|
|
selector: 'tv-requests',
|
|
|
|
templateUrl: './tvrequests.component.html'
|
|
|
|
templateUrl: './tvrequests.component.html',
|
|
|
|
|
|
|
|
styleUrls: ['./tvrequests.component.scss'],
|
|
|
|
|
|
|
|
//Was required to turn off encapsulation since CSS only should be overridden for this component
|
|
|
|
|
|
|
|
//However when encapsulation is on angular injects prefixes to all classes so css selectors
|
|
|
|
|
|
|
|
//Stop working
|
|
|
|
|
|
|
|
encapsulation: ViewEncapsulation.None
|
|
|
|
})
|
|
|
|
})
|
|
|
|
export class TvRequestsComponent implements OnInit, OnDestroy {
|
|
|
|
export class TvRequestsComponent implements OnInit, OnDestroy {
|
|
|
|
constructor(private requestService: RequestService, private identityService: IdentityService) {
|
|
|
|
constructor(private requestService: RequestService, private identityService: IdentityService) {
|
|
|
@ -32,11 +38,50 @@ export class TvRequestsComponent implements OnInit, OnDestroy {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.requestService.searchTvRequests(this.searchText)
|
|
|
|
this.requestService.searchTvRequests(this.searchText)
|
|
|
|
.takeUntil(this.subscriptions)
|
|
|
|
.takeUntil(this.subscriptions)
|
|
|
|
.subscribe(m => this.tvRequests = m);
|
|
|
|
.subscribe(m => this.tvRequests = this.transformData(m));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
openClosestTab(el:any): void {
|
|
|
|
|
|
|
|
var rowclass = "undefined";
|
|
|
|
|
|
|
|
el = el.toElement;
|
|
|
|
|
|
|
|
while (el.className != rowclass) {
|
|
|
|
|
|
|
|
// Increment the loop to the parent node until we find the row we need
|
|
|
|
|
|
|
|
el = el.parentNode;
|
|
|
|
|
|
|
|
if (!el) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
var caretright = "ui-treetable-toggler fa fa-fw ui-c fa-caret-right";
|
|
|
|
|
|
|
|
var caretdown = "ui-treetable-toggler fa fa-fw ui-c fa-caret-down";
|
|
|
|
|
|
|
|
for (var 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 === caretright || value.className === 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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
transformData(datain: ITvRequests[]): any {
|
|
|
|
|
|
|
|
var temp: TreeNode[] = [];
|
|
|
|
|
|
|
|
datain.forEach(function (value) {
|
|
|
|
|
|
|
|
temp.push({
|
|
|
|
|
|
|
|
"data": value,
|
|
|
|
|
|
|
|
"children": [{
|
|
|
|
|
|
|
|
"data": this.fixEpisodeSort(value.childRequests), leaf: true
|
|
|
|
|
|
|
|
}],
|
|
|
|
|
|
|
|
leaf: false
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}, this)
|
|
|
|
|
|
|
|
console.log(temp);
|
|
|
|
|
|
|
|
return <TreeNode[]>temp;
|
|
|
|
|
|
|
|
}
|
|
|
|
private subscriptions = new Subject<void>();
|
|
|
|
private subscriptions = new Subject<void>();
|
|
|
|
|
|
|
|
|
|
|
|
tvRequests: ITvRequests[];
|
|
|
|
tvRequests: ITvRequests[];
|
|
|
@ -52,15 +97,23 @@ export class TvRequestsComponent implements OnInit, OnDestroy {
|
|
|
|
public showChildDialogue = false; // This is for the child modal popup
|
|
|
|
public showChildDialogue = false; // This is for the child modal popup
|
|
|
|
public selectedSeason: ITvRequests;
|
|
|
|
public selectedSeason: ITvRequests;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fixEpisodeSort(items: IChildRequests[]) {
|
|
|
|
|
|
|
|
items.forEach(function (value) {
|
|
|
|
|
|
|
|
value.seasonRequests.forEach(function (requests: INewSeasonRequests) {
|
|
|
|
|
|
|
|
requests.episodes.sort(function (a: IEpisodesRequests, b: IEpisodesRequests) {
|
|
|
|
|
|
|
|
return a.episodeNumber - b.episodeNumber;
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return items;
|
|
|
|
|
|
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
ngOnInit() {
|
|
|
|
this.amountToLoad = 5;
|
|
|
|
this.amountToLoad = 5;
|
|
|
|
this.currentlyLoaded = 5;
|
|
|
|
this.currentlyLoaded = 5;
|
|
|
|
|
|
|
|
this.tvRequests = [];
|
|
|
|
this.loadInit();
|
|
|
|
this.loadInit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public loadMore() {
|
|
|
|
public loadMore() {
|
|
|
|
this.requestService.getTvRequests(this.amountToLoad, this.currentlyLoaded + 1)
|
|
|
|
this.requestService.getTvRequests(this.amountToLoad, this.currentlyLoaded + 1)
|
|
|
|
.takeUntil(this.subscriptions)
|
|
|
|
.takeUntil(this.subscriptions)
|
|
|
@ -78,6 +131,11 @@ export class TvRequestsComponent implements OnInit, OnDestroy {
|
|
|
|
this.requestService.removeTvRequest(request);
|
|
|
|
this.requestService.removeTvRequest(request);
|
|
|
|
this.removeRequestFromUi(request);
|
|
|
|
this.removeRequestFromUi(request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public removeChildRequest(request: IChildRequests) {
|
|
|
|
|
|
|
|
this.requestService.deleteChild(request)
|
|
|
|
|
|
|
|
.subscribe();
|
|
|
|
|
|
|
|
this.removeChildRequestFromUi(request);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public changeAvailability(request: IChildRequests, available: boolean) {
|
|
|
|
public changeAvailability(request: IChildRequests, available: boolean) {
|
|
|
|
request.available = available;
|
|
|
|
request.available = available;
|
|
|
@ -85,16 +143,29 @@ export class TvRequestsComponent implements OnInit, OnDestroy {
|
|
|
|
//this.updateRequest(request);
|
|
|
|
//this.updateRequest(request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Was already here but not sure what's using it...'
|
|
|
|
|
|
|
|
//public approve(request: IChildRequests) {
|
|
|
|
|
|
|
|
// request.approved = true;
|
|
|
|
|
|
|
|
// request.denied = false;
|
|
|
|
|
|
|
|
// //this.updateRequest(request);
|
|
|
|
|
|
|
|
//}
|
|
|
|
public approve(request: IChildRequests) {
|
|
|
|
public approve(request: IChildRequests) {
|
|
|
|
request.approved = true;
|
|
|
|
request.approved = true;
|
|
|
|
request.denied = false;
|
|
|
|
request.denied = false;
|
|
|
|
//this.updateRequest(request);
|
|
|
|
this.requestService.updateChild(request)
|
|
|
|
|
|
|
|
.subscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Was already here but not sure what's using it...'
|
|
|
|
|
|
|
|
//public deny(request: IChildRequests) {
|
|
|
|
|
|
|
|
// request.approved = false;
|
|
|
|
|
|
|
|
// request.denied = true;
|
|
|
|
|
|
|
|
// //this.updateRequest(request);
|
|
|
|
|
|
|
|
//}
|
|
|
|
public deny(request: IChildRequests) {
|
|
|
|
public deny(request: IChildRequests) {
|
|
|
|
request.approved = false;
|
|
|
|
request.approved = false;
|
|
|
|
request.denied = true;
|
|
|
|
request.denied = true;
|
|
|
|
//this.updateRequest(request);
|
|
|
|
this.requestService.updateChild(request)
|
|
|
|
|
|
|
|
.subscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public approveSeasonRequest(request: IChildRequests) {
|
|
|
|
public approveSeasonRequest(request: IChildRequests) {
|
|
|
@ -110,12 +181,28 @@ export class TvRequestsComponent implements OnInit, OnDestroy {
|
|
|
|
this.requestService.updateTvRequest(this.selectedSeason)
|
|
|
|
this.requestService.updateTvRequest(this.selectedSeason)
|
|
|
|
.subscribe();
|
|
|
|
.subscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public denyChildSeasonRequest(request: IChildRequests) {
|
|
|
|
|
|
|
|
request.approved = false;
|
|
|
|
|
|
|
|
request.denied = true;
|
|
|
|
|
|
|
|
this.requestService.updateChild(request)
|
|
|
|
|
|
|
|
.subscribe();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public showChildren(request: ITvRequests) {
|
|
|
|
public showChildren(request: ITvRequests) {
|
|
|
|
this.selectedSeason = request;
|
|
|
|
this.selectedSeason = request;
|
|
|
|
this.showChildDialogue = true;
|
|
|
|
this.showChildDialogue = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public getColour(ep: IEpisodesRequests): string {
|
|
|
|
|
|
|
|
if (ep.available) {
|
|
|
|
|
|
|
|
return "lime";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ep.approved) {
|
|
|
|
|
|
|
|
return "#00c0ff";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return "white";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//private updateRequest(request: ITvRequests) {
|
|
|
|
//private updateRequest(request: ITvRequests) {
|
|
|
|
// this.requestService.updateTvRequest(request)
|
|
|
|
// this.requestService.updateTvRequest(request)
|
|
|
|
// .takeUntil(this.subscriptions)
|
|
|
|
// .takeUntil(this.subscriptions)
|
|
|
@ -126,7 +213,7 @@ export class TvRequestsComponent implements OnInit, OnDestroy {
|
|
|
|
this.requestService.getTvRequests(this.amountToLoad, 0)
|
|
|
|
this.requestService.getTvRequests(this.amountToLoad, 0)
|
|
|
|
.takeUntil(this.subscriptions)
|
|
|
|
.takeUntil(this.subscriptions)
|
|
|
|
.subscribe(x => {
|
|
|
|
.subscribe(x => {
|
|
|
|
this.tvRequests = x;
|
|
|
|
this.tvRequests = this.transformData(x);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.isAdmin = this.identityService.hasRole("Admin");
|
|
|
|
this.isAdmin = this.identityService.hasRole("Admin");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -142,6 +229,14 @@ export class TvRequestsComponent implements OnInit, OnDestroy {
|
|
|
|
this.tvRequests.splice(index, 1);
|
|
|
|
this.tvRequests.splice(index, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private removeChildRequestFromUi(key: IChildRequests) {
|
|
|
|
|
|
|
|
//var index = this.childRequests.indexOf(key, 0);
|
|
|
|
|
|
|
|
//if (index > -1) {
|
|
|
|
|
|
|
|
// this.childRequests.splice(index, 1);
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//TODO FIX THIS
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.subscriptions.next();
|
|
|
|
this.subscriptions.next();
|
|
|
|