Added paging to the TV Requests page

pull/2194/head
Jamie Rees 7 years ago
parent 69e324c670
commit 0b2e488e8f

@ -18,5 +18,6 @@ namespace Ombi.Core.Engine.Interfaces
Task<RequestEngineResult> ApproveMovieById(int requestId);
Task<RequestEngineResult> DenyMovieById(int modelId);
Task<IEnumerable<MovieRequests>> Filter(FilterViewModel vm);
}
}

@ -17,5 +17,6 @@ namespace Ombi.Core.Engine.Interfaces
Task<RequestEngineResult> MarkUnavailable(int modelId);
Task<RequestEngineResult> MarkAvailable(int modelId);
Task<int> GetTotal();
}
}

@ -144,6 +144,19 @@ namespace Ombi.Core.Engine
return allRequests;
}
public async Task<int> GetTotal()
{
var shouldHide = await HideFromOtherUsers();
if (shouldHide.Hide)
{
return await MovieRepository.GetWithUser(shouldHide.UserId).CountAsync();
}
else
{
return await MovieRepository.GetWithUser().CountAsync();
}
}
/// <summary>
/// Gets the requests.
/// </summary>

@ -130,7 +130,7 @@ namespace Ombi.Core.Engine
var newRequest = tvBuilder.CreateNewRequest(tv);
return await AddRequest(newRequest.NewRequest);
}
public async Task<IEnumerable<TvRequests>> GetRequests(int count, int position)
{
var shouldHide = await HideFromOtherUsers();
@ -280,7 +280,7 @@ namespace Ombi.Core.Engine
results.Background = PosterPathHelper.FixBackgroundPath(request.Background);
results.QualityOverride = request.QualityOverride;
results.RootFolder = request.RootFolder;
await TvRepository.Update(results);
return results;
}
@ -432,6 +432,19 @@ namespace Ombi.Core.Engine
};
}
public async Task<int> GetTotal()
{
var shouldHide = await HideFromOtherUsers();
if (shouldHide.Hide)
{
return await TvRepository.Get(shouldHide.UserId).CountAsync();
}
else
{
return await TvRepository.Get().CountAsync();
}
}
private async Task<RequestEngineResult> AddExistingRequest(ChildRequests newRequest, TvRequests existingRequest)
{
// Add the child

@ -213,7 +213,7 @@
</div>
<p-paginator [rows]="10" [totalRecords]="10000" (onPageChange)="paginate($event)"></p-paginator>
<p-paginator [rows]="10" [totalRecords]="totalMovies" (onPageChange)="paginate($event)"></p-paginator>
</div>

@ -39,6 +39,7 @@ export class MovieRequestsComponent implements OnInit {
public order: string = "requestedDate";
public reverse = false;
public totalMovies: number = 100;
private currentlyLoaded: number;
private amountToLoad: number;
@ -269,6 +270,7 @@ export class MovieRequestsComponent implements OnInit {
}
private loadInit() {
this.requestService.getTotalMovies().subscribe(x => this.totalMovies = x);
this.requestService.getMovieRequests(this.amountToLoad, 0)
.subscribe(x => {
this.movieRequests = x;

@ -120,6 +120,7 @@
</p-column>
</p-treeTable>
<p-paginator [rows]="10" [totalRecords]="totalTv" (onPageChange)="paginate($event)"></p-paginator>
</div>
<issue-report [movie]="false" [visible]="issuesBarVisible" [title]="issueRequest?.title"

@ -14,7 +14,7 @@ import { AuthService } from "../auth/auth.service";
import { NotificationService, RequestService, SonarrService } from "../services";
import { TreeNode } from "primeng/primeng";
import { IIssueCategory, ISonarrProfile, ISonarrRootFolder, ITvRequests } from "../interfaces";
import { IIssueCategory, IPagenator, ISonarrProfile, ISonarrRootFolder, ITvRequests } from "../interfaces";
@Component({
selector: "tv-requests",
@ -40,6 +40,7 @@ export class TvRequestsComponent implements OnInit {
public sonarrProfiles: ISonarrProfile[] = [];
public sonarrRootFolders: ISonarrRootFolder[] = [];
public totalTv: number = 100;
private currentlyLoaded: number;
private amountToLoad: number;
@ -105,25 +106,22 @@ export class TvRequestsComponent implements OnInit {
}
public ngOnInit() {
this.amountToLoad = 1000;
this.currentlyLoaded = 1000;
this.amountToLoad = 10;
this.currentlyLoaded = 10;
this.tvRequests = [];
this.isAdmin = this.auth.hasRole("admin") || this.auth.hasRole("poweruser");
this.loadInit();
}
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.getTvRequestsTree(this.amountToLoad, this.currentlyLoaded + 1)
.subscribe(x => {
this.tvRequests = x;
this.currentlyLoaded = this.currentlyLoaded + this.amountToLoad;
});
public paginate(event: IPagenator) {
const skipAmount = event.first;
this.requestService.getTvRequestsTree(this.amountToLoad, skipAmount)
.subscribe(x => {
this.tvRequests = x;
this.currentlyLoaded = this.currentlyLoaded + this.amountToLoad;
});
}
public search(text: any) {
@ -197,6 +195,7 @@ export class TvRequestsComponent implements OnInit {
}
private loadInit() {
this.requestService.getTotalTv().subscribe(x => this.totalTv = x);
this.requestService.getTvRequestsTree(this.amountToLoad, 0)
.subscribe(x => {
this.tvRequests = x;

@ -20,6 +20,14 @@ export class RequestService extends ServiceHelpers {
return this.http.post<IRequestEngineResult>(`${this.url}Movie/`, JSON.stringify(movie), {headers: this.headers});
}
public getTotalMovies(): Observable<number> {
return this.http.get<number>(`${this.url}Movie/total`, {headers: this.headers});
}
public getTotalTv(): Observable<number> {
return this.http.get<number>(`${this.url}tv/total`, {headers: this.headers});
}
public requestTv(tv: ITvRequestViewModel): Observable<IRequestEngineResult> {
return this.http.post<IRequestEngineResult>(`${this.url}TV/`, JSON.stringify(tv), {headers: this.headers});
}

@ -37,6 +37,15 @@ namespace Ombi.Controllers
return await MovieRequestEngine.GetRequests(count, position);
}
/// <summary>
/// Gets the total amount of movie requests.
/// </summary>
[HttpGet("movie/total")]
public async Task<int> GetTotalMovies()
{
return await MovieRequestEngine.GetTotal();
}
/// <summary>
/// Gets all movie requests.
/// </summary>
@ -146,6 +155,15 @@ namespace Ombi.Controllers
return await TvRequestEngine.GetRequestsTreeNode(count, position);
}
/// <summary>
/// Gets the total amount of TV requests.
/// </summary>
[HttpGet("tv/total")]
public async Task<int> GetTotalTV()
{
return await TvRequestEngine.GetTotal();
}
/// <summary>
/// Gets the tv requests.
/// </summary>

Loading…
Cancel
Save