Integrating Content Picker

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2012-05-29 18:31:28 -07:00
parent a90a87ab76
commit 6b7d617be1
20 changed files with 326 additions and 5 deletions

View File

@@ -0,0 +1,22 @@
using Orchard.Localization;
using Orchard.UI.Navigation;
namespace Orchard.Search {
public class ContentPickerNavigationProvider : INavigationProvider {
public ContentPickerNavigationProvider() {
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public string MenuName {
get { return "content-picker"; }
}
public void GetNavigation(NavigationBuilder builder) {
builder.Add(T("Content Picker"),
menu => menu
.Add(T("Search Content"), "5", item => item.Action("Index", "ContentPicker", new {area = "Orchard.Search"}).LocalNav()));
}
}
}

View File

@@ -0,0 +1,84 @@
using System;
using System.Linq;
using System.Web.Mvc;
using Orchard.Collections;
using Orchard.ContentManagement;
using Orchard.DisplayManagement;
using Orchard.Indexing;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Mvc;
using Orchard.Search.Models;
using Orchard.Search.Services;
using Orchard.Settings;
using Orchard.Themes;
using Orchard.UI.Admin;
using Orchard.UI.Navigation;
using Orchard.UI.Notify;
namespace Orchard.Search.Controllers {
[Admin]
public class ContentPickerController : Controller {
private readonly ISearchService _searchService;
private readonly ISiteService _siteService;
public ContentPickerController(
IOrchardServices orchardServices,
ISearchService searchService,
ISiteService siteService) {
_searchService = searchService;
_siteService = siteService;
Services = orchardServices;
T = NullLocalizer.Instance;
Logger = NullLogger.Instance;
}
public IOrchardServices Services { get; set; }
public ILogger Logger { get; set; }
public Localizer T { get; set; }
[Themed(false)]
public ActionResult Index(PagerParameters pagerParameters, string searchText = "") {
Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);
var searchFields = Services.WorkContext.CurrentSite.As<SearchSettingsPart>().SearchedFields;
IPageOfItems<ISearchHit> searchHits = new PageOfItems<ISearchHit>(new ISearchHit[] { });
try {
searchHits = _searchService.Query(searchText, pager.Page, pager.PageSize,
Services.WorkContext.CurrentSite.As<SearchSettingsPart>().Record.FilterCulture,
searchFields,
searchHit => searchHit);
}
catch (Exception exception) {
Logger.Error(T("Invalid search query: {0}", exception.Message).Text);
Services.Notifier.Error(T("Invalid search query: {0}", exception.Message));
}
var list = Services.New.List();
foreach (var contentItem in searchHits.Select(searchHit => Services.ContentManager.Get(searchHit.ContentItemId))) {
// ignore search results which content item has been removed or unpublished
if (contentItem == null) {
searchHits.TotalItemCount--;
continue;
}
list.Add(Services.ContentManager.BuildDisplay(contentItem, "SummaryAdmin"));
}
var pagerShape = Services.New.Pager(pager).TotalItemCount(searchHits.TotalItemCount);
foreach(IShape item in list.Items) {
item.Metadata.Type = "ContentPicker";
}
dynamic tab = Services.New.SearchContentTab()
.ContentItems(list)
.Pager(pagerShape)
.SearchText(searchText);
return new ShapeResult(this, Services.New.ContentPicker().Tab(tab));
}
}
}

View File

@@ -14,6 +14,7 @@
<AssemblyName>Orchard.Search</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
<UseIISExpress>false</UseIISExpress>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -45,6 +46,8 @@
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
<Compile Include="ContentPickerNavigationProvider.cs" />
<Compile Include="Controllers\ContentPickerController.cs" />
<Compile Include="Drivers\SearchFormPartDriver.cs" />
<Compile Include="Models\SearchFormPart.cs" />
<Compile Include="ResourceManifest.cs" />
@@ -92,6 +95,9 @@
<ItemGroup>
<Content Include="web.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\SearchContentTab.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -0,0 +1,20 @@
@{
var pageTitle = T("Search Content");
Layout.Title = pageTitle;
}
@using (Html.BeginFormAntiForgeryPost()) {
<fieldset class="bulk-actions">
<label for="search-text">@T("Search")</label>
@Html.TextBox("searchText", (string)Model.SearchText, new { @class = "text", autofocus = "autofocus" })
<button type="submit">@T("Search")</button>
</fieldset>
<fieldset class="contentItems bulk-items">
@Display(Model.ContentItems)
</fieldset>
@Display(Model.Pager)
}