#125 start indicating in the results if an item is already requested or available

pull/158/head
Drewster727 9 years ago
parent d1c6a13226
commit c6e6583fd5

@ -274,7 +274,10 @@ $(function () {
voteAverage: result.voteAverage, voteAverage: result.voteAverage,
year: year, year: year,
type: "movie", type: "movie",
imdb: result.imdbId imdb: result.imdbId,
requested: result.requested,
approved: result.approved,
available: result.available
}; };
return context; return context;
@ -290,7 +293,10 @@ $(function () {
overview: result.overview, overview: result.overview,
year: year, year: year,
type: "tv", type: "tv",
imdb: result.imdbId imdb: result.imdbId,
requested: result.requested,
approved: result.approved,
available: result.available
}; };
return context; return context;
} }
@ -307,7 +313,10 @@ $(function () {
coverArtUrl: result.coverArtUrl, coverArtUrl: result.coverArtUrl,
artist: result.artist, artist: result.artist,
releaseType: result.releaseType, releaseType: result.releaseType,
country: result.country country: result.country,
requested: result.requested,
approved: result.approved,
available: result.available
}; };
return context; return context;

@ -0,0 +1,50 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SearchTvShowViewModel.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using System.Collections.Generic;
namespace PlexRequests.UI.Models
{
public class SearchMovieViewModel : SearchViewModel
{
public bool Adult { get; set; }
public string BackdropPath { get; set; }
public List<int> GenreIds { get; set; }
public int Id { get; set; }
public string OriginalLanguage { get; set; }
public string OriginalTitle { get; set; }
public string Overview { get; set; }
public double Popularity { get; set; }
public string PosterPath { get; set; }
public DateTime? ReleaseDate { get; set; }
public string Title { get; set; }
public bool Video { get; set; }
public double VoteAverage { get; set; }
public int VoteCount { get; set; }
}
}

@ -26,7 +26,7 @@
#endregion #endregion
namespace PlexRequests.UI.Models namespace PlexRequests.UI.Models
{ {
public class SearchMusicViewModel public class SearchMusicViewModel : SearchViewModel
{ {
public string Id { get; set; } public string Id { get; set; }
public string Overview { get; set; } public string Overview { get; set; }

@ -29,7 +29,7 @@ using System.Collections.Generic;
namespace PlexRequests.UI.Models namespace PlexRequests.UI.Models
{ {
public class SearchTvShowViewModel public class SearchTvShowViewModel : SearchViewModel
{ {
public int Id { get; set; } public int Id { get; set; }
public string SeriesName { get; set; } public string SeriesName { get; set; }

@ -0,0 +1,37 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SearchTvShowViewModel.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
namespace PlexRequests.UI.Models
{
public class SearchViewModel
{
public bool Approved { get; set; }
public bool Requested { get; set; }
public bool Available { get; set; }
}
}

@ -48,6 +48,9 @@ using PlexRequests.Services.Notification;
using PlexRequests.Store; using PlexRequests.Store;
using PlexRequests.UI.Helpers; using PlexRequests.UI.Helpers;
using PlexRequests.UI.Models; using PlexRequests.UI.Models;
using System.Threading.Tasks;
using TMDbLib.Objects.Search;
using PlexRequests.Api.Models.Tv;
namespace PlexRequests.UI.Modules namespace PlexRequests.UI.Modules
{ {
@ -109,7 +112,8 @@ namespace PlexRequests.UI.Modules
private IHeadphonesApi HeadphonesApi { get; } private IHeadphonesApi HeadphonesApi { get; }
private static Logger Log = LogManager.GetCurrentClassLogger(); private static Logger Log = LogManager.GetCurrentClassLogger();
private bool IsAdmin { private bool IsAdmin
{
get get
{ {
return Context.CurrentUser.IsAuthenticated(); return Context.CurrentUser.IsAuthenticated();
@ -124,29 +128,168 @@ namespace PlexRequests.UI.Modules
return View["Search/Index", settings]; return View["Search/Index", settings];
} }
private Response UpcomingMovies()
{
Log.Trace("Loading upcoming movies");
return ProcessMovies(new Task<List<SearchMovie>>(() =>
{
return MovieApi.GetUpcomingMovies().Result.Select(x => new SearchMovie()
{
Adult = x.Adult,
BackdropPath = x.BackdropPath,
GenreIds = x.GenreIds,
Id = x.Id,
OriginalLanguage = x.OriginalLanguage,
OriginalTitle = x.OriginalTitle,
Overview = x.Overview,
Popularity = x.Popularity,
PosterPath = x.PosterPath,
ReleaseDate = x.ReleaseDate,
Title = x.Title,
Video = x.Video,
VoteAverage = x.VoteAverage,
VoteCount = x.VoteCount
}).ToList();
}));
}
private Response CurrentlyPlayingMovies()
{
Log.Trace("Loading currently playing movies");
return ProcessMovies(new Task<List<SearchMovie>>(() =>
{
return MovieApi.GetCurrentPlayingMovies().Result.Select(x => new SearchMovie()
{
Adult = x.Adult,
BackdropPath = x.BackdropPath,
GenreIds = x.GenreIds,
Id = x.Id,
OriginalLanguage = x.OriginalLanguage,
OriginalTitle = x.OriginalTitle,
Overview = x.Overview,
Popularity = x.Popularity,
PosterPath = x.PosterPath,
ReleaseDate = x.ReleaseDate,
Title = x.Title,
Video = x.Video,
VoteAverage = x.VoteAverage,
VoteCount = x.VoteCount
}).ToList();
}));
}
private Response SearchMovie(string searchTerm) private Response SearchMovie(string searchTerm)
{ {
Log.Trace("Searching for Movie {0}", searchTerm); Log.Trace("Searching for Movie {0}", searchTerm);
var movies = MovieApi.SearchMovie(searchTerm);
var result = movies.Result; return ProcessMovies(new Task<List<SearchMovie>>(() =>
return Response.AsJson(result); {
return MovieApi.SearchMovie(searchTerm).Result;
}));
}
private Response ProcessMovies(Task<List<SearchMovie>> apiTask)
{
List<Task> taskList = new List<Task>();
List<SearchMovie> apiMovies = new List<SearchMovie>();
apiTask.ContinueWith((t) =>
{
apiMovies = t.Result;
});
taskList.Add(apiTask);
apiTask.Start();
Dictionary<int, RequestedModel> dbMovies = new Dictionary<int, RequestedModel>();
taskList.Add(Task.Factory.StartNew(() =>
{
return RequestService.GetAll().Where(x => x.Type == RequestType.Movie);
}).ContinueWith((t) =>
{
dbMovies = t.Result.ToDictionary(x => x.ProviderId);
}));
Task.WaitAll(taskList.ToArray());
List<SearchMovieViewModel> viewMovies = new List<SearchMovieViewModel>();
foreach (SearchMovie movie in apiMovies)
{
var viewMovie = new SearchMovieViewModel()
{
Adult = movie.Adult,
BackdropPath = movie.BackdropPath,
GenreIds = movie.GenreIds,
Id = movie.Id,
OriginalLanguage = movie.OriginalLanguage,
OriginalTitle = movie.OriginalTitle,
Overview = movie.Overview,
Popularity = movie.Popularity,
PosterPath = movie.PosterPath,
ReleaseDate = movie.ReleaseDate,
Title = movie.Title,
Video = movie.Video,
VoteAverage = movie.VoteAverage,
VoteCount = movie.VoteCount
};
if (dbMovies.ContainsKey(movie.Id))
{
var dbm = dbMovies[movie.Id];
viewMovie.Requested = true;
viewMovie.Approved = dbm.Approved;
viewMovie.Available = dbm.Available;
}
viewMovies.Add(viewMovie);
}
return Response.AsJson(viewMovies);
} }
private Response SearchTvShow(string searchTerm) private Response SearchTvShow(string searchTerm)
{ {
Log.Trace("Searching for TV Show {0}", searchTerm); Log.Trace("Searching for TV Show {0}", searchTerm);
//var tvShow = TvApi.SearchTv(searchTerm, AuthToken);
var tvShow = new TvMazeApi().Search(searchTerm); List<Task> taskList = new List<Task>();
if (!tvShow.Any())
List<TvMazeSearch> apiTv = new List<TvMazeSearch>();
taskList.Add(Task.Factory.StartNew(() =>
{
return new TvMazeApi().Search(searchTerm);
}).ContinueWith((t) =>
{
apiTv = t.Result;
}));
Dictionary<int, RequestedModel> dbTv = new Dictionary<int, RequestedModel>();
taskList.Add(Task.Factory.StartNew(() =>
{
return RequestService.GetAll().Where(x => x.Type == RequestType.TvShow);
}).ContinueWith((t) =>
{
dbTv = t.Result.ToDictionary(x => x.ProviderId);
}));
Task.WaitAll(taskList.ToArray());
if (!apiTv.Any())
{ {
Log.Trace("TV Show data is null"); Log.Trace("TV Show data is null");
return Response.AsJson(""); return Response.AsJson("");
} }
var model = new List<SearchTvShowViewModel>();
foreach (var t in tvShow)
var viewTv = new List<SearchTvShowViewModel>();
foreach (var t in apiTv)
{ {
model.Add(new SearchTvShowViewModel var viewT = new SearchTvShowViewModel
{ {
// We are constructing the banner with the id: // We are constructing the banner with the id:
// http://thetvdb.com/banners/_cache/posters/ID-1.jpg // http://thetvdb.com/banners/_cache/posters/ID-1.jpg
@ -161,24 +304,56 @@ namespace PlexRequests.UI.Modules
Runtime = t.show.runtime.ToString(), Runtime = t.show.runtime.ToString(),
SeriesId = t.show.id, SeriesId = t.show.id,
SeriesName = t.show.name, SeriesName = t.show.name,
Status = t.show.status
};
Status = t.show.status, if (t.show.externals.thetvdb != null && dbTv.ContainsKey((int)t.show.externals.thetvdb))
}); {
var dbt = dbTv[(int)t.show.externals.thetvdb];
viewT.Requested = true;
viewT.Approved = dbt.Approved;
viewT.Available = dbt.Available;
}
viewTv.Add(viewT);
} }
Log.Trace("Returning TV Show results: "); Log.Trace("Returning TV Show results: ");
Log.Trace(model.DumpJson()); Log.Trace(viewTv.DumpJson());
return Response.AsJson(model); return Response.AsJson(viewTv);
} }
private Response SearchMusic(string searchTerm) private Response SearchMusic(string searchTerm)
{ {
var albums = MusicBrainzApi.SearchAlbum(searchTerm); List<Task> taskList = new List<Task>();
var releases = albums.releases ?? new List<Release>();
var model = new List<SearchMusicViewModel>(); List<Release> apiAlbums = new List<Release>();
foreach (var a in releases) taskList.Add(Task.Factory.StartNew(() =>
{
return MusicBrainzApi.SearchAlbum(searchTerm);
}).ContinueWith((t) =>
{
apiAlbums = t.Result.releases ?? new List<Release>();
}));
Dictionary<string, RequestedModel> dbAlbum = new Dictionary<string, RequestedModel>();
taskList.Add(Task.Factory.StartNew(() =>
{
return RequestService.GetAll().Where(x => x.Type == RequestType.Album);
}).ContinueWith((t) =>
{
dbAlbum = t.Result.ToDictionary(x => x.MusicBrainzId);
}));
Task.WaitAll(taskList.ToArray());
var viewAlbum = new List<SearchMusicViewModel>();
foreach (var a in apiAlbums)
{ {
model.Add(new SearchMusicViewModel var viewA = new SearchMusicViewModel
{ {
Title = a.title, Title = a.title,
Id = a.id, Id = a.id,
@ -188,27 +363,20 @@ namespace PlexRequests.UI.Modules
TrackCount = a.TrackCount, TrackCount = a.TrackCount,
ReleaseType = a.status, ReleaseType = a.status,
Country = a.country Country = a.country
}); };
}
return Response.AsJson(model);
}
private Response UpcomingMovies() // TODO : Not used if (!string.IsNullOrEmpty(a.id) && dbAlbum.ContainsKey(a.id))
{ {
var movies = MovieApi.GetUpcomingMovies(); var dba = dbAlbum[a.id];
var result = movies.Result;
Log.Trace("Movie Upcoming Results: "); viewA.Requested = true;
Log.Trace(result.DumpJson()); viewA.Approved = dba.Approved;
return Response.AsJson(result); viewA.Available = dba.Available;
} }
private Response CurrentlyPlayingMovies() // TODO : Not used viewAlbum.Add(viewA);
{ }
var movies = MovieApi.GetCurrentPlayingMovies(); return Response.AsJson(viewAlbum);
var result = movies.Result;
Log.Trace("Movie Currently Playing Results: ");
Log.Trace(result.DumpJson());
return Response.AsJson(result);
} }
private Response RequestMovie(int movieId) private Response RequestMovie(int movieId)
@ -241,7 +409,7 @@ namespace PlexRequests.UI.Modules
try try
{ {
if (CheckIfTitleExistsInPlex(movieInfo.Title, movieInfo.ReleaseDate?.Year.ToString(),null, PlexType.Movie)) if (CheckIfTitleExistsInPlex(movieInfo.Title, movieInfo.ReleaseDate?.Year.ToString(), null, PlexType.Movie))
{ {
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{fullMovieName} is already in Plex!" }); return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{fullMovieName} is already in Plex!" });
} }

@ -170,7 +170,9 @@
<Compile Include="Helpers\ValidationHelper.cs" /> <Compile Include="Helpers\ValidationHelper.cs" />
<Compile Include="Models\DatatablesModel.cs" /> <Compile Include="Models\DatatablesModel.cs" />
<Compile Include="Models\QualityModel.cs" /> <Compile Include="Models\QualityModel.cs" />
<Compile Include="Models\SearchViewModel.cs" />
<Compile Include="Models\SearchMusicViewModel.cs" /> <Compile Include="Models\SearchMusicViewModel.cs" />
<Compile Include="Models\SearchMovieViewModel.cs" />
<Compile Include="Validators\PushoverSettingsValidator.cs" /> <Compile Include="Validators\PushoverSettingsValidator.cs" />
<Compile Include="Validators\PushbulletSettingsValidator.cs" /> <Compile Include="Validators\PushbulletSettingsValidator.cs" />
<Compile Include="Validators\EmailNotificationSettingsValidator.cs" /> <Compile Include="Validators\EmailNotificationSettingsValidator.cs" />

@ -124,6 +124,12 @@
<div class="col-sm-2 col-sm-push-3"> <div class="col-sm-2 col-sm-push-3">
<form method="POST" action="/search/request/{{type}}" id="form{{id}}"> <form method="POST" action="/search/request/{{type}}" id="form{{id}}">
<input name="{{type}}Id" type="text" value="{{id}}" hidden="hidden" /> <input name="{{type}}Id" type="text" value="{{id}}" hidden="hidden" />
{{#if_eq available true}}
<button style="text-align: right" class="btn btn-success-outline disabled" disabled><i class="fa fa-check"></i> Available</button>
{{else}}
{{#if_eq requested true}}
<button style="text-align: right" class="btn btn-success-outline disabled" disabled><i class="fa fa-check"></i> Requested</button>
{{else}}
{{#if_eq type "movie"}} {{#if_eq type "movie"}}
<button id="{{id}}" style="text-align: right" class="btn btn-primary-outline requestMovie" type="submit"><i class="fa fa-plus"></i> Request</button> <button id="{{id}}" style="text-align: right" class="btn btn-primary-outline requestMovie" type="submit"><i class="fa fa-plus"></i> Request</button>
{{/if_eq}} {{/if_eq}}
@ -140,6 +146,8 @@
</ul> </ul>
</div> </div>
{{/if_eq}} {{/if_eq}}
{{/if_eq}}
{{/if_eq}}
<br /> <br />
<br /> <br />
<br /> <br />
@ -181,8 +189,15 @@
<div class="col-sm-2 col-sm-push-3"> <div class="col-sm-2 col-sm-push-3">
<form method="POST" action="/search/request/{{type}}" id="form{{id}}"> <form method="POST" action="/search/request/{{type}}" id="form{{id}}">
<input name="{{type}}Id" type="text" value="{{id}}" hidden="hidden" /> <input name="{{type}}Id" type="text" value="{{id}}" hidden="hidden" />
{{#if_eq available true}}
<button style="text-align: right" class="btn btn-success-outline disabled" disabled><i class="fa fa-check"></i> Available</button>
{{else}}
{{#if_eq requested true}}
<button style="text-align: right" class="btn btn-success-outline disabled" disabled><i class="fa fa-check"></i> Requested</button>
{{else}}
<button id="{{id}}" style="text-align: right" class="btn btn-primary-outline requestAlbum" type="submit"><i class="fa fa-plus"></i> Request</button> <button id="{{id}}" style="text-align: right" class="btn btn-primary-outline requestAlbum" type="submit"><i class="fa fa-plus"></i> Request</button>
{{/if_eq}}
{{/if_eq}}
<br /> <br />
<small class="row">Track Count: {{trackCount}}</small> <small class="row">Track Count: {{trackCount}}</small>
<small class="row">Country: {{country}}</small> <small class="row">Country: {{country}}</small>

Loading…
Cancel
Save