Finished the scrolling on the discover page

pull/3895/head
Jamie Rees 6 years ago
parent 961ba4297a
commit b4bf86f03e

@ -13,9 +13,12 @@ namespace Ombi.Core.Engine.Interfaces
Task<IEnumerable<SearchMovieViewModel>> TopRatedMovies();
Task<IEnumerable<SearchMovieViewModel>> UpcomingMovies();
Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies();
Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies(int currentPosition, int amountToLoad);
Task<MovieCollectionsViewModel> GetCollection(int collectionId, string langCode = null);
Task<int> GetTvDbId(int theMovieDbId);
Task<IEnumerable<SearchMovieViewModel>> PopularMovies(int currentlyLoaded, int toLoad);
Task<IEnumerable<SearchMovieViewModel>> TopRatedMovies(int currentlyLoaded, int toLoad);
Task<IEnumerable<SearchMovieViewModel>> UpcomingMovies(int currentlyLoaded, int toLoad);
int ResultLimit { get; set; }
}
}

@ -11,8 +11,11 @@ namespace Ombi.Core.Engine.Interfaces
Task<IEnumerable<SearchTvShowViewModel>> Popular();
Task<IEnumerable<SearchTvShowViewModel>> Popular(int currentlyLoaded, int amountToLoad);
Task<IEnumerable<SearchTvShowViewModel>> Anticipated();
Task<IEnumerable<SearchTvShowViewModel>> Anticipated(int currentlyLoaded, int amountToLoad);
Task<IEnumerable<SearchTvShowViewModel>> MostWatches();
Task<IEnumerable<SearchTvShowViewModel>> Trending();
Task<IEnumerable<SearchTvShowViewModel>> MostWatches(int currentlyLoaded, int amountToLoad);
Task<IEnumerable<SearchTvShowViewModel>> Trending(int currentlyLoaded, int amountToLoad);
int ResultLimit { get; set; }
}
}

@ -22,6 +22,7 @@ using Ombi.Helpers;
using Ombi.Settings.Settings.Models;
using Ombi.Store.Entities;
using TraktApiSharp.Objects.Get.Shows;
using TraktApiSharp.Objects.Get.Shows.Common;
namespace Ombi.Core.Engine
{
@ -149,6 +150,19 @@ namespace Ombi.Core.Engine
return processed;
}
public async Task<IEnumerable<SearchTvShowViewModel>> Anticipated(int currentlyLoaded, int amountToLoad)
{
var pages = PaginationHelper.GetNextPages(currentlyLoaded, amountToLoad, ResultLimit);
var results = new List<TraktMostAnticipatedShow>();
foreach (var pagesToLoad in pages)
{
var apiResult = await TraktApi.GetAnticipatedShows(pagesToLoad.Page, ResultLimit);
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
}
var processed = ProcessResults(results);
return processed;
}
public async Task<IEnumerable<SearchTvShowViewModel>> MostWatches()
{
var result = await Cache.GetOrAdd(CacheKeys.MostWatchesTv, async () => await TraktApi.GetMostWatchesShows(null, ResultLimit), DateTime.Now.AddHours(12));
@ -163,6 +177,32 @@ namespace Ombi.Core.Engine
return processed;
}
public async Task<IEnumerable<SearchTvShowViewModel>> MostWatches(int currentlyLoaded, int amountToLoad)
{
var pages = PaginationHelper.GetNextPages(currentlyLoaded, amountToLoad, ResultLimit);
var results = new List<TraktMostWatchedShow>();
foreach (var pagesToLoad in pages)
{
var apiResult = await TraktApi.GetMostWatchesShows(null, pagesToLoad.Page, ResultLimit);
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
}
var processed = ProcessResults(results);
return processed;
}
public async Task<IEnumerable<SearchTvShowViewModel>> Trending(int currentlyLoaded, int amountToLoad)
{
var pages = PaginationHelper.GetNextPages(currentlyLoaded, amountToLoad, ResultLimit);
var results = new List<TraktTrendingShow>();
foreach (var pagesToLoad in pages)
{
var apiResult = await TraktApi.GetTrendingShows(pagesToLoad.Page, ResultLimit);
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
}
var processed = ProcessResults(results);
return processed;
}
protected IEnumerable<SearchTvShowViewModel> ProcessResults<T>(IEnumerable<T> items)
{
var retVal = new List<SearchTvShowViewModel>();

@ -138,6 +138,37 @@ namespace Ombi.Core.Engine.V2
return null;
}
public async Task<IEnumerable<SearchMovieViewModel>> TopRatedMovies(int currentPosition, int amountToLoad)
{
var langCode = await DefaultLanguageCode(null);
var pages = PaginationHelper.GetNextPages(currentPosition, amountToLoad, _theMovieDbMaxPageItems);
var results = new List<MovieSearchResult>();
foreach (var pagesToLoad in pages)
{
var apiResult = await MovieApi.TopRated(langCode, pagesToLoad.Page);
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
}
return await TransformMovieResultsToResponse(results);
}
public async Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies(int currentPosition, int amountToLoad)
{
var langCode = await DefaultLanguageCode(null);
var pages = PaginationHelper.GetNextPages(currentPosition, amountToLoad, _theMovieDbMaxPageItems);
var results = new List<MovieSearchResult>();
foreach (var pagesToLoad in pages)
{
var apiResult = await MovieApi.NowPlaying(langCode, pagesToLoad.Page);
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
}
return await TransformMovieResultsToResponse(results);
}
/// <summary>
/// Gets upcoming movies.
/// </summary>
@ -157,6 +188,21 @@ namespace Ombi.Core.Engine.V2
return null;
}
public async Task<IEnumerable<SearchMovieViewModel>> UpcomingMovies(int currentPosition, int amountToLoad)
{
var langCode = await DefaultLanguageCode(null);
var pages = PaginationHelper.GetNextPages(currentPosition, amountToLoad, _theMovieDbMaxPageItems);
var results = new List<MovieSearchResult>();
foreach (var pagesToLoad in pages)
{
var apiResult = await MovieApi.Upcoming(langCode, pagesToLoad.Page);
results.AddRange(apiResult.Skip(pagesToLoad.Skip).Take(pagesToLoad.Take));
}
return await TransformMovieResultsToResponse(results);
}
/// <summary>
/// Gets now playing movies.
/// </summary>

@ -9,12 +9,12 @@ namespace Ombi.Api.TheMovieDb
{
Task<MovieResponseDto> GetMovieInformation(int movieId);
Task<MovieResponseDto> GetMovieInformationWithExtraInfo(int movieId, string langCode = "en");
Task<List<MovieSearchResult>> NowPlaying(string languageCode);
Task<List<MovieSearchResult>> PopularMovies(string languageCode);
Task<List<MovieSearchResult>> NowPlaying(string languageCode, int? page = null);
Task<List<MovieSearchResult>> PopularMovies(string languageCode, int? page = null);
Task<List<MovieSearchResult>> SearchMovie(string searchTerm, int? year, string languageCode);
Task<List<TvSearchResult>> SearchTv(string searchTerm);
Task<List<MovieSearchResult>> TopRated(string languageCode);
Task<List<MovieSearchResult>> Upcoming(string languageCode);
Task<List<MovieSearchResult>> TopRated(string languageCode, int? page = null);
Task<List<MovieSearchResult>> Upcoming(string languageCode, int? page = null);
Task<List<MovieSearchResult>> SimilarMovies(int movieId, string langCode);
Task<FindResult> Find(string externalId, ExternalSource source);
Task<TvExternals> GetTvExternals(int theMovieDbId);
@ -25,6 +25,5 @@ namespace Ombi.Api.TheMovieDb
Task<FullMovieInfo> GetFullMovieInfo(int movieId, string langCode);
Task<TheMovieDbContainer<DiscoverMovies>> DiscoverMovies(string langCode, int keywordId);
Task<Collections> GetCollection(string langCode, int collectionId);
Task<List<MovieSearchResult>> PopularMovies(string langageCode, int page);
}
}

@ -156,52 +156,57 @@ namespace Ombi.Api.TheMovieDb
return Mapper.Map<List<MovieSearchResult>>(result.results);
}
public async Task<List<MovieSearchResult>> PopularMovies(string langageCode)
public async Task<List<MovieSearchResult>> PopularMovies(string langageCode, int? page = null)
{
var request = new Request($"movie/popular", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.FullUri = request.FullUri.AddQueryParameter("language", langageCode);
if (page != null)
{
request.FullUri = request.FullUri.AddQueryParameter("page", page.ToString());
}
AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieSearchResult>>(result.results);
}
public async Task<List<MovieSearchResult>> PopularMovies(string langageCode, int page)
{
var request = new Request($"movie/popular", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.FullUri = request.FullUri.AddQueryParameter("language", langageCode);
request.FullUri = request.FullUri.AddQueryParameter("page", page.ToString());
AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieSearchResult>>(result.results);
}
public async Task<List<MovieSearchResult>> TopRated(string langageCode)
public async Task<List<MovieSearchResult>> TopRated(string langageCode, int? page = null)
{
var request = new Request($"movie/top_rated", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.FullUri = request.FullUri.AddQueryParameter("language", langageCode);
if (page != null)
{
request.FullUri = request.FullUri.AddQueryParameter("page", page.ToString());
}
AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieSearchResult>>(result.results);
}
public async Task<List<MovieSearchResult>> Upcoming(string langageCode)
public async Task<List<MovieSearchResult>> Upcoming(string langageCode, int? page = null)
{
var request = new Request($"movie/upcoming", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.FullUri = request.FullUri.AddQueryParameter("language", langageCode);
if (page != null)
{
request.FullUri = request.FullUri.AddQueryParameter("page", page.ToString());
}
AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieSearchResult>>(result.results);
}
public async Task<List<MovieSearchResult>> NowPlaying(string langageCode)
public async Task<List<MovieSearchResult>> NowPlaying(string langageCode, int? page = null)
{
var request = new Request($"movie/now_playing", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.FullUri = request.FullUri.AddQueryParameter("language", langageCode);
if (page != null)
{
request.FullUri = request.FullUri.AddQueryParameter("page", page.ToString());
}
AddRetry(request);
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieSearchResult>>(result.results);

@ -16,8 +16,9 @@
<div *ngIf="discoverResults" class="row full-height discoverResults"
infiniteScroll
[fromRoot]="true"
[infiniteScrollDistance]="1"
[fromRoot]="false"
[infiniteScrollDistance]="0.5"
[infiniteScrollDisabled]="scrollDisabled"
(scrolled)="onScroll()">
<div class="col-xl-2 col-lg-3 col-md-3 col-6 col-sm-4 small-padding" *ngFor="let result of discoverResults">
<discover-card [result]="result"></discover-card>

@ -29,6 +29,7 @@ export class DiscoverComponent implements OnInit {
public upcomingActive: boolean;
public loadingFlag: boolean;
public scrollDisabled: boolean;
private contentLoaded: number;
private isScrolling: boolean = false;
@ -37,14 +38,14 @@ export class DiscoverComponent implements OnInit {
public async ngOnInit() {
this.loading()
this.movies = await this.searchService.popularMoviesByPage(0,12).toPromise();
this.scrollDisabled = true;
this.movies = await this.searchService.popularMoviesByPage(0,12);
this.tvShows = await this.searchService.popularTvByPage(0,12);
this.contentLoaded = 12;
this.createInitialModel();
this.scrollDisabled = false;
}
public async onScroll() {
@ -57,10 +58,18 @@ export class DiscoverComponent implements OnInit {
console.log("SCROLLED!")
this.loading();
if (this.popularActive) {
this.movies = await this.searchService.popularMoviesByPage(this.contentLoaded, 12).toPromise();
this.movies = await this.searchService.popularMoviesByPage(this.contentLoaded, 12);
this.tvShows = await this.searchService.popularTvByPage(this.contentLoaded, 12);
this.contentLoaded += 12;
}
if(this.trendingActive) {
this.movies = await this.searchService.nowPlayingMoviesByPage(this.contentLoaded, 12);
this.tvShows = await this.searchService.trendingTvByPage(this.contentLoaded, 12);
}
if(this.upcomingActive) {
this.movies = await this.searchService.upcomingMoviesByPage(this.contentLoaded, 12);
this.tvShows = await this.searchService.anticipatedTvByPage(this.contentLoaded, 12);
}
this.contentLoaded += 12;
this.createModel();
this.isScrolling = false;
@ -69,44 +78,51 @@ export class DiscoverComponent implements OnInit {
public async popular() {
this.clear();
this.scrollDisabled = true;
this.isScrolling = false;
this.contentLoaded = 12;
this.loading()
this.popularActive = true;
this.trendingActive = false;
this.upcomingActive = false;
this.movies = await this.searchService.popularMoviesByPage(0, 12).toPromise();
this.movies = await this.searchService.popularMoviesByPage(0, 12);
this.tvShows = await this.searchService.popularTvByPage(0, 12);
this.createModel();
this.scrollDisabled = false;
}
public async trending() {
this.clear();
this.scrollDisabled = true;
this.isScrolling = false;
this.contentLoaded = 12;
this.loading()
this.popularActive = false;
this.trendingActive = true;
this.upcomingActive = false;
this.movies = await this.searchService.nowPlayingMovies().toPromise();
this.tvShows = await this.searchService.trendingTv().toPromise();
this.movies = await this.searchService.nowPlayingMoviesByPage(0, 12);
this.tvShows = await this.searchService.trendingTvByPage(0, 12);
this.createModel();
this.scrollDisabled = false;
}
public async upcoming() {
this.clear();
this.scrollDisabled = true;
this.isScrolling = false;
this.contentLoaded = 12;
this.loading()
this.popularActive = false;
this.trendingActive = false;
this.upcomingActive = true;
this.movies = await this.searchService.upcomingMovies().toPromise();
this.tvShows = await this.searchService.anticipatedTv().toPromise();
this.movies = await this.searchService.upcomingMoviesByPage(0, 12);
this.tvShows = await this.searchService.anticipatedTvByPage(0, 12);
this.createModel();
this.scrollDisabled = false;
}
private createModel() {

@ -34,17 +34,24 @@ export class SearchV2Service extends ServiceHelpers {
return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/Popular`);
}
public popularMoviesByPage(currentlyLoaded: number, toLoad: number): Observable<ISearchMovieResult[]> {
return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/Popular/${currentlyLoaded}/${toLoad}`);
public popularMoviesByPage(currentlyLoaded: number, toLoad: number): Promise<ISearchMovieResult[]> {
return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/Popular/${currentlyLoaded}/${toLoad}`).toPromise();
}
public upcomingMovies(): Observable<ISearchMovieResult[]> {
return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/upcoming`);
}
public upcomingMoviesByPage(currentlyLoaded: number, toLoad: number): Promise<ISearchMovieResult[]> {
return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/upcoming/${currentlyLoaded}/${toLoad}`).toPromise();
}
public nowPlayingMovies(): Observable<ISearchMovieResult[]> {
return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/nowplaying`);
}
public nowPlayingMoviesByPage(currentlyLoaded: number, toLoad: number): Promise<ISearchMovieResult[]> {
return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/nowplaying/${currentlyLoaded}/${toLoad}`).toPromise();
}
public topRatedMovies(): Observable<ISearchMovieResult[]> {
return this.http.get<ISearchMovieResult[]>(`${this.url}/Movie/toprated`);
@ -64,10 +71,17 @@ export class SearchV2Service extends ServiceHelpers {
public anticipatedTv(): Observable<ISearchTvResult[]> {
return this.http.get<ISearchTvResult[]>(`${this.url}/Tv/anticipated`, { headers: this.headers });
}
public anticipatedTvByPage(currentlyLoaded: number, toLoad: number): Promise<ISearchTvResult[]> {
return this.http.get<ISearchTvResult[]>(`${this.url}/Tv/anticipated/${currentlyLoaded}/${toLoad}`, { headers: this.headers }).toPromise();
}
public trendingTv(): Observable<ISearchTvResult[]> {
return this.http.get<ISearchTvResult[]>(`${this.url}/Tv/trending`, { headers: this.headers });
}
public trendingTvByPage(currentlyLoaded: number, toLoad: number): Promise<ISearchTvResult[]> {
return this.http.get<ISearchTvResult[]>(`${this.url}/Tv/trending/${currentlyLoaded}/${toLoad}`, { headers: this.headers }).toPromise();
}
public getTvInfo(tvdbid: number): Promise<ISearchTvResultV2> {
return this.http.get<ISearchTvResultV2>(`${this.url}/Tv/${tvdbid}`, { headers: this.headers }).toPromise();

@ -148,6 +148,19 @@ namespace Ombi.Controllers.V2
return await _movieEngineV2.NowPlayingMovies();
}
/// <summary>
/// Returns Now Playing Movies by page
/// </summary>
/// <remarks>We use TheMovieDb as the Movie Provider</remarks>
/// <returns></returns>
[HttpGet("movie/nowplaying/{currentPosition}/{amountToLoad}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesDefaultResponseType]
public async Task<IEnumerable<SearchMovieViewModel>> NowPlayingMovies(int currentPosition, int amountToLoad)
{
return await _movieEngineV2.NowPlayingMovies(currentPosition, amountToLoad);
}
/// <summary>
/// Returns top rated movies.
/// </summary>
@ -161,6 +174,19 @@ namespace Ombi.Controllers.V2
return await _movieEngineV2.TopRatedMovies();
}
/// <summary>
/// Returns top rated movies by page.
/// </summary>
/// <returns></returns>
/// <remarks>We use TheMovieDb as the Movie Provider</remarks>
[HttpGet("movie/toprated/{currentPosition}/{amountToLoad}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesDefaultResponseType]
public async Task<IEnumerable<SearchMovieViewModel>> TopRatedMovies(int currentPosition, int amountToLoad)
{
return await _movieEngineV2.TopRatedMovies(currentPosition, amountToLoad);
}
/// <summary>
/// Returns Upcoming movies.
/// </summary>
@ -174,6 +200,19 @@ namespace Ombi.Controllers.V2
return await _movieEngineV2.UpcomingMovies();
}
/// <summary>
/// Returns Upcoming movies by page.
/// </summary>
/// <remarks>We use TheMovieDb as the Movie Provider</remarks>
/// <returns></returns>
[HttpGet("movie/upcoming/{currentPosition}/{amountToLoad}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesDefaultResponseType]
public async Task<IEnumerable<SearchMovieViewModel>> UpcomingMovies(int currentPosition, int amountToLoad)
{
return await _movieEngineV2.UpcomingMovies(currentPosition, amountToLoad);
}
/// <summary>
/// Returns Popular Tv Shows
/// </summary>
@ -201,7 +240,7 @@ namespace Ombi.Controllers.V2
}
/// <summary>
/// Returns most Anticiplateds tv shows.
/// Returns most Anticipated tv shows.
/// </summary>
/// <remarks>We use Trakt.tv as the Provider</remarks>
/// <returns></returns>
@ -213,6 +252,19 @@ namespace Ombi.Controllers.V2
return await _tvSearchEngine.Anticipated();
}
/// <summary>
/// Returns most Anticipated tv shows by page.
/// </summary>
/// <remarks>We use Trakt.tv as the Provider</remarks>
/// <returns></returns>
[HttpGet("tv/anticipated/{currentPosition}/{amountToLoad}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesDefaultResponseType]
public async Task<IEnumerable<SearchTvShowViewModel>> AnticipatedTv(int currentPosition, int amountToLoad)
{
return await _tvSearchEngine.Anticipated(currentPosition, amountToLoad);
}
/// <summary>
/// Returns Most watched shows.
@ -227,6 +279,19 @@ namespace Ombi.Controllers.V2
return await _tvSearchEngine.MostWatches();
}
/// <summary>
/// Returns Most watched shows by page.
/// </summary>
/// <remarks>We use Trakt.tv as the Provider</remarks>
/// <returns></returns>
[HttpGet("tv/mostwatched/{currentPosition}/{amountToLoad}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesDefaultResponseType]
public async Task<IEnumerable<SearchTvShowViewModel>> MostWatched(int currentPosition, int amountToLoad)
{
return await _tvSearchEngine.MostWatches(currentPosition, amountToLoad);
}
/// <summary>
/// Returns trending shows
/// </summary>
@ -239,5 +304,18 @@ namespace Ombi.Controllers.V2
{
return await _tvSearchEngine.Trending();
}
/// <summary>
/// Returns trending shows by page
/// </summary>
/// <remarks>We use Trakt.tv as the Provider</remarks>
/// <returns></returns>
[HttpGet("tv/trending/{currentPosition}/{amountToLoad}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesDefaultResponseType]
public async Task<IEnumerable<SearchTvShowViewModel>> Trending(int currentPosition, int amountToLoad)
{
return await _tvSearchEngine.Trending(currentPosition, amountToLoad);
}
}
}
Loading…
Cancel
Save