1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-21 23:32:27 +00:00

added settings view to mvc project

This commit is contained in:
kay.one 2010-09-23 22:21:45 -07:00
parent 941d516e42
commit d7bae9135c
15 changed files with 89 additions and 148 deletions

View file

@ -9,6 +9,7 @@ namespace NzbDrone.Core.Controllers
{
public class DbConfigController : IConfigController
{
private const string _seriesroots = "SeriesRoots";
private readonly IDiskController _diskController;
private readonly ILog _logger;
private readonly IRepository _sonicRepo;
@ -21,20 +22,27 @@ public DbConfigController(ILog logger, IDiskController diskController, IReposito
_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)
{
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)
{
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);
_sonicRepo.Add(new Config {Key = key, Value = value});
_sonicRepo.Add(new Config { Key = key, Value = value });
}
}
}

View file

@ -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();
}
}
}

View file

@ -1,9 +1,15 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace NzbDrone.Core.Controllers
{
public interface IConfigController
{
List<string> GetTvRoots();
String SeriesRoot
{
get;
set;
}
}
}

View file

@ -34,18 +34,17 @@ public IQueryable<Series> GetSeries()
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);
if (!_sonioRepo.Exists<Series>(s => s.Path == _diskController.CleanPath(dirInfo.FullName)))
{
_logger.InfoFormat("Folder '{0} isn't mapped to a series in the database. Trying to map it.'", seriesFolder);
AddShow(seriesFolder);
}
_logger.InfoFormat("Folder '{0} isn't mapped to a series in the database. Trying to map it.'", seriesFolder);
AddShow(seriesFolder);
}
}
}
#endregion
@ -61,7 +60,7 @@ private void AddShow(string path)
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 });
}
}
}

View file

@ -140,7 +140,6 @@
<Compile Include="Repository\Series.cs" />
<Compile Include="Main.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Controllers\FileConfigController.cs" />
<Compile Include="Controllers\DiskController.cs" />
<Compile Include="Controllers\IConfigController.cs" />
<Compile Include="Controllers\IDiskController.cs" />

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -3,6 +3,8 @@
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NzbDrone.Core.Controllers;
using NzbDrone.Web.Models;
namespace NzbDrone.Web.Controllers
{
@ -10,10 +12,27 @@ public class SettingsController : Controller
{
//
// GET: /Settings/
private IConfigController _configController;
public SettingsController(IConfigController configController)
{
_configController = configController;
}
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");
}
}

View file

@ -11,65 +11,13 @@
namespace NzbDrone.Web.Models
{
#region Models
[PropertiesMustMatch("NewPassword", "ConfirmPassword", ErrorMessage = "The new password and confirmation password do not match.")]
public class ChangePasswordModel1
public class SettingsModel
{
[Required]
[DataType(DataType.Password)]
[DisplayName("Current password")]
public string OldPassword { get; 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 String RootPath
{
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
}

View file

@ -82,6 +82,7 @@
<ItemGroup>
<Content Include="Global.asax" />
<Content Include="Views\Series\index.aspx" />
<Content Include="Views\Settings\Index.aspx" />
<Content Include="Web.config">
<SubType>Designer</SubType>
</Content>
@ -117,7 +118,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
<Folder Include="Views\Settings\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NzbDrone.Core\NzbDrone.Core.csproj">

View file

@ -12,7 +12,7 @@
<p>
New passwords are required to be a minimum of <%: ViewData["PasswordLength"] %> characters in length.
</p>
<% using (Html.BeginForm()) { %>
<%: Html.ValidationSummary(true, "Password change was unsuccessful. Please correct the errors and try again.") %>
<div>

View 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>

View file

@ -23,7 +23,7 @@
<ul id="menu">
<li><%: Html.ActionLink("Home", "Index", "Home")%></li>
<li><%: Html.ActionLink("About", "About", "Home")%></li>
<li><%: Html.ActionLink("Settings", "Index", "Settings")%></li>
</ul>
</div>