diff --git a/RequestPlex.UI/Bootstrapper.cs b/RequestPlex.UI/Bootstrapper.cs index d47f8f85b..f271e381d 100644 --- a/RequestPlex.UI/Bootstrapper.cs +++ b/RequestPlex.UI/Bootstrapper.cs @@ -24,20 +24,18 @@ namespace RequestPlex.UI protected override void ConfigureRequestContainer(TinyIoCContainer container, NancyContext context) { - container.Register(); - base.ConfigureRequestContainer(container, context); container.Register(new DbConfiguration(new SqliteFactory())); container.Register(); container.Register(); - container.Register, SettingsServiceV2>(); container.Register, SettingsServiceV2>(); container.Register, GenericRepository>(); + base.ConfigureRequestContainer(container, context); } protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) diff --git a/RequestPlex.UI/Content/requests.js b/RequestPlex.UI/Content/requests.js index 4e535fd27..5a08e0319 100644 --- a/RequestPlex.UI/Content/requests.js +++ b/RequestPlex.UI/Content/requests.js @@ -13,6 +13,34 @@ var tvimer = 0; movieLoad(); tvLoad(); +$(document).on("click", ".delete", function (e) { + e.preventDefault(); + var buttonId = e.target.id; + var $form = $('#form' + buttonId); + + $.ajax({ + type: $form.prop('method'), + url: $form.prop('action'), + data: $form.serialize(), + dataType: "json", + success: function (response) { + console.log(response); + if (response.result === true) { + generateNotify("Success!", "success"); + + $("#" + buttonId + "Template").html(""); + } else { + generateNotify(response.message, "warning"); + } + }, + error: function (e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + } + }); + +}); + function movieLoad() { $("#movieList").html(""); diff --git a/RequestPlex.UI/Content/search.js b/RequestPlex.UI/Content/search.js index 817c9ca6e..ba4591eca 100644 --- a/RequestPlex.UI/Content/search.js +++ b/RequestPlex.UI/Content/search.js @@ -21,17 +21,16 @@ $("#tvSearchContent").keypress(function (e) { if (tvimer) { clearTimeout(tvimer); } - tvimer = setTimeout(tvSearch(), 400); + tvimer = setTimeout(tvSearch, 400); }); +// Click TV dropdown option $(document).on("click", ".dropdownTv", function (e) { - e.preventDefault(); - console.log(e.target.id); - var $form = $('#form'+e.target.id); + var buttonId = e.target.id; + var $form = $('#form' + buttonId); var data = $form.serialize(); var seasons = $(this).attr("season-select"); - console.log(data); if (seasons === "1") { data = data + "&latest=true"; } @@ -45,6 +44,10 @@ $(document).on("click", ".dropdownTv", function (e) { console.log(response); if (response.result === true) { generateNotify("Success!", "success"); + + $('#' + buttonId).html(" Requested "); + $('#' + buttonId).removeClass("btn-primary"); + $('#' + buttonId).addClass("btn-success"); } else { generateNotify(response.message, "warning"); } @@ -57,10 +60,11 @@ $(document).on("click", ".dropdownTv", function (e) { }); +// Click Request for movie $(document).on("click", ".requestMovie", function (e) { e.preventDefault(); - console.log(e.target.id); - var $form = $('#form' + e.target.id); + var buttonId = e.target.id; + var $form = $('#form' + buttonId); $.ajax({ type: $form.prop('method'), @@ -71,6 +75,10 @@ $(document).on("click", ".requestMovie", function (e) { console.log(response); if (response.result === true) { generateNotify("Success!", "success"); + + $('#' + buttonId).html(" Requested"); + $('#' + buttonId).removeClass("btn-primary"); + $('#' + buttonId).addClass("btn-success"); } else { generateNotify(response.message, "warning"); } diff --git a/RequestPlex.UI/Modules/RequestsModule.cs b/RequestPlex.UI/Modules/RequestsModule.cs index 8f50becbe..e940cd8c7 100644 --- a/RequestPlex.UI/Modules/RequestsModule.cs +++ b/RequestPlex.UI/Modules/RequestsModule.cs @@ -13,13 +13,18 @@ namespace RequestPlex.UI.Modules public class RequestsModule : NancyModule { private IRepository Service { get; set; } - public RequestsModule(IRepository service) + public RequestsModule(IRepository service) : base("requests") { Service = service; - Get["requests/"] = _ => LoadRequests(); - Get["requests/movies"] = _ => GetMovies(); - Get["requests/tvshows"] = _ => GetTvShows(); + Get["/"] = _ => LoadRequests(); + Get["/movies"] = _ => GetMovies(); + Get["/tvshows"] = _ => GetTvShows(); + Post["/delete"] = _ => + { + var convertedType = (string)Request.Form.type == "movie" ? RequestType.Movie : RequestType.TvShow; + return Delete((int)Request.Form.id, convertedType); + }; } @@ -39,5 +44,12 @@ namespace RequestPlex.UI.Modules var dbTv = Service.GetAll().Where(x => x.Type == RequestType.TvShow); return Response.AsJson(dbTv); } + + private Response Delete(int tmdbId, RequestType type) + { + var currentEntity = Service.GetAll().FirstOrDefault(x => x.Tmdbid == tmdbId && x.Type == type); + Service.Delete(currentEntity); + return Response.AsJson(new { Result = true }); + } } } \ No newline at end of file diff --git a/RequestPlex.UI/Modules/SearchModule.cs b/RequestPlex.UI/Modules/SearchModule.cs index 067416474..7eeab7a02 100644 --- a/RequestPlex.UI/Modules/SearchModule.cs +++ b/RequestPlex.UI/Modules/SearchModule.cs @@ -9,38 +9,21 @@ namespace RequestPlex.UI.Modules { public class SearchModule : NancyModule { - public SearchModule() + public SearchModule() : base("search") { - Get["search/"] = parameters => RequestLoad(); + Api = new TheMovieDbApi(); + Get["/"] = parameters => RequestLoad(); - Get["search/movie/{searchTerm}"] = parameters => - { - var search = (string)parameters.searchTerm; - return SearchMovie(search); - }; - - Get["search/tv/{searchTerm}"] = parameters => - { - var search = (string)parameters.searchTerm; - return SearchTvShow(search); - }; + Get["movie/{searchTerm}"] = parameters => SearchMovie((string)parameters.searchTerm); + Get["tv/{searchTerm}"] = parameters => SearchTvShow((string)parameters.searchTerm); - Get["search/movie/upcoming"] = parameters => UpcomingMovies(); - Get["search/movie/playing"] = parameters => CurrentlyPlayingMovies(); + Get["movie/upcoming"] = parameters => UpcomingMovies(); + Get["movie/playing"] = parameters => CurrentlyPlayingMovies(); - Post["search/request/movie"] = parameters => - { - var movieId = (int)Request.Form.movieId; - return RequestMovie(movieId); - }; - - Post["search/request/tv"] = parameters => - { - var tvShowId = (int)Request.Form.tvId; - var latest = (bool)Request.Form.latest; - return RequestTvShow(tvShowId, latest); - }; + Post["request/movie"] = parameters => RequestMovie((int)Request.Form.movieId); + Post["request/tv"] = parameters => RequestTvShow((int)Request.Form.tvId, (bool)Request.Form.latest); } + private TheMovieDbApi Api { get; } private Negotiator RequestLoad() { @@ -49,32 +32,28 @@ namespace RequestPlex.UI.Modules private Response SearchMovie(string searchTerm) { - var api = new TheMovieDbApi(); - var movies = api.SearchMovie(searchTerm); + var movies = Api.SearchMovie(searchTerm); var result = movies.Result; return Response.AsJson(result); } private Response SearchTvShow(string searchTerm) { - var api = new TheMovieDbApi(); - var tvShow = api.SearchTv(searchTerm); + var tvShow = Api.SearchTv(searchTerm); var result = tvShow.Result; return Response.AsJson(result); } private Response UpcomingMovies() { - var api = new TheMovieDbApi(); - var movies = api.GetUpcomingMovies(); + var movies = Api.GetUpcomingMovies(); var result = movies.Result; return Response.AsJson(result); } private Response CurrentlyPlayingMovies() { - var api = new TheMovieDbApi(); - var movies = api.GetCurrentPlayingMovies(); + var movies = Api.GetCurrentPlayingMovies(); var result = movies.Result; return Response.AsJson(result); } diff --git a/RequestPlex.UI/Startup.cs b/RequestPlex.UI/Startup.cs index a6015ed39..3ca409302 100644 --- a/RequestPlex.UI/Startup.cs +++ b/RequestPlex.UI/Startup.cs @@ -10,11 +10,11 @@ namespace RequestPlex.UI { try { - app.UseNancy(); + app.UseNancy(); } catch (Exception exception) { - Console.WriteLine(exception.Message); + Console.WriteLine(exception.Message); throw; } diff --git a/RequestPlex.UI/Views/Requests/Index.cshtml b/RequestPlex.UI/Views/Requests/Index.cshtml index 00317833b..84ccd6720 100644 --- a/RequestPlex.UI/Views/Requests/Index.cshtml +++ b/RequestPlex.UI/Views/Requests/Index.cshtml @@ -12,7 +12,7 @@
-
+

@@ -33,32 +33,35 @@