mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-10 23:42:36 -07:00
Started working on #26
This commit is contained in:
parent
2b20af5df0
commit
748fe2ca2d
6 changed files with 169 additions and 8 deletions
|
@ -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<Season> seasons { get; set; }
|
||||
}
|
||||
}
|
|
@ -85,7 +85,7 @@ namespace PlexRequests.Api
|
|||
return obj;
|
||||
}
|
||||
|
||||
public int GetSeasonCount(int id)
|
||||
public List<TvMazeSeasons> 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<List<TvMazeSeasons>>(request, new Uri(Uri));
|
||||
return Api.Execute<List<TvMazeSeasons>>(request, new Uri(Uri));
|
||||
}
|
||||
public int GetSeasonCount(int id)
|
||||
{
|
||||
var obj = GetSeasons(id);
|
||||
var seasons = obj.Select(x => x.number > 0);
|
||||
return seasons.Count();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@
|
|||
<div class="input-group">
|
||||
<div class="input-group-addon input-group-sm"></div>
|
||||
</div>
|
||||
<br/>
|
||||
<br />
|
||||
|
||||
<!-- Notifications content -->
|
||||
<form class="form-horizontal" method="POST" id="notificationsForm">
|
||||
|
@ -190,6 +190,7 @@
|
|||
<li><a id="{{id}}" season-select="0" class="dropdownTv " href="#">All Seasons</a></li>
|
||||
<li><a id="{{id}}" season-select="1" class="dropdownTv" href="#">First Season</a></li>
|
||||
<li><a id="{{id}}" season-select="2" class="dropdownTv" href="#">Latest Season</a></li>
|
||||
<li><a id="SeasonSelect" data-identifier="{{id}}" data-toggle="modal" data-target="#seasonsModal" href="#">Select...</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
{{/if_eq}}
|
||||
|
@ -253,7 +254,36 @@
|
|||
|
||||
</div>
|
||||
<hr />
|
||||
|
||||
</script>
|
||||
|
||||
<div class="modal fade" id="seasonsModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title">Seasons</h4>
|
||||
</div>
|
||||
<div class="modal-body" id="seasonsBody">
|
||||
|
||||
</div>
|
||||
|
||||
<div hidden="hidden" id="selectedSeasonsId"></div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
<button type="button" id="seasonsRequest" class="btn btn-primary">Request</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script id="seasons-template" type="text/x-handlebars-template">
|
||||
<div class="form-group">
|
||||
<div class="checkbox">
|
||||
<input type="checkbox" class=".selectedSeasons" id="{{id}}" name="{{id}}"><label for="{{id}}">Season {{id}}</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</script>
|
||||
|
||||
@Html.LoadSearchAssets()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue