@ -1,5 +1,5 @@
import { Component , Input } from "@angular/core" ;
import { IChildRequests , IEpisodesRequests , INewSeasonRequests , I SeasonsViewModel, ITvRequestViewModelV2 , RequestType } from "../../../../../interfaces" ;
import { IChildRequests , IEpisodesRequests , INewSeasonRequests , I RequestEngineResult, I SeasonsViewModel, ITvRequestViewModelV2 , RequestType } from "../../../../../interfaces" ;
import { RequestService } from "../../../../../services/request.service" ;
import { MessageService } from "../../../../../services" ;
import { DenyDialogComponent } from "../../../shared/deny-dialog/deny-dialog.component" ;
@ -7,6 +7,7 @@ import { ISearchTvResultV2 } from "../../../../../interfaces/ISearchTvResultV2";
import { MatDialog } from "@angular/material/dialog" ;
import { SelectionModel } from "@angular/cdk/collections" ;
import { RequestServiceV2 } from "../../../../../services/requestV2.service" ;
import { AdminRequestDialogComponent } from "../../../../../shared/admin-request-dialog/admin-request-dialog.component" ;
@Component ( {
templateUrl : "./tv-request-grid.component.html" ,
@ -59,38 +60,21 @@ export class TvRequestGridComponent {
viewModel . seasons . push ( seasonsViewModel ) ;
} ) ;
const requestResult = await this . requestServiceV2 . requestTv ( viewModel ) . toPromise ( ) ;
if ( requestResult . result ) {
this . notificationService . send (
` Request for ${ this . tv . title } has been added successfully ` ) ;
debugger ;
this . selection . clear ( ) ;
if ( this . tv . firstSeason ) {
this . tv . seasonRequests [ 0 ] . episodes . forEach ( ep = > {
ep . requested = true ;
ep . requestStatus = "Common.PendingApproval" ;
} ) ;
}
if ( this . tv . requestAll ) {
this . tv . seasonRequests . forEach ( season = > {
season . episodes . forEach ( ep = > {
ep . requested = true ;
ep . requestStatus = "Common.PendingApproval" ;
} ) ;
} ) ;
}
if ( this . tv . latestSeason ) {
this . tv . seasonRequests [ this . tv . seasonRequests . length - 1 ] . episodes . forEach ( ep = > {
ep . requested = true ;
ep . requestStatus = "Common.PendingApproval" ;
} ) ;
}
if ( this . isAdmin ) {
const dialog = this . dialog . open ( AdminRequestDialogComponent , { width : "700px" , data : { type : RequestType . tvShow , id : this.tv.id } , panelClass : 'modal-panel' } ) ;
dialog . afterClosed ( ) . subscribe ( async ( result ) = > {
if ( result ) {
viewModel . requestOnBehalf = result . username ? . id ;
viewModel . qualityPathOverride = result ? . sonarrPathId ;
viewModel . rootFolderOverride = result ? . sonarrFolderId ;
const requestResult = await this . requestServiceV2 . requestTv ( viewModel ) . toPromise ( ) ;
this . postRequest ( requestResult ) ;
}
} ) ;
} else {
this . notificationService . send ( requestResult . errorMessage ? requestResult.errorMessage : requestResult.message ) ;
const requestResult = await this . requestServiceV2 . requestTv ( viewModel ) . toPromise ( ) ;
this . postRequest ( requestResult ) ;
}
}
@ -236,4 +220,37 @@ export class TvRequestGridComponent {
}
return "" ;
}
private postRequest ( requestResult : IRequestEngineResult ) {
if ( requestResult . result ) {
this . notificationService . send (
` Request for ${ this . tv . title } has been added successfully ` ) ;
this . selection . clear ( ) ;
if ( this . tv . firstSeason ) {
this . tv . seasonRequests [ 0 ] . episodes . forEach ( ep = > {
ep . requested = true ;
ep . requestStatus = "Common.PendingApproval" ;
} ) ;
}
if ( this . tv . requestAll ) {
this . tv . seasonRequests . forEach ( season = > {
season . episodes . forEach ( ep = > {
ep . requested = true ;
ep . requestStatus = "Common.PendingApproval" ;
} ) ;
} ) ;
}
if ( this . tv . latestSeason ) {
this . tv . seasonRequests [ this . tv . seasonRequests . length - 1 ] . episodes . forEach ( ep = > {
ep . requested = true ;
ep . requestStatus = "Common.PendingApproval" ;
} ) ;
}
} else {
this . notificationService . send ( requestResult . errorMessage ? requestResult.errorMessage : requestResult.message ) ;
}
}
}