From 9ffe184dd35ed166c76f0fc1f5f401065bee9f4e Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 1 Jun 2016 18:32:52 +0100 Subject: [PATCH] More for #273 --- .../PlexAvailabilityCheckerTests.cs | 4 -- PlexRequests.Services/Jobs/StoreBackup.cs | 1 - PlexRequests.UI/Content/requests-1.7.js | 4 +- PlexRequests.UI/Models/RequestViewModel.cs | 4 +- PlexRequests.UI/Modules/BaseAuthModule.cs | 8 ++-- PlexRequests.UI/Modules/IssuesModule.cs | 30 ++++++++++-- PlexRequests.UI/Modules/RequestsModule.cs | 14 ++---- PlexRequests.UI/PlexRequests.UI.csproj | 3 ++ PlexRequests.UI/Views/Issues/Index.cshtml | 1 + PlexRequests.UI/Views/Requests/Index.cshtml | 48 +++++++++---------- PlexRequests.UI/Views/Shared/_Layout.cshtml | 6 ++- 11 files changed, 67 insertions(+), 56 deletions(-) create mode 100644 PlexRequests.UI/Views/Issues/Index.cshtml diff --git a/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs b/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs index b5d3f4e10..5e7cc5aa0 100644 --- a/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs +++ b/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs @@ -25,19 +25,15 @@ // ************************************************************************/ #endregion using System; -using System.Collections.Generic; using Moq; using NUnit.Framework; using PlexRequests.Api.Interfaces; -using PlexRequests.Api.Models.Plex; using PlexRequests.Core; using PlexRequests.Core.SettingModels; -using PlexRequests.Helpers.Exceptions; using PlexRequests.Services.Interfaces; -using PlexRequests.Store; using PlexRequests.Helpers; using PlexRequests.Services.Jobs; using PlexRequests.Store.Models; diff --git a/PlexRequests.Services/Jobs/StoreBackup.cs b/PlexRequests.Services/Jobs/StoreBackup.cs index 68c7db69e..dea5d7df0 100644 --- a/PlexRequests.Services/Jobs/StoreBackup.cs +++ b/PlexRequests.Services/Jobs/StoreBackup.cs @@ -152,7 +152,6 @@ namespace PlexRequests.Services.Jobs if (names.Length > 1) { DateTime parsed; - //DateTime.TryParseExcat(names[1], "yyyy-MM-dd hh.mm.ss",CultureInfo.CurrentUICulture, DateTimeStyles.None, out parsed); DateTime.TryParse(names[2], out parsed); return parsed; diff --git a/PlexRequests.UI/Content/requests-1.7.js b/PlexRequests.UI/Content/requests-1.7.js index bb3cf2f1e..f7c7aff42 100644 --- a/PlexRequests.UI/Content/requests-1.7.js +++ b/PlexRequests.UI/Content/requests-1.7.js @@ -654,10 +654,8 @@ function buildRequestContext(result, type) { released: result.released, available: result.available, admin: result.admin, - issues: result.issues, - otherMessage: result.otherMessage, + issueId: result.issueId, requestId: result.id, - adminNote: result.adminNotes, imdb: result.imdbId, seriesRequested: result.tvSeriesRequestType, coverArtUrl: result.coverArtUrl, diff --git a/PlexRequests.UI/Models/RequestViewModel.cs b/PlexRequests.UI/Models/RequestViewModel.cs index 136c511aa..0b434d3c5 100644 --- a/PlexRequests.UI/Models/RequestViewModel.cs +++ b/PlexRequests.UI/Models/RequestViewModel.cs @@ -49,9 +49,7 @@ namespace PlexRequests.UI.Models public string ReleaseYear { get; set; } public bool Available { get; set; } public bool Admin { get; set; } - public string Issues { get; set; } - public string OtherMessage { get; set; } - public string AdminNotes { get; set; } + public int IssueId { get; set; } public string TvSeriesRequestType { get; set; } public string MusicBrainzId { get; set; } public QualityModel[] Qualities { get; set; } diff --git a/PlexRequests.UI/Modules/BaseAuthModule.cs b/PlexRequests.UI/Modules/BaseAuthModule.cs index 708a4cb49..2d6bbffee 100644 --- a/PlexRequests.UI/Modules/BaseAuthModule.cs +++ b/PlexRequests.UI/Modules/BaseAuthModule.cs @@ -87,21 +87,21 @@ namespace PlexRequests.UI.Modules protected BaseAuthModule(ISettingsService pr) : base(pr) { - Service = pr; + PlexRequestSettings = pr; Before += (ctx) => CheckAuth(); } protected BaseAuthModule(string modulePath, ISettingsService pr) : base(modulePath, pr) { - Service = pr; + PlexRequestSettings = pr; Before += (ctx) => CheckAuth(); } - private ISettingsService Service { get; } + protected ISettingsService PlexRequestSettings { get; } private Response CheckAuth() { - var settings = Service.GetSettings(); + var settings = PlexRequestSettings.GetSettings(); var baseUrl = settings.BaseUrl; var redirectPath = string.IsNullOrEmpty(baseUrl) ? "~/userlogin" : $"~/{baseUrl}/userlogin"; diff --git a/PlexRequests.UI/Modules/IssuesModule.cs b/PlexRequests.UI/Modules/IssuesModule.cs index a5433ac00..5371ae260 100644 --- a/PlexRequests.UI/Modules/IssuesModule.cs +++ b/PlexRequests.UI/Modules/IssuesModule.cs @@ -1,4 +1,6 @@ -using System.Linq; +using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Nancy; @@ -23,7 +25,7 @@ namespace PlexRequests.UI.Modules Get["/issuecount", true] = async (x, ct) => await IssueCount(); - Get["/details/{id}", true] = async (x, ct) => await Details(x.id); + Get["/{id}", true] = async (x, ct) => await Details(x.id); Post["/issue", true] = async (x, ct) => await ReportIssue((int)Request.Form.requestId, (IssueState)(int)Request.Form.issue, null); Post["/issuecomment", true] = async (x, ct) => await ReportIssue((int)Request.Form.requestId, IssueState.Other, (string)Request.Form.commentArea); @@ -40,13 +42,35 @@ namespace PlexRequests.UI.Modules public async Task IssueCount() { var issues = await IssuesService.GetAllAsync(); - var count = issues.Count(x => x.Deleted == false); + var settings = PlexRequestSettings.GetSettings(); + + IEnumerable myIssues; + + if (IsAdmin) + { + myIssues = issues.Where(x => x.Deleted == false).SelectMany(i => i.Issues); + } + else if (settings.UsersCanViewOnlyOwnRequests) + { + myIssues = (from issuesModel in issues + from i in issuesModel.Issues + where i.UserReported.Equals(Username, StringComparison.CurrentCultureIgnoreCase) + select i).ToList(); + } + else + { + myIssues = issues.Where(x => x.Deleted == false).SelectMany(i => i.Issues); + } + + + var count = myIssues.Count(); return Response.AsJson(count); } public async Task Details(int id) { + var issue = await IssuesService.GetAsync(id); return issue == null diff --git a/PlexRequests.UI/Modules/RequestsModule.cs b/PlexRequests.UI/Modules/RequestsModule.cs index 16bbd1cb2..365c7f6b3 100644 --- a/PlexRequests.UI/Modules/RequestsModule.cs +++ b/PlexRequests.UI/Modules/RequestsModule.cs @@ -76,7 +76,7 @@ namespace PlexRequests.UI.Modules Get["/"] = _ => LoadRequests(); Get["/movies", true] = async (x, ct) => await GetMovies(); Get["/tvshows", true] = async (c, ct) => await GetTvShows(); - Get["/albums", true] = async (x,ct) => await GetAlbumRequests(); + Get["/albums", true] = async (x, ct) => await GetAlbumRequests(); Post["/delete", true] = async (x, ct) => await DeleteRequest((int)Request.Form.id); Post["/reportissue", true] = async (x, ct) => await ReportIssue((int)Request.Form.requestId, (IssueState)(int)Request.Form.issue, null); Post["/reportissuecomment", true] = async (x, ct) => await ReportIssue((int)Request.Form.requestId, IssueState.Other, (string)Request.Form.commentArea); @@ -156,9 +156,7 @@ namespace PlexRequests.UI.Modules ReleaseYear = movie.ReleaseDate.Year.ToString(), Available = movie.Available, Admin = IsAdmin, - Issues = movie.Issues.ToString().CamelCaseToWords(), - OtherMessage = movie.OtherMessage, - AdminNotes = movie.AdminNote, + IssueId = movie.IssueId, Qualities = qualities.ToArray() }).ToList(); @@ -223,9 +221,7 @@ namespace PlexRequests.UI.Modules ReleaseYear = tv.ReleaseDate.Year.ToString(), Available = tv.Available, Admin = IsAdmin, - Issues = tv.Issues.ToString().CamelCaseToWords(), - OtherMessage = tv.OtherMessage, - AdminNotes = tv.AdminNote, + IssueId = tv.IssueId, TvSeriesRequestType = tv.SeasonsRequested, Qualities = qualities.ToArray() }; @@ -266,9 +262,7 @@ namespace PlexRequests.UI.Modules ReleaseYear = album.ReleaseDate.Year.ToString(), Available = album.Available, Admin = IsAdmin, - Issues = album.Issues.ToString().CamelCaseToWords(), - OtherMessage = album.OtherMessage, - AdminNotes = album.AdminNote, + IssueId = album.IssueId, TvSeriesRequestType = album.SeasonsRequested, MusicBrainzId = album.MusicBrainzId, ArtistName = album.ArtistName diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index 5e0f356b2..5abede801 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -510,6 +510,9 @@ Always + + Always + web.config diff --git a/PlexRequests.UI/Views/Issues/Index.cshtml b/PlexRequests.UI/Views/Issues/Index.cshtml new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/PlexRequests.UI/Views/Issues/Index.cshtml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/PlexRequests.UI/Views/Requests/Index.cshtml b/PlexRequests.UI/Views/Requests/Index.cshtml index 532f3df4f..5ca96c171 100644 --- a/PlexRequests.UI/Views/Requests/Index.cshtml +++ b/PlexRequests.UI/Views/Requests/Index.cshtml @@ -65,7 +65,7 @@
  • Approved
  • Not Approved
  • Available
  • -
  • Not Available
  • +
  • Not Available
  • Released
  • Not Released
  • @@ -135,7 +135,7 @@
    {{#if_eq type "movie"}} {{#if posterPath}} - poster + poster {{/if}} {{/if_eq}} {{#if_eq type "tv"}} @@ -178,17 +178,13 @@
    Requested By: {{requestedUsers}}
    {{/if}}
    Requested Date: {{requestedDate}}
    -
    - {{#if otherMessage}} -
    Message: {{otherMessage}}
    +
    + Issue: + {{#if_eq issueId 0}} + {{else}} -
    Issue: {{issues}}
    - {{/if}} -
    -
    - {{#if adminNote}} -
    Note from Admin: {{adminNote}}
    - {{/if}} + + {{/if_eq}}
    @@ -197,20 +193,20 @@
    {{#if_eq hasQualities true}} -
    - - - -
    +
    + + + +
    {{else}} - + {{/if_eq}}
    {{/if_eq}} @@ -405,7 +401,7 @@