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

3
.hgsub
View File

@@ -9,4 +9,5 @@ src/orchard.web/Modules/Orchard.Alias = https://hg.codeplex.com/orchardalias
src/orchard.web/Modules/Orchard.Projections = https://hg.codeplex.com/orchardprojections
src/Orchard.Web/Modules/Orchard.AntiSpam = https://hg.codeplex.com/orchardantispam
src/Orchard.Web/Modules/Orchard.CustomForms = https://hg.codeplex.com/orchardcustomforms
src/Orchard.Web/Modules/Orchard.ViewPermissions = https://hg.codeplex.com/orchardpermissions
src/Orchard.Web/Modules/Orchard.ViewPermissions = https://hg.codeplex.com/orchardpermissions
src/Orchard.Web/Modules/Orchard.ContentPicker = https://hg.codeplex.com/orchardcontentpicker

View File

@@ -1,5 +1,6 @@
fdaecfbb0eab3673a3074313f5adcedc6a678506 src/Orchard.Web/Modules/Orchard.AntiSpam
bf20391f8fe1ba5d67cadc0643d79ad9fe892d4e src/Orchard.Web/Modules/Orchard.Autoroute
da175731d643b675472e893689641066db827a7c src/Orchard.Web/Modules/Orchard.ContentPicker
37b71cc2949b792b8da48ee4b5450684e3f8b4cf src/Orchard.Web/Modules/Orchard.CustomForms
b8e23b1daab66d46b6d2196f87aceb91aed2f582 src/Orchard.Web/Modules/Orchard.Forms
cfc264d41c1d299c104d76c5032d8ffee3047dcd src/Orchard.Web/Modules/Orchard.Rules
@@ -8,4 +9,4 @@ cfc264d41c1d299c104d76c5032d8ffee3047dcd src/Orchard.Web/Modules/Orchard.Rules
f6fecd1702066225a84a482ac029e3e6daff38f3 src/Orchard.Web/Modules/Orchard.ViewPermissions
4ed51e0e76c2aacc2de90ce9984fd00cfdfae2ce src/orchard.web/Modules/Orchard.Alias
29857523c5275b8566ee3a6f4ba2a3d641e7fa0c src/orchard.web/Modules/Orchard.Projections
0ce46c4e39390472b82459007c0e5a05c18d22d8 src/orchard.web/modules/Orchard.Fields
5a25640f15b1a5a336e424324f1c4baf0a8ee73c src/orchard.web/modules/Orchard.Fields

View File

@@ -0,0 +1,82 @@
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Core.Navigation.Models;
using Orchard.Core.Navigation.ViewModels;
using Orchard.Localization;
using Orchard.Security;
namespace Orchard.Core.Navigation.Drivers {
[UsedImplicitly]
public class ContentMenuItemPartDriver : ContentPartDriver<ContentMenuItemPart> {
private readonly IContentManager _contentManager;
private readonly IAuthorizationService _authorizationService;
private readonly IWorkContextAccessor _workContextAccessor;
public ContentMenuItemPartDriver(
IContentManager contentManager,
IAuthorizationService authorizationService,
IWorkContextAccessor workContextAccessor) {
_contentManager = contentManager;
_authorizationService = authorizationService;
_workContextAccessor = workContextAccessor;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
protected override DriverResult Editor(ContentMenuItemPart part, dynamic shapeHelper) {
return ContentShape("Parts_ContentMenuItem_Edit",
() => {
var model = new ContentMenuItemEditViewModel {
ContentItemId = part.Content == null ? -1 : part.Content.Id,
Part = part
};
return shapeHelper.EditorTemplate(TemplateName: "Parts.ContentMenuItem.Edit", Model: model, Prefix: Prefix);
});
}
protected override DriverResult Editor(ContentMenuItemPart part, IUpdateModel updater, dynamic shapeHelper) {
var currentUser = _workContextAccessor.GetContext().CurrentUser;
if (!_authorizationService.TryCheckAccess(Permissions.ManageMainMenu, currentUser, part))
return null;
var model = new ContentMenuItemEditViewModel();
if(updater.TryUpdateModel(model, Prefix, null, null)) {
var contentItem = _contentManager.Get(model.ContentItemId);
if(contentItem == null) {
updater.AddModelError("ContentItemId", T("You must select a Content Item"));
}
else {
part.Content = contentItem;
}
}
return Editor(part, shapeHelper);
}
protected override void Importing(ContentMenuItemPart part, ImportContentContext context) {
var contentItemId = context.Attribute(part.PartDefinition.Name, "ContentItem");
if (contentItemId != null) {
var contentItem = context.GetItemFromSession(contentItemId);
part.Content = contentItem;
}
else {
part.Content = null;
}
}
protected override void Exporting(ContentMenuItemPart part, ExportContentContext context) {
if (part.Content != null) {
var contentItem = _contentManager.Get(part.Content.Id);
if (contentItem != null) {
var containerIdentity = _contentManager.GetItemMetadata(contentItem).Identity;
context.Element(part.PartDefinition.Name).SetAttributeValue("ContentItem", containerIdentity.ToString());
}
}
}
}
}

View File

@@ -0,0 +1,18 @@
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.Core.Navigation.Models;
using Orchard.Data;
using Orchard.ContentManagement.Handlers;
namespace Orchard.Core.Navigation.Handlers {
[UsedImplicitly]
public class ContentMenuItemPartHandler : ContentHandler {
public ContentMenuItemPartHandler(IContentManager contentManager, IRepository<ContentMenuItemPartRecord> repository) {
Filters.Add(new ActivatingFilter<ContentMenuItemPart>("ContentMenuItem"));
Filters.Add(StorageFilter.For(repository));
OnLoading<ContentMenuItemPart>((context, part) => part._content.Loader(p => contentManager.Get(part.Record.ContentMenuItemRecord.Id)));
}
}
}

View File

@@ -72,6 +72,21 @@ namespace Orchard.Core.Navigation {
ContentDefinitionManager.AlterPartDefinition("AdminMenuPart", builder => builder.Attachable());
SchemaBuilder.CreateTable("ContentMenuItemPartRecord",
table => table
.ContentPartRecord()
.Column<int>("ContentMenuItemRecord_id")
);
ContentDefinitionManager.AlterTypeDefinition("ContentMenuItem", cfg => cfg
.WithPart("MenuPart")
.WithPart("CommonPart")
.WithPart("ContentMenuItemPart")
.DisplayedAs("Content Menu Item")
.WithSetting("Description", "Adds a Content Item to the menu.")
.WithSetting("Stereotype", "MenuItem")
);
return 3;
}

View File

@@ -0,0 +1,17 @@
using Orchard.ContentManagement;
using Orchard.ContentManagement.Utilities;
namespace Orchard.Core.Navigation.Models {
public class ContentMenuItemPart : ContentPart<ContentMenuItemPartRecord> {
public readonly LazyField<ContentItem> _content = new LazyField<ContentItem>();
public ContentItem Content {
get { return _content.Value; }
set {
_content.Value = value;
Record.ContentMenuItemRecord = value == null ? null : value.Record;
}
}
}
}

View File

@@ -2,6 +2,6 @@
namespace Orchard.Core.Navigation.Models {
public class ContentMenuItemPartRecord : ContentPartRecord {
public virtual ContentItemRecord ContentItemRecord { get; set; }
public virtual ContentItemRecord ContentMenuItemRecord { get; set; }
}
}

View File

@@ -7,3 +7,4 @@ OrchardVersion: 1.4.1
Description: The navigation module creates and manages a simple navigation menu for the front-end of the application and allows you to add content items to the admin menu.
FeatureDescription: Menu management.
Category: Core
FeatureDependencies: Orchard.ContentPicker

View File

@@ -2,6 +2,7 @@
<Place Parts_Navigation_Menu_Edit="Content:9"/>
<Place Parts_Navigation_AdminMenu_Edit="Content:9.1"/>
<Place Parts_MenuItem_Edit="Content:10"/>
<Place Parts_ContentMenuItem_Edit="Content:10"/>
<Place Parts_MenuWidget_Edit="Content:10"/>
<Place Parts_MenuWidget="Content"/>
</Placement>

View File

@@ -0,0 +1,8 @@
using Orchard.Core.Navigation.Models;
namespace Orchard.Core.Navigation.ViewModels {
public class ContentMenuItemEditViewModel {
public int ContentItemId { get; set; }
public ContentMenuItemPart Part { get; set; }
}
}

View File

@@ -0,0 +1,25 @@
@model Orchard.Core.Navigation.ViewModels.ContentMenuItemEditViewModel
@{
Script.Require("ContentPicker").AtFoot();
}
<fieldset>
<label for="@Html.FieldIdFor(m => m.ContentItemId)">@T("Content Item")</label>
@Html.TextBoxFor(m => m.ContentItemId, new { @class = "small text", @readonly = "readonly" }) <span id="btn-@Html.FieldIdFor(m => m.ContentItemId)" class="button">@T("Browse")</span>
<span class="hint">@T("Select the Content Item to display in the menu.")</span>
</fieldset>
@using(Script.Foot()) {
<script type="text/javascript">
//<![CDATA[
jQuery('#btn-@Html.FieldIdFor(m => m.ContentItemId)').click(function () {
jQuery('#btn-@Html.FieldIdFor(m => m.ContentItemId)').trigger("orchard-admin-contentpicker-open", {
callback: function (data) {
var id = data.id;
jQuery('#@Html.FieldIdFor(m => m.ContentItemId)').val(id);
}
});
});
//]]>
</script>
}

View File

@@ -0,0 +1,2 @@
@using Orchard.ContentManagement
<a href="@Url.ItemDisplayUrl((ContentItem)Model.Content.ContentItem.ContentMenuItemPart.Content)">@Model.Text</a>

View File

@@ -131,12 +131,15 @@
<Compile Include="Dashboard\Services\CompilationErrorBanner.cs" />
<Compile Include="Navigation\Commands\MenuCommands.cs" />
<Compile Include="Navigation\Drivers\AdminMenuPartDriver.cs" />
<Compile Include="Navigation\Drivers\MenuItemPartDriver.cs" />
<Compile Include="Navigation\Drivers\MenuWidgetPartDriver.cs" />
<Compile Include="Navigation\Handlers\AdminMenuPartHandler.cs" />
<Compile Include="Navigation\Handlers\ContentMenuItemPartHandler.cs" />
<Compile Include="Navigation\Handlers\MenuWidgetPartHandler.cs" />
<Compile Include="Navigation\Models\AdminMenuPart.cs" />
<Compile Include="Navigation\Models\AdminMenuPartRecord.cs" />
<Compile Include="Navigation\Models\ContentMenuItemPartRecord.cs" />
<Compile Include="Navigation\Models\ContentMenuItemPart.cs" />
<Compile Include="Navigation\Models\MenuWidgetPartRecord.cs" />
<Compile Include="Navigation\Models\MenuWidgetPart.cs" />
<Compile Include="Navigation\Services\AdminMenuNavigationProvider.cs" />
@@ -146,6 +149,7 @@
<Compile Include="Navigation\Settings\AdminMenuPartTypeSettings.cs" />
<Compile Include="Contents\ViewModels\ListContentsViewModel.cs" />
<Compile Include="Contents\ViewModels\ListContentTypesViewModel.cs" />
<Compile Include="Navigation\ViewModels\ContentMenuItemEditViewModel.cs" />
<Compile Include="Navigation\ViewModels\MenuPartViewModel.cs" />
<Compile Include="Navigation\ViewModels\MenuWidgetViewModel.cs" />
<Compile Include="Reports\AdminMenu.cs" />
@@ -189,7 +193,7 @@
<Compile Include="Navigation\AdminMenu.cs" />
<Compile Include="Navigation\Controllers\AdminController.cs" />
<Compile Include="Navigation\Models\MenuItemPart.cs" />
<Compile Include="Navigation\Drivers\MenuItemPartDriver.cs" />
<Compile Include="Navigation\Drivers\ContentMenuItemPartDriver.cs" />
<Compile Include="Navigation\Handlers\MenuItemPartHandler.cs" />
<Compile Include="Navigation\Models\MenuPart.cs" />
<Compile Include="Navigation\Drivers\MenuPartDriver.cs" />
@@ -528,6 +532,12 @@
<ItemGroup>
<Content Include="Navigation\Views\MenuItemLink-HtmlMenuItem.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Navigation\Views\EditorTemplates\Parts.ContentMenuItem.Edit.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Navigation\Views\MenuItemLink-ContentMenuItem.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

@@ -18,6 +18,7 @@
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation />
<TargetFrameworkProfile />
<UseIISExpress>false</UseIISExpress>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

View File

@@ -31,7 +31,7 @@
<script type="text/javascript">
$.mediaPicker.cannotPerformMsg="@T("Cannot perform requested operation")";
$.mediaPicker.accessDeniedMsg="@T("Authentification timed-out: please log-on again")";
$.mediaPicker.accessDeniedMsg="@T("Authentication timed-out: please log-on again")";
$.mediaPicker.logonUrl="@Url.Action("LogOn", new { Controller = "Account", Area = "Orchard.Users" })";
</script>

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)
}

View File

@@ -148,6 +148,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.CustomForms", "Orch
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.ViewPermissions", "Orchard.Web\Modules\Orchard.ViewPermissions\Orchard.ViewPermissions.csproj", "{E826F796-8CE3-4B5B-8423-5AA5F81D2FC3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.ContentPicker", "Orchard.Web\Modules\Orchard.ContentPicker\Orchard.ContentPicker.csproj", "{F301EF7D-F19C-4D83-AA94-CB64F29C037D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
CodeCoverage|Any CPU = CodeCoverage|Any CPU
@@ -157,6 +159,10 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F301EF7D-F19C-4D83-AA94-CB64F29C037D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F301EF7D-F19C-4D83-AA94-CB64F29C037D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F301EF7D-F19C-4D83-AA94-CB64F29C037D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F301EF7D-F19C-4D83-AA94-CB64F29C037D}.Release|Any CPU.Build.0 = Release|Any CPU
{50B779EA-EC00-4699-84C0-03B395C365D2}.CodeCoverage|Any CPU.ActiveCfg = Release|Any CPU
{50B779EA-EC00-4699-84C0-03B395C365D2}.CodeCoverage|Any CPU.Build.0 = Release|Any CPU
{50B779EA-EC00-4699-84C0-03B395C365D2}.Coverage|Any CPU.ActiveCfg = Release|Any CPU
@@ -875,5 +881,6 @@ Global
{34BE9011-A5A9-49DD-9E53-C3D5CA7D7CE3} = {3E10BF6D-ADA5-417D-B36C-EBB0660B475E}
{AC4402A1-61C4-4229-B840-FB1777DAE10C} = {3E10BF6D-ADA5-417D-B36C-EBB0660B475E}
{CB70A642-8CEC-4DDE-8C9F-AD08900EC98D} = {74492CBC-7201-417E-BC29-28B4C25A58B0}
{F301EF7D-F19C-4D83-AA94-CB64F29C037D} = {E9C9F120-07BA-4DFB-B9C3-3AFB9D44C9D5}
EndGlobalSection
EndGlobal