mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-07 13:41:13 -07:00
Some more work. Need to stop the form submitting on a request
This commit is contained in:
parent
9a78f790a6
commit
96a3970a53
7 changed files with 106 additions and 8 deletions
|
@ -38,5 +38,36 @@ namespace RequestPlex.Core
|
|||
|
||||
return settings;
|
||||
}
|
||||
|
||||
public void AddRequest(int tmdbid, RequestType type)
|
||||
{
|
||||
var model = new RequestedModel
|
||||
{
|
||||
Tmdbid = tmdbid,
|
||||
Type = type
|
||||
};
|
||||
|
||||
var db = new DbConfiguration(new SqliteFactory());
|
||||
var repo = new GenericRepository<RequestedModel>(db);
|
||||
|
||||
repo.Insert(model);
|
||||
}
|
||||
|
||||
public bool CheckRequest(int tmdbid)
|
||||
{
|
||||
var db = new DbConfiguration(new SqliteFactory());
|
||||
var repo = new GenericRepository<RequestedModel>(db);
|
||||
|
||||
return repo.GetAll().Any(x => x.Tmdbid == tmdbid);
|
||||
}
|
||||
|
||||
public void DeleteRequest(int tmdbId)
|
||||
{
|
||||
var db = new DbConfiguration(new SqliteFactory());
|
||||
var repo = new GenericRepository<RequestedModel>(db);
|
||||
var entity = repo.GetAll().FirstOrDefault(x => x.Tmdbid == tmdbId);
|
||||
repo.Delete(entity);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SettingsModel.cs" />
|
||||
<Compile Include="GenericRepository.cs" />
|
||||
<Compile Include="RequestedModel.cs" />
|
||||
<Compile Include="UserRepository.cs" />
|
||||
<Compile Include="Sql.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
|
|
18
RequestPlex.Store/RequestedModel.cs
Normal file
18
RequestPlex.Store/RequestedModel.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using Dapper.Contrib.Extensions;
|
||||
|
||||
namespace RequestPlex.Store
|
||||
{
|
||||
[Table("Requested")]
|
||||
public class RequestedModel : Entity
|
||||
{
|
||||
// ReSharper disable once IdentifierTypo
|
||||
public int Tmdbid { get; set; }
|
||||
public RequestType Type { get; set; }
|
||||
}
|
||||
|
||||
public enum RequestType
|
||||
{
|
||||
Movie,
|
||||
TvShow
|
||||
}
|
||||
}
|
|
@ -13,3 +13,10 @@ CREATE TABLE IF NOT EXISTS Settings
|
|||
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
Port INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Requested
|
||||
(
|
||||
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
Type INTEGER NOT NULL,
|
||||
Tmdbid INTEGER NOT NULL
|
||||
);
|
|
@ -17,6 +17,34 @@ $("#tvSearchContent").on("keyup", function (e) {
|
|||
tvimer = setTimeout(tvSearch(), 400);
|
||||
});
|
||||
|
||||
|
||||
$("#test").click(function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
var $form = $('#form'+e.target.id);
|
||||
|
||||
$.ajax({
|
||||
type: $form.prop('method'),
|
||||
url: $form.prop('action'),
|
||||
data: $form.serialize(),
|
||||
dataType: "json",
|
||||
success: function (response) {
|
||||
console.log(response);
|
||||
if (response.Result === true) {
|
||||
generateNotify("Success!", "success");
|
||||
} else {
|
||||
generateNotify(response.Message, "warning");
|
||||
}
|
||||
},
|
||||
error: function (e) {
|
||||
console.log(e);
|
||||
generateNotify("Something went wrong!", "danger");
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
function movieSearch() {
|
||||
$("#movieList").html("");
|
||||
var query = $("#movieSearchContent").val();
|
||||
|
|
|
@ -2,6 +2,8 @@ using Nancy;
|
|||
using Nancy.Responses.Negotiation;
|
||||
|
||||
using RequestPlex.Api;
|
||||
using RequestPlex.Core;
|
||||
using RequestPlex.Store;
|
||||
|
||||
namespace RequestPlex.UI.Modules
|
||||
{
|
||||
|
@ -34,7 +36,7 @@ namespace RequestPlex.UI.Modules
|
|||
|
||||
Post["search/request/tv"] = parameters =>
|
||||
{
|
||||
var tvShowId = (int)Request.Form.showId;
|
||||
var tvShowId = (int)Request.Form.tvId;
|
||||
var latest = (bool)Request.Form.latestSeason;
|
||||
return RequestTvShow(tvShowId, latest);
|
||||
};
|
||||
|
@ -47,6 +49,7 @@ namespace RequestPlex.UI.Modules
|
|||
|
||||
private Response SearchMovie(string searchTerm)
|
||||
{
|
||||
var s = new SettingsService();
|
||||
var api = new TheMovieDbApi();
|
||||
var movies = api.SearchMovie(searchTerm);
|
||||
var result = movies.Result;
|
||||
|
@ -79,12 +82,21 @@ namespace RequestPlex.UI.Modules
|
|||
|
||||
private Response RequestMovie(int movieId)
|
||||
{
|
||||
return Response.AsJson("");
|
||||
var s = new SettingsService();
|
||||
if (s.CheckRequest(movieId))
|
||||
{
|
||||
return Response.AsJson(new { Result = false, Message = "Movie has already been requested!" });
|
||||
}
|
||||
s.AddRequest(movieId, RequestType.Movie);
|
||||
return Response.AsJson(new { Result = true });
|
||||
}
|
||||
|
||||
private Response RequestTvShow(int showId, bool latest)
|
||||
{
|
||||
return Response.AsJson("");
|
||||
// Latest send to Sonarr and no need to store in DB
|
||||
var s = new SettingsService();
|
||||
s.AddRequest(showId, RequestType.TvShow);
|
||||
return Response.AsJson(new {Result = true });
|
||||
}
|
||||
}
|
||||
}
|
|
@ -52,7 +52,7 @@
|
|||
{{/if}}
|
||||
</div>
|
||||
<div class="col-sm-5">
|
||||
<div id="{{id}}">
|
||||
<div>
|
||||
<a href="https://www.themoviedb.org/{{type}}/{{id}}">
|
||||
<h4>{{title}} ({{year}})</h4>
|
||||
</a>
|
||||
|
@ -62,9 +62,10 @@
|
|||
<div class="col-sm-5">
|
||||
<small>Vote Average: {{voteAverage}}</small>
|
||||
<small>Vote Count: {{voteCount}}</small>
|
||||
<button style="text-align: right" class="btn btn-primary bottom-align-text">
|
||||
<i class="fa fa-plus"></i>Request
|
||||
</button>
|
||||
<form method="POST" action="/search/request/{{type}}" id="form{{id}}">
|
||||
<input name="{{type}}Id" type="text" value="{{id}}" hidden="hidden"/>
|
||||
<button id="test" style="text-align: right" class="btn btn-primary bottom-align-text requestClass" type="submit"><i class="fa fa-plus"></i>Request</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue