This commit is contained in:
tidusjar 2016-03-15 14:03:07 +00:00
parent 15d1b9f525
commit 67ecbbf178
7 changed files with 112 additions and 16 deletions

View file

@ -24,6 +24,7 @@ namespace PlexRequests.Store
public IssueState Issues { get; set; }
public string OtherMessage { get; set; }
public bool LatestTv { get; set; }
public string AdminNote { get; set; }
}
public enum RequestType

View file

@ -27,6 +27,7 @@ CREATE TABLE IF NOT EXISTS Requested
PosterPath varchar(50) NOT NULL,
ReleaseDate varchar(50) NOT NULL,
Status varchar(50) NOT NULL,
AdminNote varchar(50),
Approved INTEGER NOT NULL,
LatestTv INTEGER NOT NULL,
RequestedBy varchar(50),

View file

@ -90,6 +90,34 @@ $(".theSaveButton").click(function (e) {
});
});
// Note Modal click
$(".theNoteSaveButton").click(function (e) {
var comment = $("#noteArea").val();
e.preventDefault();
var $form = $("#noteForm");
var data = $form.serialize();
$.ajax({
type: $form.prop("method"),
url: $form.prop("action"),
data: data,
dataType: "json",
success: function (response) {
if (checkJsonResponse(response)) {
generateNotify("Success! Added Note.", "success");
$("#myModal").modal("hide");
$('#adminNotesArea').html("<div>Note from Admin: " + comment + "</div>");
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
}
});
});
// Update the modal
$('#myModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget); // Button that triggered the modal
@ -101,6 +129,17 @@ $('#myModal').on('show.bs.modal', function (event) {
requestField.val(id); // Add ID to the hidden field
});
// Update the note modal
$('#noteModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget); // Button that triggered the modal
var id = button.data('identifier'); // Extract info from data-* attributes
var modal = $(this);
modal.find('.theNoteSaveButton').val(id); // Add ID to the button
var requestField = modal.find('input');
requestField.val(id); // Add ID to the hidden field
});
// Delete
$(document).on("click", ".delete", function (e) {
e.preventDefault();
@ -268,7 +307,8 @@ function buildRequestContext(result, type) {
admin: result.admin,
issues: result.issues,
otherMessage: result.otherMessage,
requestId: result.id
requestId: result.id,
adminNote: result.adminNotes
};
return context;

View file

@ -47,5 +47,6 @@ namespace PlexRequests.UI.Models
public bool Admin { get; set; }
public string Issues { get; set; }
public string OtherMessage { get; set; }
public string AdminNotes { get; set; }
}
}

View file

@ -61,7 +61,9 @@ namespace PlexRequests.UI.Modules
Post["/clearissues"] = _ => ClearIssue((int)Request.Form.Id);
Post["/changeavailability"] = _ => ChangeRequestAvailability((int)Request.Form.Id, (bool)Request.Form.Available);
Post["/addnote"] = _ => AddNote((int)Request.Form.Id, (string)Request.Form.noteArea);
}
private IRepository<RequestedModel> Service { get; }
private ISettingsService<PlexRequestSettings> PrSettings { get; }
private ISettingsService<PlexSettings> PlexSettings { get; }
@ -94,7 +96,8 @@ namespace PlexRequests.UI.Modules
Available = movie.Available,
Admin = isAdmin,
Issues = movie.Issues.Humanize(LetterCasing.Title),
OtherMessage = movie.OtherMessage
OtherMessage = movie.OtherMessage,
AdminNotes = movie.AdminNote
}).ToList();
return Response.AsJson(viewModel);
@ -122,7 +125,8 @@ namespace PlexRequests.UI.Modules
Available = tv.Available,
Admin = isAdmin,
Issues = tv.Issues.Humanize(LetterCasing.Title),
OtherMessage = tv.OtherMessage
OtherMessage = tv.OtherMessage,
AdminNotes = tv.AdminNote
}).ToList();
return Response.AsJson(viewModel);
@ -203,5 +207,21 @@ namespace PlexRequests.UI.Modules
? new { Result = true, Available = available, Message = string.Empty }
: new { Result = false, Available = false, Message = "Could not update the availability, please try again or check the logs" });
}
private Response AddNote(int requestId, string noteArea)
{
var originalRequest = Service.Get(requestId);
if (originalRequest == null)
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Request does not exist to change the availability!" });
}
originalRequest.AdminNote = noteArea;
var result = Service.Update(originalRequest);
return Response.AsJson(result
? new JsonResponseModel { Result = true }
: new JsonResponseModel { Result = false, Message = "Could not update the notes, please try again or check the logs" });
}
}
}

View file

@ -189,10 +189,12 @@ namespace PlexRequests.UI.Modules
Log.Trace("Getting movie info from TheMovieDb");
Log.Trace(movieInfo.DumpJson);
#if !DEBUG
if (CheckIfTitleExistsInPlex(movieInfo.Title))
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{movieInfo.Title} is already in Plex!" });
}
#endif
var model = new RequestedModel
{
@ -263,10 +265,12 @@ namespace PlexRequests.UI.Modules
var showInfo = tvApi.GetInformation(showId, token).data;
#if !DEBUG
if (CheckIfTitleExistsInPlex(showInfo.seriesName))
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = $"{showInfo.seriesName} is already in Plex!" });
}
#endif
DateTime firstAir;
DateTime.TryParse(showInfo.firstAired, out firstAir);

View file

@ -102,10 +102,13 @@
<div>Issue: {{issues}}</div>
{{/if}}
</div>
<div id="adminNotesArea">
{{#if adminNote}}
<div>Note from Admin: {{adminNote}}</div>
{{/if}}
</div>
</div>
<div class="col-sm-2 col-sm-push-3">
<br />
<br />
{{#if_eq admin true}}
{{#if_eq approved false}}
<form method="POST" action="/approval/approve" id="approve{{requestId}}">
@ -150,6 +153,11 @@
</ul>
</div>
</form>
{{#if_eq admin true}}
<button id="{{requestId}}" data-identifier="{{requestId}}" style="text-align: right" value="false" href="#" class="btn btn-sm btn-info-outline note" data-toggle="modal" data-target="#noteModal">Add Note</button>
{{/if_eq}}
</div>
@* // TODO add Issues to the view *@
</div>
@ -170,7 +178,7 @@
<textarea class="form-control form-control-custom" rows="3" id="commentArea" name="commentArea"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-danger-outline" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary-outline theSaveButton" data-dismiss="modal">Save changes</button>
</div>
</form>
@ -178,4 +186,25 @@
</div>
</div>
<div class="modal fade" id="noteModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
<h4 class="modal-title">Add a note</h4>
</div>
<form method="POST" action="/requests/addnote" id="noteForm">
<div class="modal-body">
<input name="requestId" class="requestId" type="text" hidden="hidden" value="" />
<textarea class="form-control form-control-custom" rows="3" id="noteArea" name="noteArea"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger-outline" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary-outline theNoteSaveButton" data-dismiss="modal">Save changes</button>
</div>
</form>
</div>
</div>
</div>
<script src="/Content/requests.js" type="text/javascript"></script>