More work on #27 Added a new notify button to the search UI (Needs styling). Also fixed a bug where if the user could only see their own requests, if they search for something that has been requested, it will show as requested.

pull/193/head
tidusjar 9 years ago
parent 186b18ccb9
commit 7051c31dd3

@ -40,6 +40,7 @@ namespace PlexRequests.Store
public List<string> RequestedUsers { get; set; } public List<string> RequestedUsers { get; set; }
public string ArtistName { get; set; } public string ArtistName { get; set; }
public string ArtistId { get; set; } public string ArtistId { get; set; }
public List<string> UsersToNotify { get; private set; }
[JsonIgnore] [JsonIgnore]
public List<string> AllUsers public List<string> AllUsers
@ -61,18 +62,27 @@ namespace PlexRequests.Store
} }
[JsonIgnore] [JsonIgnore]
public bool CanApprove public bool CanApprove => !Approved && !Available;
{
get
{
return !Approved && !Available;
}
}
public bool UserHasRequested(string username) public bool UserHasRequested(string username)
{ {
return AllUsers.Any(x => x.Equals(username, StringComparison.OrdinalIgnoreCase)); return AllUsers.Any(x => x.Equals(username, StringComparison.OrdinalIgnoreCase));
} }
public void AddUserToNotification(string username)
{
if (UsersToNotify == null)
{
UsersToNotify = new List<string>();
}
if (UsersToNotify.FirstOrDefault(x => x == username) != null)
{
// User already exists in the notification list
return;
}
UsersToNotify.Add(username);
}
} }
public enum RequestType public enum RequestType

@ -114,6 +114,10 @@ $(function () {
var url = $form.prop('action'); var url = $form.prop('action');
var data = $form.serialize(); var data = $form.serialize();
var $notify = $('#notifyUser').is(':checked');
data = data + "&notify=" + $notify;
sendRequestAjax(data, type, url, buttonId); sendRequestAjax(data, type, url, buttonId);
}); });

@ -97,7 +97,7 @@ namespace PlexRequests.UI.Modules
Get["movie/upcoming"] = parameters => UpcomingMovies(); Get["movie/upcoming"] = parameters => UpcomingMovies();
Get["movie/playing"] = parameters => CurrentlyPlayingMovies(); Get["movie/playing"] = parameters => CurrentlyPlayingMovies();
Post["request/movie"] = parameters => RequestMovie((int)Request.Form.movieId); Post["request/movie"] = parameters => RequestMovie((int)Request.Form.movieId, (bool)Request.Form.notify);
Post["request/tv"] = parameters => RequestTvShow((int)Request.Form.tvId, (string)Request.Form.seasons); Post["request/tv"] = parameters => RequestTvShow((int)Request.Form.tvId, (string)Request.Form.seasons);
Post["request/album"] = parameters => RequestAlbum((string)Request.Form.albumId); Post["request/album"] = parameters => RequestAlbum((string)Request.Form.albumId);
} }
@ -211,7 +211,7 @@ namespace PlexRequests.UI.Modules
var cpCached = CpCacher.QueuedIds(); var cpCached = CpCacher.QueuedIds();
var plexMovies = Checker.GetPlexMovies(); var plexMovies = Checker.GetPlexMovies();
var settings = PrService.GetSettings();
var viewMovies = new List<SearchMovieViewModel>(); var viewMovies = new List<SearchMovieViewModel>();
foreach (MovieResult movie in apiMovies) foreach (MovieResult movie in apiMovies)
{ {
@ -232,12 +232,12 @@ namespace PlexRequests.UI.Modules
VoteAverage = movie.VoteAverage, VoteAverage = movie.VoteAverage,
VoteCount = movie.VoteCount VoteCount = movie.VoteCount
}; };
var canSee = CanUserSeeThisRequest(viewMovie.Id, settings.UsersCanViewOnlyOwnRequests, dbMovies);
if (Checker.IsMovieAvailable(plexMovies.ToArray(), movie.Title, movie.ReleaseDate?.Year.ToString())) if (Checker.IsMovieAvailable(plexMovies.ToArray(), movie.Title, movie.ReleaseDate?.Year.ToString()))
{ {
viewMovie.Available = true; viewMovie.Available = true;
} }
else if (dbMovies.ContainsKey(movie.Id)) // compare to the requests db else if (dbMovies.ContainsKey(movie.Id) && canSee) // compare to the requests db
{ {
var dbm = dbMovies[movie.Id]; var dbm = dbMovies[movie.Id];
@ -245,7 +245,7 @@ namespace PlexRequests.UI.Modules
viewMovie.Approved = dbm.Approved; viewMovie.Approved = dbm.Approved;
viewMovie.Available = dbm.Available; viewMovie.Available = dbm.Available;
} }
else if (cpCached.Contains(movie.Id)) // compare to the couchpotato db else if (cpCached.Contains(movie.Id) && canSee) // compare to the couchpotato db
{ {
viewMovie.Requested = true; viewMovie.Requested = true;
} }
@ -256,6 +256,17 @@ namespace PlexRequests.UI.Modules
return Response.AsJson(viewMovies); return Response.AsJson(viewMovies);
} }
private bool CanUserSeeThisRequest(int movieId, bool usersCanViewOnlyOwnRequests, Dictionary<int, RequestedModel> moviesInDb)
{
if (usersCanViewOnlyOwnRequests)
{
var result = moviesInDb.FirstOrDefault(x => x.Value.ProviderId == movieId);
return result.Value != null && result.Value.UserHasRequested(Username);
}
return true;
}
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);
@ -409,7 +420,7 @@ namespace PlexRequests.UI.Modules
return Response.AsJson(viewAlbum); return Response.AsJson(viewAlbum);
} }
private Response RequestMovie(int movieId) private Response RequestMovie(int movieId, bool notify = false)
{ {
var movieApi = new TheMovieDbApi(); var movieApi = new TheMovieDbApi();
var movieInfo = movieApi.GetMovieInformation(movieId).Result; var movieInfo = movieApi.GetMovieInformation(movieId).Result;
@ -428,6 +439,10 @@ namespace PlexRequests.UI.Modules
// check if the current user is already marked as a requester for this movie, if not, add them // check if the current user is already marked as a requester for this movie, if not, add them
if (!existingRequest.UserHasRequested(Username)) if (!existingRequest.UserHasRequested(Username))
{ {
if (notify)
{
existingRequest.AddUserToNotification(Username);
}
existingRequest.RequestedUsers.Add(Username); existingRequest.RequestedUsers.Add(Username);
RequestService.UpdateRequest(existingRequest); RequestService.UpdateRequest(existingRequest);
} }
@ -463,10 +478,16 @@ namespace PlexRequests.UI.Modules
Status = movieInfo.Status, Status = movieInfo.Status,
RequestedDate = DateTime.UtcNow, RequestedDate = DateTime.UtcNow,
Approved = false, Approved = false,
RequestedUsers = new List<string>() { Username }, RequestedUsers = new List<string> { Username },
Issues = IssueState.None, Issues = IssueState.None,
}; };
if (notify)
{
model.AddUserToNotification(Username);
}
Log.Trace(settings.DumpJson()); Log.Trace(settings.DumpJson());
if (ShouldAutoApprove(RequestType.Movie, settings)) if (ShouldAutoApprove(RequestType.Movie, settings))
{ {

@ -12,6 +12,14 @@
<h4>Want to watch something that is not currently on Plex?! No problem! Just search for it below and request it!</h4> <h4>Want to watch something that is not currently on Plex?! No problem! Just search for it below and request it!</h4>
<br /> <br />
<!-- Nav tabs --> <!-- Nav tabs -->
<div class="form-group">
<div class="checkbox">
<label>
<input type="checkbox" id="notifyUser" name="Notify">Notify
</label>
</div>
</div>
<ul id="nav-tabs" class="nav nav-tabs" role="tablist"> <ul id="nav-tabs" class="nav nav-tabs" role="tablist">
@if (Model.SearchForMovies) @if (Model.SearchForMovies)
{ {
@ -27,7 +35,7 @@
} }
</ul> </ul>
<!-- Tab panes --> <!-- Tab panes -->
<div class="tab-content"> <div class="tab-content">
@if (Model.SearchForMovies) @if (Model.SearchForMovies)
@ -136,26 +144,26 @@
{{#if_eq available true}} {{#if_eq available true}}
<button style="text-align: right" class="btn btn-success-outline disabled" disabled><i class="fa fa-check"></i> Available</button> <button style="text-align: right" class="btn btn-success-outline disabled" disabled><i class="fa fa-check"></i> Available</button>
{{else}} {{else}}
{{#if_eq requested true}} {{#if_eq requested true}}
<button style="text-align: right" class="btn btn-primary-outline disabled" disabled><i class="fa fa-check"></i> Requested</button> <button style="text-align: right" class="btn btn-primary-outline disabled" disabled><i class="fa fa-check"></i> Requested</button>
{{else}} {{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}}
{{#if_eq type "tv"}} {{#if_eq type "tv"}}
<div class="dropdown"> <div class="dropdown">
<button id="{{id}}" class="btn btn-primary-outline dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> <button id="{{id}}" class="btn btn-primary-outline dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<i class="fa fa-plus"></i> Request <i class="fa fa-plus"></i> Request
<span class="caret"></span> <span class="caret"></span>
</button> </button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a id="{{id}}" season-select="0" class="dropdownTv " href="#">All Seasons</a></li> <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="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="{{id}}" season-select="2" class="dropdownTv" href="#">Latest Season</a></li>
</ul> </ul>
</div> </div>
{{/if_eq}} {{/if_eq}}
{{/if_eq}} {{/if_eq}}
{{/if_eq}} {{/if_eq}}
<br /> <br />
<br /> <br />
@ -201,11 +209,11 @@
{{#if_eq available true}} {{#if_eq available true}}
<button style="text-align: right" class="btn btn-success-outline disabled" disabled><i class="fa fa-check"></i> Available</button> <button style="text-align: right" class="btn btn-success-outline disabled" disabled><i class="fa fa-check"></i> Available</button>
{{else}} {{else}}
{{#if_eq requested true}} {{#if_eq requested true}}
<button style="text-align: right" class="btn btn-success-outline disabled" disabled><i class="fa fa-check"></i> Requested</button> <button style="text-align: right" class="btn btn-success-outline disabled" disabled><i class="fa fa-check"></i> Requested</button>
{{else}} {{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}}
{{/if_eq}} {{/if_eq}}
<br /> <br />
<small class="row">Track Count: {{trackCount}}</small> <small class="row">Track Count: {{trackCount}}</small>

Loading…
Cancel
Save