mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Use checkboxes in Site Settings to select terms to include in search
--HG-- branch : dev
This commit is contained in:
@@ -5,7 +5,7 @@ using Orchard.Localization;
|
|||||||
|
|
||||||
namespace Orchard.Email.Drivers {
|
namespace Orchard.Email.Drivers {
|
||||||
|
|
||||||
// We define a specific driver instead of using a TemplateFilterForRecord, because we need the ;odel to be the part and not the record.
|
// We define a specific driver instead of using a TemplateFilterForRecord, because we need the model to be the part and not the record.
|
||||||
// Thus the encryption/decryption will be done when accessing the part's property
|
// Thus the encryption/decryption will be done when accessing the part's property
|
||||||
|
|
||||||
public class SmtpSettingsPartDriver : ContentPartDriver<SmtpSettingsPart> {
|
public class SmtpSettingsPartDriver : ContentPartDriver<SmtpSettingsPart> {
|
||||||
@@ -17,13 +17,13 @@ namespace Orchard.Email.Drivers {
|
|||||||
|
|
||||||
protected override string Prefix { get { return "SmtpSettings"; } }
|
protected override string Prefix { get { return "SmtpSettings"; } }
|
||||||
|
|
||||||
protected override DriverResult Editor(SmtpSettingsPart termPart) {
|
protected override DriverResult Editor(SmtpSettingsPart part) {
|
||||||
return ContentPartTemplate(termPart, "Parts/Smtp.SiteSettings");
|
return ContentPartTemplate(part, "Parts/Smtp.SiteSettings");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override DriverResult Editor(SmtpSettingsPart termPart, IUpdateModel updater) {
|
protected override DriverResult Editor(SmtpSettingsPart part, IUpdateModel updater) {
|
||||||
updater.TryUpdateModel(termPart, Prefix, null, null);
|
updater.TryUpdateModel(part, Prefix, null, null);
|
||||||
return Editor(termPart);
|
return Editor(part);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -24,7 +24,7 @@ namespace Orchard.Search.Controllers {
|
|||||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||||
|
|
||||||
public ActionResult Index(string q, int page = 1, int pageSize = 10) {
|
public ActionResult Index(string q, int page = 1, int pageSize = 10) {
|
||||||
var searchFields = CurrentSite.As<SearchSettingsPart>().Record.SearchedFields.Split(new[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);
|
var searchFields = CurrentSite.As<SearchSettingsPart>().SearchedFields;
|
||||||
|
|
||||||
var searchHits = _searchService.Query(q, page, pageSize,
|
var searchHits = _searchService.Query(q, page, pageSize,
|
||||||
CurrentSite.As<SearchSettingsPart>().Record.FilterCulture,
|
CurrentSite.As<SearchSettingsPart>().Record.FilterCulture,
|
||||||
|
@@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.Drivers;
|
||||||
|
using Orchard.Indexing;
|
||||||
|
using Orchard.Localization;
|
||||||
|
using Orchard.Search.Models;
|
||||||
|
using Orchard.Search.ViewModels;
|
||||||
|
|
||||||
|
namespace Orchard.Search.Drivers {
|
||||||
|
|
||||||
|
public class SearchSettingsPartDriver : ContentPartDriver<SearchSettingsPart> {
|
||||||
|
private const string SearchIndexName = "Search";
|
||||||
|
private readonly IIndexManager _indexManager;
|
||||||
|
|
||||||
|
public SearchSettingsPartDriver(IIndexManager indexManager) {
|
||||||
|
_indexManager = indexManager;
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
protected override string Prefix { get { return "SearchSettings"; } }
|
||||||
|
|
||||||
|
protected override DriverResult Editor(SearchSettingsPart part) {
|
||||||
|
var model = new SearchSettingsViewModel();
|
||||||
|
var searchedFields = part.SearchedFields;
|
||||||
|
|
||||||
|
if (_indexManager.HasIndexProvider()) {
|
||||||
|
model.Entries = new List<SearchSettingsEntry>();
|
||||||
|
foreach (var field in _indexManager.GetSearchIndexProvider().GetFields(SearchIndexName)) {
|
||||||
|
model.Entries.Add(new SearchSettingsEntry { Field = field, Selected = searchedFields.Contains(field) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ContentPartTemplate(model, "Parts/Search.SiteSettings");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DriverResult Editor(SearchSettingsPart part, IUpdateModel updater) {
|
||||||
|
var model = new SearchSettingsViewModel();
|
||||||
|
|
||||||
|
if(updater.TryUpdateModel(model, Prefix, null, null)) {
|
||||||
|
part.SearchedFields = model.Entries.Where(e => e.Selected).Select(e => e.Field).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Editor(part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -9,7 +9,6 @@ namespace Orchard.Search.Handlers {
|
|||||||
public SearchSettingsPartHandler(IRepository<SearchSettingsPartRecord> repository) {
|
public SearchSettingsPartHandler(IRepository<SearchSettingsPartRecord> repository) {
|
||||||
Filters.Add(new ActivatingFilter<SearchSettingsPart>("Site"));
|
Filters.Add(new ActivatingFilter<SearchSettingsPart>("Site"));
|
||||||
Filters.Add(StorageFilter.For(repository));
|
Filters.Add(StorageFilter.For(repository));
|
||||||
Filters.Add(new TemplateFilterForRecord<SearchSettingsPartRecord>("CommentSettings", "Parts/Search.SiteSettings"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,6 +1,11 @@
|
|||||||
using Orchard.ContentManagement;
|
using System;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
|
||||||
namespace Orchard.Search.Models {
|
namespace Orchard.Search.Models {
|
||||||
public class SearchSettingsPart : ContentPart<SearchSettingsPartRecord> {
|
public class SearchSettingsPart : ContentPart<SearchSettingsPartRecord> {
|
||||||
|
public string[] SearchedFields {
|
||||||
|
get { return Record.SearchedFields.Split(new[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries); }
|
||||||
|
set { Record.SearchedFields = String.Join(", ", value); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -67,6 +67,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Controllers\SearchController.cs" />
|
<Compile Include="Controllers\SearchController.cs" />
|
||||||
<Compile Include="DataMigrations\SearchDataMigration.cs" />
|
<Compile Include="DataMigrations\SearchDataMigration.cs" />
|
||||||
|
<Compile Include="Drivers\SearchSettingsPartDriver.cs" />
|
||||||
<Compile Include="Filters\SearchFilter.cs" />
|
<Compile Include="Filters\SearchFilter.cs" />
|
||||||
<Compile Include="Models\SearchSettingsPart.cs" />
|
<Compile Include="Models\SearchSettingsPart.cs" />
|
||||||
<Compile Include="Models\SearchSettingsPartRecord.cs" />
|
<Compile Include="Models\SearchSettingsPartRecord.cs" />
|
||||||
@@ -74,6 +75,7 @@
|
|||||||
<Compile Include="Handlers\SearchSettingsPartHandler.cs" />
|
<Compile Include="Handlers\SearchSettingsPartHandler.cs" />
|
||||||
<Compile Include="Services\ISearchService.cs" />
|
<Compile Include="Services\ISearchService.cs" />
|
||||||
<Compile Include="Services\SearchService.cs" />
|
<Compile Include="Services\SearchService.cs" />
|
||||||
|
<Compile Include="ViewModels\SearchSettingsViewModel.cs" />
|
||||||
<Compile Include="ViewModels\SearchResultViewModel.cs" />
|
<Compile Include="ViewModels\SearchResultViewModel.cs" />
|
||||||
<Compile Include="ViewModels\SearchViewModel.cs" />
|
<Compile Include="ViewModels\SearchViewModel.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
@@ -0,0 +1,14 @@
|
|||||||
|
using Orchard.Mvc.ViewModels;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Orchard.Search.ViewModels {
|
||||||
|
public class SearchSettingsViewModel : BaseViewModel {
|
||||||
|
public IList<SearchSettingsEntry> Entries { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SearchSettingsEntry {
|
||||||
|
public string Field { get; set; }
|
||||||
|
public bool Selected { get; set; }
|
||||||
|
public int Weight { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<SearchSettingsPartRecord>" %>
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<SearchSettingsViewModel>" %>
|
||||||
<%@ Import Namespace="Orchard.Search.Models"%>
|
<%@ Import Namespace="Orchard.Search.ViewModels"%>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend><%: T("Search")%></legend>
|
<legend><%: T("Search")%></legend>
|
||||||
<%-- TODO: (sebros) Implementation details after Alpha
|
<%-- TODO: (sebros) Implementation details after Alpha
|
||||||
@@ -10,8 +10,14 @@
|
|||||||
</div>
|
</div>
|
||||||
--%>
|
--%>
|
||||||
<div>
|
<div>
|
||||||
<label for="SearchSettings_SearchedFields"><%: T("Searched fields")%></label>
|
<%
|
||||||
<%: Html.EditorFor(m => m.SearchedFields)%>
|
for(var i=0; i<Model.Entries.Count; i++) {
|
||||||
<%: Html.ValidationMessage("SearchedFields", "*")%>
|
var j = i;%>
|
||||||
|
<input type="checkbox" value="true" <% if(Model.Entries[j].Selected ) { %> checked="checked" <% } %>
|
||||||
|
name="<%:Html.FieldNameFor(m => m.Entries[j].Selected)%>" id="<%:Html.FieldIdFor(m => m.Entries[j].Selected)%>"/>
|
||||||
|
<%: Html.HiddenFor(m => m.Entries[j].Field)%>
|
||||||
|
<label class="forcheckbox" for="<%:Html.FieldIdFor(m => m.Entries[j].Selected)%>"><%: Model.Entries[j].Field%></label>
|
||||||
|
<%
|
||||||
|
}%>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
Reference in New Issue
Block a user