Moved root dir config to add series.

Cleaned up Indexers.cshtml.
Indexers is the new default Settings page.
This commit is contained in:
Mark McDowall 2011-05-30 23:13:46 -07:00
parent f6578bd535
commit f27c1d89f6
12 changed files with 355 additions and 357 deletions

View file

@ -3,16 +3,19 @@ using System.Collections.Generic;
using System.IO;
using System.Web.Mvc;
using System.Linq;
using NLog;
using NzbDrone.Core.Helpers;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Providers.Jobs;
using NzbDrone.Core.Repository;
using NzbDrone.Web.Models;
namespace NzbDrone.Web.Controllers
{
public class AddSeriesController : Controller
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly ConfigProvider _configProvider;
private readonly QualityProvider _qualityProvider;
private readonly RootDirProvider _rootFolderProvider;
@ -70,6 +73,8 @@ namespace NzbDrone.Web.Controllers
public ActionResult Add()
{
ViewData["RootDirs"] = _rootFolderProvider.GetAll();
var unmappedList = new List<String>();
var profiles = _qualityProvider.GetAllProfiles();
@ -109,15 +114,25 @@ namespace NzbDrone.Web.Controllers
[HttpPost]
public JsonResult AddNewSeries(string rootPath, string seriesName, int seriesId, int qualityProfileId)
{
var path = rootPath.Replace('|', Path.DirectorySeparatorChar).Replace('^', Path.VolumeSeparatorChar).Replace('`', '\'') +
Path.DirectorySeparatorChar + EpisodeRenameHelper.CleanFilename(seriesName);
try
{
var path =
rootPath.Replace('|', Path.DirectorySeparatorChar).Replace('^', Path.VolumeSeparatorChar).Replace(
'`', '\'') +
Path.DirectorySeparatorChar + EpisodeRenameHelper.CleanFilename(seriesName);
//Create the folder for the new series and then Add it
_diskProvider.CreateDirectory(path);
//Create the folder for the new series and then Add it
_diskProvider.CreateDirectory(path);
_seriesProvider.AddSeries(path, seriesId, qualityProfileId);
ScanNewSeries();
return new JsonResult { Data = "ok" };
_seriesProvider.AddSeries(path, seriesId, qualityProfileId);
ScanNewSeries();
return new JsonResult {Data = "ok"};
}
catch(Exception ex)
{
return new JsonResult { Data = "failed" };
}
}
public JsonResult AddSeries(string path, int seriesId, int qualityProfileId)
@ -157,5 +172,80 @@ namespace NzbDrone.Web.Controllers
return new SelectList(dataVal, "Id", "SeriesName", selectId);
}
[HttpPost]
public JsonResult SaveRootDir(int id, string path)
{
try
{
_rootFolderProvider.Update(new RootDir { Id = id, Path = path });
}
catch (Exception ex)
{
Logger.Debug("Failed to save Root Dir");
Logger.DebugException(ex.Message, ex);
return new JsonResult { Data = "failed" };
}
return new JsonResult { Data = "ok" };
}
public ViewResult AddRootDir()
{
var rootDir = new RootDir { Path = String.Empty };
var id = _rootFolderProvider.Add(rootDir);
rootDir.Id = id;
ViewData["RootDirId"] = id;
return View("RootDir", rootDir);
}
public ActionResult GetRootDirView(RootDir rootDir)
{
ViewData["RootDirId"] = rootDir.Id;
return PartialView("RootDir", rootDir);
}
public JsonResult DeleteRootDir(int rootDirId)
{
try
{
_rootFolderProvider.Remove(rootDirId);
}
catch (Exception)
{
return new JsonResult { Data = "failed" };
}
return new JsonResult { Data = "ok" };
}
public JsonResult JsonAutoCompletePath(string term)
{
var windowsSep = term.LastIndexOf('\\');
if (windowsSep > -1)
{
var start = term.Substring(windowsSep + 1);
var dirs = _diskProvider.GetDirectories(term.Substring(0, windowsSep + 1)).Where(d => new DirectoryInfo(d).Name.ToLower().StartsWith(start.ToLower())).Take(10);
return Json(dirs.ToArray(), JsonRequestBehavior.AllowGet);
}
var index = term.LastIndexOf('/');
if (index > -1)
{
var start = term.Substring(index + 1);
var dirs = _diskProvider.GetDirectories(term.Substring(0, index + 1)).Where(d => new DirectoryInfo(d).Name.ToLower().StartsWith(start.ToLower())).Take(10);
return Json(dirs.ToArray(), JsonRequestBehavior.AllowGet);
}
return Json(new JsonResult(), JsonRequestBehavior.AllowGet);
}
}
}