Implimented the features #218

This commit is contained in:
tidusjar 2016-11-20 19:50:33 +00:00
commit 00cd6969e0
11 changed files with 277 additions and 150 deletions

View file

@ -51,21 +51,6 @@ $(function () {
});
focusSearch($('li.active a', '#nav-tabs').first().attr('href'));
// Get the user notification setting
var url = createBaseUrl(base, '/search/notifyuser/');
$.ajax({
type: "get",
url: url,
dataType: "json",
success: function (response) {
$('#notifyUser').prop("checked", response);
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
}
});
// Type in movie search
$("#movieSearchContent").on("input", function () {
if (searchTimer) {
@ -184,32 +169,6 @@ $(function () {
sendRequestAjax(data, type, url, buttonId);
});
// Enable/Disable user notifications
$('#saveNotificationSettings')
.click(function (e) {
e.preventDefault();
var url = createBaseUrl(base, '/search/notifyuser/');
var checked = $('#notifyUser').prop('checked');
$.ajax({
type: "post",
url: url,
data: { notify: checked },
dataType: "json",
success: function (response) {
console.log(response);
if (response.result === true) {
generateNotify(response.message || "Success!", "success");
} else {
generateNotify(response.message, "warning");
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
}
});
});
// Report Issue
$(document).on("click", ".dropdownIssue", function (e) {
var issue = $(this).attr("issue-select");

View file

@ -132,10 +132,7 @@ namespace PlexRequests.UI.Modules
async (x, ct) => await RequestTvShow((int)Request.Form.tvId, (string)Request.Form.seasons);
Post["request/tvEpisodes", true] = async (x, ct) => await RequestTvShow(0, "episode");
Post["request/album", true] = async (x, ct) => await RequestAlbum((string)Request.Form.albumId);
Post["/notifyuser", true] = async (x, ct) => await NotifyUser((bool)Request.Form.notify);
Get["/notifyuser", true] = async (x, ct) => await GetUserNotificationSettings();
Get["/seasons"] = x => GetSeasons();
Get["/episodes", true] = async (x, ct) => await GetEpisodes();
}
@ -1146,66 +1143,7 @@ namespace PlexRequests.UI.Modules
return img;
}
private async Task<Response> NotifyUser(bool notify)
{
Analytics.TrackEventAsync(Category.Search, Action.Save, "NotifyUser", Username, CookieHelper.GetAnalyticClientId(Cookies), notify ? 1 : 0);
var authSettings = await Auth.GetSettingsAsync();
var auth = authSettings.UserAuthentication;
var emailSettings = await EmailNotificationSettings.GetSettingsAsync();
var email = emailSettings.EnableUserEmailNotifications;
if (!auth)
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = Resources.UI.Search_ErrorPlexAccountOnly });
}
if (!email)
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = Resources.UI.Search_ErrorNotEnabled });
}
var username = Username;
var originalList = await UsersToNotifyRepo.GetAllAsync();
if (!notify)
{
if (originalList == null)
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = Resources.UI.Search_NotificationError });
}
var userToRemove = originalList.FirstOrDefault(x => x.Username == username);
if (userToRemove != null)
{
await UsersToNotifyRepo.DeleteAsync(userToRemove);
}
return Response.AsJson(new JsonResponseModel { Result = true });
}
if (originalList == null)
{
var userModel = new UsersToNotify { Username = username };
var insertResult = await UsersToNotifyRepo.InsertAsync(userModel);
return Response.AsJson(insertResult != -1 ? new JsonResponseModel { Result = true } : new JsonResponseModel { Result = false, Message = Resources.UI.Common_CouldNotSave });
}
var existingUser = originalList.FirstOrDefault(x => x.Username == username);
if (existingUser != null)
{
return Response.AsJson(new JsonResponseModel { Result = true }); // It's already enabled
}
else
{
var userModel = new UsersToNotify { Username = username };
var insertResult = await UsersToNotifyRepo.InsertAsync(userModel);
return Response.AsJson(insertResult != -1 ? new JsonResponseModel { Result = true } : new JsonResponseModel { Result = false, Message = Resources.UI.Common_CouldNotSave });
}
}
private async Task<Response> GetUserNotificationSettings()
{
var all = await UsersToNotifyRepo.GetAllAsync();
var retVal = all.FirstOrDefault(x => x.Username == Username);
return Response.AsJson(retVal != null);
}
private Response GetSeasons()
{
var seriesId = (int)Request.Query.tvId;

View file

@ -111,33 +111,6 @@
</div>
}
<!-- Notification tab -->
<div role="tabpanel" class="tab-pane" id="NotificationsTab">
<div class="input-group">
<div class="input-group-addon input-group-sm"></div>
</div>
<br />
<!-- Notifications content -->
<form class="form-horizontal" method="POST" id="notificationsForm">
<fieldset>
<div class="form-group">
<div class="checkbox">
<input type="checkbox" id="notifyUser" name="Notify">
<label for="notifyUser">@UI.Search_SendNotificationText</label>
</div>
</div>
<div class="form-group">
<div>
<button id="saveNotificationSettings" class="btn btn-primary-outline">@UI.Common_Save</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
<!-- Movie and TV Results template -->
<script id="search-template" type="text/x-handlebars-template">
<div class="row">