From e33f5206fab92b71f1f17aa02206243c705c776d Mon Sep 17 00:00:00 2001 From: Keivan Date: Fri, 1 Apr 2011 16:11:09 -0700 Subject: [PATCH] Add existing now does is reall time TvDb lookup --- NzbDrone.Core/CentralDispatch.cs | 15 +- NzbDrone.Core/NzbDrone.Core.csproj | 2 +- NzbDrone.Web.Test/App.config | 24 -- .../Controllers/AccountControllerTest.cs | 402 ------------------ .../Controllers/HomeControllerTest.cs | 42 -- NzbDrone.Web.Test/NzbDrone.Web.Tests.csproj | 79 ---- NzbDrone.Web.Test/Properties/AssemblyInfo.cs | 35 -- .../Controllers/AddSeriesController.cs | 44 +- .../Views/AddSeries/AddExistingManual.aspx | 94 ---- .../Views/AddSeries/AddSeriesItem.ascx | 6 +- 10 files changed, 33 insertions(+), 710 deletions(-) delete mode 100644 NzbDrone.Web.Test/App.config delete mode 100644 NzbDrone.Web.Test/Controllers/AccountControllerTest.cs delete mode 100644 NzbDrone.Web.Test/Controllers/HomeControllerTest.cs delete mode 100644 NzbDrone.Web.Test/NzbDrone.Web.Tests.csproj delete mode 100644 NzbDrone.Web.Test/Properties/AssemblyInfo.cs delete mode 100644 NzbDrone.Web/Views/AddSeries/AddExistingManual.aspx diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index fb2a8e6b3..53ba15338 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -37,17 +37,16 @@ namespace NzbDrone.Core _startupPath = AppPath; //Sqlite - string connectionString = String.Format("Data Source={0};Version=3;", Path.Combine(AppPath, "nzbdrone.db")); - var dbProvider = ProviderFactory.GetProvider(connectionString, "System.Data.SQLite"); + var AppDataPath = new DirectoryInfo(Path.Combine(AppPath, "App_Data", "nzbdrone.db")); + if (!AppDataPath.Exists) AppDataPath.Create(); - //SQLExpress - //string connectionString = String.Format(@"server=.\SQLExpress; database=NzbDrone; Trusted_Connection=True;"); - //var dbProvider = ProviderFactory.GetProvider(connectionString, "System.Data.SqlClient"); + string connectionString = String.Format("Data Source={0};Version=3;", Path.Combine(AppDataPath.FullName, "nzbdrone.db")); + var dbProvider = ProviderFactory.GetProvider(connectionString, "System.Data.SQLite"); - //Sqlite - string logConnectionString = String.Format("Data Source={0};Version=3;", Path.Combine(AppPath, "log.db")); + string logConnectionString = String.Format("Data Source={0};Version=3;", Path.Combine(AppDataPath.FullName, "log.db")); var logDbProvider = ProviderFactory.GetProvider(logConnectionString, "System.Data.SQLite"); + //SQLExpress //string logConnectionString = String.Format(@"server=.\SQLExpress; database=NzbDroneLogs; Trusted_Connection=True;"); //var logDbProvider = ProviderFactory.GetProvider(logConnectionString, "System.Data.SqlClient"); @@ -55,7 +54,7 @@ namespace NzbDrone.Core //dbProvider.ExecuteQuery(new QueryCommand("VACUUM", dbProvider)); dbProvider.Log = new NlogWriter(); - + _kernel.Bind().To().InSingletonScope(); _kernel.Bind().To(); _kernel.Bind().To(); diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index ae6c4afd0..eac082a46 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -31,7 +31,7 @@ true - AnyCPU + x86 true full false diff --git a/NzbDrone.Web.Test/App.config b/NzbDrone.Web.Test/App.config deleted file mode 100644 index 64ee57c34..000000000 --- a/NzbDrone.Web.Test/App.config +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/NzbDrone.Web.Test/Controllers/AccountControllerTest.cs b/NzbDrone.Web.Test/Controllers/AccountControllerTest.cs deleted file mode 100644 index bf7e24da3..000000000 --- a/NzbDrone.Web.Test/Controllers/AccountControllerTest.cs +++ /dev/null @@ -1,402 +0,0 @@ -using System; -using System.Security.Principal; -using System.Web; -using System.Web.Mvc; -using System.Web.Routing; -using System.Web.Security; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using NzbDrone.Web; -using NzbDrone.Web.Controllers; -using NzbDrone.Web.Models; - -namespace NzbDrone.Web.Tests.Controllers -{ - - [TestClass] - public class AccountControllerTest - { - - [TestMethod] - public void ChangePassword_Get_ReturnsView() - { - // Arrange - AccountController controller = GetAccountController(); - - // Act - ActionResult result = controller.ChangePassword(); - - // Assert - Assert.IsInstanceOfType(result, typeof(ViewResult)); - Assert.AreEqual(10, ((ViewResult)result).ViewData["PasswordLength"]); - } - - [TestMethod] - public void ChangePassword_Post_ReturnsRedirectOnSuccess() - { - // Arrange - AccountController controller = GetAccountController(); - ChangePasswordModel model = new ChangePasswordModel() - { - OldPassword = "goodOldPassword", - NewPassword = "goodNewPassword", - ConfirmPassword = "goodNewPassword" - }; - - // Act - ActionResult result = controller.ChangePassword(model); - - // Assert - Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); - RedirectToRouteResult redirectResult = (RedirectToRouteResult)result; - Assert.AreEqual("ChangePasswordSuccess", redirectResult.RouteValues["action"]); - } - - [TestMethod] - public void ChangePassword_Post_ReturnsViewIfChangePasswordFails() - { - // Arrange - AccountController controller = GetAccountController(); - ChangePasswordModel model = new ChangePasswordModel() - { - OldPassword = "goodOldPassword", - NewPassword = "badNewPassword", - ConfirmPassword = "badNewPassword" - }; - - // Act - ActionResult result = controller.ChangePassword(model); - - // Assert - Assert.IsInstanceOfType(result, typeof(ViewResult)); - ViewResult viewResult = (ViewResult)result; - Assert.AreEqual(model, viewResult.ViewData.Model); - Assert.AreEqual("The current password is incorrect or the new password is invalid.", controller.ModelState[""].Errors[0].ErrorMessage); - Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]); - } - - [TestMethod] - public void ChangePassword_Post_ReturnsViewIfModelStateIsInvalid() - { - // Arrange - AccountController controller = GetAccountController(); - ChangePasswordModel model = new ChangePasswordModel() - { - OldPassword = "goodOldPassword", - NewPassword = "goodNewPassword", - ConfirmPassword = "goodNewPassword" - }; - controller.ModelState.AddModelError("", "Dummy error message."); - - // Act - ActionResult result = controller.ChangePassword(model); - - // Assert - Assert.IsInstanceOfType(result, typeof(ViewResult)); - ViewResult viewResult = (ViewResult)result; - Assert.AreEqual(model, viewResult.ViewData.Model); - Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]); - } - - [TestMethod] - public void ChangePasswordSuccess_ReturnsView() - { - // Arrange - AccountController controller = GetAccountController(); - - // Act - ActionResult result = controller.ChangePasswordSuccess(); - - // Assert - Assert.IsInstanceOfType(result, typeof(ViewResult)); - } - - [TestMethod] - public void LogOff_LogsOutAndRedirects() - { - // Arrange - AccountController controller = GetAccountController(); - - // Act - ActionResult result = controller.LogOff(); - - // Assert - Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); - RedirectToRouteResult redirectResult = (RedirectToRouteResult)result; - Assert.AreEqual("Home", redirectResult.RouteValues["controller"]); - Assert.AreEqual("Index", redirectResult.RouteValues["action"]); - Assert.IsTrue(((MockFormsAuthenticationService)controller.FormsService).SignOut_WasCalled); - } - - [TestMethod] - public void LogOn_Get_ReturnsView() - { - // Arrange - AccountController controller = GetAccountController(); - - // Act - ActionResult result = controller.LogOn(); - - // Assert - Assert.IsInstanceOfType(result, typeof(ViewResult)); - } - - [TestMethod] - public void LogOn_Post_ReturnsRedirectOnSuccess_WithoutReturnUrl() - { - // Arrange - AccountController controller = GetAccountController(); - LogOnModel model = new LogOnModel() - { - UserName = "someUser", - Password = "goodPassword", - RememberMe = false - }; - - // Act - ActionResult result = controller.LogOn(model, null); - - // Assert - Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); - RedirectToRouteResult redirectResult = (RedirectToRouteResult)result; - Assert.AreEqual("Home", redirectResult.RouteValues["controller"]); - Assert.AreEqual("Index", redirectResult.RouteValues["action"]); - Assert.IsTrue(((MockFormsAuthenticationService)controller.FormsService).SignIn_WasCalled); - } - - [TestMethod] - public void LogOn_Post_ReturnsRedirectOnSuccess_WithReturnUrl() - { - // Arrange - AccountController controller = GetAccountController(); - LogOnModel model = new LogOnModel() - { - UserName = "someUser", - Password = "goodPassword", - RememberMe = false - }; - - // Act - ActionResult result = controller.LogOn(model, "/someUrl"); - - // Assert - Assert.IsInstanceOfType(result, typeof(RedirectResult)); - RedirectResult redirectResult = (RedirectResult)result; - Assert.AreEqual("/someUrl", redirectResult.Url); - Assert.IsTrue(((MockFormsAuthenticationService)controller.FormsService).SignIn_WasCalled); - } - - [TestMethod] - public void LogOn_Post_ReturnsViewIfModelStateIsInvalid() - { - // Arrange - AccountController controller = GetAccountController(); - LogOnModel model = new LogOnModel() - { - UserName = "someUser", - Password = "goodPassword", - RememberMe = false - }; - controller.ModelState.AddModelError("", "Dummy error message."); - - // Act - ActionResult result = controller.LogOn(model, null); - - // Assert - Assert.IsInstanceOfType(result, typeof(ViewResult)); - ViewResult viewResult = (ViewResult)result; - Assert.AreEqual(model, viewResult.ViewData.Model); - } - - [TestMethod] - public void LogOn_Post_ReturnsViewIfValidateUserFails() - { - // Arrange - AccountController controller = GetAccountController(); - LogOnModel model = new LogOnModel() - { - UserName = "someUser", - Password = "badPassword", - RememberMe = false - }; - - // Act - ActionResult result = controller.LogOn(model, null); - - // Assert - Assert.IsInstanceOfType(result, typeof(ViewResult)); - ViewResult viewResult = (ViewResult)result; - Assert.AreEqual(model, viewResult.ViewData.Model); - Assert.AreEqual("The user name or password provided is incorrect.", controller.ModelState[""].Errors[0].ErrorMessage); - } - - [TestMethod] - public void Register_Get_ReturnsView() - { - // Arrange - AccountController controller = GetAccountController(); - - // Act - ActionResult result = controller.Register(); - - // Assert - Assert.IsInstanceOfType(result, typeof(ViewResult)); - Assert.AreEqual(10, ((ViewResult)result).ViewData["PasswordLength"]); - } - - [TestMethod] - public void Register_Post_ReturnsRedirectOnSuccess() - { - // Arrange - AccountController controller = GetAccountController(); - RegisterModel model = new RegisterModel() - { - UserName = "someUser", - Email = "goodEmail", - Password = "goodPassword", - ConfirmPassword = "goodPassword" - }; - - // Act - ActionResult result = controller.Register(model); - - // Assert - Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); - RedirectToRouteResult redirectResult = (RedirectToRouteResult)result; - Assert.AreEqual("Home", redirectResult.RouteValues["controller"]); - Assert.AreEqual("Index", redirectResult.RouteValues["action"]); - } - - [TestMethod] - public void Register_Post_ReturnsViewIfRegistrationFails() - { - // Arrange - AccountController controller = GetAccountController(); - RegisterModel model = new RegisterModel() - { - UserName = "duplicateUser", - Email = "goodEmail", - Password = "goodPassword", - ConfirmPassword = "goodPassword" - }; - - // Act - ActionResult result = controller.Register(model); - - // Assert - Assert.IsInstanceOfType(result, typeof(ViewResult)); - ViewResult viewResult = (ViewResult)result; - Assert.AreEqual(model, viewResult.ViewData.Model); - Assert.AreEqual("Username already exists. Please enter a different user name.", controller.ModelState[""].Errors[0].ErrorMessage); - Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]); - } - - [TestMethod] - public void Register_Post_ReturnsViewIfModelStateIsInvalid() - { - // Arrange - AccountController controller = GetAccountController(); - RegisterModel model = new RegisterModel() - { - UserName = "someUser", - Email = "goodEmail", - Password = "goodPassword", - ConfirmPassword = "goodPassword" - }; - controller.ModelState.AddModelError("", "Dummy error message."); - - // Act - ActionResult result = controller.Register(model); - - // Assert - Assert.IsInstanceOfType(result, typeof(ViewResult)); - ViewResult viewResult = (ViewResult)result; - Assert.AreEqual(model, viewResult.ViewData.Model); - Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]); - } - - private static AccountController GetAccountController() - { - AccountController controller = new AccountController() - { - FormsService = new MockFormsAuthenticationService(), - MembershipService = new MockMembershipService() - }; - controller.ControllerContext = new ControllerContext() - { - Controller = controller, - RequestContext = new RequestContext(new MockHttpContext(), new RouteData()) - }; - return controller; - } - - private class MockFormsAuthenticationService : IFormsAuthenticationService - { - public bool SignIn_WasCalled; - public bool SignOut_WasCalled; - - public void SignIn(string userName, bool createPersistentCookie) - { - // verify that the arguments are what we expected - Assert.AreEqual("someUser", userName); - Assert.IsFalse(createPersistentCookie); - - SignIn_WasCalled = true; - } - - public void SignOut() - { - SignOut_WasCalled = true; - } - } - - private class MockHttpContext : HttpContextBase - { - private readonly IPrincipal _user = new GenericPrincipal(new GenericIdentity("someUser"), null /* roles */); - - public override IPrincipal User - { - get - { - return _user; - } - set - { - base.User = value; - } - } - } - - private class MockMembershipService : IMembershipService - { - public int MinPasswordLength - { - get { return 10; } - } - - public bool ValidateUser(string userName, string password) - { - return (userName == "someUser" && password == "goodPassword"); - } - - public MembershipCreateStatus CreateUser(string userName, string password, string email) - { - if (userName == "duplicateUser") - { - return MembershipCreateStatus.DuplicateUserName; - } - - // verify that values are what we expected - Assert.AreEqual("goodPassword", password); - Assert.AreEqual("goodEmail", email); - - return MembershipCreateStatus.Success; - } - - public bool ChangePassword(string userName, string oldPassword, string newPassword) - { - return (userName == "someUser" && oldPassword == "goodOldPassword" && newPassword == "goodNewPassword"); - } - } - - } -} diff --git a/NzbDrone.Web.Test/Controllers/HomeControllerTest.cs b/NzbDrone.Web.Test/Controllers/HomeControllerTest.cs deleted file mode 100644 index 5c7cf67e4..000000000 --- a/NzbDrone.Web.Test/Controllers/HomeControllerTest.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Web.Mvc; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using NzbDrone.Web; -using NzbDrone.Web.Controllers; - -namespace NzbDrone.Web.Tests.Controllers -{ - [TestClass] - public class HomeControllerTest - { - [TestMethod] - public void Index() - { - // Arrange - HomeController controller = new HomeController(); - - // Act - ViewResult result = controller.Index() as ViewResult; - - // Assert - ViewDataDictionary viewData = result.ViewData; - Assert.AreEqual("Welcome to ASP.NET MVC!", viewData["Message"]); - } - - [TestMethod] - public void About() - { - // Arrange - HomeController controller = new HomeController(); - - // Act - ViewResult result = controller.About() as ViewResult; - - // Assert - Assert.IsNotNull(result); - } - } -} diff --git a/NzbDrone.Web.Test/NzbDrone.Web.Tests.csproj b/NzbDrone.Web.Test/NzbDrone.Web.Tests.csproj deleted file mode 100644 index 4315eadbe..000000000 --- a/NzbDrone.Web.Test/NzbDrone.Web.Tests.csproj +++ /dev/null @@ -1,79 +0,0 @@ - - - - Debug - AnyCPU - - - 2.0 - {99CDD5DC-698F-4624-B431-2D6381CE3A15} - Library - Properties - NzbDrone.Web.Tests - NzbDrone.Web.Tests - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - x86 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - 3.5 - - - - 3.5 - - - - - - 3.5 - - - - - - - - - - - - - - - - - {43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD} - NzbDrone.Web - - - - - \ No newline at end of file diff --git a/NzbDrone.Web.Test/Properties/AssemblyInfo.cs b/NzbDrone.Web.Test/Properties/AssemblyInfo.cs deleted file mode 100644 index d66b2f586..000000000 --- a/NzbDrone.Web.Test/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("NzbDrone.Web.Tests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("NzbDrone.Web.Tests")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("c9fcd1a2-85d4-4224-863f-83afe37490d0")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/NzbDrone.Web/Controllers/AddSeriesController.cs b/NzbDrone.Web/Controllers/AddSeriesController.cs index 01495d232..298ab2e71 100644 --- a/NzbDrone.Web/Controllers/AddSeriesController.cs +++ b/NzbDrone.Web/Controllers/AddSeriesController.cs @@ -77,39 +77,18 @@ namespace NzbDrone.Web.Controllers return View(unmappedList); } - public ActionResult AddExistingManual(string path) - { - var profiles = _qualityProvider.GetAllProfiles(); - var selectList = new SelectList(profiles, "QualityProfileId", "Name"); - var defaultQuality = _configProvider.DefaultQualityProfile; - - var model = new AddExistingManualModel(); - model.Path = path; - model.FolderName = new DirectoryInfo(path).Name; - model.QualityProfileId = defaultQuality; - model.QualitySelectList = selectList; - - return View(model); - } - - public ActionResult RenderPartial(string path) { - var dataVal = _tvDbProvider.SearchSeries(new DirectoryInfo(path).Name); - var names = dataVal.Select(tvdb => tvdb.SeriesName).ToList(); - if (dataVal.Count == 0) return null; - var ids = dataVal.Select(tvdb => tvdb.Id).ToList(); - var list = new SelectList(dataVal, "Id", "SeriesName"); + var suggestions = GetSuggestionList(new DirectoryInfo(path).Name); ViewData["guid"] = Guid.NewGuid(); ViewData["path"] = path; ViewData["javaPath"] = path.Replace(Path.DirectorySeparatorChar, '|').Replace(Path.VolumeSeparatorChar, '^'); - return PartialView("AddSeriesItem", list); + return PartialView("AddSeriesItem", suggestions); } - public JsonResult AddSeries(string path, int seriesId, int qualityProfileId) { //Get TVDB Series Name @@ -121,5 +100,24 @@ 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); + + return new SelectList(dataVal, "Id", "SeriesName"); + } + } } diff --git a/NzbDrone.Web/Views/AddSeries/AddExistingManual.aspx b/NzbDrone.Web/Views/AddSeries/AddExistingManual.aspx deleted file mode 100644 index ab73b84ad..000000000 --- a/NzbDrone.Web/Views/AddSeries/AddExistingManual.aspx +++ /dev/null @@ -1,94 +0,0 @@ -<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> - - - Add Series Manually - - - - - - -
-

<%= Html.Label(Model.Path) %>

-
- -
-
- <%= Html.Label("Enter a Series Name") %> - <%= Html.TextBoxFor(m => m.FolderName, new { id="existing_series_id" }) %> - <%= Html.TextBoxFor(m => m.Path, new { id ="series_path", style="display:none" }) %> -
- -
- <%= Html.LabelFor(m => m.QualityProfileId)%> - <%: Html.DropDownListFor(m => m.QualityProfileId, Model.QualitySelectList)%> -
-
- -

- -

- -
- - - -
- - -
- -
diff --git a/NzbDrone.Web/Views/AddSeries/AddSeriesItem.ascx b/NzbDrone.Web/Views/AddSeries/AddSeriesItem.ascx index 08f1f7caa..3d59069f7 100644 --- a/NzbDrone.Web/Views/AddSeries/AddSeriesItem.ascx +++ b/NzbDrone.Web/Views/AddSeries/AddSeriesItem.ascx @@ -10,6 +10,8 @@ // .AutoFill(true) .BindTo(Model) // .DataBinding(b => b.Ajax().Select("TvDbLookup", "AddSeries")) + .DataBinding(binding => binding.Ajax().Select("_textLookUp", "AddSeries").Delay(400).Cache(false)) + .Filterable(f => f.FilterMode(AutoCompleteFilterMode.Contains)) .HighlightFirstMatch(true) .HtmlAttributes(new { style = "width:70%; align:right" }) @@ -28,8 +30,8 @@ function addSeries(guid, path) { var qualityProfileId = $("#qualityProfileId").val(); - var comboBox = $("#" + guid).data("tComboBox"); - sendToServer(comboBox.value(), path, qualityProfileId); + var comboBox = $("#" + guid).data("tComboBox"); + sendToServer(comboBox.value(), path, qualityProfileId); $("#div_" + guid).hide(); }