2010-09-23 05:19:47 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2010-10-08 05:35:04 +02:00
|
|
|
|
using System.Threading;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Web.Mvc;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
using NLog;
|
2011-02-26 05:07:22 +01:00
|
|
|
|
using NzbDrone.Core;
|
2011-03-03 09:50:33 +01:00
|
|
|
|
using NzbDrone.Core.Helpers;
|
2011-02-11 02:22:29 +01:00
|
|
|
|
using NzbDrone.Core.Model;
|
2011-02-05 07:07:25 +01:00
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2010-09-24 07:21:45 +02:00
|
|
|
|
using NzbDrone.Web.Models;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
2010-10-08 05:35:04 +02:00
|
|
|
|
[HandleError]
|
2010-09-23 05:19:47 +02:00
|
|
|
|
public class SettingsController : Controller
|
|
|
|
|
{
|
2010-09-28 06:25:41 +02:00
|
|
|
|
private IConfigProvider _configProvider;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
private IIndexerProvider _indexerProvider;
|
2011-02-03 03:49:52 +01:00
|
|
|
|
private IQualityProvider _qualityProvider;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
2011-02-15 02:20:17 +01:00
|
|
|
|
private string _settingsSaved = "Settings Saved.";
|
|
|
|
|
private string _settingsFailed = "Error Saving Settings, please fix any errors";
|
2010-09-24 07:21:45 +02:00
|
|
|
|
|
2011-02-03 03:49:52 +01:00
|
|
|
|
public SettingsController(IConfigProvider configProvider, IIndexerProvider indexerProvider, IQualityProvider qualityProvider)
|
2010-09-24 07:21:45 +02:00
|
|
|
|
{
|
2010-09-28 06:25:41 +02:00
|
|
|
|
_configProvider = configProvider;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
_indexerProvider = indexerProvider;
|
2011-02-03 03:49:52 +01:00
|
|
|
|
_qualityProvider = qualityProvider;
|
2010-09-24 07:21:45 +02:00
|
|
|
|
}
|
2010-09-23 05:19:47 +02:00
|
|
|
|
|
2011-01-29 07:10:22 +01:00
|
|
|
|
public ActionResult Index(string viewName)
|
2010-09-23 05:19:47 +02:00
|
|
|
|
{
|
2011-01-29 07:10:22 +01:00
|
|
|
|
if (viewName != null)
|
|
|
|
|
ViewData["viewName"] = viewName;
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
ViewData["viewName"] = "General";
|
|
|
|
|
|
|
|
|
|
return View("Index", new SettingsModel
|
|
|
|
|
{
|
|
|
|
|
TvFolder = _configProvider.SeriesRoot
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult General()
|
|
|
|
|
{
|
|
|
|
|
ViewData["viewName"] = "General";
|
|
|
|
|
return View("Index", new SettingsModel
|
|
|
|
|
{
|
2011-01-31 08:42:44 +01:00
|
|
|
|
TvFolder = _configProvider.SeriesRoot,
|
|
|
|
|
Quality = Convert.ToInt32(_configProvider.GetValue("Quality", "1", true)),
|
2011-01-29 07:10:22 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Indexers()
|
|
|
|
|
{
|
|
|
|
|
ViewData["viewName"] = "Indexers";
|
2011-02-11 02:22:29 +01:00
|
|
|
|
return View("Index", new IndexerSettingsModel
|
2011-01-29 07:10:22 +01:00
|
|
|
|
{
|
|
|
|
|
NzbMatrixUsername = _configProvider.GetValue("NzbMatrixUsername", String.Empty, false),
|
|
|
|
|
NzbMatrixApiKey = _configProvider.GetValue("NzbMatrixApiKey", String.Empty, false),
|
|
|
|
|
NzbsOrgUId = _configProvider.GetValue("NzbsOrgUId", String.Empty, false),
|
|
|
|
|
NzbsOrgHash = _configProvider.GetValue("NzbsOrgHash", String.Empty, false),
|
|
|
|
|
NzbsrusUId = _configProvider.GetValue("NzbsrusUId", String.Empty, false),
|
|
|
|
|
NzbsrusHash = _configProvider.GetValue("NzbsrusHash", String.Empty, false),
|
|
|
|
|
Indexers = _indexerProvider.AllIndexers()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Downloads()
|
|
|
|
|
{
|
|
|
|
|
ViewData["viewName"] = "Downloads";
|
2011-02-11 02:22:29 +01:00
|
|
|
|
|
|
|
|
|
var model = new DownloadSettingsModel
|
|
|
|
|
{
|
|
|
|
|
SyncFrequency = Convert.ToInt32(_configProvider.GetValue("SyncFrequency", "15", true)),
|
|
|
|
|
DownloadPropers = Convert.ToBoolean(_configProvider.GetValue("DownloadPropers", "false", true)),
|
|
|
|
|
Retention = Convert.ToInt32(_configProvider.GetValue("Retention", "500", true)),
|
|
|
|
|
SabHost = _configProvider.GetValue("SabHost", "localhost", false),
|
|
|
|
|
SabPort = Convert.ToInt32(_configProvider.GetValue("SabPort", "8080", true)),
|
|
|
|
|
SabApiKey = _configProvider.GetValue("SabApiKey", String.Empty, false),
|
|
|
|
|
SabUsername = _configProvider.GetValue("SabUsername", String.Empty, false),
|
|
|
|
|
SabPassword = _configProvider.GetValue("SabPassword", String.Empty, false),
|
|
|
|
|
SabCategory = _configProvider.GetValue("SabCategory", String.Empty, false),
|
|
|
|
|
SabPriority = (SabnzbdPriorityType)Enum.Parse(typeof(SabnzbdPriorityType), _configProvider.GetValue("SabPriority", "Normal", true)),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("Index", model);
|
2011-01-29 07:10:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-03 03:49:52 +01:00
|
|
|
|
public ActionResult Quality()
|
|
|
|
|
{
|
2011-02-03 19:28:14 +01:00
|
|
|
|
ViewData["viewName"] = "Quality";
|
2011-02-03 03:49:52 +01:00
|
|
|
|
|
2011-02-05 07:07:25 +01:00
|
|
|
|
var qualityTypes = new List<QualityTypes>();
|
2011-02-03 03:49:52 +01:00
|
|
|
|
|
2011-02-05 07:07:25 +01:00
|
|
|
|
foreach (QualityTypes qual in Enum.GetValues(typeof(QualityTypes)))
|
|
|
|
|
{
|
|
|
|
|
qualityTypes.Add(qual);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-06 03:52:49 +01:00
|
|
|
|
ViewData["Qualities"] = qualityTypes;
|
|
|
|
|
|
|
|
|
|
var userProfiles = _qualityProvider.GetAllProfiles().Where(q => q.UserProfile).ToList();
|
|
|
|
|
var profiles = _qualityProvider.GetAllProfiles().ToList();
|
2011-02-11 02:22:29 +01:00
|
|
|
|
|
2011-02-17 18:45:02 +01:00
|
|
|
|
var defaultQualityQualityProfileId = Convert.ToInt32(_configProvider.GetValue("DefaultQualityProfile", profiles[0].QualityProfileId, true));
|
2011-02-05 07:07:25 +01:00
|
|
|
|
|
2011-02-17 18:45:02 +01:00
|
|
|
|
var selectList = new SelectList(profiles, "QualityProfileId", "Name");
|
2011-02-05 07:07:25 +01:00
|
|
|
|
|
|
|
|
|
var model = new QualityModel
|
|
|
|
|
{
|
|
|
|
|
Profiles = profiles,
|
|
|
|
|
UserProfiles = userProfiles,
|
2011-02-17 18:45:02 +01:00
|
|
|
|
DefaultQualityProfileId = defaultQualityQualityProfileId,
|
2011-02-05 07:07:25 +01:00
|
|
|
|
SelectList = selectList
|
|
|
|
|
};
|
2011-02-03 03:49:52 +01:00
|
|
|
|
|
|
|
|
|
return View("Index", model);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-26 05:07:22 +01:00
|
|
|
|
public ActionResult EpisodeSorting()
|
|
|
|
|
{
|
|
|
|
|
ViewData["viewName"] = "EpisodeSorting";
|
|
|
|
|
|
|
|
|
|
var model = new EpisodeSortingModel();
|
|
|
|
|
|
|
|
|
|
model.ShowName = Convert.ToBoolean(_configProvider.GetValue("Sorting_ShowName", true, true));
|
|
|
|
|
model.EpisodeName = Convert.ToBoolean(_configProvider.GetValue("Sorting_EpisodeName", true, true));
|
|
|
|
|
model.ReplaceSpaces = Convert.ToBoolean(_configProvider.GetValue("Sorting_ReplaceSpaces", false, true));
|
|
|
|
|
model.AppendQuality = Convert.ToBoolean(_configProvider.GetValue("Sorting_AppendQuality", false, true));
|
|
|
|
|
model.UseAirByDate = Convert.ToBoolean(_configProvider.GetValue("Sorting_UseAirByDate", true, true));
|
|
|
|
|
model.SeasonFolders = Convert.ToBoolean(_configProvider.GetValue("Sorting_SeasonFolder", true, true));
|
|
|
|
|
model.SeasonFolderFormat = _configProvider.GetValue("Sorting_SeasonFolderFormat", "Season %s", true);
|
|
|
|
|
model.SeparatorStyle = Convert.ToInt32(_configProvider.GetValue("Sorting_SeparatorStyle", 0, true));
|
|
|
|
|
model.NumberStyle = Convert.ToInt32(_configProvider.GetValue("Sorting_NumberStyle", 2, true));
|
|
|
|
|
model.MultiEpisodeStyle = Convert.ToInt32(_configProvider.GetValue("Sorting_MultiEpisodeStyle", 0, true));
|
|
|
|
|
|
|
|
|
|
model.SeparatorStyles = new SelectList(EpisodeSortingHelper.GetSeparatorStyles(), "Id", "Name");
|
|
|
|
|
model.NumberStyles = new SelectList(EpisodeSortingHelper.GetNumberStyles(), "Id", "Name");
|
|
|
|
|
model.MultiEpisodeStyles = new SelectList(EpisodeSortingHelper.GetMultiEpisodeStyles(), "Id", "Name");
|
|
|
|
|
|
|
|
|
|
return View("Index", model);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-05 19:27:14 +01:00
|
|
|
|
public ViewResult AddUserProfile()
|
|
|
|
|
{
|
2011-02-06 08:13:17 +01:00
|
|
|
|
var qualityTypes = new List<QualityTypes>();
|
|
|
|
|
|
|
|
|
|
foreach (QualityTypes qual in Enum.GetValues(typeof(QualityTypes)))
|
|
|
|
|
{
|
|
|
|
|
qualityTypes.Add(qual);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ViewData["Qualities"] = qualityTypes;
|
|
|
|
|
|
|
|
|
|
return View("UserProfileSection", new QualityProfile { Name = "New Profile", UserProfile = true });
|
2011-02-05 19:27:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-29 07:10:22 +01:00
|
|
|
|
public ActionResult SubMenu()
|
|
|
|
|
{
|
|
|
|
|
return PartialView();
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-12 07:10:38 +01:00
|
|
|
|
public QualityModel GetUpdatedProfileList()
|
|
|
|
|
{
|
|
|
|
|
var profiles = _qualityProvider.GetAllProfiles().ToList();
|
2011-02-17 18:45:02 +01:00
|
|
|
|
var defaultQualityQualityProfileId = Convert.ToInt32(_configProvider.GetValue("DefaultQualityProfile", profiles[0].QualityProfileId, true));
|
|
|
|
|
var selectList = new SelectList(profiles, "QualityProfileId", "Name");
|
2011-02-16 05:44:19 +01:00
|
|
|
|
|
2011-02-17 18:45:02 +01:00
|
|
|
|
return new QualityModel { DefaultQualityProfileId = defaultQualityQualityProfileId, SelectList = selectList };
|
2011-02-12 07:10:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-29 07:10:22 +01:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult SaveGeneral(SettingsModel data)
|
|
|
|
|
{
|
2011-02-15 02:20:17 +01:00
|
|
|
|
if (ModelState.IsValid)
|
2011-01-29 07:10:22 +01:00
|
|
|
|
{
|
2011-02-15 02:20:17 +01:00
|
|
|
|
_configProvider.SeriesRoot = data.TvFolder;
|
|
|
|
|
return Content(_settingsSaved);
|
2011-01-29 07:10:22 +01:00
|
|
|
|
}
|
2011-02-11 02:22:29 +01:00
|
|
|
|
|
2011-02-16 05:44:19 +01:00
|
|
|
|
return Content(_settingsFailed);
|
2010-09-24 07:21:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2011-02-11 02:22:29 +01:00
|
|
|
|
public ActionResult SaveIndexers(IndexerSettingsModel data)
|
2010-09-24 07:21:45 +02:00
|
|
|
|
{
|
2011-02-15 02:20:17 +01:00
|
|
|
|
if (ModelState.IsValid)
|
2010-09-24 07:21:45 +02:00
|
|
|
|
{
|
2011-01-31 02:30:59 +01:00
|
|
|
|
//Todo: Only allow indexers to be enabled if user information has been provided
|
2011-01-29 07:10:22 +01:00
|
|
|
|
foreach (var indexer in data.Indexers)
|
|
|
|
|
_indexerProvider.Update(indexer);
|
|
|
|
|
|
2011-02-15 02:20:17 +01:00
|
|
|
|
_configProvider.SetValue("NzbMatrixUsername", data.NzbMatrixUsername);
|
|
|
|
|
_configProvider.SetValue("NzbMatrixApiKey", data.NzbMatrixApiKey);
|
|
|
|
|
_configProvider.SetValue("NzbsOrgUId", data.NzbsOrgUId);
|
|
|
|
|
_configProvider.SetValue("NzbsOrgHash", data.NzbsOrgHash);
|
|
|
|
|
_configProvider.SetValue("NzbsrusUId", data.NzbsrusUId);
|
|
|
|
|
_configProvider.SetValue("NzbsrusHash", data.NzbsrusHash);
|
2011-01-31 02:30:59 +01:00
|
|
|
|
|
2011-02-15 02:20:17 +01:00
|
|
|
|
return Content(_settingsSaved);
|
2011-01-29 07:10:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-15 02:20:17 +01:00
|
|
|
|
return Content(_settingsFailed);
|
2010-09-23 05:19:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-29 07:10:22 +01:00
|
|
|
|
[HttpPost]
|
2011-02-11 02:22:29 +01:00
|
|
|
|
public ActionResult SaveDownloads(DownloadSettingsModel data)
|
2011-01-29 07:10:22 +01:00
|
|
|
|
{
|
2011-02-11 02:22:29 +01:00
|
|
|
|
if (ModelState.IsValid)
|
2011-01-29 07:10:22 +01:00
|
|
|
|
{
|
2011-02-16 05:44:19 +01:00
|
|
|
|
_configProvider.SetValue("SyncFrequency", data.SyncFrequency.ToString());
|
|
|
|
|
_configProvider.SetValue("DownloadPropers", data.DownloadPropers.ToString());
|
|
|
|
|
_configProvider.SetValue("Retention", data.Retention.ToString());
|
|
|
|
|
_configProvider.SetValue("SabHost", data.SabHost);
|
|
|
|
|
_configProvider.SetValue("SabPort", data.SabPort.ToString());
|
|
|
|
|
_configProvider.SetValue("SabApiKey", data.SabApiKey);
|
|
|
|
|
_configProvider.SetValue("SabUsername", data.SabUsername);
|
|
|
|
|
_configProvider.SetValue("SabPassword", data.SabPassword);
|
|
|
|
|
_configProvider.SetValue("SabCategory", data.SabCategory);
|
|
|
|
|
_configProvider.SetValue("SabPriority", data.SabPriority.ToString());
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
2011-02-16 05:44:19 +01:00
|
|
|
|
return Content(_settingsSaved);
|
2011-02-11 02:22:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-15 02:20:17 +01:00
|
|
|
|
return Content(_settingsFailed);
|
2011-01-29 07:10:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-04 03:58:02 +01:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult SaveQuality(QualityModel data)
|
|
|
|
|
{
|
2011-02-15 02:20:17 +01:00
|
|
|
|
if (ModelState.IsValid)
|
2011-02-04 03:58:02 +01:00
|
|
|
|
{
|
2011-02-17 18:45:02 +01:00
|
|
|
|
_configProvider.SetValue("DefaultQualityProfile", data.DefaultQualityProfileId.ToString());
|
2011-02-15 02:20:17 +01:00
|
|
|
|
|
|
|
|
|
//Saves only the Default Quality, skips User Profiles since none exist
|
|
|
|
|
if (data.UserProfiles == null)
|
|
|
|
|
return Content(_settingsSaved);
|
|
|
|
|
|
|
|
|
|
foreach (var dbProfile in _qualityProvider.GetAllProfiles().Where(q => q.UserProfile))
|
2011-02-06 08:13:17 +01:00
|
|
|
|
{
|
2011-02-17 18:45:02 +01:00
|
|
|
|
if (!data.UserProfiles.Exists(p => p.QualityProfileId == dbProfile.QualityProfileId))
|
|
|
|
|
_qualityProvider.Delete(dbProfile.QualityProfileId);
|
2011-02-15 02:20:17 +01:00
|
|
|
|
}
|
2011-02-07 22:22:45 +01:00
|
|
|
|
|
2011-02-15 02:20:17 +01:00
|
|
|
|
foreach (var profile in data.UserProfiles)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug(String.Format("Updating User Profile: {0}", profile));
|
2011-02-06 08:13:17 +01:00
|
|
|
|
|
2011-02-15 02:20:17 +01:00
|
|
|
|
profile.Allowed = new List<QualityTypes>();
|
|
|
|
|
foreach (var quality in profile.AllowedString.Split(','))
|
2011-02-15 01:45:31 +01:00
|
|
|
|
{
|
2011-02-15 02:20:17 +01:00
|
|
|
|
var qType = (QualityTypes)Enum.Parse(typeof(QualityTypes), quality);
|
|
|
|
|
profile.Allowed.Add(qType);
|
|
|
|
|
}
|
2011-02-15 01:45:31 +01:00
|
|
|
|
|
2011-02-15 02:20:17 +01:00
|
|
|
|
//If the Cutoff value selected is not in the allowed list then use the last allowed value, this should be validated on submit
|
|
|
|
|
if (!profile.Allowed.Contains(profile.Cutoff))
|
|
|
|
|
return Content("Error Saving Settings, please fix any errors");
|
|
|
|
|
//profile.Cutoff = profile.Allowed.Last();
|
2011-02-06 08:13:17 +01:00
|
|
|
|
|
2011-02-17 18:45:02 +01:00
|
|
|
|
if (profile.QualityProfileId > 0)
|
2011-02-15 02:20:17 +01:00
|
|
|
|
_qualityProvider.Update(profile);
|
2011-02-06 08:13:17 +01:00
|
|
|
|
|
2011-02-15 02:20:17 +01:00
|
|
|
|
else
|
|
|
|
|
_qualityProvider.Add(profile);
|
2011-02-15 01:45:31 +01:00
|
|
|
|
|
2011-02-15 02:20:17 +01:00
|
|
|
|
return Content(_settingsSaved);
|
2011-02-06 08:13:17 +01:00
|
|
|
|
}
|
2011-02-04 03:58:02 +01:00
|
|
|
|
}
|
2011-02-05 07:07:25 +01:00
|
|
|
|
|
2011-02-15 02:20:17 +01:00
|
|
|
|
return Content(_settingsFailed);
|
2011-02-11 02:22:29 +01:00
|
|
|
|
}
|
2011-02-26 05:07:22 +01:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult SaveEpisodeSorting(EpisodeSortingModel data)
|
|
|
|
|
{
|
|
|
|
|
if (ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
_configProvider.SetValue("Sorting_ShowName", data.ShowName.ToString());
|
|
|
|
|
_configProvider.SetValue("Sorting_EpisodeName", data.EpisodeName.ToString());
|
|
|
|
|
_configProvider.SetValue("Sorting_ReplaceSpaces", data.ReplaceSpaces.ToString());
|
|
|
|
|
_configProvider.SetValue("Sorting_AppendQuality", data.AppendQuality.ToString());
|
|
|
|
|
_configProvider.SetValue("Sorting_UseAirByDate", data.UseAirByDate.ToString());
|
|
|
|
|
_configProvider.SetValue("Sorting_SeasonFolder", data.SeasonFolders.ToString());
|
|
|
|
|
_configProvider.SetValue("Sorting_SeasonFolderFormat", data.SeasonFolderFormat);
|
|
|
|
|
_configProvider.SetValue("Sorting_SeparatorStyle", data.SeparatorStyle.ToString());
|
|
|
|
|
_configProvider.SetValue("Sorting_NumberStyle", data.NumberStyle.ToString());
|
|
|
|
|
_configProvider.SetValue("Sorting_MultiEpisodeStyle", data.MultiEpisodeStyle.ToString());
|
|
|
|
|
|
|
|
|
|
return Content(_settingsSaved);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Content(_settingsFailed);
|
|
|
|
|
}
|
2010-09-23 05:19:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|