Updated Add Series

This commit is contained in:
kay.one 2011-07-27 15:59:48 -07:00
parent 68321c98d0
commit b4fb3002a4
38 changed files with 1339 additions and 867 deletions

View file

@ -67,70 +67,61 @@ namespace NzbDrone.Web.Controllers
public ActionResult Index()
{
var rootDirs = _rootFolderProvider.GetAll();
var profiles = _qualityProvider.All();
var defaultQuality = Convert.ToInt32(_configProvider.DefaultQualityProfile);
var selectList = new SelectList(profiles, "QualityProfileId", "Name", defaultQuality);
ViewData["qualities"] = selectList;
ViewData["ShowRootDirs"] = false;
//There are no RootDirs Show the RootDirs Panel
if (rootDirs.Count == 0)
ViewData["ShowRootDirs"] = true;
return View(rootDirs);
return View();
}
public ActionResult AddExisting()
public ActionResult ExistingSeries()
{
var rootDirs = _rootFolderProvider.GetAll();
var result = new ExistingSeriesModel();
var unmappedList = new List<String>();
foreach (var folder in rootDirs)
foreach (var folder in _rootFolderProvider.GetAll())
{
unmappedList.AddRange(_rootFolderProvider.GetUnmappedFolders(folder.Path));
}
return View(unmappedList);
}
result.ExistingSeries = new List<Tuple<string, string>>();
public ActionResult RenderPartial(string path)
{
var suggestions = GetSuggestionList(new DirectoryInfo(path).Name);
foreach (var folder in unmappedList)
{
var foldername = new DirectoryInfo(folder).Name;
var tvdbResult = _tvDbProvider.SearchSeries(foldername).FirstOrDefault();
ViewData["guid"] = Guid.NewGuid();
ViewData["path"] = path;
ViewData["javaPath"] = path.Replace(Path.DirectorySeparatorChar, '|').Replace(Path.VolumeSeparatorChar, '^').Replace('\'', '`');
var title = String.Empty;
if (tvdbResult != null)
{
title = tvdbResult.SeriesName;
}
var defaultQuality = _configProvider.DefaultQualityProfile;
var qualityProfiles = _qualityProvider.All();
result.ExistingSeries.Add(new Tuple<string, string>(folder, title));
}
ViewData["quality"] = new SelectList(
qualityProfiles,
"QualityProfileId",
"Name",
defaultQuality);
var defaultQuality = Convert.ToInt32(_configProvider.DefaultQualityProfile);
result.Quality = new SelectList(_qualityProvider.All(), "QualityProfileId", "Name", defaultQuality);
return PartialView("AddSeriesItem", suggestions);
return View(result);
}
[HttpPost]
public JsonResult AddNewSeries(string rootPath, string seriesName, int seriesId, int qualityProfileId)
public JsonResult AddNewSeries(string path, string seriesName, int qualityProfileId)
{
path = Path.Combine(path, MediaFileProvider.CleanFilename(seriesName));
return AddExistingSeries(path, seriesName, qualityProfileId);
}
[HttpPost]
public JsonResult AddExistingSeries(string path, string seriesName, int qualityProfileId)
{
try
{
var path = Path.Combine(rootPath.Replace('|', Path.DirectorySeparatorChar)
.Replace('^', Path.VolumeSeparatorChar)
.Replace('`', '\''),
MediaFileProvider.CleanFilename(seriesName));
//Create the folder for the new series and then Add it
_diskProvider.CreateDirectory(path);
_seriesProvider.AddSeries(path, seriesId, qualityProfileId);
var series = _tvDbProvider.SearchSeries(seriesName).Where(s => s.SeriesName == seriesName).Single();
_seriesProvider.AddSeries(path, series.Id, qualityProfileId);
ScanNewSeries();
return new JsonResult { Data = "ok" };
}
@ -154,30 +145,6 @@ namespace NzbDrone.Web.Controllers
return new JsonResult { Data = "ok" };
}
[HttpPost]
public ActionResult _textLookUp(string text, int? filterMode)
{
var suggestions = GetSuggestionList(text);
return new JsonResult
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
Data = suggestions
};
}
public SelectList GetSuggestionList(string searchString)
{
var dataVal = _tvDbProvider.SearchSeries(searchString);
int selectId = 0;
if (dataVal.Count != 0)
{
selectId = dataVal[0].Id;
}
return new SelectList(dataVal, "Id", "SeriesName", selectId);
}
//Root Directory
[HttpPost]
@ -202,36 +169,15 @@ namespace NzbDrone.Web.Controllers
return new JsonResult { };
}
public PartialViewResult AddRootDir()
[HttpGet]
public JsonResult LookupSeries(string q)
{
var model = new RootDirModel
{
Id = 0,
Path = "",
CleanPath = "",
SelectList = new SelectList(new List<string> { "" }, "")
};
ViewData["guid"] = Guid.NewGuid();
var dataVal = _tvDbProvider.SearchSeries(q);
return PartialView("RootDir", model);
return Json(dataVal.Select(c => new KeyValuePair<int, string>(c.Id, c.SeriesName)), JsonRequestBehavior.AllowGet);
}
public ActionResult GetRootDirView(RootDir rootDir)
{
var model = new RootDirModel
{
Id = rootDir.Id,
Path = rootDir.Path,
SelectList = new SelectList(new List<string> { rootDir.Path }, rootDir.Path)
};
ViewData["guid"] = Guid.NewGuid();
return PartialView("RootDir", model);
}
public ActionResult RootList()
{
IEnumerable<String> rootDir = _rootFolderProvider.GetAll().Select(c => c.Path).OrderBy(e => e);