diff --git a/RequestPlex.UI/Content/search.js b/RequestPlex.UI/Content/search.js index 0f0898521..4849648d9 100644 --- a/RequestPlex.UI/Content/search.js +++ b/RequestPlex.UI/Content/search.js @@ -1,26 +1,69 @@ -var searchSource = $("#search-template").html(); +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; -$("#movieSearchContent").on("keyup", function (e) { +$("#movieSearchContent").keypress(function (e) { if (movieTimer) { clearTimeout(movieTimer); } movieTimer = setTimeout(movieSearch, 400); }); -$("#tvSearchContent").on("keyup", function (e) { +$("#tvSearchContent").keypress(function (e) { if (tvimer) { clearTimeout(tvimer); } tvimer = setTimeout(tvSearch(), 400); }); -$("#test").click(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; + } + + $.ajax({ + type: $form.prop('method'), + url: $form.prop('action'), + data: data, + dataType: "json", + success: function (response) { + console.log(response); + if (response.result === true) { + generateNotify("Success!", "success"); + } else { + generateNotify(response.message, "warning"); + } + }, + error: function (e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + } + }); + +}); + +$(document).on("click", ".requesttv", function (e) { + e.preventDefault(); + console.log(e.target.id); + var $form = $('#form' + e.target.id); $.ajax({ type: $form.prop('method'), @@ -29,10 +72,10 @@ $("#test").click(function (e) { dataType: "json", success: function (response) { console.log(response); - if (response.Result === true) { + if (response.result === true) { generateNotify("Success!", "success"); } else { - generateNotify(response.Message, "warning"); + generateNotify(response.message, "warning"); } }, error: function (e) { diff --git a/RequestPlex.UI/Content/site.js b/RequestPlex.UI/Content/site.js index 8f69d979c..331957fd0 100644 --- a/RequestPlex.UI/Content/site.js +++ b/RequestPlex.UI/Content/site.js @@ -1,7 +1,4 @@ - - - -function generateNotify(message, type) { +function generateNotify(message, type) { // type = danger, warning, info, successs $.notify({ // options diff --git a/RequestPlex.UI/Modules/SearchModule.cs b/RequestPlex.UI/Modules/SearchModule.cs index 1f177499e..0268b67e2 100644 --- a/RequestPlex.UI/Modules/SearchModule.cs +++ b/RequestPlex.UI/Modules/SearchModule.cs @@ -37,7 +37,7 @@ namespace RequestPlex.UI.Modules Post["search/request/tv"] = parameters => { var tvShowId = (int)Request.Form.tvId; - var latest = (bool)Request.Form.latestSeason; + var latest = (bool)Request.Form.latest; return RequestTvShow(tvShowId, latest); }; } @@ -94,6 +94,10 @@ namespace RequestPlex.UI.Modules { // Latest send to Sonarr and no need to store in DB var s = new SettingsService(); + if (s.CheckRequest(showId)) + { + return Response.AsJson(new { Result = false, Message = "TV Show has already been requested!" }); + } s.AddRequest(showId, RequestType.TvShow); return Response.AsJson(new {Result = true }); } diff --git a/RequestPlex.UI/Program.cs b/RequestPlex.UI/Program.cs index 73fba9091..1d863eee8 100644 --- a/RequestPlex.UI/Program.cs +++ b/RequestPlex.UI/Program.cs @@ -25,7 +25,7 @@ namespace RequestPlex.UI var service = new SettingsServiceV2(new JsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider())); var settings = service.GetSettings(); - if (settings != null) + if (settings.Port != 0) { uri = $"http://localhost:{settings.Port}"; } diff --git a/RequestPlex.UI/Views/Search/Index.cshtml b/RequestPlex.UI/Views/Search/Index.cshtml index 8dc337963..a9cc68241 100644 --- a/RequestPlex.UI/Views/Search/Index.cshtml +++ b/RequestPlex.UI/Views/Search/Index.cshtml @@ -63,8 +63,22 @@ Vote Average: {{voteAverage}} Vote Count: {{voteCount}}
- - + + {{#if_eq type "movie"}} + + {{/if_eq}} + {{#if_eq type "tv"}} + + {{/if_eq}}