mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 10:54:50 +08:00
- Tags: Search content items by tag and display links to view the tagged content items...
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4042114
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
@@ -132,6 +131,23 @@ namespace Orchard.Tags.Controllers {
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult Search(int id) {
|
||||
try {
|
||||
Tag tag = _tagService.GetTag(id);
|
||||
IEnumerable<IContent> contents = _tagService.GetTaggedContentItems(id).ToList();
|
||||
var viewModel = new TagsAdminSearchViewModel {
|
||||
TagName = tag.TagName,
|
||||
Contents = contents,
|
||||
};
|
||||
return View(viewModel);
|
||||
|
||||
}
|
||||
catch (Exception exception) {
|
||||
_notifier.Error(T("Retrieving tagged items failed: " + exception.Message));
|
||||
return Index();
|
||||
}
|
||||
}
|
||||
|
||||
private static TagEntry CreateTagEntry(Tag tag) {
|
||||
return new TagEntry {
|
||||
Tag = tag,
|
||||
|
@@ -73,6 +73,7 @@
|
||||
<Compile Include="ViewModels\TagsAdminCreateViewModel.cs" />
|
||||
<Compile Include="ViewModels\TagsAdminEditViewModel.cs" />
|
||||
<Compile Include="ViewModels\TagsAdminIndexViewModel.cs" />
|
||||
<Compile Include="ViewModels\TagsAdminSearchViewModel.cs" />
|
||||
<Compile Include="ViewModels\TagsCreateViewModel.cs" />
|
||||
<Compile Include="ViewModels\TagsIndexViewModel.cs" />
|
||||
</ItemGroup>
|
||||
@@ -81,6 +82,7 @@
|
||||
<Content Include="Views\Admin\Create.aspx" />
|
||||
<Content Include="Views\Admin\Edit.aspx" />
|
||||
<Content Include="Views\Admin\Index.aspx" />
|
||||
<Content Include="Views\Admin\Search.aspx" />
|
||||
<Content Include="Views\Models\DisplayTemplates\HasTags.ascx" />
|
||||
<Content Include="Views\Models\EditorTemplates\TagSettingsRecord.ascx" />
|
||||
<Content Include="Views\Tags\Create.aspx" />
|
||||
|
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using Orchard.Data;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Models;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Tags.Models;
|
||||
using Orchard.UI.Notify;
|
||||
@@ -16,6 +17,7 @@ namespace Orchard.Tags.Services {
|
||||
void CreateTag(string tagName);
|
||||
void DeleteTag(int id);
|
||||
void UpdateTag(int id, string tagName);
|
||||
IEnumerable<IContent> GetTaggedContentItems(int id);
|
||||
void TagContentItem(int contentItemId, string tagName);
|
||||
void UpdateTagsForContentItem(int contentItemId, IEnumerable<int> tagsForContentItem);
|
||||
}
|
||||
@@ -23,13 +25,16 @@ namespace Orchard.Tags.Services {
|
||||
public class TagService : ITagService {
|
||||
private readonly IRepository<Tag> _tagRepository;
|
||||
private readonly IRepository<TagsContentItems> _tagsContentItemsRepository;
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public TagService(IRepository<Tag> tagRepository,
|
||||
IRepository<TagsContentItems> tagsContentItemsRepository,
|
||||
IContentManager contentManager,
|
||||
INotifier notifier) {
|
||||
_tagRepository = tagRepository;
|
||||
_tagsContentItemsRepository = tagsContentItemsRepository;
|
||||
_contentManager = contentManager;
|
||||
_notifier = notifier;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
@@ -80,6 +85,15 @@ namespace Orchard.Tags.Services {
|
||||
tag.TagName = tagName;
|
||||
}
|
||||
|
||||
public IEnumerable<IContent> GetTaggedContentItems(int id) {
|
||||
List<IContent> contentItems = new List<IContent>();
|
||||
IEnumerable<TagsContentItems> tagsContentItems = _tagsContentItemsRepository.Fetch(x => x.TagId == id);
|
||||
foreach (var tagContentItem in tagsContentItems) {
|
||||
contentItems.Add(_contentManager.Get(tagContentItem.ContentItemId));
|
||||
}
|
||||
return contentItems;
|
||||
}
|
||||
|
||||
public void TagContentItem(int contentItemId, string tagName) {
|
||||
Tag tag = GetTagByName(tagName);
|
||||
TagsContentItems tagsContentItems = new TagsContentItems { ContentItemId = contentItemId, TagId = tag.Id };
|
||||
|
@@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Models;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.Tags.ViewModels {
|
||||
public class TagsAdminSearchViewModel : AdminViewModel {
|
||||
public string TagName { get; set; }
|
||||
public IEnumerable<IContent> Contents { get; set; }
|
||||
}
|
||||
}
|
@@ -4,7 +4,7 @@
|
||||
<% Html.Include("Header"); %>
|
||||
<% Html.BeginForm(); %>
|
||||
<div class="yui-g">
|
||||
<h2 class="separator">Manage Comments</h2>
|
||||
<h2 class="separator">Manage Tags</h2>
|
||||
<%=Html.ValidationSummary() %>
|
||||
<ol class="horizontal actions floatLeft">
|
||||
<li>
|
||||
@@ -44,7 +44,7 @@
|
||||
<input type="checkbox" value="true" name="<%=Html.NameOf(m => m.Tags[tagIndex].IsChecked)%>"/>
|
||||
</td>
|
||||
<td>
|
||||
<%= tagEntry.Tag.TagName %>
|
||||
<%=Html.ActionLink(tagEntry.Tag.TagName, "Search", new {id = tagEntry.Tag.Id}, new {@class="floatRight topSpacer"}) %>
|
||||
</td>
|
||||
<td>
|
||||
<%=Html.ActionLink("Edit", "Edit", new {id = tagEntry.Tag.Id}, new {@class="floatRight topSpacer"}) %>
|
||||
|
@@ -0,0 +1,34 @@
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<TagsAdminSearchViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Models"%>
|
||||
<%@ Import Namespace="Orchard.Tags.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
<% Html.Include("Header"); %>
|
||||
<% Html.BeginForm(); %>
|
||||
<div class="yui-g">
|
||||
<h2 class="separator">List of contents tagged with <%= Model.TagName %></h2>
|
||||
<%=Html.ValidationSummary() %>
|
||||
<table id="Table1" cellspacing="0" class="roundCorners clearLayout">
|
||||
<colgroup>
|
||||
<col id="Col2" />
|
||||
<col id="Col3" />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Name</th>
|
||||
<th scope="col">Link to the content item</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<% foreach (var contentItem in Model.Contents) { %>
|
||||
<tr>
|
||||
<td>
|
||||
<%=contentItem.As<IContentDisplayInfo>().DisplayText%>
|
||||
</td>
|
||||
<td>
|
||||
<%=Html.ItemDisplayLink(contentItem)%>
|
||||
</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
</table>
|
||||
</div>
|
||||
<% Html.EndForm(); %>
|
||||
<% Html.Include("Footer"); %>
|
Reference in New Issue
Block a user