- 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:
suhacan
2009-11-25 01:09:44 +00:00
parent 3d7c2019fd
commit 8bd6e8acf4
5 changed files with 47 additions and 3 deletions

View File

@@ -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();
}
}
}
}

View File

@@ -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>

View File

@@ -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; }
}
}

View File

@@ -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"}) %>
&nbsp;
<% } %>
</div>

View 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)%>
&nbsp;
<% } %>
</div>
<% Html.EndForm(); %>
<% Html.Include("Footer"); %>