From a21db34d603e05d8cbd71c4da001b6276798110c Mon Sep 17 00:00:00 2001 From: tidusjar Date: Mon, 10 Apr 2017 22:18:27 +0100 Subject: [PATCH] More on the search and requests page. It's almost there for movies. Need to add some filtering logic #865 --- .../Engine/Interfaces/IMovieEngine.cs | 1 + Ombi/Ombi.Core/Engine/MovieEngine.cs | 69 ++++++++--- Ombi/Ombi.Core/Engine/RequestEngine.cs | 16 +++ Ombi/Ombi/Controllers/SearchController.cs | 6 + Ombi/Ombi/Styles/base.scss | 2 +- Ombi/Ombi/gulpfile.js | 11 +- Ombi/Ombi/package.json | 1 + Ombi/Ombi/wwwroot/app/app.component.html | 6 +- .../app/requests/request.component.html | 117 +++++++++--------- .../wwwroot/app/requests/request.component.ts | 2 + .../wwwroot/app/search/search.component.html | 14 +-- .../wwwroot/app/search/search.component.ts | 32 ++++- .../wwwroot/app/services/search.service.ts | 3 + 13 files changed, 187 insertions(+), 93 deletions(-) diff --git a/Ombi/Ombi.Core/Engine/Interfaces/IMovieEngine.cs b/Ombi/Ombi.Core/Engine/Interfaces/IMovieEngine.cs index fcd397093..e4bc37ace 100644 --- a/Ombi/Ombi.Core/Engine/Interfaces/IMovieEngine.cs +++ b/Ombi/Ombi.Core/Engine/Interfaces/IMovieEngine.cs @@ -11,5 +11,6 @@ namespace Ombi.Core Task> ProcessMovieSearch(string search); Task> TopRatedMovies(); Task> UpcomingMovies(); + Task> LookupImdbInformation(IEnumerable movies); } } \ No newline at end of file diff --git a/Ombi/Ombi.Core/Engine/MovieEngine.cs b/Ombi/Ombi.Core/Engine/MovieEngine.cs index fa6eae68a..d9b3c9c31 100644 --- a/Ombi/Ombi.Core/Engine/MovieEngine.cs +++ b/Ombi/Ombi.Core/Engine/MovieEngine.cs @@ -23,6 +23,57 @@ namespace Ombi.Core.Engine private IRequestService RequestService { get; } private IMovieDbApi MovieApi { get; } + public async Task> LookupImdbInformation(IEnumerable movies) + { + var retVal = new List(); + Dictionary dbMovies = await RequestedMovies(); + foreach (var m in movies) + { + + var movieInfo = await MovieApi.GetMovieInformationWithVideo(m.Id); + var viewMovie = new SearchMovieViewModel + { + Adult = movieInfo.adult, + BackdropPath = movieInfo.backdrop_path, + Id = movieInfo.id, + OriginalLanguage = movieInfo.original_language, + OriginalTitle = movieInfo.original_title, + Overview = movieInfo.overview, + Popularity = movieInfo.popularity, + PosterPath = movieInfo.poster_path, + ReleaseDate = + string.IsNullOrEmpty(movieInfo.release_date) + ? DateTime.MinValue + : DateTime.Parse(movieInfo.release_date), + Title = movieInfo.title, + Video = movieInfo.video, + VoteAverage = movieInfo.vote_average, + VoteCount = movieInfo.vote_count, + ImdbId = movieInfo?.imdb_id, + Homepage = movieInfo?.homepage + }; + retVal.Add(viewMovie); + // TODO needs to be careful about this, it's adding extra time to search... + // https://www.themoviedb.org/talk/5807f4cdc3a36812160041f2 + //var videoId = movieInfo?.video ?? false + // ? movieInfo?.videos?.results?.FirstOrDefault()?.key + // : string.Empty; + + //viewMovie.Trailer = string.IsNullOrEmpty(videoId) + // ? string.Empty + // : $"https://www.youtube.com/watch?v={videoId}"; + if (dbMovies.ContainsKey(movieInfo.id) /*&& canSee*/) // compare to the requests db + { + var dbm = dbMovies[movieInfo.id]; + + viewMovie.Requested = true; + viewMovie.Approved = dbm.Approved; + viewMovie.Available = dbm.Available; + } + } + return retVal; + } + public async Task> ProcessMovieSearch(string search) { var api = new TheMovieDbApi.TheMovieDbApi(); @@ -103,25 +154,7 @@ namespace Ombi.Core.Engine }; viewMovies.Add(viewMovie); - var counter = 0; - if (counter <= 5) // Let's only do it for the first 5 items - { - var movieInfo = await MovieApi.GetMovieInformationWithVideo(movie.id); - - // TODO needs to be careful about this, it's adding extra time to search... - // https://www.themoviedb.org/talk/5807f4cdc3a36812160041f2 - viewMovie.ImdbId = movieInfo?.imdb_id; - viewMovie.Homepage = movieInfo?.homepage; - //var videoId = movieInfo?.video ?? false - // ? movieInfo?.videos?.results?.FirstOrDefault()?.key - // : string.Empty; - //viewMovie.Trailer = string.IsNullOrEmpty(videoId) - // ? string.Empty - // : $"https://www.youtube.com/watch?v={videoId}"; - - counter++; - } // var canSee = CanUserSeeThisRequest(viewMovie.Id, Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests), dbMovies); diff --git a/Ombi/Ombi.Core/Engine/RequestEngine.cs b/Ombi/Ombi.Core/Engine/RequestEngine.cs index 3cf325122..2bb21d183 100644 --- a/Ombi/Ombi.Core/Engine/RequestEngine.cs +++ b/Ombi/Ombi.Core/Engine/RequestEngine.cs @@ -257,6 +257,22 @@ namespace Ombi.Core.Engine var allRequests = await RequestService.GetAllAsync(); var results = allRequests.FirstOrDefault(x => x.Id == request.Id); + results.Approved = request.Approved; + results.Available = request.Available; + results.Denied = request.Denied; + results.DeniedReason = request.DeniedReason; + //results.AdminNote = request.AdminNote; + results.ImdbId = request.ImdbId; + results.Episodes = request.Episodes?.ToList() ?? new List(); + results.IssueId = request.IssueId; + //results.Issues = request.Issues; + //results.OtherMessage = request.OtherMessage; + results.Overview = request.Overview; + results.PosterPath = request.PosterPath; + results.RequestedUsers = request.RequestedUsers?.ToList() ?? new List(); + //results.RootFolderSelected = request.RootFolderSelected; + + var model = RequestService.UpdateRequest(results); return MapToVm(new List{model}).FirstOrDefault(); } diff --git a/Ombi/Ombi/Controllers/SearchController.cs b/Ombi/Ombi/Controllers/SearchController.cs index 3001791a4..c7d48b8b9 100644 --- a/Ombi/Ombi/Controllers/SearchController.cs +++ b/Ombi/Ombi/Controllers/SearchController.cs @@ -23,6 +23,12 @@ namespace Ombi.Controllers return await MovieEngine.ProcessMovieSearch(searchTerm); } + [HttpPost("movie/extrainfo")] + public async Task> GetImdbInfo([FromBody]IEnumerable model) + { + return await MovieEngine.LookupImdbInformation(model); + } + [HttpGet("movie/popular")] public async Task> Popular() { diff --git a/Ombi/Ombi/Styles/base.scss b/Ombi/Ombi/Styles/base.scss index 095d7d2ab..7755b64e6 100644 --- a/Ombi/Ombi/Styles/base.scss +++ b/Ombi/Ombi/Styles/base.scss @@ -692,7 +692,7 @@ $border-radius: 10px; // Bootstrap overrides html { - font-size: 10px; + font-size: 16px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } body { diff --git a/Ombi/Ombi/gulpfile.js b/Ombi/Ombi/gulpfile.js index 1e5496d7c..c4697e4c7 100644 --- a/Ombi/Ombi/gulpfile.js +++ b/Ombi/Ombi/gulpfile.js @@ -32,6 +32,7 @@ var paths = { '@angular/http', '@angular/router', '@angular/forms', + ], dest: './lib' }, @@ -122,7 +123,7 @@ var paths = { { name: "angular2-infinite-scroll", src: ['./node_modules/angular2-infinite-scroll/**/*.js', '!./node_modules/angular2-infinite-scroll/bundles/**/*.js'], - dest:"./lib/angular2-infinite-scroll/" + dest: "./lib/angular2-infinite-scroll/" }, ], sass: { // Simple sass->css compilation @@ -273,11 +274,17 @@ gulp.task('typescript', function () { return run('tsc').exec(); }); +uglify().on('error', + function(err) { + gutil.log(gutil.colors.red('[Error]'), err.toString()); + this.emit('end'); + }); + gulp.task('fullvar', () => { global.full = true }); gulp.task('copy', ['lib', 'libcss', 'libfonts', 'libimages', 'npm', 'modules']); gulp.task('compile', callback => runSequence('copy', 'sass', callback)); gulp.task('build', callback => runSequence('compile', 'bundle', callback)); -gulp.task('full', callback => runSequence('clean', 'compile', callback)); +gulp.task('full', callback => runSequence(/*'clean',*/ 'compile', callback)); // Use this in a build server environment to compile and bundle everything gulp.task('publish', callback => runSequence('fullvar', 'full', 'typescript', 'bundle', callback)); diff --git a/Ombi/Ombi/package.json b/Ombi/Ombi/package.json index 02951242e..f74d68e3e 100644 --- a/Ombi/Ombi/package.json +++ b/Ombi/Ombi/package.json @@ -17,6 +17,7 @@ "@types/jquery": "^2.0.33", "@types/systemjs": "^0.20.2", "angular2-infinite-scroll": "^0.3.4", + "angular2-moment": "^1.3.3", "bootstrap": "3.3.6", "core-js": "^2.4.1", "del": "^2.2.2", diff --git a/Ombi/Ombi/wwwroot/app/app.component.html b/Ombi/Ombi/wwwroot/app/app.component.html index e9d555ec4..a75b30406 100644 --- a/Ombi/Ombi/wwwroot/app/app.component.html +++ b/Ombi/Ombi/wwwroot/app/app.component.html @@ -14,13 +14,13 @@ diff --git a/Ombi/Ombi/wwwroot/app/requests/request.component.html b/Ombi/Ombi/wwwroot/app/requests/request.component.html index f743e16d4..4c43df249 100644 --- a/Ombi/Ombi/wwwroot/app/requests/request.component.html +++ b/Ombi/Ombi/wwwroot/app/requests/request.component.html @@ -1,5 +1,5 @@ 

Requests

- +

Below you can see yours and all other requests, as well as their download and approval status.

@@ -26,8 +26,8 @@

@@ -38,11 +38,11 @@
Request status: - Request Available - Processing Request + Available + Processing Request Request Denied - Pending Approval + Pending Approval
@@ -51,8 +51,8 @@
-
Release Date: {{request.releaseDate}}
- +
Release Date: {{request.releaseDate | date}}
+
Requested By: {{request.requestedUsers}}
-
Requested Date: {{request.requestedDate}}
+
Requested Date: {{request.requestedDate | date}}
-
- +
- + + - - - -
- - + + {{#if_eq hasRootFolders true}}
- - +
-
-
+ {{/if_eq}} + --> - - - +
+
+ + +
+ + + +
+
+
+ +
+ +
+ +
+ + +
- + @@ -163,11 +168,11 @@ diff --git a/Ombi/Ombi/wwwroot/app/requests/request.component.ts b/Ombi/Ombi/wwwroot/app/requests/request.component.ts index 3f7d96e51..1ffd2f80b 100644 --- a/Ombi/Ombi/wwwroot/app/requests/request.component.ts +++ b/Ombi/Ombi/wwwroot/app/requests/request.component.ts @@ -66,11 +66,13 @@ export class RequestComponent implements OnInit { changeAvailability(request: IRequestModel, available: boolean) { request.available = available; + this.updateRequest(request); } approve(request: IRequestModel) { request.approved = true; + request.denied = false; this.updateRequest(request); } diff --git a/Ombi/Ombi/wwwroot/app/search/search.component.html b/Ombi/Ombi/wwwroot/app/search/search.component.html index 1ef35faf1..464e08e31 100644 --- a/Ombi/Ombi/wwwroot/app/search/search.component.html +++ b/Ombi/Ombi/wwwroot/app/search/search.component.html @@ -1,5 +1,5 @@ 

Search

-

Search Paragraph

+

Want to watch something that is not currently available?! No problem! Just search for it below and request it!


@@ -137,17 +137,15 @@ Release Date: {{result.releaseDate | date: 'dd/MM/yyyy'}} - @UI.Search_Available - - @UI.Search_Processing_Request - -
+ Available + Processing Request +
diff --git a/Ombi/Ombi/wwwroot/app/search/search.component.ts b/Ombi/Ombi/wwwroot/app/search/search.component.ts index 20a5a6a7a..fc61a6651 100644 --- a/Ombi/Ombi/wwwroot/app/search/search.component.ts +++ b/Ombi/Ombi/wwwroot/app/search/search.component.ts @@ -33,7 +33,13 @@ export class SearchComponent implements OnInit { this.clearResults(); return; } - this.searchService.searchMovie(this.searchText).subscribe(x => this.movieResults = x); + this.searchService.searchMovie(this.searchText).subscribe(x => { + this.movieResults = x; + + // Now let's load some exta info including IMDBId + // This way the search is fast at displaying results. + this.getExtaInfo(); + }); }); } @@ -66,19 +72,35 @@ export class SearchComponent implements OnInit { popularMovies() { this.clearResults(); - this.searchService.popularMovies().subscribe(x => this.movieResults = x); + this.searchService.popularMovies().subscribe(x => { + this.movieResults = x; + this.getExtaInfo(); + }); } nowPlayingMovies() { this.clearResults(); - this.searchService.nowPlayingMovies().subscribe(x => this.movieResults = x); + this.searchService.nowPlayingMovies().subscribe(x => { + this.movieResults = x; + this.getExtaInfo(); + }); } topRatedMovies() { this.clearResults(); - this.searchService.topRatedMovies().subscribe(x => this.movieResults = x); + this.searchService.topRatedMovies().subscribe(x => { + this.movieResults = x; + this.getExtaInfo(); + }); } upcomingMovies() { this.clearResults(); - this.searchService.upcomignMovies().subscribe(x => this.movieResults = x); + this.searchService.upcomignMovies().subscribe(x => { + this.movieResults = x; + this.getExtaInfo(); + }); + } + + private getExtaInfo() { + this.searchService.extraInfo(this.movieResults).subscribe(m => this.movieResults = m); } private clearResults() { diff --git a/Ombi/Ombi/wwwroot/app/services/search.service.ts b/Ombi/Ombi/wwwroot/app/services/search.service.ts index a9de2ddfe..f0abe17e0 100644 --- a/Ombi/Ombi/wwwroot/app/services/search.service.ts +++ b/Ombi/Ombi/wwwroot/app/services/search.service.ts @@ -27,4 +27,7 @@ export class SearchService extends ServiceHelpers { topRatedMovies(): Observable { return this.http.get(`${this.url}/Movie/toprated`).map(this.extractData); } + extraInfo(movies: ISearchMovieResult[]): Observable { + return this.http.post(`${this.url}/Movie/extrainfo`, JSON.stringify(movies), { headers: this.headers }).map(this.extractData); + } } \ No newline at end of file