|
|
@ -10,7 +10,6 @@ import 'rxjs/add/operator/distinctUntilChanged';
|
|
|
|
import 'rxjs/add/operator/map';
|
|
|
|
import 'rxjs/add/operator/map';
|
|
|
|
|
|
|
|
|
|
|
|
import { RequestService } from '../services/request.service';
|
|
|
|
import { RequestService } from '../services/request.service';
|
|
|
|
import { AuthService } from '../auth/auth.service';
|
|
|
|
|
|
|
|
import { IdentityService } from '../services/identity.service';
|
|
|
|
import { IdentityService } from '../services/identity.service';
|
|
|
|
|
|
|
|
|
|
|
|
import { ITvRequests, IChildRequests, INewSeasonRequests, IEpisodesRequests } from '../interfaces/IRequestModel';
|
|
|
|
import { ITvRequests, IChildRequests, INewSeasonRequests, IEpisodesRequests } from '../interfaces/IRequestModel';
|
|
|
@ -26,8 +25,7 @@ import { TreeNode, } from "primeng/primeng";
|
|
|
|
encapsulation: ViewEncapsulation.None
|
|
|
|
encapsulation: ViewEncapsulation.None
|
|
|
|
})
|
|
|
|
})
|
|
|
|
export class TvRequestsComponent implements OnInit, OnDestroy {
|
|
|
|
export class TvRequestsComponent implements OnInit, OnDestroy {
|
|
|
|
constructor(private requestService: RequestService,
|
|
|
|
constructor(private requestService: RequestService, private identityService: IdentityService) {
|
|
|
|
private identityService: IdentityService, private authService : AuthService) {
|
|
|
|
|
|
|
|
this.searchChanged
|
|
|
|
this.searchChanged
|
|
|
|
.debounceTime(600) // Wait Xms afterthe last event before emitting last event
|
|
|
|
.debounceTime(600) // Wait Xms afterthe last event before emitting last event
|
|
|
|
.distinctUntilChanged() // only emit if value is different from previous value
|
|
|
|
.distinctUntilChanged() // only emit if value is different from previous value
|
|
|
@ -43,17 +41,6 @@ export class TvRequestsComponent implements OnInit, OnDestroy {
|
|
|
|
.subscribe(m => this.tvRequests = this.transformData(m));
|
|
|
|
.subscribe(m => this.tvRequests = this.transformData(m));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
|
|
|
this.amountToLoad = 5;
|
|
|
|
|
|
|
|
this.currentlyLoaded = 5;
|
|
|
|
|
|
|
|
this.tvRequests = [];
|
|
|
|
|
|
|
|
this.loadInit();
|
|
|
|
|
|
|
|
this.admin = this.authService.hasRole("admin");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public admin = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
openClosestTab(el:any): void {
|
|
|
|
openClosestTab(el:any): void {
|
|
|
|
var rowclass = "undefined";
|
|
|
|
var rowclass = "undefined";
|
|
|
|
el = el.toElement;
|
|
|
|
el = el.toElement;
|
|
|
@ -81,27 +68,22 @@ export class TvRequestsComponent implements OnInit, OnDestroy {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
transformData(datain: ITvRequests[]): any {
|
|
|
|
transformData(data: ITvRequests[]): TreeNode[] {
|
|
|
|
var temp: TreeNode[] = [];
|
|
|
|
var temp: TreeNode[] = [];
|
|
|
|
datain.forEach(function(value) {
|
|
|
|
data.forEach(function (value) {
|
|
|
|
temp.push({
|
|
|
|
temp.push({
|
|
|
|
"data": value,
|
|
|
|
"data": value,
|
|
|
|
"children": [
|
|
|
|
"children": [{
|
|
|
|
{
|
|
|
|
"data": this.fixEpisodeSort(value.childRequests), leaf: true
|
|
|
|
"data": this.fixEpisodeSort(value.childRequests),
|
|
|
|
}],
|
|
|
|
leaf: true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
leaf: false
|
|
|
|
leaf: false
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}, this)
|
|
|
|
this);
|
|
|
|
return <TreeNode[]>temp;
|
|
|
|
console.log(temp);
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private subscriptions = new Subject<void>();
|
|
|
|
private subscriptions = new Subject<void>();
|
|
|
|
|
|
|
|
|
|
|
|
tvRequests: ITvRequests[];
|
|
|
|
tvRequests: TreeNode[];
|
|
|
|
|
|
|
|
|
|
|
|
searchChanged = new Subject<string>();
|
|
|
|
searchChanged = new Subject<string>();
|
|
|
|
searchText: string;
|
|
|
|
searchText: string;
|
|
|
@ -114,22 +96,33 @@ 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;
|
|
|
|
|
|
|
|
|
|
|
|
private fixEpisodeSort(items: IChildRequests[]) : IChildRequests[] {
|
|
|
|
fixEpisodeSort(items: IChildRequests[]) {
|
|
|
|
items.forEach(value => {
|
|
|
|
items.forEach(function (value) {
|
|
|
|
value.seasonRequests.forEach((requests: INewSeasonRequests) => {
|
|
|
|
value.seasonRequests.forEach(function (requests: INewSeasonRequests) {
|
|
|
|
requests.episodes.sort(
|
|
|
|
requests.episodes.sort(function (a: IEpisodesRequests, b: IEpisodesRequests) {
|
|
|
|
(a: IEpisodesRequests, b: IEpisodesRequests) => a.episodeNumber - b.episodeNumber)
|
|
|
|
return a.episodeNumber - b.episodeNumber;
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
return items;
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
|
|
|
this.amountToLoad = 1000;
|
|
|
|
|
|
|
|
this.currentlyLoaded = 5;
|
|
|
|
|
|
|
|
this.tvRequests = [];
|
|
|
|
|
|
|
|
this.loadInit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public loadMore() {
|
|
|
|
public loadMore() {
|
|
|
|
|
|
|
|
//TODO: I believe this +1 is causing off by one error skipping loading of tv shows
|
|
|
|
|
|
|
|
//When removed and scrolling very slowly everything works as expected, however
|
|
|
|
|
|
|
|
//if you scroll really quickly then you start getting duplicates of movies
|
|
|
|
|
|
|
|
//since it's async and some subsequent results return first and then incrementer
|
|
|
|
|
|
|
|
//is increased so you see movies which had already been gotten show up...
|
|
|
|
this.requestService.getTvRequests(this.amountToLoad, this.currentlyLoaded +1)
|
|
|
|
this.requestService.getTvRequests(this.amountToLoad, this.currentlyLoaded +1)
|
|
|
|
.takeUntil(this.subscriptions)
|
|
|
|
.takeUntil(this.subscriptions)
|
|
|
|
.subscribe(x => {
|
|
|
|
.subscribe(x => {
|
|
|
|
this.tvRequests.push.apply(this.tvRequests, x);
|
|
|
|
this.tvRequests.push.apply(this.tvRequests, this.transformData(x));
|
|
|
|
this.currentlyLoaded = this.currentlyLoaded + this.amountToLoad;
|
|
|
|
this.currentlyLoaded = this.currentlyLoaded + this.amountToLoad;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -142,11 +135,6 @@ 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;
|
|
|
@ -154,15 +142,25 @@ 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.requestService.updateChild(request)
|
|
|
|
this.requestService.updateChild(request)
|
|
|
|
.subscribe();
|
|
|
|
.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) {
|
|
|
|
debugger;
|
|
|
|
|
|
|
|
request.approved = false;
|
|
|
|
request.approved = false;
|
|
|
|
request.denied = true;
|
|
|
|
request.denied = true;
|
|
|
|
this.requestService.updateChild(request)
|
|
|
|
this.requestService.updateChild(request)
|
|
|
@ -182,12 +180,6 @@ 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;
|
|
|
@ -214,7 +206,6 @@ 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 => {
|
|
|
|
debugger;
|
|
|
|
|
|
|
|
this.tvRequests = this.transformData(x);
|
|
|
|
this.tvRequests = this.transformData(x);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.isAdmin = this.identityService.hasRole("Admin");
|
|
|
|
this.isAdmin = this.identityService.hasRole("Admin");
|
|
|
@ -231,16 +222,6 @@ export class TvRequestsComponent implements OnInit, OnDestroy {
|
|
|
|
this.tvRequests.splice(index, 1);
|
|
|
|
this.tvRequests.splice(index, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private removeChildRequestFromUi(key: IChildRequests) {
|
|
|
|
|
|
|
|
this.tvRequests.forEach((val) => {
|
|
|
|
|
|
|
|
var data = (<any>val).data;
|
|
|
|
|
|
|
|
var index = data.childRequests.indexOf(key, 0);
|
|
|
|
|
|
|
|
if (index > -1) {
|
|
|
|
|
|
|
|
data.childRequests.splice(index, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.subscriptions.next();
|
|
|
|
this.subscriptions.next();
|
|
|
|