Auto complete for paths added. Config text boxes are now wider.

This commit is contained in:
Mark McDowall 2011-06-08 18:45:06 -07:00
commit bda226096b
12 changed files with 117 additions and 41 deletions

View file

@ -184,6 +184,7 @@ namespace NzbDrone.Web.Controllers
return new SelectList(dataVal, "Id", "SeriesName", selectId);
}
//Root Directory
[HttpPost]
public JsonResult SaveRootDir(int id, string path)
{
@ -202,23 +203,29 @@ namespace NzbDrone.Web.Controllers
return new JsonResult { Data = "ok" };
}
public ViewResult AddRootDir()
public PartialViewResult AddRootDir()
{
var rootDir = new RootDir { Path = String.Empty };
var id = _rootFolderProvider.Add(rootDir);
rootDir.Id = id;
ViewData["RootDirId"] = id;
var model = new RootDirModel();
model.Id = rootDir.Id;
model.Path = rootDir.Path;
model.SelectList = new SelectList(new List<string> { rootDir.Path }, rootDir.Path);
return View("RootDir", rootDir);
return PartialView("RootDir", model);
}
public ActionResult GetRootDirView(RootDir rootDir)
{
ViewData["RootDirId"] = rootDir.Id;
var model = new RootDirModel();
model.Id = rootDir.Id;
model.Path = rootDir.Path;
model.SelectList = new SelectList(new List<string> { rootDir.Path }, rootDir.Path);
return PartialView("RootDir", rootDir);
return PartialView("RootDir", model);
}
public JsonResult DeleteRootDir(int rootDirId)
@ -235,28 +242,5 @@ namespace NzbDrone.Web.Controllers
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);
}
}
}

View file

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Web.Controllers
{
public class DirectoryController : Controller
{
private readonly DiskProvider _diskProvider;
public DirectoryController(DiskProvider diskProvider)
{
_diskProvider = diskProvider;
}
public ActionResult Test()
{
return Content("Testing...");
}
[HttpPost]
public ActionResult _autoCompletePath(string text, int? filterMode)
{
var data = GetDirectories(text);
return new JsonResult
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
Data = data
};
}
public SelectList GetDirectories(string text)
{
//Windows (Including UNC)
var windowsSep = text.LastIndexOf('\\');
if (windowsSep > -1)
{
var dirs = _diskProvider.GetDirectories(text.Substring(0, windowsSep + 1));
return new SelectList(dirs, dirs.FirstOrDefault());
}
//Unix
var index = text.LastIndexOf('/');
if (index > -1)
{
var dirs = _diskProvider.GetDirectories(text.Substring(0, index + 1));
return new SelectList(dirs, dirs.FirstOrDefault());
}
return new SelectList(new List<string>());
}
}
}

View file

@ -96,6 +96,9 @@ namespace NzbDrone.Web.Controllers
{
ViewData["viewName"] = "Sabnzbd";
var sabDropDir = _configProvider.SabDropDirectory;
var selectList = new SelectList(new List<string> {sabDropDir}, sabDropDir);
var model = new SabnzbdSettingsModel
{
SabHost = _configProvider.SabHost,
@ -105,7 +108,8 @@ namespace NzbDrone.Web.Controllers
SabPassword = _configProvider.SabPassword,
SabTvCategory = _configProvider.SabTvCategory,
SabTvPriority = _configProvider.SabTvPriority,
SabDropDirectory = _configProvider.SabDropDirectory
SabDropDirectory = sabDropDir,
SabDropDirectorySelectList = selectList
};
return View("Index", model);