diff --git a/RequestPlex.Api/TheMovieDbApi.cs b/RequestPlex.Api/TheMovieDbApi.cs index 9fd1e544c..6ee80ab27 100644 --- a/RequestPlex.Api/TheMovieDbApi.cs +++ b/RequestPlex.Api/TheMovieDbApi.cs @@ -5,6 +5,7 @@ using TMDbLib.Client; using TMDbLib.Objects.General; using TMDbLib.Objects.Movies; using TMDbLib.Objects.Search; +using TMDbLib.Objects.TvShows; namespace RequestPlex.Api { @@ -39,5 +40,17 @@ namespace RequestPlex.Api var movies = await Client.GetMovieList(MovieListType.Upcoming); return movies.Results; } + + public async Task GetMovieInformation(int tmdbId) + { + var movies = await Client.GetMovie(tmdbId); + return movies; + } + + public async Task GetTvShowInformation(int tmdbId) + { + var show = await Client.GetTvShow(tmdbId); + return show; + } } } diff --git a/RequestPlex.Core/RequestPlex.Core.csproj b/RequestPlex.Core/RequestPlex.Core.csproj index 76b5f7074..62122a746 100644 --- a/RequestPlex.Core/RequestPlex.Core.csproj +++ b/RequestPlex.Core/RequestPlex.Core.csproj @@ -57,6 +57,9 @@ + + ..\packages\TMDbLib.0.9.0.0-alpha\lib\net45\TMDbLib.dll + @@ -74,6 +77,10 @@ + + {8CB8D235-2674-442D-9C6A-35FCAEEB160D} + RequestPlex.Api + {1252336D-42A3-482A-804C-836E60173DFA} RequestPlex.Helpers diff --git a/RequestPlex.Core/SettingsService.cs b/RequestPlex.Core/SettingsService.cs index bb12e0d21..1362e4125 100644 --- a/RequestPlex.Core/SettingsService.cs +++ b/RequestPlex.Core/SettingsService.cs @@ -24,10 +24,12 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ************************************************************************/ #endregion +using System; using System.Linq; using Mono.Data.Sqlite; +using RequestPlex.Api; using RequestPlex.Store; namespace RequestPlex.Core @@ -47,12 +49,38 @@ namespace RequestPlex.Core public void AddRequest(int tmdbid, RequestType type) { - var model = new RequestedModel + var api = new TheMovieDbApi(); + var model = new RequestedModel(); + if (type == RequestType.Movie) { - Tmdbid = tmdbid, - Type = type - }; + var movieInfo = api.GetMovieInformation(tmdbid).Result; + model = new RequestedModel + { + Tmdbid = tmdbid, + Type = type, + Overview = movieInfo.Overview, + ImdbId = movieInfo.ImdbId, + PosterPath = "http://image.tmdb.org/t/p/w150/" + movieInfo.PosterPath, + Title = movieInfo.Title, + ReleaseDate = movieInfo.ReleaseDate ?? DateTime.MinValue + }; + } + else + { + var showInfo = api.GetTvShowInformation(tmdbid).Result; + + model = new RequestedModel + { + Tmdbid = tmdbid, + Type = type, + Overview = showInfo.Overview, + //ImdbId = showInfo.ImdbId, //TODO where's the IMDBId? + PosterPath = "http://image.tmdb.org/t/p/w150/" + showInfo.PosterPath, + Title = showInfo.Name, + ReleaseDate = showInfo.FirstAirDate ?? DateTime.MinValue + }; + } var db = new DbConfiguration(new SqliteFactory()); var repo = new GenericRepository(db); diff --git a/RequestPlex.Core/UserMapper.cs b/RequestPlex.Core/UserMapper.cs index 083aba90b..ae70167a1 100644 --- a/RequestPlex.Core/UserMapper.cs +++ b/RequestPlex.Core/UserMapper.cs @@ -27,8 +27,6 @@ using System; using System.Linq; -using Mono.Data.Sqlite; - using Nancy; using Nancy.Authentication.Forms; using Nancy.Security; @@ -63,7 +61,6 @@ namespace RequestPlex.Core public static Guid? ValidateUser(string username, string password) { - var db = new DbConfiguration(new SqliteFactory()); var repo = new UserRepository(Db); var users = repo.GetAll(); var userRecord = users.FirstOrDefault(u => u.UserName.Equals(username, StringComparison.InvariantCultureIgnoreCase) && u.Password.Equals(password)); // TODO hashing @@ -78,7 +75,6 @@ namespace RequestPlex.Core public static bool DoUsersExist() { - var db = new DbConfiguration(new SqliteFactory()); var repo = new UserRepository(Db); var users = repo.GetAll(); return users.Any(); @@ -86,7 +82,6 @@ namespace RequestPlex.Core public static Guid? CreateUser(string username, string password) { - var db = new DbConfiguration(new SqliteFactory()); var repo = new UserRepository(Db); var userModel = new UserModel { UserName = username, User = Guid.NewGuid().ToString(), Password = password }; diff --git a/RequestPlex.Store/RequestedModel.cs b/RequestPlex.Store/RequestedModel.cs index 3f594c613..1b4cfb66e 100644 --- a/RequestPlex.Store/RequestedModel.cs +++ b/RequestPlex.Store/RequestedModel.cs @@ -1,4 +1,6 @@ -using Dapper.Contrib.Extensions; +using System; + +using Dapper.Contrib.Extensions; namespace RequestPlex.Store { @@ -7,6 +9,11 @@ namespace RequestPlex.Store { // ReSharper disable once IdentifierTypo public int Tmdbid { get; set; } + public string ImdbId { get; set; } + public string Overview { get; set; } + public string Title { get; set; } + public string PosterPath { get; set; } + public DateTime ReleaseDate { get; set; } public RequestType Type { get; set; } } diff --git a/RequestPlex.Store/SqlTables.sql b/RequestPlex.Store/SqlTables.sql index 0df12cec5..16d66320c 100644 --- a/RequestPlex.Store/SqlTables.sql +++ b/RequestPlex.Store/SqlTables.sql @@ -20,7 +20,12 @@ CREATE TABLE IF NOT EXISTS Requested ( Id INTEGER PRIMARY KEY AUTOINCREMENT, Type INTEGER NOT NULL, - Tmdbid INTEGER NOT NULL + Tmdbid INTEGER NOT NULL, + ImdbId varchar(50) NOT NULL, + Overview varchar(50) NOT NULL, + Title varchar(50) NOT NULL, + PosterPath varchar(50) NOT NULL, + ReleaseDate varchar(50) NOT NULL ); CREATE TABLE IF NOT EXISTS GlobalSettings diff --git a/RequestPlex.UI/Bootstrapper.cs b/RequestPlex.UI/Bootstrapper.cs index 75e06ebaf..1995c6d1f 100644 --- a/RequestPlex.UI/Bootstrapper.cs +++ b/RequestPlex.UI/Bootstrapper.cs @@ -35,6 +35,7 @@ namespace RequestPlex.UI container.Register, SettingsServiceV2>(); + container.Register, GenericRepository>(); diff --git a/RequestPlex.UI/Content/requests.js b/RequestPlex.UI/Content/requests.js new file mode 100644 index 000000000..15295a169 --- /dev/null +++ b/RequestPlex.UI/Content/requests.js @@ -0,0 +1,71 @@ +Handlebars.registerHelper('if_eq', function (a, b, opts) { + if (a == b) + return opts.fn(this); + else + return opts.inverse(this); +}); + +var searchSource = $("#search-template").html(); +var searchTemplate = Handlebars.compile(searchSource); +var movieTimer = 0; +var tvimer = 0; + +movieLoad(); +tvLoad(); + + +function movieLoad() { + $("#movieList").html(""); + + $.ajax("/requests/movies/").success(function (results) { + results.forEach(function (result) { + var context = buildMovieRequestContext(result); + + var html = searchTemplate(context); + $("#movieList").append(html); + }); + }); +}; + +function tvLoad() { + $("#tvList").html(""); + + $.ajax("/requests/tvshows/").success(function (results) { + results.forEach(function (result) { + var context = buildTvShowRequestContext(result); + var html = searchTemplate(context); + $("#tvList").append(html); + }); + }); +}; + +function buildMovieRequestContext(result) { + var date = new Date(result.releaseDate); + var year = date.getFullYear(); + var context = { + posterPath: result.posterPath, + id: result.tmdbid, + title: result.title, + overview: result.overview, + year: year, + type: "movie" + }; + + return context; +} + +function buildTvShowRequestContext(result) { + var date = new Date(result.releaseDate); + var year = date.getFullYear(); + var context = { + posterPath: result.posterPath, + id: result.tmdbid, + title: result.name, + overview: result.overview, + voteCount: result.voteCount, + voteAverage: result.voteAverage, + year: year, + type: "tv" + }; + return context; +} diff --git a/RequestPlex.UI/Content/search.js b/RequestPlex.UI/Content/search.js index 4849648d9..817c9ca6e 100644 --- a/RequestPlex.UI/Content/search.js +++ b/RequestPlex.UI/Content/search.js @@ -25,18 +25,15 @@ $("#tvSearchContent").keypress(function (e) { }); $(document).on("click", ".dropdownTv", function (e) { - var formData = []; + e.preventDefault(); console.log(e.target.id); var $form = $('#form'+e.target.id); var data = $form.serialize(); var seasons = $(this).attr("season-select"); console.log(data); - formData.push(data); if (seasons === "1") { - formData.push("latest=true"); - } else { - data.latest = false; + data = data + "&latest=true"; } $.ajax({ @@ -60,7 +57,7 @@ $(document).on("click", ".dropdownTv", function (e) { }); -$(document).on("click", ".requesttv", function (e) { +$(document).on("click", ".requestMovie", function (e) { e.preventDefault(); console.log(e.target.id); var $form = $('#form' + e.target.id); @@ -114,35 +111,3 @@ function tvSearch() { }); }; -function buildMovieContext(result) { - var date = new Date(result.releaseDate); - var year = date.getFullYear(); - var context = { - posterPath: result.posterPath, - id: result.id, - title: result.title, - overview: result.overview, - voteCount: result.voteCount, - voteAverage: result.voteAverage, - year: year, - type : "movie" - }; - - return context; -} - -function buildTvShowContext(result) { - var date = new Date(result.firstAirDate); - var year = date.getFullYear(); - var context = { - posterPath: result.posterPath, - id: result.id, - title: result.name, - overview: result.overview, - voteCount: result.voteCount, - voteAverage: result.voteAverage, - year: year, - type: "tv" - }; - return context; -} diff --git a/RequestPlex.UI/Content/site.js b/RequestPlex.UI/Content/site.js index 331957fd0..4c05770ee 100644 --- a/RequestPlex.UI/Content/site.js +++ b/RequestPlex.UI/Content/site.js @@ -7,4 +7,37 @@ // settings type: type }); -} \ No newline at end of file +} + +function buildMovieContext(result) { + var date = new Date(result.releaseDate); + var year = date.getFullYear(); + var context = { + posterPath: result.posterPath, + id: result.id, + title: result.title, + overview: result.overview, + voteCount: result.voteCount, + voteAverage: result.voteAverage, + year: year, + type: "movie" + }; + + return context; +} + +function buildTvShowContext(result) { + var date = new Date(result.firstAirDate); + var year = date.getFullYear(); + var context = { + posterPath: result.posterPath, + id: result.id, + title: result.name, + overview: result.overview, + voteCount: result.voteCount, + voteAverage: result.voteAverage, + year: year, + type: "tv" + }; + return context; +} diff --git a/RequestPlex.UI/Modules/IndexModule.cs b/RequestPlex.UI/Modules/IndexModule.cs index 50519141d..e71f1077e 100644 --- a/RequestPlex.UI/Modules/IndexModule.cs +++ b/RequestPlex.UI/Modules/IndexModule.cs @@ -1,4 +1,6 @@ using Nancy; +using Nancy.Extensions; +using Nancy.Responses; namespace RequestPlex.UI.Modules { @@ -6,8 +8,8 @@ namespace RequestPlex.UI.Modules { public IndexModule() { - Get["/"] = parameters => View["Index"]; - Get["/Index"] = parameters => View["Index"]; + Get["/"] = parameters => Context.GetRedirect("~/search"); + Get["/Index"] = parameters => Context.GetRedirect("~/search"); } } } \ No newline at end of file diff --git a/RequestPlex.UI/Modules/RequestsModule.cs b/RequestPlex.UI/Modules/RequestsModule.cs index 2906d23eb..8f50becbe 100644 --- a/RequestPlex.UI/Modules/RequestsModule.cs +++ b/RequestPlex.UI/Modules/RequestsModule.cs @@ -1,28 +1,43 @@ -using Nancy; +using System.Linq; +using Nancy; +using Nancy.Responses.Negotiation; + +using RequestPlex.Api; using RequestPlex.Core; using RequestPlex.Core.SettingModels; +using RequestPlex.Store; namespace RequestPlex.UI.Modules { public class RequestsModule : NancyModule { - public RequestsModule(ISettingsService s) + private IRepository Service { get; set; } + public RequestsModule(IRepository service) { - Get["requests/"] = _ => "Hello!"; - Get["requests/test"] = _ => - { - var se = new RequestPlexSettings - { - PlexAuthToken = "abc", - Port = 2344, - UserAuthentication = false - }; - s.SaveSettings(se); - var a = s.GetSettings(); - return "Hi!"; - }; + Service = service; + Get["requests/"] = _ => LoadRequests(); + Get["requests/movies"] = _ => GetMovies(); + Get["requests/tvshows"] = _ => GetTvShows(); + } + + + private Negotiator LoadRequests() + { + return View["Requests/Index"]; + } + + private Response GetMovies() + { + var dbMovies = Service.GetAll().Where(x => x.Type == RequestType.Movie); + return Response.AsJson(dbMovies); + } + + private Response GetTvShows() + { + var dbTv = Service.GetAll().Where(x => x.Type == RequestType.TvShow); + return Response.AsJson(dbTv); } } } \ No newline at end of file diff --git a/RequestPlex.UI/Modules/SearchModule.cs b/RequestPlex.UI/Modules/SearchModule.cs index 0268b67e2..067416474 100644 --- a/RequestPlex.UI/Modules/SearchModule.cs +++ b/RequestPlex.UI/Modules/SearchModule.cs @@ -86,10 +86,17 @@ namespace RequestPlex.UI.Modules { return Response.AsJson(new { Result = false, Message = "Movie has already been requested!" }); } + s.AddRequest(movieId, RequestType.Movie); return Response.AsJson(new { Result = true }); } + /// + /// Requests the tv show. + /// + /// The show identifier. + /// if set to true [latest]. + /// private Response RequestTvShow(int showId, bool latest) { // Latest send to Sonarr and no need to store in DB diff --git a/RequestPlex.UI/RequestPlex.UI.csproj b/RequestPlex.UI/RequestPlex.UI.csproj index 6355c6548..305d9cb2f 100644 --- a/RequestPlex.UI/RequestPlex.UI.csproj +++ b/RequestPlex.UI/RequestPlex.UI.csproj @@ -138,6 +138,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -189,6 +192,9 @@ Always + + Always + web.config @@ -198,7 +204,6 @@ - diff --git a/RequestPlex.UI/Views/Admin/Settings.cshtml b/RequestPlex.UI/Views/Admin/Settings.cshtml index bcddbb872..eda9c6d55 100644 --- a/RequestPlex.UI/Views/Admin/Settings.cshtml +++ b/RequestPlex.UI/Views/Admin/Settings.cshtml @@ -2,7 +2,7 @@ @{ int port; var authToken = string.Empty; - if (Model.Port == null) + if (Model.Port == 0) { port = 3579; } diff --git a/RequestPlex.UI/Views/Requests/Index.cshtml b/RequestPlex.UI/Views/Requests/Index.cshtml new file mode 100644 index 000000000..817615243 --- /dev/null +++ b/RequestPlex.UI/Views/Requests/Index.cshtml @@ -0,0 +1,62 @@ +
+

Requests

+ + + + +
+ + +
+
+
+ +
+
+
+ + +
+
+
+ +
+
+
+
+ +
+ + + + + + diff --git a/RequestPlex.UI/Views/Search/Index.cshtml b/RequestPlex.UI/Views/Search/Index.cshtml index a9cc68241..a054dde29 100644 --- a/RequestPlex.UI/Views/Search/Index.cshtml +++ b/RequestPlex.UI/Views/Search/Index.cshtml @@ -51,34 +51,37 @@ poster {{/if}} -
+
-

{{overview}}.

+

{{overview}}

-
- Vote Average: {{voteAverage}} - Vote Count: {{voteCount}} +
{{#if_eq type "movie"}} - + {{/if_eq}} {{#if_eq type "tv"}} {{/if_eq}} +
+
+
+ Vote Average: {{voteAverage}} + Vote Count: {{voteCount}}