mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-19 10:07:55 +08:00
- Tags: search by tags for the front end...
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4042122
This commit is contained in:
@@ -4,13 +4,16 @@ using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Models;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Tags.Models;
|
||||
using Orchard.Tags.Services;
|
||||
using Orchard.Tags.ViewModels;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Security;
|
||||
|
||||
namespace Orchard.Tags.Controllers {
|
||||
//TODO: might as well make this the home controller...
|
||||
[ValidateInput(false)]
|
||||
public class TagsController : Controller {
|
||||
private readonly ITagService _tagService;
|
||||
@@ -78,8 +81,21 @@ namespace Orchard.Tags.Controllers {
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult TagName(int tagId) {
|
||||
return RedirectToAction("Index");
|
||||
public ActionResult Search(string tagName) {
|
||||
try {
|
||||
Tag tag = _tagService.GetTagByName(tagName);
|
||||
IEnumerable<IContent> contents = _tagService.GetTaggedContentItems(tag.Id).ToList();
|
||||
var viewModel = new TagsSearchViewModel {
|
||||
TagName = tag.TagName,
|
||||
Contents = contents,
|
||||
};
|
||||
return View(viewModel);
|
||||
|
||||
}
|
||||
catch (Exception exception) {
|
||||
_notifier.Error(T("Retrieving tagged items failed: " + exception.Message));
|
||||
return Index();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -74,6 +74,7 @@
|
||||
<Compile Include="ViewModels\TagsAdminEditViewModel.cs" />
|
||||
<Compile Include="ViewModels\TagsAdminIndexViewModel.cs" />
|
||||
<Compile Include="ViewModels\TagsAdminSearchViewModel.cs" />
|
||||
<Compile Include="ViewModels\TagsSearchViewModel.cs" />
|
||||
<Compile Include="ViewModels\TagsIndexViewModel.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -85,6 +86,7 @@
|
||||
<Content Include="Views\Models\DisplayTemplates\HasTags.ascx" />
|
||||
<Content Include="Views\Models\EditorTemplates\TagSettingsRecord.ascx" />
|
||||
<Content Include="Views\Tags\Index.aspx" />
|
||||
<Content Include="Views\Tags\Search.aspx" />
|
||||
<Content Include="Web.config" />
|
||||
<Content Include="Views\Web.config" />
|
||||
</ItemGroup>
|
||||
|
@@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Models;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.Tags.ViewModels {
|
||||
public class TagsSearchViewModel : BaseViewModel {
|
||||
public string TagName { get; set; }
|
||||
public IEnumerable<IContent> Contents { get; set; }
|
||||
}
|
||||
}
|
@@ -6,7 +6,7 @@
|
||||
<h2 class="separator">Tags</h2>
|
||||
<%=Html.ValidationSummary() %>
|
||||
<% foreach (var tag in Model.Tags) { %>
|
||||
<%=Html.ActionLink(tag.TagName, "Search", new {tagId = tag.Id}, new {@class="floatRight topSpacer"}) %>
|
||||
<%=Html.ActionLink(tag.TagName, "Search", new {tagName = tag.TagName}, new {@class="floatRight topSpacer"}) %>
|
||||
|
||||
<% } %>
|
||||
</div>
|
||||
|
16
src/Orchard.Web/Packages/Orchard.Tags/Views/Tags/Search.aspx
Normal file
16
src/Orchard.Web/Packages/Orchard.Tags/Views/Tags/Search.aspx
Normal file
@@ -0,0 +1,16 @@
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<TagsSearchViewModel>" %>
|
||||
<%@ 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() %>
|
||||
<% foreach (var contentItem in Model.Contents) { %>
|
||||
<%=Html.ItemDisplayLink(contentItem)%>
|
||||
|
||||
<% } %>
|
||||
</div>
|
||||
<% Html.EndForm(); %>
|
||||
<% Html.Include("Footer"); %>
|
Reference in New Issue
Block a user