mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-10 23:42:36 -07:00
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.
This commit is contained in:
parent
186b18ccb9
commit
7051c31dd3
4 changed files with 83 additions and 40 deletions
|
@ -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 + "¬ify=" + $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)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue