diff --git a/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs b/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs index 3f456a4a4..36ae7da61 100644 --- a/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs +++ b/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs @@ -21,5 +21,7 @@ namespace Ombi.Core.Engine.Interfaces Task RemoveTvChild(int requestId); Task ApproveChildRequest(int id); Task> GetRequestsLite(); + Task UpdateQualityProfile(int requestId, int profileId); + Task UpdateRootPath(int requestId, int rootPath); } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/TvRequestEngine.cs b/src/Ombi.Core/Engine/TvRequestEngine.cs index b8062dadb..abb854021 100644 --- a/src/Ombi.Core/Engine/TvRequestEngine.cs +++ b/src/Ombi.Core/Engine/TvRequestEngine.cs @@ -328,7 +328,25 @@ namespace Ombi.Core.Engine return results; } - public async Task UpdateTvRequest(TvRequests request) + public async Task UpdateRootPath(int requestId, int rootPath) + { + var allRequests = TvRepository.Get(); + var results = await allRequests.FirstOrDefaultAsync(x => x.Id == requestId); + results.RootFolder = rootPath; + + await TvRepository.Update(results); + } + + public async Task UpdateQualityProfile(int requestId, int profileId) + { + var allRequests = TvRepository.Get(); + var results = await allRequests.FirstOrDefaultAsync(x => x.Id == requestId); + results.QualityOverride = profileId; + + await TvRepository.Update(results); + } + + public async Task UpdateTvRequest(TvRequests request) { await Audit.Record(AuditType.Updated, AuditArea.TvRequest, $"Updated Request {request.Title}", Username); var allRequests = TvRepository.Get(); diff --git a/src/Ombi/ClientApp/app/requests/tvrequests.component.ts b/src/Ombi/ClientApp/app/requests/tvrequests.component.ts index 27469af0b..6a17066d7 100644 --- a/src/Ombi/ClientApp/app/requests/tvrequests.component.ts +++ b/src/Ombi/ClientApp/app/requests/tvrequests.component.ts @@ -46,6 +46,27 @@ export class TvRequestsComponent implements OnInit { private sonarrService: SonarrService, private notificationService: NotificationService, private readonly platformLocation: PlatformLocation) { + + this.isAdmin = this.auth.hasRole("admin") || this.auth.hasRole("poweruser"); + if (this.isAdmin) { + this.sonarrService.getQualityProfilesWithoutSettings() + .subscribe(x => this.sonarrProfiles = x); + + this.sonarrService.getRootFoldersWithoutSettings() + .subscribe(x => this.sonarrRootFolders = x); + } + } + + public openClosestTab(node: ITvRequests,el: any) { + el.preventDefault(); + node.open = !node.open; + } + + public ngOnInit() { + this.amountToLoad = 10; + this.currentlyLoaded = 10; + this.tvRequests = {collection:[], total:0}; + this.searchChanged.pipe( debounceTime(600), // Wait Xms after the last event before emitting last event distinctUntilChanged(), // only emit if value is different from previous value @@ -67,18 +88,6 @@ export class TvRequestsComponent implements OnInit { if (base) { this.defaultPoster = "../../.." + base + "/images/default_tv_poster.png"; } - } - - public openClosestTab(node: ITvRequests,el: any) { - el.preventDefault(); - node.open = !node.open; - } - - public ngOnInit() { - this.amountToLoad = 10; - this.currentlyLoaded = 10; - this.tvRequests = {collection:[], total:0}; - this.isAdmin = this.auth.hasRole("admin") || this.auth.hasRole("poweruser"); this.loadInit(); } @@ -111,14 +120,14 @@ export class TvRequestsComponent implements OnInit { event.preventDefault(); searchResult.rootFolder = rootFolderSelected.id; this.setOverride(searchResult); - this.updateRequest(searchResult); + this.setRootFolder(searchResult); } public selectQualityProfile(searchResult: ITvRequests, profileSelected: ISonarrProfile, event: any) { event.preventDefault(); searchResult.qualityOverride = profileSelected.id; this.setOverride(searchResult); - this.updateRequest(searchResult); + this.setQualityProfile(searchResult); } public reportIssue(catId: IIssueCategory, req: ITvRequests) { @@ -133,13 +142,24 @@ export class TvRequestsComponent implements OnInit { this.setRootFolderOverrides(req); } - private updateRequest(request: ITvRequests) { - this.requestService.updateTvRequest(request) - .subscribe(x => { - this.notificationService.success("Request Updated"); - this.setOverride(x); - request = x; - }); + private setQualityProfile(req: ITvRequests) { + this.requestService.setQualityProfile(req.id, req.qualityOverride).subscribe(x => { + if(x) { + this.notificationService.success("Quality profile updated"); + } else { + this.notificationService.error("Could not update the quality profile"); + } + }); + } + + private setRootFolder(req: ITvRequests) { + this.requestService.setRootFolder(req.id, req.rootFolder).subscribe(x => { + if(x) { + this.notificationService.success("Quality profile updated"); + } else { + this.notificationService.error("Could not update the quality profile"); + } + }); } private setQualityOverrides(req: ITvRequests): void { @@ -174,14 +194,6 @@ export class TvRequestsComponent implements OnInit { this.setOverride(val); }); }); - - if (this.isAdmin) { - this.sonarrService.getQualityProfilesWithoutSettings() - .subscribe(x => this.sonarrProfiles = x); - - this.sonarrService.getRootFoldersWithoutSettings() - .subscribe(x => this.sonarrRootFolders = x); - } } private resetSearch() { diff --git a/src/Ombi/ClientApp/app/services/request.service.ts b/src/Ombi/ClientApp/app/services/request.service.ts index 94cb15fd9..48fa5622d 100644 --- a/src/Ombi/ClientApp/app/services/request.service.ts +++ b/src/Ombi/ClientApp/app/services/request.service.ts @@ -126,4 +126,10 @@ export class RequestService extends ServiceHelpers { public unSubscribeToTv(requestId: number): Observable { return this.http.post(`${this.url}tv/unsubscribe/${requestId}`, {headers: this.headers}); } + public setQualityProfile(requestId: number, qualityId: number): Observable { + return this.http.put(`${this.url}tv/quality/${requestId}/${qualityId}`, {headers: this.headers}); + } + public setRootFolder(requestId: number, rootFolderId: number): Observable { + return this.http.put(`${this.url}tv/root/${requestId}/${rootFolderId}`, {headers: this.headers}); + } } diff --git a/src/Ombi/Controllers/RequestController.cs b/src/Ombi/Controllers/RequestController.cs index c60261d1b..d794f6001 100644 --- a/src/Ombi/Controllers/RequestController.cs +++ b/src/Ombi/Controllers/RequestController.cs @@ -286,6 +286,34 @@ namespace Ombi.Controllers return await TvRequestEngine.UpdateTvRequest(model); } + /// + /// Updates the root path for this tv show + /// + /// + /// + /// + [HttpPut("tv/root/{requestId:int}/{rootFolderId:int}")] + [PowerUser] + public async Task UpdateRootFolder(int requestId, int rootFolderId) + { + await TvRequestEngine.UpdateRootPath(requestId, rootFolderId); + return true; + } + + /// + /// Updates the quality profile for this tv show + /// + /// + /// + /// + [HttpPut("tv/quality/{requestId:int}/{qualityId:int}")] + [PowerUser] + public async Task UpdateQuality(int requestId, int qualityId) + { + await TvRequestEngine.UpdateQualityProfile(requestId, qualityId); + return true; + } + /// /// Updates the a specific child request ///