Skip to content

Commit

Permalink
More work on #273
Browse files Browse the repository at this point in the history
  • Loading branch information
tidusjar committed May 31, 2016
1 parent 1d3520c commit ebeedb9
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 9 deletions.
6 changes: 5 additions & 1 deletion PlexRequests.Core/Models/IssuesModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ namespace PlexRequests.Core.Models
{
public class IssuesModel : Entity
{
public IssuesModel()
{
Issues = new List<IssueModel>();
}
public string Title { get; set; }
public string PosterUrl1 { get; set; }
public string PosterUrl { get; set; }
public int RequestId { get; set; }
public List<IssueModel> Issues { get; set; }
public bool Deleted { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion PlexRequests.Store/RequestedModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public RequestedModel()
public List<string> RequestedUsers { get; set; }
public string ArtistName { get; set; }
public string ArtistId { get; set; }
public int IssueId { get; set; }

[JsonIgnore]
public List<string> AllUsers
Expand Down Expand Up @@ -83,6 +84,6 @@ public enum IssueState
NoSubtitles = 1,
WrongContent = 2,
PlaybackIssues = 3,
Other = 4 // Provide a message
Other = 4, // Provide a message
}
}
60 changes: 57 additions & 3 deletions PlexRequests.UI/Modules/IssuesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,32 @@
using Nancy.Responses.Negotiation;

using PlexRequests.Core;
using PlexRequests.Core.Models;
using PlexRequests.Core.SettingModels;
using PlexRequests.Store;
using PlexRequests.UI.Models;

namespace PlexRequests.UI.Modules
{
public class IssuesModule : BaseAuthModule
{
public IssuesModule(ISettingsService<PlexRequestSettings> pr, IIssueService issueService) : base("issues", pr)
public IssuesModule(ISettingsService<PlexRequestSettings> pr, IIssueService issueService, IRequestService request) : base("issues", pr)
{
IssuesService = issueService;
RequestService = request;

Get["/"] = x => Index();

Get["/issuecount", true] = async (x, ct) => await IssueCount();

Get["/details/{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);
}

private IIssueService IssuesService { get; }
private IRequestService RequestService { get; }

public Negotiator Index()
{
Expand All @@ -41,11 +49,57 @@ public async Task<Negotiator> Details(int id)
{
var issue = await IssuesService.GetAsync(id);

return issue == null
? Index()
return issue == null
? Index()
: View["Details", issue];
}

private async Task<Response> ReportIssue(int requestId, IssueState issue, string comment)
{

var model = new IssueModel
{
Issue = issue,
IssueStatus = IssueStatus.PendingIssue,
UserReported = Username,
UserNote = !string.IsNullOrEmpty(comment)
? $"{Username} - {comment}"
: string.Empty,
};

var request = await RequestService.GetAsync(requestId);

var issueEntity = await IssuesService.GetAllAsync();
var existingIssue = issueEntity.FirstOrDefault(x => x.RequestId == requestId);

// An issue already exists
if (existingIssue != null)
{
existingIssue.Issues.Add(model);
var result = await IssuesService.UpdateIssueAsync(existingIssue);

return Response.AsJson(result
? new JsonResponseModel { Result = true }
: new JsonResponseModel { Result = false });
}

// New issue
var issues = new IssuesModel
{
Title = request.Title,
PosterUrl = request.PosterPath,
RequestId = requestId,
Type = request.Type
};
issues.Issues.Add(model);

var issueId = await IssuesService.AddIssueAsync(issues);

request.IssueId = issueId;
await RequestService.UpdateRequestAsync(request);


return Response.AsJson(new JsonResponseModel { Result = true });
}
}
}
10 changes: 9 additions & 1 deletion PlexRequests.UI/Modules/SearchModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@
using System.Threading.Tasks;

using Nancy.Extensions;
using Nancy.Responses;

using PlexRequests.Api.Models.Tv;
using PlexRequests.Core.Models;
using PlexRequests.Store.Models;
using PlexRequests.Store.Repository;

Expand All @@ -65,7 +68,8 @@ public SearchModule(ICacheProvider cache, ISettingsService<CouchPotatoSettings>
ISettingsService<SickRageSettings> sickRageService, ICouchPotatoApi cpApi, ISickRageApi srApi,
INotificationService notify, IMusicBrainzApi mbApi, IHeadphonesApi hpApi, ISettingsService<HeadphonesSettings> hpService,
ICouchPotatoCacher cpCacher, ISonarrCacher sonarrCacher, ISickRageCacher sickRageCacher, IPlexApi plexApi,
ISettingsService<PlexSettings> plexService, ISettingsService<AuthenticationSettings> auth, IRepository<UsersToNotify> u, ISettingsService<EmailNotificationSettings> email) : base("search", prSettings)
ISettingsService<PlexSettings> plexService, ISettingsService<AuthenticationSettings> auth, IRepository<UsersToNotify> u, ISettingsService<EmailNotificationSettings> email,
IIssueService issue) : base("search", prSettings)
{
Auth = auth;
PlexService = plexService;
Expand All @@ -90,6 +94,7 @@ public SearchModule(ICacheProvider cache, ISettingsService<CouchPotatoSettings>
HeadphonesService = hpService;
UsersToNotifyRepo = u;
EmailNotificationSettings = email;
IssueService = issue;


Get["/", true] = async (x, ct) => await RequestLoad();
Expand Down Expand Up @@ -134,6 +139,7 @@ public SearchModule(ICacheProvider cache, ISettingsService<CouchPotatoSettings>
private IMusicBrainzApi MusicBrainzApi { get; }
private IHeadphonesApi HeadphonesApi { get; }
private IRepository<UsersToNotify> UsersToNotifyRepo { get; }
private IIssueService IssueService { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();

private async Task<Negotiator> RequestLoad()
Expand Down Expand Up @@ -968,5 +974,7 @@ private Response GetSeasons()
var model = seasons.Select(x => x.number);
return Response.AsJson(model);
}


}
}
6 changes: 3 additions & 3 deletions PlexRequests.UI/Views/Requests/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@

{{/if_eq}}

<form method="POST" action="@formAction/requests/reportissue/" id="report{{requestId}}">
<form method="POST" action="@formAction/issues/issue/" id="report{{requestId}}">
<input name="requestId" type="text" value="{{requestId}}" hidden="hidden" />
<div class="dropdown">
<button id="{{requestId}}" class="btn btn-sm btn-primary-outline dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Expand Down Expand Up @@ -348,7 +348,7 @@

{{/if_eq}}

<form method="POST" action="@formAction/requests/reportissue/" id="report{{requestId}}">
<form method="POST" action="@formAction/issues/issue/" id="report{{requestId}}">
<input name="requestId" type="text" value="{{requestId}}" hidden="hidden" />
<div class="dropdown">
<button id="{{requestId}}" class="btn btn-sm btn-primary-outline dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Expand Down Expand Up @@ -382,7 +382,7 @@
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
<h4 class="modal-title">Add issue/comment</h4>
</div>
<form method="POST" action="@formAction/requests/reportissuecomment" id="commentForm">
<form method="POST" action="@formAction/issues/issuecomment" id="commentForm">
<div class="modal-body">
<input name="requestId" class="requestId" type="text" hidden="hidden" value="" />
<textarea class="form-control form-control-custom" rows="3" id="commentArea" name="commentArea"></textarea>
Expand Down

0 comments on commit ebeedb9

Please sign in to comment.