diff --git a/PlexRequests.Api.Models/Tv/TVMazeShow.cs b/PlexRequests.Api.Models/Tv/TVMazeShow.cs index faebd6d84..840edfdf8 100644 --- a/PlexRequests.Api.Models/Tv/TVMazeShow.cs +++ b/PlexRequests.Api.Models/Tv/TVMazeShow.cs @@ -24,5 +24,56 @@ namespace PlexRequests.Api.Models.Tv public int updated { get; set; } public Links _links { get; set; } public int seasonCount { get; set; } + public Embedded _embedded { get; set; } + } + + public class Season + { + public int id { get; set; } + public string url { get; set; } + public int number { get; set; } + public string name { get; set; } + public int? episodeOrder { get; set; } + public string premiereDate { get; set; } + public string endDate { get; set; } + public Network2 network { get; set; } + public object webChannel { get; set; } + public Image2 image { get; set; } + public string summary { get; set; } + public Links2 _links { get; set; } + } + public class Country2 +{ + public string name { get; set; } + public string code { get; set; } + public string timezone { get; set; } +} + +public class Network2 +{ + public int id { get; set; } + public string name { get; set; } + public Country2 country { get; set; } +} + +public class Image2 +{ + public string medium { get; set; } + public string original { get; set; } +} + +public class Self2 +{ + public string href { get; set; } +} + +public class Links2 +{ + public Self2 self { get; set; } +} + + public class Embedded + { + public List seasons { get; set; } } } \ No newline at end of file diff --git a/PlexRequests.Api/TvMazeApi.cs b/PlexRequests.Api/TvMazeApi.cs index 6043710d7..d287e80bf 100644 --- a/PlexRequests.Api/TvMazeApi.cs +++ b/PlexRequests.Api/TvMazeApi.cs @@ -85,7 +85,7 @@ namespace PlexRequests.Api return obj; } - public int GetSeasonCount(int id) + public List GetSeasons(int id) { var request = new RestRequest { @@ -95,7 +95,11 @@ namespace PlexRequests.Api request.AddUrlSegment("id", id.ToString()); request.AddHeader("Content-Type", "application/json"); - var obj = Api.Execute>(request, new Uri(Uri)); + return Api.Execute>(request, new Uri(Uri)); + } + public int GetSeasonCount(int id) + { + var obj = GetSeasons(id); var seasons = obj.Select(x => x.number > 0); return seasons.Count(); } diff --git a/PlexRequests.UI/Content/search.js b/PlexRequests.UI/Content/search.js index 6c502eef0..7bbd54a63 100644 --- a/PlexRequests.UI/Content/search.js +++ b/PlexRequests.UI/Content/search.js @@ -10,9 +10,11 @@ $(function () { var searchSource = $("#search-template").html(); + var seasonsSource = $("#seasons-template").html(); var musicSource = $("#music-template").html(); var searchTemplate = Handlebars.compile(searchSource); var musicTemplate = Handlebars.compile(musicSource); + var seasonsTemplate = Handlebars.compile(seasonsSource); var base = $('#baseUrl').text(); @@ -162,7 +164,7 @@ $(function () { $.ajax({ type: "post", url: url, - data: {notify: checked}, + data: { notify: checked }, dataType: "json", success: function (response) { console.log(response); @@ -301,7 +303,7 @@ $(function () { var html = musicTemplate(context); $("#musicList").append(html); - getCoverArt(context.id); + getCoverArt(context.id); }); } else { @@ -385,4 +387,67 @@ $(function () { return context; } + $('#seasonsModal').on('show.bs.modal', function (event) { + var button = $(event.relatedTarget); // Button that triggered the modal + var id = button.data('identifier'); // Extract info from data-* attributes + var url = createBaseUrl(base, '/search/seasons/'); + + $.ajax({ + type: "get", + url: url, + data: { tvId: id }, + dataType: "json", + success: function (results) { + var $content = $("#seasonsBody"); + $('#selectedSeasonsId').val(id); + results.forEach(function(result) { + var context = buildSeasonsContext(result); + $content.append(seasonsTemplate(context)); + }); + }, + error: function (e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + } + }); + + function buildSeasonsContext(result) { + var context = { + id: result + }; + return context; + }; + }); + + $('#seasonsRequest').click(function(e) { + e.preventDefault(); + var tvId = $('#selectedSeasonsId').val(); + var url = createBaseUrl(base, '/search/seasons/'); + + if ($("#" + tvId).attr('disabled')) { + return; + } + + $("#" + tvId).prop("disabled", true); + loadingButton(tvId, "primary"); + + + var $form = $('#form' + tvId); + var data = $form.serialize(); + var seasonsParam = "&seasons="; + + var testimonials = document.querySelectorAll('.selectedSeasons'); + Array.prototype.forEach.call(testimonials, function (elements, index) { + seasonsParam = seasonsParam + elements.text() + ","; + }); + + data = data + seasonsParam; + + var type = $form.prop('method'); + var url = $form.prop('action'); + + sendRequestAjax(data, type, url, tvId); + + }); + }); diff --git a/PlexRequests.UI/Modules/RequestsModule.cs b/PlexRequests.UI/Modules/RequestsModule.cs index 94e01a90b..020aab78d 100644 --- a/PlexRequests.UI/Modules/RequestsModule.cs +++ b/PlexRequests.UI/Modules/RequestsModule.cs @@ -310,7 +310,7 @@ namespace PlexRequests.UI.Modules private Response DeleteRequest(int requestid) { - this.RequiresClaims (UserClaims.PowerUser, UserClaims.Admin); + this.RequiresClaims (UserClaims.Admin); var currentEntity = Service.Get(requestid); Service.DeleteRequest(currentEntity); diff --git a/PlexRequests.UI/Modules/SearchModule.cs b/PlexRequests.UI/Modules/SearchModule.cs index 29a39fa37..843ce6e70 100644 --- a/PlexRequests.UI/Modules/SearchModule.cs +++ b/PlexRequests.UI/Modules/SearchModule.cs @@ -106,6 +106,8 @@ namespace PlexRequests.UI.Modules Post["/notifyuser"] = x => NotifyUser((bool)Request.Form.notify); Get["/notifyuser"] = x => GetUserNotificationSettings(); + + Get["/seasons"] = x => GetSeasons(); } private IPlexApi PlexApi { get; } private TheMovieDbApi MovieApi { get; } @@ -942,11 +944,20 @@ namespace PlexRequests.UI.Modules } } - - public Response GetUserNotificationSettings() + private Response GetUserNotificationSettings() { var retval = UsersToNotifyRepo.GetAll().FirstOrDefault(x => x.Username == Username); return Response.AsJson(retval != null); } + + private Response GetSeasons() + { + var tv = new TvMazeApi(); + var seriesId = (int)Request.Query.tvId; + var show = tv.ShowLookupByTheTvDbId(seriesId); + var seasons = tv.GetSeasons(show.id); + var model = seasons.Select(x => x.number); + return Response.AsJson(model); + } } } diff --git a/PlexRequests.UI/Views/Search/Index.cshtml b/PlexRequests.UI/Views/Search/Index.cshtml index 20a1251b9..ce2769fdb 100644 --- a/PlexRequests.UI/Views/Search/Index.cshtml +++ b/PlexRequests.UI/Views/Search/Index.cshtml @@ -115,7 +115,7 @@
-
+
@@ -190,6 +190,7 @@
  • All Seasons
  • First Season
  • Latest Season
  • +
  • Select...
  • {{/if_eq}} @@ -253,7 +254,36 @@
    + + + + @Html.LoadSearchAssets()