Work on the requests page mostly done.

pull/13/head
tidusjar 9 years ago
parent 70362b908f
commit 98d143c9b2

@ -5,6 +5,7 @@ using TMDbLib.Client;
using TMDbLib.Objects.General;
using TMDbLib.Objects.Movies;
using TMDbLib.Objects.Search;
using TMDbLib.Objects.TvShows;
namespace RequestPlex.Api
{
@ -39,5 +40,17 @@ namespace RequestPlex.Api
var movies = await Client.GetMovieList(MovieListType.Upcoming);
return movies.Results;
}
public async Task<Movie> GetMovieInformation(int tmdbId)
{
var movies = await Client.GetMovie(tmdbId);
return movies;
}
public async Task<TvShow> GetTvShowInformation(int tmdbId)
{
var show = await Client.GetTvShow(tmdbId);
return show;
}
}
}

@ -57,6 +57,9 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="TMDbLib">
<HintPath>..\packages\TMDbLib.0.9.0.0-alpha\lib\net45\TMDbLib.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ISettingsService.cs" />
@ -74,6 +77,10 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RequestPlex.Api\RequestPlex.Api.csproj">
<Project>{8CB8D235-2674-442D-9C6A-35FCAEEB160D}</Project>
<Name>RequestPlex.Api</Name>
</ProjectReference>
<ProjectReference Include="..\RequestPlex.Helpers\RequestPlex.Helpers.csproj">
<Project>{1252336D-42A3-482A-804C-836E60173DFA}</Project>
<Name>RequestPlex.Helpers</Name>

@ -24,10 +24,12 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using System.Linq;
using Mono.Data.Sqlite;
using RequestPlex.Api;
using RequestPlex.Store;
namespace RequestPlex.Core
@ -47,12 +49,38 @@ namespace RequestPlex.Core
public void AddRequest(int tmdbid, RequestType type)
{
var model = new RequestedModel
var api = new TheMovieDbApi();
var model = new RequestedModel();
if (type == RequestType.Movie)
{
Tmdbid = tmdbid,
Type = type
};
var movieInfo = api.GetMovieInformation(tmdbid).Result;
model = new RequestedModel
{
Tmdbid = tmdbid,
Type = type,
Overview = movieInfo.Overview,
ImdbId = movieInfo.ImdbId,
PosterPath = "http://image.tmdb.org/t/p/w150/" + movieInfo.PosterPath,
Title = movieInfo.Title,
ReleaseDate = movieInfo.ReleaseDate ?? DateTime.MinValue
};
}
else
{
var showInfo = api.GetTvShowInformation(tmdbid).Result;
model = new RequestedModel
{
Tmdbid = tmdbid,
Type = type,
Overview = showInfo.Overview,
//ImdbId = showInfo.ImdbId, //TODO where's the IMDBId?
PosterPath = "http://image.tmdb.org/t/p/w150/" + showInfo.PosterPath,
Title = showInfo.Name,
ReleaseDate = showInfo.FirstAirDate ?? DateTime.MinValue
};
}
var db = new DbConfiguration(new SqliteFactory());
var repo = new GenericRepository<RequestedModel>(db);

@ -27,8 +27,6 @@
using System;
using System.Linq;
using Mono.Data.Sqlite;
using Nancy;
using Nancy.Authentication.Forms;
using Nancy.Security;
@ -63,7 +61,6 @@ namespace RequestPlex.Core
public static Guid? ValidateUser(string username, string password)
{
var db = new DbConfiguration(new SqliteFactory());
var repo = new UserRepository<UserModel>(Db);
var users = repo.GetAll();
var userRecord = users.FirstOrDefault(u => u.UserName.Equals(username, StringComparison.InvariantCultureIgnoreCase) && u.Password.Equals(password)); // TODO hashing
@ -78,7 +75,6 @@ namespace RequestPlex.Core
public static bool DoUsersExist()
{
var db = new DbConfiguration(new SqliteFactory());
var repo = new UserRepository<UserModel>(Db);
var users = repo.GetAll();
return users.Any();
@ -86,7 +82,6 @@ namespace RequestPlex.Core
public static Guid? CreateUser(string username, string password)
{
var db = new DbConfiguration(new SqliteFactory());
var repo = new UserRepository<UserModel>(Db);
var userModel = new UserModel { UserName = username, User = Guid.NewGuid().ToString(), Password = password };

@ -1,4 +1,6 @@
using Dapper.Contrib.Extensions;
using System;
using Dapper.Contrib.Extensions;
namespace RequestPlex.Store
{
@ -7,6 +9,11 @@ namespace RequestPlex.Store
{
// ReSharper disable once IdentifierTypo
public int Tmdbid { get; set; }
public string ImdbId { get; set; }
public string Overview { get; set; }
public string Title { get; set; }
public string PosterPath { get; set; }
public DateTime ReleaseDate { get; set; }
public RequestType Type { get; set; }
}

@ -20,7 +20,12 @@ CREATE TABLE IF NOT EXISTS Requested
(
Id INTEGER PRIMARY KEY AUTOINCREMENT,
Type INTEGER NOT NULL,
Tmdbid INTEGER NOT NULL
Tmdbid INTEGER NOT NULL,
ImdbId varchar(50) NOT NULL,
Overview varchar(50) NOT NULL,
Title varchar(50) NOT NULL,
PosterPath varchar(50) NOT NULL,
ReleaseDate varchar(50) NOT NULL
);
CREATE TABLE IF NOT EXISTS GlobalSettings

@ -35,6 +35,7 @@ namespace RequestPlex.UI
container.Register<ISettingsService<RequestPlexSettings>, SettingsServiceV2<RequestPlexSettings>>();
container.Register<IRepository<RequestedModel>, GenericRepository<RequestedModel>>();

@ -0,0 +1,71 @@
Handlebars.registerHelper('if_eq', function (a, b, opts) {
if (a == b)
return opts.fn(this);
else
return opts.inverse(this);
});
var searchSource = $("#search-template").html();
var searchTemplate = Handlebars.compile(searchSource);
var movieTimer = 0;
var tvimer = 0;
movieLoad();
tvLoad();
function movieLoad() {
$("#movieList").html("");
$.ajax("/requests/movies/").success(function (results) {
results.forEach(function (result) {
var context = buildMovieRequestContext(result);
var html = searchTemplate(context);
$("#movieList").append(html);
});
});
};
function tvLoad() {
$("#tvList").html("");
$.ajax("/requests/tvshows/").success(function (results) {
results.forEach(function (result) {
var context = buildTvShowRequestContext(result);
var html = searchTemplate(context);
$("#tvList").append(html);
});
});
};
function buildMovieRequestContext(result) {
var date = new Date(result.releaseDate);
var year = date.getFullYear();
var context = {
posterPath: result.posterPath,
id: result.tmdbid,
title: result.title,
overview: result.overview,
year: year,
type: "movie"
};
return context;
}
function buildTvShowRequestContext(result) {
var date = new Date(result.releaseDate);
var year = date.getFullYear();
var context = {
posterPath: result.posterPath,
id: result.tmdbid,
title: result.name,
overview: result.overview,
voteCount: result.voteCount,
voteAverage: result.voteAverage,
year: year,
type: "tv"
};
return context;
}

@ -25,18 +25,15 @@ $("#tvSearchContent").keypress(function (e) {
});
$(document).on("click", ".dropdownTv", function (e) {
var formData = [];
e.preventDefault();
console.log(e.target.id);
var $form = $('#form'+e.target.id);
var data = $form.serialize();
var seasons = $(this).attr("season-select");
console.log(data);
formData.push(data);
if (seasons === "1") {
formData.push("latest=true");
} else {
data.latest = false;
data = data + "&latest=true";
}
$.ajax({
@ -60,7 +57,7 @@ $(document).on("click", ".dropdownTv", function (e) {
});
$(document).on("click", ".requesttv", function (e) {
$(document).on("click", ".requestMovie", function (e) {
e.preventDefault();
console.log(e.target.id);
var $form = $('#form' + e.target.id);
@ -114,35 +111,3 @@ function tvSearch() {
});
};
function buildMovieContext(result) {
var date = new Date(result.releaseDate);
var year = date.getFullYear();
var context = {
posterPath: result.posterPath,
id: result.id,
title: result.title,
overview: result.overview,
voteCount: result.voteCount,
voteAverage: result.voteAverage,
year: year,
type : "movie"
};
return context;
}
function buildTvShowContext(result) {
var date = new Date(result.firstAirDate);
var year = date.getFullYear();
var context = {
posterPath: result.posterPath,
id: result.id,
title: result.name,
overview: result.overview,
voteCount: result.voteCount,
voteAverage: result.voteAverage,
year: year,
type: "tv"
};
return context;
}

@ -7,4 +7,37 @@
// settings
type: type
});
}
}
function buildMovieContext(result) {
var date = new Date(result.releaseDate);
var year = date.getFullYear();
var context = {
posterPath: result.posterPath,
id: result.id,
title: result.title,
overview: result.overview,
voteCount: result.voteCount,
voteAverage: result.voteAverage,
year: year,
type: "movie"
};
return context;
}
function buildTvShowContext(result) {
var date = new Date(result.firstAirDate);
var year = date.getFullYear();
var context = {
posterPath: result.posterPath,
id: result.id,
title: result.name,
overview: result.overview,
voteCount: result.voteCount,
voteAverage: result.voteAverage,
year: year,
type: "tv"
};
return context;
}

@ -1,4 +1,6 @@
using Nancy;
using Nancy.Extensions;
using Nancy.Responses;
namespace RequestPlex.UI.Modules
{
@ -6,8 +8,8 @@ namespace RequestPlex.UI.Modules
{
public IndexModule()
{
Get["/"] = parameters => View["Index"];
Get["/Index"] = parameters => View["Index"];
Get["/"] = parameters => Context.GetRedirect("~/search");
Get["/Index"] = parameters => Context.GetRedirect("~/search");
}
}
}

@ -1,28 +1,43 @@
using System.Linq;
using Nancy;
using Nancy.Responses.Negotiation;
using RequestPlex.Api;
using RequestPlex.Core;
using RequestPlex.Core.SettingModels;
using RequestPlex.Store;
namespace RequestPlex.UI.Modules
{
public class RequestsModule : NancyModule
{
public RequestsModule(ISettingsService<RequestPlexSettings> s)
private IRepository<RequestedModel> Service { get; set; }
public RequestsModule(IRepository<RequestedModel> service)
{
Get["requests/"] = _ => "Hello!";
Get["requests/test"] = _ =>
{
var se = new RequestPlexSettings
{
PlexAuthToken = "abc",
Port = 2344,
UserAuthentication = false
};
s.SaveSettings(se);
var a = s.GetSettings();
return "Hi!";
};
Service = service;
Get["requests/"] = _ => LoadRequests();
Get["requests/movies"] = _ => GetMovies();
Get["requests/tvshows"] = _ => GetTvShows();
}
private Negotiator LoadRequests()
{
return View["Requests/Index"];
}
private Response GetMovies()
{
var dbMovies = Service.GetAll().Where(x => x.Type == RequestType.Movie);
return Response.AsJson(dbMovies);
}
private Response GetTvShows()
{
var dbTv = Service.GetAll().Where(x => x.Type == RequestType.TvShow);
return Response.AsJson(dbTv);
}
}
}

@ -86,10 +86,17 @@ namespace RequestPlex.UI.Modules
{
return Response.AsJson(new { Result = false, Message = "Movie has already been requested!" });
}
s.AddRequest(movieId, RequestType.Movie);
return Response.AsJson(new { Result = true });
}
/// <summary>
/// Requests the tv show.
/// </summary>
/// <param name="showId">The show identifier.</param>
/// <param name="latest">if set to <c>true</c> [latest].</param>
/// <returns></returns>
private Response RequestTvShow(int showId, bool latest)
{
// Latest send to Sonarr and no need to store in DB

@ -138,6 +138,9 @@
<Content Include="Content\jquery-2.2.1.min.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\requests.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\site.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@ -189,6 +192,9 @@
<Content Include="Views\Login\Register.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Views\Requests\Index.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Web.Debug.config">
<DependentUpon>web.config</DependentUpon>
</None>
@ -198,7 +204,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Auth\" />
<Folder Include="Views\Requests\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RequestPlex.Api\RequestPlex.Api.csproj">

@ -2,7 +2,7 @@
@{
int port;
var authToken = string.Empty;
if (Model.Port == null)
if (Model.Port == 0)
{
port = 3579;
}

@ -0,0 +1,62 @@
<div>
<h2>Requests</h2>
<!-- Nav tabs -->
<ul id="nav-tabs" class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#MoviesTab" aria-controls="home" role="tab" data-toggle="tab">Movies</a></li>
<li role="presentation"><a href="#TvShowTab" aria-controls="profile" role="tab" data-toggle="tab">TV Shows</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<!-- Movie tab -->
<div role="tabpanel" class="tab-pane active" id="MoviesTab">
<br />
<br />
<!-- Movie content -->
<div id="movieList">
</div>
</div>
<!-- TV tab -->
<div role="tabpanel" class="tab-pane" id="TvShowTab">
<br />
<br />
<!-- TV content -->
<div id="tvList">
</div>
</div>
</div>
</div>
<script id="search-template" type="text/x-handlebars-template">
<div class="row">
<div class="col-sm-2">
{{#if posterPath}}
<img src="http://image.tmdb.org/t/p/w150/{{posterPath}}" alt="poster">
{{/if}}
</div>
<div class="col-sm-5 ">
<div>
<a href="https://www.themoviedb.org/{{type}}/{{id}}">
<h4>{{title}} ({{year}})</h4>
</a>
</div>
<p>{{overview}}</p>
</div>
<div class="col-sm-2 col-sm-push-3">
<form method="POST" action="/search/request/{{type}}" id="form{{id}}">
<input name="{{type}}Id" type="text" value="{{id}}" hidden="hidden" />
<button id="{{id}}" style="text-align: right" class="btn btn-primary requestMovie" type="submit"><i class="fa fa-plus"></i> TestBtn</button>
</form>
</div>
</div>
<hr />
</script>
<script src="/Content/requests.js" type="text/javascript"></script>

@ -51,34 +51,37 @@
<img src="http://image.tmdb.org/t/p/w150/{{posterPath}}" alt="poster">
{{/if}}
</div>
<div class="col-sm-5">
<div class="col-sm-5 ">
<div>
<a href="https://www.themoviedb.org/{{type}}/{{id}}">
<h4>{{title}} ({{year}})</h4>
</a>
</div>
<p>{{overview}}.</p>
<p>{{overview}}</p>
</div>
<div class="col-sm-5">
<small>Vote Average: {{voteAverage}}</small>
<small>Vote Count: {{voteCount}}</small>
<div class="col-sm-2 col-sm-push-3">
<form method="POST" action="/search/request/{{type}}" id="form{{id}}">
<input name="{{type}}Id" type="text" value="{{id}}" hidden="hidden" />
{{#if_eq type "movie"}}
<button id="{{id}}" style="text-align: right" class="btn btn-primary bottom-align-text requestMovie" type="submit"><i class="fa fa-plus"></i>Request</button>
<button id="{{id}}" style="text-align: right" class="btn btn-primary requestMovie" type="submit"><i class="fa fa-plus"></i> Request</button>
{{/if_eq}}
{{#if_eq type "tv"}}
<div class="dropdown">
<button class="btn btn-primary bottom-align-text dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<i class="fa fa-plus"></i>Request
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<i class="fa fa-plus"></i> Request
<span class="caret"></span>
</button>
<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="#">Latest Season</a></li>
</ul>
</div>
{{/if_eq}}
<br />
<br />
<br />
<small class="row">Vote Average: {{voteAverage}}</small>
<small class="row">Vote Count: {{voteCount}}</small>
</form>
</div>

Loading…
Cancel
Save