Revert "TagCloud Functionality to filter by User"

This reverts commit ff1e1bf25a.
This commit is contained in:
Stanley Goldman
2014-10-23 13:01:12 -04:00
parent ff1e1bf25a
commit 4f4ad4d48f
9 changed files with 51 additions and 66 deletions

View File

@@ -40,13 +40,11 @@ namespace Orchard.Tags.Drivers {
protected override void Exporting(TagCloudPart part, ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Slug", part.Slug);
context.Element(part.PartDefinition.Name).SetAttributeValue("Buckets", part.Buckets);
context.Element(part.PartDefinition.Name).SetAttributeValue("Username", part.Username);
}
protected override void Importing(TagCloudPart part, ImportContentContext context) {
part.Slug = context.Attribute(part.PartDefinition.Name, "Slug");
part.Buckets = Convert.ToInt32(context.Attribute(part.PartDefinition.Name, "Buckets"));
part.Username = context.Attribute(part.PartDefinition.Name, "Username");
}
}
}

View File

@@ -4,27 +4,22 @@ using Orchard.ContentManagement.Handlers;
using Orchard.Environment.Extensions;
using Orchard.Tags.Models;
using Orchard.Tags.Services;
using Orchard.Tokens;
namespace Orchard.Tags.Handlers {
[OrchardFeature("Orchard.Tags.TagCloud")]
public class TagCloudHandler : ContentHandler {
private readonly ISignals _signals;
private readonly ITokenizer _tokenizer;
public TagCloudHandler(
ITagCloudService tagCloudService,
ISignals signals,
ITokenizer tokenizer) {
ISignals signals) {
_signals = signals;
_tokenizer = tokenizer;
OnInitializing<TagCloudPart>((context, part) => part
._tagCountField.Loader(tags => {
var username = _tokenizer.Replace(part.Username, new object());
return tagCloudService.GetPopularTags(part.Buckets, part.Slug, username).ToList();
}));
._tagCountField.Loader(tags =>
tagCloudService.GetPopularTags(part.Buckets, part.Slug).ToList()
));
OnPublished<TagsPart>((context, part) => InvalidateTagCloudCache());
OnRemoved<TagsPart>((context, part) => InvalidateTagCloudCache());

View File

@@ -19,10 +19,5 @@ namespace Orchard.Tags.Models {
get { return this.Retrieve(r => r.Slug); }
set { this.Store(r => r.Slug, value); }
}
public string Username {
get { return this.Retrieve(r => r.Username); }
set { this.Store(r => r.Username, value); }
}
}
}

View File

@@ -18,5 +18,5 @@ Features:
Orchard.Tags.TagCloud:
Name: Tag Cloud
Description: Adds a tag cloud widget.
Dependencies: Orchard.Tags, Orchard.Autoroute, Orchard.Tokens
Dependencies: Orchard.Tags, Orchard.Autoroute
Category: Navigation

View File

@@ -133,10 +133,6 @@
<Project>{66FCCD76-2761-47E3-8D11-B45D0001DDAA}</Project>
<Name>Orchard.Autoroute</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Tokens\Orchard.Tokens.csproj">
<Project>{6f759635-13d7-4e94-bcc9-80445d63f117}</Project>
<Name>Orchard.Tokens</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Placement.info">

View File

@@ -3,6 +3,6 @@ using Orchard.Tags.Models;
namespace Orchard.Tags.Services {
public interface ITagCloudService : IDependency {
IEnumerable<TagCount> GetPopularTags(int buckets, string slug, string username = null);
IEnumerable<TagCount> GetPopularTags(int buckets, string slug);
}
}

View File

@@ -7,7 +7,6 @@ using Orchard.ContentManagement;
using Orchard.Core.Common.Models;
using Orchard.Data;
using Orchard.Environment.Extensions;
using Orchard.Security;
using Orchard.Tags.Models;
namespace Orchard.Tags.Services {
@@ -18,7 +17,6 @@ namespace Orchard.Tags.Services {
private readonly IContentManager _contentManager;
private readonly ICacheManager _cacheManager;
private readonly ISignals _signals;
private readonly IMembershipService _membershipService;
internal static readonly string TagCloudTagsChanged = "Orchard.Tags.TagCloud.TagsChanged";
public TagCloudService(
@@ -26,33 +24,33 @@ namespace Orchard.Tags.Services {
IRepository<AutoroutePartRecord> autorouteRepository,
IContentManager contentManager,
ICacheManager cacheManager,
ISignals signals,
IMembershipService membershipService) {
ISignals signals) {
_contentTagRepository = contentTagRepository;
_autorouteRepository = autorouteRepository;
_contentManager = contentManager;
_cacheManager = cacheManager;
_signals = signals;
_membershipService = membershipService;
}
public IEnumerable<TagCount> GetPopularTags(int buckets, string slug, string username = null) {
var cacheKey = "Orchard.Tags.TagCloud."
+ (!string.IsNullOrWhiteSpace(slug) ? "slug-" + slug : string.Empty)
+ (!string.IsNullOrWhiteSpace(username) ? "username-" + username : string.Empty)
+ '.' + buckets;
public IEnumerable<TagCount> GetPopularTags(int buckets, string slug) {
var cacheKey = "Orchard.Tags.TagCloud." + (slug ?? "") + '.' + buckets;
return _cacheManager.Get(cacheKey,
ctx => {
ctx.Monitor(_signals.When(TagCloudTagsChanged));
var tagQuery = _contentManager
.Query<TagsPart, TagsPartRecord>(VersionOptions.Published)
.Join<CommonPartRecord>();
if (!string.IsNullOrWhiteSpace(slug)) {
if (slug == "/"){
IEnumerable<TagCount> tagCounts;
if (string.IsNullOrWhiteSpace(slug)) {
tagCounts = (from tc in _contentTagRepository.Table
where tc.TagsPartRecord.ContentItemRecord.Versions.Any(v => v.Published)
group tc by tc.TagRecord.TagName
into g
select new TagCount {
TagName = g.Key,
Count = g.Count()
}).ToList();
}
else {
if (slug == "/") {
slug = "";
}
@@ -62,24 +60,26 @@ namespace Orchard.Tags.Services {
.ToList() // don't try to optimize with slicing as there should be only one result
.FirstOrDefault();
tagQuery = tagQuery.Where(record => record.Container.Id == containerId);
}
if (containerId == 0) {
return new List<TagCount>();
}
if (!string.IsNullOrWhiteSpace(username)) {
var user = _membershipService.GetUser(username);
tagQuery = tagQuery.Where(record => record.OwnerId == user.Id);
}
tagCounts = _contentManager
.Query<TagsPart, TagsPartRecord>(VersionOptions.Published)
.Join<CommonPartRecord>()
.Where(t => t.Container.Id == containerId)
.List()
.SelectMany(t => t.CurrentTags)
.GroupBy(t => t)
.Select(g => new TagCount {
TagName = g.Key,
Count = g.Count()
})
.ToList();
var tagCounts = tagQuery.List()
.SelectMany(t => t.CurrentTags)
.GroupBy(t => t)
.Select(g => new TagCount {
TagName = g.Key,
Count = g.Count()
}).ToList();
if (!tagCounts.Any()) {
return new List<TagCount>();
if (!tagCounts.Any()) {
return new List<TagCount>();
}
}
// initialize centroids with a linear distribution

View File

@@ -16,13 +16,5 @@
@Html.ValidationMessageFor(model => model.Slug)
<span class="hint">@T("Enter the slug of the container for which you want the tag cloud, e.g. blog, /, or leave empty for the cloud to be scoped to the whole site. ")</span>
</div>
<div class="group">
@Html.LabelFor(model => model.Username)
@Html.TextBoxFor(model => model.Username, new { @class = "text medium tokenized" })
@Html.ValidationMessageFor(model => model.Username)
<span class="hint">@T("The Username owning content whose tags that will get rendered in the cloud.")</span>
</div>
</fieldset>
@Display.TokenHint()
</fieldset>

View File

@@ -221,7 +221,16 @@
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<SaveServerSettingsInUserFile>True</SaveServerSettingsInUserFile>
<UseIIS>False</UseIIS>
<AutoAssignPort>False</AutoAssignPort>
<DevelopmentServerPort>30321</DevelopmentServerPort>
<DevelopmentServerVPath>/OrchardLocal</DevelopmentServerVPath>
<IISUrl>http://localhost:30322/OrchardLocal</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>