Skip to content

Commit

Permalink
Merge pull request #98 from tidusjar/dev
Browse files Browse the repository at this point in the history
Dev merge
  • Loading branch information
Jamie committed Mar 26, 2016
2 parents b7ce53c + f77d5f2 commit 0ee27c2
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 27 deletions.
12 changes: 12 additions & 0 deletions PlexRequests.Helpers/LoggingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ public static void ConfigureLogging(string connectionString)
var rule1 = new LoggingRule("*", LogLevel.Info, databaseTarget);
config.LoggingRules.Add(rule1);


var fileTarget = new FileTarget
{
Name = "file",
FileName = "logs/${shortdate}.log",
Layout = "${date} ${logger} ${level}: ${message} ${exception:tostring}",
CreateDirs = true
};
config.AddTarget(fileTarget);
var rule2 = new LoggingRule("*", LogLevel.Trace, fileTarget);
config.LoggingRules.Add(rule2);

// Step 5. Activate the configuration
LogManager.Configuration = config;
}
Expand Down
20 changes: 16 additions & 4 deletions PlexRequests.UI/Content/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ $("#tvSearchContent").on("input", function () {

// Click TV dropdown option
$(document).on("click", ".dropdownTv", function (e) {
e.preventDefault();
var buttonId = e.target.id;
if ($("#" + buttonId).attr('disabled')) {
return;
}

$("#" + buttonId).prop("disabled", true);
loadingButton(buttonId, "primary");

e.preventDefault();

var $form = $('#form' + buttonId);
var data = $form.serialize();
Expand All @@ -53,15 +58,19 @@ $(document).on("click", ".dropdownTv", function (e) {
var url = $form.prop('action');

sendRequestAjax(data, type, url, buttonId);
$("#" + buttonId).prop("disabled", false);
});

// Click Request for movie
$(document).on("click", ".requestMovie", function (e) {
e.preventDefault();
var buttonId = e.target.id;
if ($("#" + buttonId).attr('disabled')) {
return;
}

$("#" + buttonId).prop("disabled", true);
loadingButton(buttonId, "primary");
e.preventDefault();


var $form = $('#form' + buttonId);

Expand All @@ -70,7 +79,7 @@ $(document).on("click", ".requestMovie", function (e) {
var data = $form.serialize();

sendRequestAjax(data, type, url, buttonId);
$("#" + buttonId).prop("disabled", false);

});

function sendRequestAjax(data, type, url, buttonId) {
Expand All @@ -90,6 +99,9 @@ function sendRequestAjax(data, type, url, buttonId) {
$('#' + buttonId).addClass("btn-success-outline");
} else {
generateNotify(response.message, "warning");
$('#' + buttonId).html("<i class='fa fa-plus'></i> Request");
$('#' + buttonId).attr("data-toggle", "dropdown");
$("#" + buttonId).removeAttr("disabled");
}
},
error: function (e) {
Expand Down
48 changes: 40 additions & 8 deletions PlexRequests.UI/Modules/SearchModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,22 +224,54 @@ private Response RequestMovie(int movieId)

Log.Trace("Settings: ");
Log.Trace(cpSettings.DumpJson);
if (cpSettings.Enabled)
{
Log.Info("Adding movie to CP (No approval required)");
var result = CouchPotatoApi.AddMovie(model.ImdbId, cpSettings.ApiKey, model.Title,
cpSettings.FullUri, cpSettings.ProfileId);
Log.Debug("Adding movie to CP result {0}", result);
if (result)
{
model.Approved = true;
Log.Debug("Adding movie to database requests (No approval required)");
RequestService.AddRequest(model);

var notificationModel = new NotificationModel
{
Title = model.Title,
User = model.RequestedBy,
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest
};
NotificationService.Publish(notificationModel);

Log.Info("Adding movie to CP (No approval required)");
var result = CouchPotatoApi.AddMovie(model.ImdbId, cpSettings.ApiKey, model.Title, cpSettings.FullUri, cpSettings.ProfileId);
Log.Debug("Adding movie to CP result {0}", result);
if (result)
return Response.AsJson(new JsonResponseModel {Result = true});
}
return
Response.AsJson(new JsonResponseModel
{
Result = false,
Message =
"Something went wrong adding the movie to CouchPotato! Please check your settings."
});
}
else
{
model.Approved = true;
Log.Debug("Adding movie to database requests (No approval required)");
RequestService.AddRequest(model);

var notificationModel = new NotificationModel { Title = model.Title, User = model.RequestedBy, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest };
var notificationModel = new NotificationModel
{
Title = model.Title,
User = model.RequestedBy,
DateTime = DateTime.Now,
NotificationType = NotificationType.NewRequest
};
NotificationService.Publish(notificationModel);

return Response.AsJson(new JsonResponseModel { Result = true });
}
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Something went wrong adding the movie to CouchPotato! Please check your settings." });
}

try
Expand Down Expand Up @@ -305,7 +337,7 @@ private Response RequestTvShow(int showId, string seasons)
Approved = false,
RequestedBy = Session[SessionKeys.UsernameKey].ToString(),
Issues = IssueState.None,
ImdbId = showInfo.externals?.imdb ?? string.Empty,
ImdbId = showInfo.externals?.imdb ?? string.Empty,
SeasonCount = showInfo.seasonCount
};
var seasonsList = new List<int>();
Expand All @@ -323,7 +355,7 @@ private Response RequestTvShow(int showId, string seasons)
model.SeasonsRequested = "All";
break;
}

model.SeasonList = seasonsList.ToArray();

var settings = PrService.GetSettings();
Expand Down
14 changes: 0 additions & 14 deletions PlexRequests.UI/NLog.config
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,8 @@
layout="${date} ${logger} ${level}: ${message}" />


<!--<target name="Database" xsi:type="Database"
dbProvider="Mono.Data.Sqlite.SqliteConnection, Mono.Data.Sqlite, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" keepConnection="false"
connectionString="Data Source=PlexRequests.sqlite, version=3"
commandText="INSERT into Logs(Date, Level, Logger, Callsite, Message, Exception)
values(@Date, @Loglevel, @Logger, @Callsite, @Message, @Exception)">
<parameter name="@Date" layout="${longdate}"/>
<parameter name="@Loglevel" layout="${level:uppercase=true}"/>
<parameter name="@Logger" layout="${logger}"/>
<parameter name="@Callsite" layout="${callsite:filename=true}"/>
<parameter name="@Message" layout="${message}"/>
<parameter name="@Exception" layout="${exception:format=tostring}"/>
</target>-->

</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="filelog" />
<!--<logger name="*" minlevel="Trace" writeTo="Database" />-->
</rules>
</nlog>
8 changes: 7 additions & 1 deletion PlexRequests.UI/Views/Search/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,15 @@
</div>
<div class="col-sm-5 ">
<div>
<a href="http://www.imdb.com/title/{{imdb}}/" targe="_blank">
{{#if_eq type "movie"}}
<a href="https://www.themoviedb.org/movie/{{id}}/" target="_blank">
<h4>{{title}} ({{year}})</h4>
</a>
{{else}}
<a href="http://www.imdb.com/title/{{imdb}}/" target="_blank">
<h4>{{title}} ({{year}})</h4>
</a>
{{/if_eq}}
</div>
<p>{{overview}}</p>
</div>
Expand Down

0 comments on commit 0ee27c2

Please sign in to comment.