Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #47 from umco/develop
Browse files Browse the repository at this point in the history
Preparing v2.0.3 release
  • Loading branch information
leekelleher authored Feb 6, 2019
2 parents ccc168f + 40cb701 commit 24202b0
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 170 deletions.
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
image: Visual Studio 2017

# version format
version: 2.0.2.{build}
version: 2.0.3.{build}

# UMBRACO_PACKAGE_PRERELEASE_SUFFIX if a rtm release build this should be blank, otherwise if empty will default to alpha
# example UMBRACO_PACKAGE_PRERELEASE_SUFFIX=beta
Expand Down Expand Up @@ -47,7 +47,7 @@ deploy:
- provider: NuGet
server:
api_key:
secure: 0+oAleUTnr9UuJrhLW5rphRR+QGz00XX1Ui3k5kwyr2kUdEamiQ3F+gW0q8MJbDT
secure: vEophXSqus5F60LRBY4/j1l6K/S5+n3/yYpiID3O7JJW1gyj+0q0enuHhN3tgdhl
artifact: /.*\.nupkg/
on:
branch: master
Expand Down
4 changes: 2 additions & 2 deletions src/Our.Umbraco.InnerContent/Bootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplica
return;

// NOTE: The properties for the JSON payload are available here: (Currently there isn't a public API to deserialize the payload)
// https://github.com/umbraco/Umbraco-CMS/blob/release-7.4.0/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs#L64-L68
// https://github.com/umbraco/Umbraco-CMS/blob/release-7.7.0/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs#L66-L70
var payload = JsonConvert.DeserializeAnonymousType((string)e.MessageObject, new[] { new { Id = default(int) } });
if (payload == null)
return;
Expand All @@ -34,7 +34,7 @@ protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplica
return;

// NOTE: The properties for the JSON payload are available here: (Currently there isn't a public API to deserialize the payload)
// https://github.com/umbraco/Umbraco-CMS/blob/release-7.4.0/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs#L93-L109
// https://github.com/umbraco/Umbraco-CMS/blob/release-7.7.0/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs#L91-L109
var payload = JsonConvert.DeserializeAnonymousType((string)e.MessageObject, new[] { new { Id = default(int), AliasChanged = default(bool) } });
if (payload == null)
return;
Expand Down
2 changes: 2 additions & 0 deletions src/Our.Umbraco.InnerContent/InnerContentConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public static class InnerContentConstants
internal const string ContentTypesPreValueKey = "contentTypes";

internal const string HideLabelPreValueKey = "hideLabel";

internal const string EnableFilterPreValueKey = "enableFilter";
}
}
145 changes: 9 additions & 136 deletions src/Our.Umbraco.InnerContent/Models/DetachedPublishedContent.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Models;
using UmbracoWebModels = Umbraco.Web.Models;

namespace Our.Umbraco.InnerContent.Models
{
public class DetachedPublishedContent : PublishedContentBase, IPublishedContentWithKey
// NOTE: Inherits from https://github.com/umbraco/Umbraco-CMS/blob/release-7.7.0/src/Umbraco.Web/Models/DetachedPublishedContent.cs
// The main differences are that this one can set the Level, Children and Parent, (and includes a recursive `GetProperty` method).
public class DetachedPublishedContent : UmbracoWebModels.DetachedPublishedContent
{
private readonly Guid _key;
private readonly string _name;
private readonly PublishedContentType _contentType;
private readonly IEnumerable<IPublishedProperty> _properties;
private readonly int _sortOrder;
private readonly bool _isPreviewing;
private readonly IPublishedContent _containerNode;

private readonly IPublishedContent _parentNode;
private IEnumerable<IPublishedContent> _children;
private int _level;
private readonly int _level;

public DetachedPublishedContent(Guid key,
string name,
Expand All @@ -31,15 +24,9 @@ public DetachedPublishedContent(Guid key,
int sortOrder = 0,
int level = 0,
bool isPreviewing = false)
: base(key, name, contentType, properties, containerNode, sortOrder, isPreviewing)
{
_key = key;
_name = name;
_contentType = contentType;
_properties = properties;
_sortOrder = sortOrder;
_level = level;
_isPreviewing = isPreviewing;
_containerNode = containerNode;
_parentNode = parentNode;
_children = Enumerable.Empty<IPublishedContent>();
}
Expand All @@ -49,56 +36,6 @@ public void SetChildren(IEnumerable<IPublishedContent> children)
_children = children;
}

public Guid Key
{
get { return _key; }
}

public override int Id
{
get { return 0; }
}

public override string Name
{
get { return _name; }
}

public override bool IsDraft
{
get { return _isPreviewing; }
}

public override PublishedItemType ItemType
{
get { return PublishedItemType.Content; }
}

public override PublishedContentType ContentType
{
get { return _contentType; }
}

public override string DocumentTypeAlias
{
get { return _contentType.Alias; }
}

public override int DocumentTypeId
{
get { return _contentType.Id; }
}

public override ICollection<IPublishedProperty> Properties
{
get { return _properties.ToArray(); }
}

public override IPublishedProperty GetProperty(string alias)
{
return _properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias));
}

public override IPublishedProperty GetProperty(string alias, bool recurse)
{
var prop = GetProperty(alias);
Expand All @@ -109,74 +46,10 @@ public override IPublishedProperty GetProperty(string alias, bool recurse)
return prop;
}

public override IPublishedContent Parent
{
get { return _parentNode; }
}

public override IEnumerable<IPublishedContent> Children
{
get { return _children; }
}

public override int TemplateId
{
get { return 0; }
}

public override int SortOrder
{
get { return _sortOrder; }
}

public override string UrlName
{
get { return null; }
}

public override string WriterName
{
get { return _containerNode != null ? _containerNode.WriterName : null; }
}
public override IPublishedContent Parent => _parentNode;

public override string CreatorName
{
get { return _containerNode != null ? _containerNode.CreatorName : null; }
}

public override int WriterId
{
get { return _containerNode != null ? _containerNode.WriterId : 0; }
}
public override IEnumerable<IPublishedContent> Children => _children;

public override int CreatorId
{
get { return _containerNode != null ? _containerNode.CreatorId : 0; }
}

public override string Path
{
get { return null; }
}

public override DateTime CreateDate
{
get { return _containerNode != null ? _containerNode.CreateDate : DateTime.MinValue; }
}

public override DateTime UpdateDate
{
get { return _containerNode != null ? _containerNode.UpdateDate : DateTime.MinValue; }
}

public override Guid Version
{
get { return _containerNode != null ? _containerNode.Version : Guid.Empty; }
}

public override int Level
{
get { return _level; }
}
public override int Level => _level;
}
}
16 changes: 6 additions & 10 deletions src/Our.Umbraco.InnerContent/Models/DetachedPublishedProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Our.Umbraco.InnerContent.Models
{
// NOTE: If Umbraco's `DetachedPublishedProperty` isn't currently publicly available.
// https://github.com/umbraco/Umbraco-CMS/blob/release-7.7.0/src/Umbraco.Web/Models/DetachedPublishedProperty.cs#L7
public class DetachedPublishedProperty : IPublishedProperty
{
private readonly PublishedPropertyType _propertyType;
Expand All @@ -29,23 +31,17 @@ public DetachedPublishedProperty(PublishedPropertyType propertyType, object valu
_xpathValue = new Lazy<object>(() => _propertyType.ConvertSourceToXPath(_sourceValue.Value, _isPreview));
}

public string PropertyTypeAlias
{
get
{
return _propertyType.PropertyTypeAlias;
}
}
public string PropertyTypeAlias => _propertyType.PropertyTypeAlias;

public bool HasValue
{
get { return DataValue != null && DataValue.ToString().Trim().Length > 0; }
}

public object DataValue { get { return _rawValue; } }
public object DataValue => _rawValue;

public object Value { get { return _objectValue.Value; } }
public object Value => _objectValue.Value;

public object XPathValue { get { return _xpathValue.Value; } }
public object XPathValue => _xpathValue.Value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@ public class SimpleInnerContentPreValueEditor : InnerContentPreValueEditor
public SimpleInnerContentPreValueEditor()
: base()
{
// This ensures that the "contentTypes" field is always at the top of the prevalue fields.
Fields.Insert(0, new PreValueField
// This ensures that the "contentTypes" and "enableFilter" fields are always at the top of the prevalue fields.
Fields.InsertRange(0, new[]
{
Key = InnerContentConstants.ContentTypesPreValueKey,
Name = "Content Types",
View = IOHelper.ResolveUrl("~/App_Plugins/InnerContent/views/innercontent.doctypepicker.html"),
Description = "Select the content types to use as the data blueprint."
new PreValueField
{
Key = InnerContentConstants.ContentTypesPreValueKey,
Name = "Content Types",
View = IOHelper.ResolveUrl("~/App_Plugins/InnerContent/views/innercontent.doctypepicker.html"),
Description = "Select the content types to use as the data blueprint."
},
new PreValueField
{
Key = InnerContentConstants.EnableFilterPreValueKey,
Name = "Enable Filter?",
View = "boolean",
Description = "Select to enable a filter bar at the top of the Content Type selection."
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public SimpleInnerContentPropertyEditor()
{
this.defaultPreValues = new Dictionary<string, object>
{
{ InnerContentConstants.ContentTypesPreValueKey, string.Empty }
{ InnerContentConstants.ContentTypesPreValueKey, string.Empty },
{ InnerContentConstants.EnableFilterPreValueKey, false }
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Newtonsoft.Json.Linq;
using Our.Umbraco.InnerContent.Helpers;
using Our.Umbraco.InnerContent.Web.WebApi.Filters;
using Umbraco.Core;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Services;
using Umbraco.Web.Editors;
using Umbraco.Web.Models.ContentEditing;
Expand All @@ -25,7 +27,7 @@ public IEnumerable<object> GetAllContentTypes()
{
id = x.Id,
guid = x.Key,
name = x.Name,
name = UmbracoDictionaryTranslate(x.Name),
alias = x.Alias,
icon = string.IsNullOrWhiteSpace(x.Icon) || x.Icon == ".sprTreeFolder" ? "icon-folder" : x.Icon,
tabs = x.CompositionPropertyGroups.Select(y => y.Name).Distinct()
Expand All @@ -41,11 +43,7 @@ public IEnumerable<object> GetContentTypesByGuid([ModelBinder] Guid[] guids)
// NOTE: Using an anonymous class, as the `ContentTypeBasic` type is heavier than what we need (for our requirements)
return contentTypes.Select(ct => new
{
// TODO: localize the name and description (in case of dictionary items)
// Umbraco core uses `localizedTextService.UmbracoDictionaryTranslate`, but this is currently marked as internal.
// https://github.com/umbraco/Umbraco-CMS/blob/release-7.7.0/src/Umbraco.Core/Services/LocalizedTextServiceExtensions.cs#L76

name = ct.Name,
name = UmbracoDictionaryTranslate(ct.Name),
description = ct.Description,
guid = ct.Key,
key = ct.Key,
Expand All @@ -64,7 +62,7 @@ public IEnumerable<object> GetContentTypesByAlias([ModelBinder] string[] aliases
{
id = x.Id,
guid = x.Key,
name = x.Name,
name = UmbracoDictionaryTranslate(x.Name),
alias = x.Alias,
icon = string.IsNullOrWhiteSpace(x.Icon) || x.Icon == ".sprTreeFolder" ? "icon-folder" : x.Icon,
tabs = x.CompositionPropertyGroups.Select(y => y.Name).Distinct()
Expand Down Expand Up @@ -108,5 +106,31 @@ public SimpleNotificationModel CreateBlueprintFromContent([FromBody] JObject ite
Services.TextService.Localize("blueprints/createdBlueprintMessage", new[] { blueprint.Name }),
global::Umbraco.Web.UI.SpeechBubbleIcon.Success));
}

// Umbraco core's `localizedTextService.UmbracoDictionaryTranslate` is internal. Until it's made public, we have to roll our own.
// https://github.com/umbraco/Umbraco-CMS/blob/release-7.7.0/src/Umbraco.Core/Services/LocalizedTextServiceExtensions.cs#L76
private string UmbracoDictionaryTranslate(string text)
{
if (text == null)
{
return null;
}

if (text.StartsWith("#") == false)
{
return text;
}

text = text.Substring(1);

if (_cultureDictionary == null)
{
_cultureDictionary = CultureDictionaryFactoryResolver.Current.Factory.CreateDictionary();
}

return _cultureDictionary[text].IfNullOrWhiteSpace(text);
}

private static ICultureDictionary _cultureDictionary;
}
}
Loading

0 comments on commit 24202b0

Please sign in to comment.