From 5d7d0bde3e5bdb87b67c3f15cceb0647d27f4862 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 12 Oct 2010 18:16:54 -0700 Subject: [PATCH] Adding SearchForm widget --HG-- branch : dev --- .../Controllers/SearchController.cs | 2 -- .../Drivers/SearchFormPartDriver.cs | 13 +++++++++++ .../Orchard.Search/Filters/SearchFilter.cs | 23 ------------------- .../Modules/Orchard.Search/Migrations.cs | 15 +++++++++++- .../Orchard.Search/Models/SearchFormPart.cs | 9 ++++++++ .../Orchard.Search/Orchard.Search.csproj | 8 +++++-- .../Parts/Search.SearchForm.cshtml} | 1 - .../Parts/Search.SearchForm.cshtml | 1 + .../Orchard.Search/Views/Search/Index.cshtml | 15 ++++++++---- 9 files changed, 54 insertions(+), 33 deletions(-) create mode 100644 src/Orchard.Web/Modules/Orchard.Search/Drivers/SearchFormPartDriver.cs delete mode 100644 src/Orchard.Web/Modules/Orchard.Search/Filters/SearchFilter.cs create mode 100644 src/Orchard.Web/Modules/Orchard.Search/Models/SearchFormPart.cs rename src/Orchard.Web/Modules/Orchard.Search/Views/{SearchForm.cshtml => DisplayTemplates/Parts/Search.SearchForm.cshtml} (87%) create mode 100644 src/Orchard.Web/Modules/Orchard.Search/Views/EditorTemplates/Parts/Search.SearchForm.cshtml diff --git a/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs b/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs index a21e1de56..fc8226ac6 100644 --- a/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs +++ b/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs @@ -5,8 +5,6 @@ using Orchard.Search.Services; using Orchard.Search.ViewModels; using Orchard.Settings; using Orchard.Search.Models; -using System.Linq; -using System; using System.Collections.Generic; using Orchard.Collections; using Orchard.Themes; diff --git a/src/Orchard.Web/Modules/Orchard.Search/Drivers/SearchFormPartDriver.cs b/src/Orchard.Web/Modules/Orchard.Search/Drivers/SearchFormPartDriver.cs new file mode 100644 index 000000000..26a78c124 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Search/Drivers/SearchFormPartDriver.cs @@ -0,0 +1,13 @@ +using Orchard.ContentManagement.Drivers; +using Orchard.Search.Models; +using Orchard.Search.ViewModels; + +namespace Orchard.Search.Drivers { + public class SearchFormPartDriver : ContentPartDriver { + + protected override DriverResult Display(SearchFormPart part, string displayType, dynamic shapeHelper) { + var model = new SearchViewModel(); + return ContentPartTemplate(model, "Parts/Search.SearchForm"); + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Search/Filters/SearchFilter.cs b/src/Orchard.Web/Modules/Orchard.Search/Filters/SearchFilter.cs deleted file mode 100644 index 06c52eb97..000000000 --- a/src/Orchard.Web/Modules/Orchard.Search/Filters/SearchFilter.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Web.Mvc; -using Orchard.Mvc.Filters; - -namespace Orchard.Search.Filters { - public class SearchFilter : FilterProvider, IResultFilter { - private readonly IWorkContextAccessor _workContextAccessor; - - public SearchFilter(IWorkContextAccessor workContextAccessor) { - _workContextAccessor = workContextAccessor; - } - - public void OnResultExecuting(ResultExecutingContext filterContext) { - dynamic search = filterContext.Controller.ViewData.Model; - var workContext = _workContextAccessor.GetContext(filterContext); - - if (search != null) - workContext.Layout.Search.Add(search); - } - - public void OnResultExecuted(ResultExecutedContext filterContext) { - } - } -} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Search/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Search/Migrations.cs index 67552aae3..5273c3e00 100644 --- a/src/Orchard.Web/Modules/Orchard.Search/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Search/Migrations.cs @@ -1,4 +1,5 @@ -using Orchard.Data.Migration; +using Orchard.ContentManagement.MetaData; +using Orchard.Data.Migration; namespace Orchard.Search { public class SearchDataMigration : DataMigrationImpl { @@ -13,5 +14,17 @@ namespace Orchard.Search { return 1; } + + public int UpdateFrom1() { + ContentDefinitionManager.AlterTypeDefinition("SearchForm", + cfg => cfg + .WithPart("SearchFormPart") + .WithPart("CommonPart") + .WithPart("WidgetPart") + .WithSetting("Stereotype", "Widget") + ); + + return 5; + } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Search/Models/SearchFormPart.cs b/src/Orchard.Web/Modules/Orchard.Search/Models/SearchFormPart.cs new file mode 100644 index 000000000..da21fddca --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Search/Models/SearchFormPart.cs @@ -0,0 +1,9 @@ +using Orchard.ContentManagement; + +namespace Orchard.Search.Models { + /// + /// Cotnent part for the search form widget + /// + public class SearchFormPart : ContentPart { + } +} diff --git a/src/Orchard.Web/Modules/Orchard.Search/Orchard.Search.csproj b/src/Orchard.Web/Modules/Orchard.Search/Orchard.Search.csproj index 42f140448..e0e430aeb 100644 --- a/src/Orchard.Web/Modules/Orchard.Search/Orchard.Search.csproj +++ b/src/Orchard.Web/Modules/Orchard.Search/Orchard.Search.csproj @@ -67,11 +67,12 @@ + + - @@ -100,9 +101,12 @@ - + + + +