mirror of
https://github.com/Radarr/Radarr.git
synced 2024-08-16 23:39:44 +02:00
added settings view to mvc project
This commit is contained in:
parent
941d516e42
commit
d7bae9135c
@ -9,6 +9,7 @@ namespace NzbDrone.Core.Controllers
|
|||||||
{
|
{
|
||||||
public class DbConfigController : IConfigController
|
public class DbConfigController : IConfigController
|
||||||
{
|
{
|
||||||
|
private const string _seriesroots = "SeriesRoots";
|
||||||
private readonly IDiskController _diskController;
|
private readonly IDiskController _diskController;
|
||||||
private readonly ILog _logger;
|
private readonly ILog _logger;
|
||||||
private readonly IRepository _sonicRepo;
|
private readonly IRepository _sonicRepo;
|
||||||
@ -21,20 +22,27 @@ public DbConfigController(ILog logger, IDiskController diskController, IReposito
|
|||||||
_sonicRepo = dataRepository;
|
_sonicRepo = dataRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IConfigController Members
|
|
||||||
|
|
||||||
public List<String> GetTvRoots()
|
|
||||||
{
|
|
||||||
return (GetValue("tvRoot").Trim(';').Split(';').Where(path => _diskController.Exists(path))).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private string GetValue(string key)
|
private string GetValue(string key)
|
||||||
{
|
{
|
||||||
return GetValue(key, String.Empty, false);
|
return GetValue(key, String.Empty, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String SeriesRoot
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return GetValue(_seriesroots);
|
||||||
|
}
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
SetValue(_seriesroots, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private string GetValue(string key, object defaultValue, bool makePermanent)
|
private string GetValue(string key, object defaultValue, bool makePermanent)
|
||||||
{
|
{
|
||||||
string value;
|
string value;
|
||||||
@ -62,7 +70,7 @@ private void SetValue(string key, string value)
|
|||||||
{
|
{
|
||||||
_logger.DebugFormat("Writing Setting to file. Key:'{0}' Value:'{1}'", key, value);
|
_logger.DebugFormat("Writing Setting to file. Key:'{0}' Value:'{1}'", key, value);
|
||||||
|
|
||||||
_sonicRepo.Add(new Config {Key = key, Value = value});
|
_sonicRepo.Add(new Config { Key = key, Value = value });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,65 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Configuration;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using log4net;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Controllers
|
|
||||||
{
|
|
||||||
public class FileConfigController : IConfigController
|
|
||||||
{
|
|
||||||
private readonly Configuration _config = ConfigurationManager.OpenExeConfiguration(Path.Combine(Main.AppPath, @"NzbDrone.exe"));
|
|
||||||
private readonly IDiskController _diskController;
|
|
||||||
private readonly ILog _logger;
|
|
||||||
|
|
||||||
public FileConfigController(ILog logger, IDiskController diskController)
|
|
||||||
{
|
|
||||||
_logger = logger;
|
|
||||||
_diskController = diskController;
|
|
||||||
}
|
|
||||||
|
|
||||||
#region IConfigController Members
|
|
||||||
|
|
||||||
public List<String> GetTvRoots()
|
|
||||||
{
|
|
||||||
return (GetValue("tvRoot").Trim(';').Split(';').Where(path => _diskController.Exists(path))).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private string GetValue(string key)
|
|
||||||
{
|
|
||||||
return GetValue(key, String.Empty, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetValue(string key, object defaultValue, bool makePermanent)
|
|
||||||
{
|
|
||||||
string value;
|
|
||||||
|
|
||||||
if (_config.AppSettings.Settings[key] != null)
|
|
||||||
{
|
|
||||||
value = _config.AppSettings.Settings[key].Value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.WarnFormat("Unable to find config key '{0}' defaultValue:'{1}'", key, defaultValue);
|
|
||||||
if (makePermanent)
|
|
||||||
{
|
|
||||||
SetValue(key, defaultValue.ToString());
|
|
||||||
}
|
|
||||||
value = defaultValue.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetValue(string key, object value)
|
|
||||||
{
|
|
||||||
_logger.DebugFormat("Writing Setting to file. Key:'{0}' Value:'{1}'", key, value);
|
|
||||||
_config.AppSettings.Settings.Remove(key);
|
|
||||||
_config.AppSettings.Settings.Add(key, value.ToString());
|
|
||||||
_config.Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +1,15 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Controllers
|
namespace NzbDrone.Core.Controllers
|
||||||
{
|
{
|
||||||
public interface IConfigController
|
public interface IConfigController
|
||||||
{
|
{
|
||||||
List<string> GetTvRoots();
|
String SeriesRoot
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
|
||||||
|
set;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -34,18 +34,17 @@ public IQueryable<Series> GetSeries()
|
|||||||
|
|
||||||
public void SyncSeriesWithDisk()
|
public void SyncSeriesWithDisk()
|
||||||
{
|
{
|
||||||
foreach (string root in _config.GetTvRoots())
|
|
||||||
|
foreach (string seriesFolder in _diskController.GetDirectories(_config.SeriesRoot))
|
||||||
{
|
{
|
||||||
foreach (string seriesFolder in _diskController.GetDirectories(root))
|
var dirInfo = new DirectoryInfo(seriesFolder);
|
||||||
|
if (!_sonioRepo.Exists<Series>(s => s.Path == _diskController.CleanPath(dirInfo.FullName)))
|
||||||
{
|
{
|
||||||
var dirInfo = new DirectoryInfo(seriesFolder);
|
_logger.InfoFormat("Folder '{0} isn't mapped to a series in the database. Trying to map it.'", seriesFolder);
|
||||||
if (!_sonioRepo.Exists<Series>(s => s.Path == _diskController.CleanPath(dirInfo.FullName)))
|
AddShow(seriesFolder);
|
||||||
{
|
|
||||||
_logger.InfoFormat("Folder '{0} isn't mapped to a series in the database. Trying to map it.'", seriesFolder);
|
|
||||||
AddShow(seriesFolder);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -61,7 +60,7 @@ private void AddShow(string path)
|
|||||||
|
|
||||||
private void AddShow(string path, TvdbSeries series)
|
private void AddShow(string path, TvdbSeries series)
|
||||||
{
|
{
|
||||||
_sonioRepo.Add(new Series {Id = series.Id, SeriesName = series.SeriesName, AirTimes = series.AirsTime, AirsDayOfWeek = series.AirsDayOfWeek, Overview = series.Overview, Status = series.Status, Language = series.Language.Name, Path = path});
|
_sonioRepo.Add(new Series { Id = series.Id, SeriesName = series.SeriesName, AirTimes = series.AirsTime, AirsDayOfWeek = series.AirsDayOfWeek, Overview = series.Overview, Status = series.Status, Language = series.Language.Name, Path = path });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -140,7 +140,6 @@
|
|||||||
<Compile Include="Repository\Series.cs" />
|
<Compile Include="Repository\Series.cs" />
|
||||||
<Compile Include="Main.cs" />
|
<Compile Include="Main.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Controllers\FileConfigController.cs" />
|
|
||||||
<Compile Include="Controllers\DiskController.cs" />
|
<Compile Include="Controllers\DiskController.cs" />
|
||||||
<Compile Include="Controllers\IConfigController.cs" />
|
<Compile Include="Controllers\IConfigController.cs" />
|
||||||
<Compile Include="Controllers\IDiskController.cs" />
|
<Compile Include="Controllers\IDiskController.cs" />
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -3,6 +3,8 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using NzbDrone.Core.Controllers;
|
||||||
|
using NzbDrone.Web.Models;
|
||||||
|
|
||||||
namespace NzbDrone.Web.Controllers
|
namespace NzbDrone.Web.Controllers
|
||||||
{
|
{
|
||||||
@ -10,10 +12,27 @@ public class SettingsController : Controller
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
// GET: /Settings/
|
// GET: /Settings/
|
||||||
|
private IConfigController _configController;
|
||||||
|
|
||||||
|
public SettingsController(IConfigController configController)
|
||||||
|
{
|
||||||
|
_configController = configController;
|
||||||
|
}
|
||||||
|
|
||||||
public ActionResult Index()
|
public ActionResult Index()
|
||||||
{
|
{
|
||||||
return View();
|
return View(new SettingsModel() { RootPath = _configController.SeriesRoot });
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult Save(SettingsModel model)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
_configController.SeriesRoot = model.RootPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RedirectToAction("index");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,65 +11,13 @@
|
|||||||
namespace NzbDrone.Web.Models
|
namespace NzbDrone.Web.Models
|
||||||
{
|
{
|
||||||
|
|
||||||
#region Models
|
public class SettingsModel
|
||||||
[PropertiesMustMatch("NewPassword", "ConfirmPassword", ErrorMessage = "The new password and confirmation password do not match.")]
|
|
||||||
public class ChangePasswordModel1
|
|
||||||
{
|
{
|
||||||
[Required]
|
public String RootPath
|
||||||
[DataType(DataType.Password)]
|
{
|
||||||
[DisplayName("Current password")]
|
get;
|
||||||
public string OldPassword { get; set; }
|
set;
|
||||||
|
}
|
||||||
[Required]
|
|
||||||
[ValidatePasswordLength]
|
|
||||||
[DataType(DataType.Password)]
|
|
||||||
[DisplayName("New password")]
|
|
||||||
public string NewPassword { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
[DataType(DataType.Password)]
|
|
||||||
[DisplayName("Confirm new password")]
|
|
||||||
public string ConfirmPassword { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LogOnModel1
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
[DisplayName("User name")]
|
|
||||||
public string UserName { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
[DataType(DataType.Password)]
|
|
||||||
[DisplayName("Password")]
|
|
||||||
public string Password { get; set; }
|
|
||||||
|
|
||||||
[DisplayName("Remember me?")]
|
|
||||||
public bool RememberMe { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[PropertiesMustMatch("Password", "ConfirmPassword", ErrorMessage = "The password and confirmation password do not match.")]
|
|
||||||
public class RegisterModel1
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
[DisplayName("User name")]
|
|
||||||
public string UserName { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
[DataType(DataType.EmailAddress)]
|
|
||||||
[DisplayName("Email address")]
|
|
||||||
public string Email { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
[ValidatePasswordLength]
|
|
||||||
[DataType(DataType.Password)]
|
|
||||||
[DisplayName("Password")]
|
|
||||||
public string Password { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
[DataType(DataType.Password)]
|
|
||||||
[DisplayName("Confirm password")]
|
|
||||||
public string ConfirmPassword { get; set; }
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Global.asax" />
|
<Content Include="Global.asax" />
|
||||||
<Content Include="Views\Series\index.aspx" />
|
<Content Include="Views\Series\index.aspx" />
|
||||||
|
<Content Include="Views\Settings\Index.aspx" />
|
||||||
<Content Include="Web.config">
|
<Content Include="Web.config">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</Content>
|
</Content>
|
||||||
@ -117,7 +118,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="App_Data\" />
|
<Folder Include="App_Data\" />
|
||||||
<Folder Include="Views\Settings\" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\NzbDrone.Core\NzbDrone.Core.csproj">
|
<ProjectReference Include="..\NzbDrone.Core\NzbDrone.Core.csproj">
|
||||||
|
27
NzbDrone.Web/Views/Settings/Index.aspx
Normal file
27
NzbDrone.Web/Views/Settings/Index.aspx
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<NzbDrone.Web.Models.SettingsModel>" %>
|
||||||
|
<%@ Import Namespace="NzbDrone.Web.Controllers" %>
|
||||||
|
|
||||||
|
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
|
||||||
|
Index
|
||||||
|
</asp:Content>
|
||||||
|
<asp:Content ID="General" ContentPlaceHolderID="MainContent" runat="server">
|
||||||
|
<h2>
|
||||||
|
Settings</h2>
|
||||||
|
<% using (Html.BeginForm())
|
||||||
|
{ %>
|
||||||
|
<div>
|
||||||
|
<fieldset>
|
||||||
|
<legend>General</legend>
|
||||||
|
<div class="editor-label">
|
||||||
|
<%: Html.LabelFor(m => m.RootPath) %>
|
||||||
|
</div>
|
||||||
|
<div class="editor-field">
|
||||||
|
<%: Html.TextBoxFor(m => m.RootPath) %>
|
||||||
|
</div>
|
||||||
|
<p>
|
||||||
|
<input type="submit" value="Save" />
|
||||||
|
</p>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
<% } %>
|
||||||
|
</asp:Content>
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
<ul id="menu">
|
<ul id="menu">
|
||||||
<li><%: Html.ActionLink("Home", "Index", "Home")%></li>
|
<li><%: Html.ActionLink("Home", "Index", "Home")%></li>
|
||||||
<li><%: Html.ActionLink("About", "About", "Home")%></li>
|
<li><%: Html.ActionLink("Settings", "Index", "Settings")%></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user