mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-18 17:47:54 +08:00
- Tags: tagging content items, tag settings, tag permissions, creating/listing tags...
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4041971
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Comments.Models;
|
||||
using Orchard.Data;
|
||||
|
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
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 {
|
||||
[ValidateInput(false)]
|
||||
public class TagsController : Controller {
|
||||
private readonly ITagService _tagService;
|
||||
private readonly IAuthorizer _authorizer;
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public TagsController(ITagService tagService, INotifier notifier, IAuthorizer authorizer) {
|
||||
_tagService = tagService;
|
||||
_authorizer = authorizer;
|
||||
_notifier = notifier;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public IUser CurrentUser { get; set; }
|
||||
public ISite CurrentSite { get; set; }
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ActionResult Index() {
|
||||
try {
|
||||
var tags = _tagService.GetTags();
|
||||
var model = new TagsIndexViewModel { Tags = tags.ToList() };
|
||||
return View(model);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
_notifier.Error(T("Listing tags failed: " + exception.Message));
|
||||
return Index();
|
||||
}
|
||||
}
|
||||
|
||||
[AcceptVerbs(HttpVerbs.Post)]
|
||||
public ActionResult Edit(FormCollection input, string returnUrl) {
|
||||
try {
|
||||
if (!String.IsNullOrEmpty(returnUrl)) {
|
||||
return Redirect(returnUrl);
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
_notifier.Error(T("Editing tags failed: " + exception.Message));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult Create() {
|
||||
return View(new TagsCreateViewModel());
|
||||
}
|
||||
|
||||
[AcceptVerbs(HttpVerbs.Post)]
|
||||
public ActionResult Create(FormCollection input) {
|
||||
var viewModel = new TagsCreateViewModel();
|
||||
try {
|
||||
UpdateModel(viewModel, input.ToValueProvider());
|
||||
if (!_authorizer.Authorize(Permissions.CreateTag, T("Couldn't create tag")))
|
||||
return new HttpUnauthorizedResult();
|
||||
Tag tag = new Tag { TagName = viewModel.TagName };
|
||||
_tagService.CreateTag(tag);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
_notifier.Error(T("Creating Tag failed: " + exception.Message));
|
||||
return View(viewModel);
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult TagName(int tagId) {
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
}
|
6
src/Orchard.Web/Packages/Orchard.Tags/Models/Tag.cs
Normal file
6
src/Orchard.Web/Packages/Orchard.Tags/Models/Tag.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Orchard.Tags.Models {
|
||||
public class Tag {
|
||||
public virtual int Id { get; set; }
|
||||
public virtual string TagName { get; set; }
|
||||
}
|
||||
}
|
21
src/Orchard.Web/Packages/Orchard.Tags/Models/TagSettings.cs
Normal file
21
src/Orchard.Web/Packages/Orchard.Tags/Models/TagSettings.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Orchard.Data;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.Models.Records;
|
||||
|
||||
namespace Orchard.Tags.Models {
|
||||
public class TagSettings : ContentPart<TagSettingsRecord> {
|
||||
}
|
||||
|
||||
public class TagSettingsRecord : ContentPartRecord {
|
||||
public virtual bool EnableTagsOnPages { get; set; }
|
||||
}
|
||||
|
||||
public class TagSettingsProvider : ContentProvider {
|
||||
public TagSettingsProvider(IRepository<TagSettingsRecord> repository) {
|
||||
Filters.Add(new ActivatingFilter<TagSettings>("site"));
|
||||
Filters.Add(new StorageFilter<TagSettingsRecord>(repository) { AutomaticallyCreateMissingRecord = true });
|
||||
Filters.Add(new TemplateFilterForRecord<TagSettingsRecord>("TagSettings"));
|
||||
}
|
||||
}
|
||||
}
|
42
src/Orchard.Web/Packages/Orchard.Tags/Models/TagsHandler.cs
Normal file
42
src/Orchard.Web/Packages/Orchard.Tags/Models/TagsHandler.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Data;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.UI.Models;
|
||||
|
||||
namespace Orchard.Tags.Models {
|
||||
public class HasTags : ContentPart {
|
||||
public HasTags() {
|
||||
AllTags = new List<Tag>();
|
||||
}
|
||||
|
||||
public IEnumerable<Tag> AllTags { get; set; }
|
||||
}
|
||||
|
||||
public class HasTagsProvider : ContentProvider {
|
||||
private readonly IRepository<Tag> _tagsRepository;
|
||||
|
||||
public HasTagsProvider(IRepository<Tag> tagsRepository) {
|
||||
_tagsRepository = tagsRepository;
|
||||
Filters.Add(new ActivatingFilter<HasTags>("sandboxpage"));
|
||||
}
|
||||
|
||||
protected override void GetDisplays(GetDisplaysContext context) {
|
||||
if (context.ContentItem.Has<HasTags>() == false) {
|
||||
return;
|
||||
}
|
||||
context.Displays.Add(new ModelTemplate { Model = context.ContentItem.Get<HasTags>(), Prefix = String.Empty });
|
||||
}
|
||||
|
||||
protected override void Loading(LoadContentContext context) {
|
||||
if (context.ContentItem.Has<HasTags>() == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
HasTags tags = context.ContentItem.Get<HasTags>();
|
||||
tags.AllTags = _tagsRepository.Table.ToList();
|
||||
}
|
||||
}
|
||||
}
|
@@ -61,10 +61,22 @@
|
||||
<Reference Include="System.Web.Mobile" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Controllers\TagsController.cs" />
|
||||
<Compile Include="Models\Tag.cs" />
|
||||
<Compile Include="Models\TagSettings.cs" />
|
||||
<Compile Include="Models\TagsHandler.cs" />
|
||||
<Compile Include="Permissions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\TagService.cs" />
|
||||
<Compile Include="ViewModels\TagsCreateViewModel.cs" />
|
||||
<Compile Include="ViewModels\TagsIndexViewModel.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Package.txt" />
|
||||
<Content Include="Views\Models\DisplayTemplates\HasTags.ascx" />
|
||||
<Content Include="Views\Models\EditorTemplates\TagSettingsRecord.ascx" />
|
||||
<Content Include="Views\Tags\Create.aspx" />
|
||||
<Content Include="Views\Tags\Index.aspx" />
|
||||
<Content Include="Web.config" />
|
||||
<Content Include="Views\Web.config" />
|
||||
</ItemGroup>
|
||||
@@ -77,8 +89,6 @@
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
<Folder Include="Content\" />
|
||||
<Folder Include="Controllers\" />
|
||||
<Folder Include="Models\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||
|
20
src/Orchard.Web/Packages/Orchard.Tags/Permissions.cs
Normal file
20
src/Orchard.Web/Packages/Orchard.Tags/Permissions.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Security.Permissions;
|
||||
|
||||
namespace Orchard.Tags {
|
||||
public class Permissions : IPermissionProvider {
|
||||
public static readonly Permission CreateTag = new Permission { Description = "Creating a Tag", Name = "CreateTag" };
|
||||
|
||||
public string PackageName {
|
||||
get {
|
||||
return "Tags";
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Permission> GetPermissions() {
|
||||
return new List<Permission> {
|
||||
CreateTag,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
43
src/Orchard.Web/Packages/Orchard.Tags/Services/TagService.cs
Normal file
43
src/Orchard.Web/Packages/Orchard.Tags/Services/TagService.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Data;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Security;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Tags.Models;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Tags.Services {
|
||||
public interface ITagService : IDependency {
|
||||
IEnumerable<Tag> GetTags();
|
||||
void CreateTag(Tag tag);
|
||||
}
|
||||
|
||||
public class TagService : ITagService {
|
||||
private readonly IRepository<Tag> _tagRepository;
|
||||
private readonly IAuthorizer _authorizer;
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public TagService(IRepository<Tag> tagRepository, IAuthorizer authorizer, INotifier notifier) {
|
||||
_tagRepository = tagRepository;
|
||||
_authorizer = authorizer;
|
||||
_notifier = notifier;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
public ISite CurrentSite { get; set; }
|
||||
|
||||
#region ITagService Members
|
||||
|
||||
public IEnumerable<Tag> GetTags() {
|
||||
return from comment in _tagRepository.Table.ToList() select comment;
|
||||
}
|
||||
|
||||
public void CreateTag(Tag tag) {
|
||||
_tagRepository.Create(tag);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.Tags.ViewModels {
|
||||
public class TagsCreateViewModel : BaseViewModel {
|
||||
public string TagName { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.Tags.Models;
|
||||
|
||||
namespace Orchard.Tags.ViewModels {
|
||||
public class TagsIndexViewModel : BaseViewModel {
|
||||
public IList<Tag> Tags { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<HasTags>" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
<%@ Import Namespace="Orchard.Tags.Models"%>
|
||||
<h3>Tags</h3>
|
||||
<% Html.BeginForm("Edit", "Tags", new { area = "Orchard.Tags" }); %>
|
||||
<%= Html.ValidationSummary() %>
|
||||
<div class="yui-g">
|
||||
<h2 class="separator">Edit Tags</h2>
|
||||
<ol>
|
||||
<%= Html.Hidden("ReturnUrl", Context.Request.Url) %>
|
||||
<% foreach (var tag in Model.AllTags) { %>
|
||||
<li>
|
||||
<label for"<%= tag.TagName %>"><%= tag.TagName %>:</label>
|
||||
<input type="checkbox" value="true" name="<%= tag.TagName %>"/>
|
||||
</li>
|
||||
<% } %>
|
||||
<li>
|
||||
<input type="submit" class="button" value="Save" />
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
<% Html.EndForm(); %>
|
@@ -0,0 +1,10 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<TagSettingsRecord>" %>
|
||||
<%@ Import Namespace="Orchard.Tags.Models"%>
|
||||
<h3>Tags</h3>
|
||||
<ol>
|
||||
<li>
|
||||
<%= Html.LabelFor(x=>x.EnableTagsOnPages) %>
|
||||
<%= Html.EditorFor(x=>x.EnableTagsOnPages) %>
|
||||
<%= Html.ValidationMessage("EnableTagsOnPages", "*")%>
|
||||
</li>
|
||||
</ol>
|
14
src/Orchard.Web/Packages/Orchard.Tags/Views/Tags/Create.aspx
Normal file
14
src/Orchard.Web/Packages/Orchard.Tags/Views/Tags/Create.aspx
Normal file
@@ -0,0 +1,14 @@
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<TagsCreateViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Tags.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||
<% Html.Include("Header"); %>
|
||||
<% Html.BeginForm(); %>
|
||||
<%= Html.ValidationSummary() %>
|
||||
<div class="yui-g">
|
||||
<h2 class="separator">Add a Tag</h2>
|
||||
<label for="TagName">Name:</label>
|
||||
<input id="TagName" class="inputText inputTextLarge" name="TagName" type="text" value="<%= Model.TagName %>" />
|
||||
<input type="submit" class="button" value="Save" />
|
||||
</div>
|
||||
<% Html.EndForm(); %>
|
||||
<% Html.Include("Footer"); %>
|
14
src/Orchard.Web/Packages/Orchard.Tags/Views/Tags/Index.aspx
Normal file
14
src/Orchard.Web/Packages/Orchard.Tags/Views/Tags/Index.aspx
Normal file
@@ -0,0 +1,14 @@
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<TagsIndexViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Tags.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
<% Html.Include("Header"); %>
|
||||
<div class="yui-g">
|
||||
<h2 class="separator">Tags</h2>
|
||||
<%=Html.ValidationSummary() %>
|
||||
<% foreach (var tag in Model.Tags) { %>
|
||||
<%=Html.ActionLink(tag.TagName, "TagName", new {tagId = tag.Id}, new {@class="floatRight topSpacer"}) %>
|
||||
|
||||
<% } %>
|
||||
</div>
|
||||
<% Html.EndForm(); %>
|
||||
<% Html.Include("Footer"); %>
|
Reference in New Issue
Block a user