From 48fd182e525d1dff1bd2c319cf49044fe294c17c Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 2 Mar 2016 14:38:54 +0000 Subject: [PATCH] Some work on the requests page --- RequestPlex.UI/Content/requests.js | 35 ++++------- RequestPlex.UI/Models/RequestViewModel.cs | 50 +++++++++++++++ RequestPlex.UI/Modules/RequestsModule.cs | 71 ++++++++++++++++++++-- RequestPlex.UI/Program.cs | 18 ++++-- RequestPlex.UI/RequestPlex.UI.csproj | 5 ++ RequestPlex.UI/Startup.cs | 28 ++++++++- RequestPlex.UI/Views/Requests/Index.cshtml | 28 ++++++++- RequestPlex.UI/packages.config | 11 ++++ 8 files changed, 209 insertions(+), 37 deletions(-) create mode 100644 RequestPlex.UI/Models/RequestViewModel.cs diff --git a/RequestPlex.UI/Content/requests.js b/RequestPlex.UI/Content/requests.js index 2519696e3..671a29e72 100644 --- a/RequestPlex.UI/Content/requests.js +++ b/RequestPlex.UI/Content/requests.js @@ -47,7 +47,7 @@ function movieLoad() { $.ajax("/requests/movies/").success(function (results) { results.forEach(function (result) { - var context = buildMovieRequestContext(result); + var context = buildRequestContext(result, "movie"); var html = searchTemplate(context); $("#movieList").append(html); @@ -60,40 +60,29 @@ function tvLoad() { $.ajax("/requests/tvshows/").success(function (results) { results.forEach(function (result) { - var context = buildTvShowRequestContext(result); + var context = buildRequestContext(result, "tv"); 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", - status: result.status - }; +function buildRequestContext(result, type) { - 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.title, overview: result.overview, - year: year, - type: "tv", - status: result.status + year: result.releaseYear, + type: type, + status: result.status, + releaseDate: result.releaseDate, + approved: result.approved, + requestedBy: result.requestedBy, + requestedDate: result.requestedDate, + available: result.available }; + return context; } diff --git a/RequestPlex.UI/Models/RequestViewModel.cs b/RequestPlex.UI/Models/RequestViewModel.cs new file mode 100644 index 000000000..809223d71 --- /dev/null +++ b/RequestPlex.UI/Models/RequestViewModel.cs @@ -0,0 +1,50 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: RequestViewModel.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 RequestPlex.Store; + +namespace RequestPlex.UI.Models +{ + public class RequestViewModel + { + public int Id { get; set; } + 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 string ReleaseDate { get; set; } + public RequestType Type { get; set; } + public string Status { get; set; } + public bool Approved { get; set; } + public string RequestedBy { get; set; } + public string RequestedDate { get; set; } + public string ReleaseYear { get; set; } + public bool Available { get; set; } + } +} diff --git a/RequestPlex.UI/Modules/RequestsModule.cs b/RequestPlex.UI/Modules/RequestsModule.cs index e940cd8c7..3fec747ed 100644 --- a/RequestPlex.UI/Modules/RequestsModule.cs +++ b/RequestPlex.UI/Modules/RequestsModule.cs @@ -1,12 +1,39 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: RequestsModule.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.Collections.Generic; using System.Linq; +using Humanizer; + using Nancy; using Nancy.Responses.Negotiation; -using RequestPlex.Api; -using RequestPlex.Core; -using RequestPlex.Core.SettingModels; using RequestPlex.Store; +using RequestPlex.UI.Models; namespace RequestPlex.UI.Modules { @@ -36,13 +63,47 @@ namespace RequestPlex.UI.Modules private Response GetMovies() { var dbMovies = Service.GetAll().Where(x => x.Type == RequestType.Movie); - return Response.AsJson(dbMovies); + var viewModel = dbMovies.Select(tv => new RequestViewModel + { + Tmdbid = tv.Tmdbid, + Type = tv.Type, + Status = tv.Status, + ImdbId = tv.ImdbId, + Id = tv.Id, + PosterPath = tv.PosterPath, + ReleaseDate = tv.ReleaseDate.Humanize(), + RequestedDate = tv.RequestedDate.Humanize(), + Approved = tv.Approved, + Title = tv.Title, + Overview = tv.Overview, + RequestedBy = tv.RequestedBy, + ReleaseYear = tv.ReleaseDate.Year.ToString() + }).ToList(); + //TODO check if Available + return Response.AsJson(viewModel); } private Response GetTvShows() { var dbTv = Service.GetAll().Where(x => x.Type == RequestType.TvShow); - return Response.AsJson(dbTv); + var viewModel = dbTv.Select(tv => new RequestViewModel + { + Tmdbid = tv.Tmdbid, + Type = tv.Type, + Status = tv.Status, + ImdbId = tv.ImdbId, + Id = tv.Id, + PosterPath = tv.PosterPath, + ReleaseDate = tv.ReleaseDate.Humanize(), + RequestedDate = tv.RequestedDate.Humanize(), + Approved = tv.Approved, + Title = tv.Title, + Overview = tv.Overview, + RequestedBy = tv.RequestedBy, + ReleaseYear = tv.ReleaseDate.Year.ToString() + }).ToList(); + //TODO check if Available + return Response.AsJson(viewModel); } private Response Delete(int tmdbId, RequestType type) diff --git a/RequestPlex.UI/Program.cs b/RequestPlex.UI/Program.cs index 8af87e2cb..a34b3d5d0 100644 --- a/RequestPlex.UI/Program.cs +++ b/RequestPlex.UI/Program.cs @@ -48,13 +48,21 @@ namespace RequestPlex.UI s.SetupDb(); var uri = GetStartupUri(); - - using (WebApp.Start(uri)) + try + { + using (WebApp.Start(uri)) + { + Console.WriteLine($"Request Plex is running on {uri}"); + Console.WriteLine("Press any key to exit"); + Console.ReadLine(); + } + } + catch (Exception e) { - Console.WriteLine($"Request Plex is running on {uri}"); - Console.WriteLine("Press any key to exit"); - Console.ReadLine(); + + throw; } + } private static void WriteOutVersion() diff --git a/RequestPlex.UI/RequestPlex.UI.csproj b/RequestPlex.UI/RequestPlex.UI.csproj index dd1599b52..b0ac33a7c 100644 --- a/RequestPlex.UI/RequestPlex.UI.csproj +++ b/RequestPlex.UI/RequestPlex.UI.csproj @@ -54,6 +54,10 @@ + + ..\packages\Humanizer.Core.2.0.1\lib\dotnet\Humanizer.dll + True + ..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll True @@ -126,6 +130,7 @@ PreserveNewest + diff --git a/RequestPlex.UI/Startup.cs b/RequestPlex.UI/Startup.cs index 3ca409302..cf85c2572 100644 --- a/RequestPlex.UI/Startup.cs +++ b/RequestPlex.UI/Startup.cs @@ -1,4 +1,30 @@ -using System; +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: Startup.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 Owin; diff --git a/RequestPlex.UI/Views/Requests/Index.cshtml b/RequestPlex.UI/Views/Requests/Index.cshtml index 84ccd6720..558c2e8da 100644 --- a/RequestPlex.UI/Views/Requests/Index.cshtml +++ b/RequestPlex.UI/Views/Requests/Index.cshtml @@ -1,5 +1,6 @@ 
-

Requests

+

Requests

+

Below you can see yours and all other requests, as well as their download and approval status.

-

{{overview}}

+
+

Release Date: {{releaseDate}}

+

+ Approved: + {{#if_eq approved false}} + + {{/if_eq}} + {{#if_eq approved true}} + + {{/if_eq}} +

+

+ Available + {{#if_eq available false}} + + {{/if_eq}} + {{#if_eq available true}} + + {{/if_eq}} +

+

Requested By: {{requestedBy}}

+

Requested Date: {{requestedDate}}

- {{status}}

diff --git a/RequestPlex.UI/packages.config b/RequestPlex.UI/packages.config index 149d4de12..2bb1a72bd 100644 --- a/RequestPlex.UI/packages.config +++ b/RequestPlex.UI/packages.config @@ -1,5 +1,6 @@  + @@ -12,5 +13,15 @@ + + + + + + + + + + \ No newline at end of file