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 #34 from umco/develop
Browse files Browse the repository at this point in the history
Preparing v2.0.0 release
  • Loading branch information
leekelleher authored Jul 20, 2018
2 parents 08b473e + 2af2068 commit e6cae23
Show file tree
Hide file tree
Showing 18 changed files with 484 additions and 312 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
image: Visual Studio 2017

# version format
version: 1.1.2.{build}
version: 2.0.0.{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
37 changes: 37 additions & 0 deletions src/Our.Umbraco.InnerContent/Helpers/InnerContentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,42 @@ internal static PublishedContentType GetPublishedContentTypeFromItem(JObject ite

return PublishedContentType.Get(PublishedItemType.Content, contentTypeAlias);
}

internal static IContent ConvertInnerContentToBlueprint(JObject item, int userId = 0)
{
var contentType = GetContentTypeFromItem(item);

// creates a fast lookup of the property types
var propertyTypes = contentType.PropertyTypes.ToDictionary(x => x.Alias, x => x, StringComparer.InvariantCultureIgnoreCase);

var propValues = item.ToObject<Dictionary<string, object>>();
var properties = new List<Property>();

foreach (var jProp in propValues)
{
if (propertyTypes.ContainsKey(jProp.Key) == false)
continue;

var propType = propertyTypes[jProp.Key];
if (propType != null)
{
// TODO: Check if we need to call `ConvertEditorToDb`?
properties.Add(new Property(propType, jProp.Value));
}
}

// Manually parse out the special properties
propValues.TryGetValue("name", out object name);
propValues.TryGetValue("key", out object key);

return new Content(name?.ToString(), -1, contentType, new PropertyCollection(properties))
{
Key = key == null ? Guid.Empty : Guid.Parse(key.ToString()),
ParentId = -1,
Path = "-1",
CreatorId = userId,
WriterId = userId
};
}
}
}
37 changes: 12 additions & 25 deletions src/Our.Umbraco.InnerContent/Our.Umbraco.InnerContent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ClientDependency.Core, Version=1.8.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ClientDependency.1.8.4\lib\net45\ClientDependency.Core.dll</HintPath>
<Reference Include="interfaces, Version=1.0.6470.38233, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.7.0\lib\net45\interfaces.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="interfaces">
<HintPath>..\packages\UmbracoCms.Core.7.4.0\lib\interfaces.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="log4net, Version=1.2.11.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.4.0\lib\log4net.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MiniProfiler, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b44f9351044011a3, processorArchitecture=MSIL">
<HintPath>..\packages\MiniProfiler.2.1.0\lib\net40\MiniProfiler.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Semver, Version=1.1.2.0, Culture=neutral, processorArchitecture=MSIL">
Expand All @@ -68,18 +56,18 @@
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Xml" />
<Reference Include="umbraco, Version=1.0.5885.31230, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.4.0\lib\umbraco.dll</HintPath>
<Reference Include="umbraco, Version=1.0.6470.38242, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.7.0\lib\net45\umbraco.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Umbraco.Core, Version=1.0.5885.31226, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.4.0\lib\Umbraco.Core.dll</HintPath>
<Reference Include="Umbraco.Core, Version=1.0.6470.38234, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.7.0\lib\net45\Umbraco.Core.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Bootstrap.cs" />
<Compile Include="Converters\InnerContentValueConverter.cs" />
<Compile Include="ValueConverters\InnerContentValueConverter.cs" />
<Compile Include="Helpers\ContentTypeCacheHelper.cs" />
<Compile Include="Helpers\InnerContentHelper.cs" />
<Compile Include="InnerContentConstants.cs" />
Expand All @@ -88,7 +76,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\VersionInfo.cs" />
<Compile Include="PropertyEditors\InnerContentPreValueEditor.cs" />
<Compile Include="PropertyEditors\InnerContentPropertyValueEditorWrapper.cs" />
<Compile Include="PropertyEditors\InnerContentPropertyValueEditor.cs" />
<Compile Include="PropertyEditors\SimpleInnerContentPropertyEditor.cs" />
<Compile Include="PropertyEditors\SimpleInnerContentPreValueEditor.cs" />
<Compile Include="PropertyEditors\SimpleInnerContentPropertyValueEditor.cs" />
Expand All @@ -102,12 +90,11 @@
</ItemGroup>
<ItemGroup>
<Content Include="Web\UI\App_Plugins\InnerContent\css\innercontent.css" />
<Content Include="Web\UI\App_Plugins\InnerContent\js\innercontent.controllers.js" />
<Content Include="Web\UI\App_Plugins\InnerContent\js\innercontent.resources.js" />
<Content Include="Web\UI\App_Plugins\InnerContent\js\innercontent.js" />
<Content Include="Web\UI\App_Plugins\InnerContent\views\innercontent.create.html" />
<Content Include="Web\UI\App_Plugins\InnerContent\views\innercontent.dialog.html" />
<Content Include="Web\UI\App_Plugins\InnerContent\views\innercontent.unsavedchanges.html" />
<Content Include="Web\UI\App_Plugins\InnerContent\views\innercontent.overlay.html" />
<Content Include="Web\UI\App_Plugins\InnerContent\views\innercontent.doctypetabpicker.html" />
<Content Include="Web\UI\App_Plugins\InnerContent\views\innercontent.doctypepicker.html" />
</ItemGroup>
<ItemGroup />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,19 @@

namespace Our.Umbraco.InnerContent.PropertyEditors
{
public abstract class InnerContentPropertyValueEditorWrapper : PropertyValueEditorWrapper
public abstract class InnerContentPropertyValueEditor : PropertyValueEditorWrapper
{
protected InnerContentPropertyValueEditorWrapper(PropertyValueEditor wrapped)
protected InnerContentPropertyValueEditor(PropertyValueEditor wrapped)
: base(wrapped)
{ }

public override void ConfigureForDisplay(PreValueCollection preValues)
{
base.ConfigureForDisplay(preValues);

var asDictionary = preValues.PreValuesAsDictionary;
if (asDictionary.ContainsKey("hideLabel"))
if (preValues.PreValuesAsDictionary.ContainsKey("hideLabel"))
{
var boolAttempt = asDictionary["hideLabel"].Value.TryConvertTo<bool>();
if (boolAttempt.Success)
{
HideLabel = boolAttempt.Result;
}
HideLabel = preValues.PreValuesAsDictionary["hideLabel"].Value == "1";
}
}

Expand Down Expand Up @@ -76,7 +71,7 @@ protected void ConvertInnerContentDbToString(JObject item, IDataTypeService data
var propEditor = PropertyEditorResolver.Current.GetByAlias(propType.PropertyEditorAlias);

// Get the editor to do it's conversion, and store it back
item[propKey] = propEditor.ValueEditor.ConvertDbToString(prop, propType, dataTypeService);
item[propKey] = propEditor?.ValueEditor?.ConvertDbToString(prop, propType, dataTypeService);
}
catch (InvalidOperationException)
{
Expand Down Expand Up @@ -122,7 +117,7 @@ protected void ConvertInnerContentDbToEditor(JObject item, IDataTypeService data

foreach (var propKey in propValueKeys)
{
var propType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == propKey);
var propType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias.InvariantEquals(propKey));
if (propType == null)
{
if (IsSystemPropertyKey(propKey) == false)
Expand All @@ -142,15 +137,15 @@ protected void ConvertInnerContentDbToEditor(JObject item, IDataTypeService data
var propEditor = PropertyEditorResolver.Current.GetByAlias(propType.PropertyEditorAlias);

// Get the editor to do it's conversion
var newValue = propEditor.ValueEditor.ConvertDbToEditor(prop, propType, dataTypeService);
var newValue = propEditor?.ValueEditor?.ConvertDbToEditor(prop, propType, dataTypeService);

// Store the value back
item[propKey] = (newValue == null) ? null : JToken.FromObject(newValue);
}
catch (InvalidOperationException)
{
// https://github.com/umco/umbraco-nested-content/issues/111
// Catch any invalid cast operations as likely means courier failed due to missing
// Catch any invalid cast operations as likely means Courier failed due to missing
// or trashed item so couldn't convert a guid back to an int

item[propKey] = null;
Expand All @@ -159,7 +154,7 @@ protected void ConvertInnerContentDbToEditor(JObject item, IDataTypeService data
}

// Process children
var childrenProp = item.Properties().FirstOrDefault(x => x.Name == "children");
var childrenProp = item.Properties().FirstOrDefault(x => x.Name.InvariantEquals("children"));
if (childrenProp != null)
{
ConvertInnerContentDbToEditor(childrenProp.Value.Value<JArray>(), dataTypeService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Our.Umbraco.InnerContent.PropertyEditors
{
public class SimpleInnerContentPropertyValueEditor : InnerContentPropertyValueEditorWrapper
public class SimpleInnerContentPropertyValueEditor : InnerContentPropertyValueEditor
{
public SimpleInnerContentPropertyValueEditor(PropertyValueEditor wrapped)
: base(wrapped)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;

namespace Our.Umbraco.InnerContent.Converters
namespace Our.Umbraco.InnerContent.ValueConverters
{
public abstract class InnerContentValueConverter : PropertyValueConverterBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
using System.Linq;
using System.Web.Http;
using System.Web.Http.ModelBinding;
using Newtonsoft.Json.Linq;
using Our.Umbraco.InnerContent.Helpers;
using Our.Umbraco.InnerContent.Web.WebApi.Filters;
using Umbraco.Core.Services;
using Umbraco.Web.Editors;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.Mvc;
Expand Down Expand Up @@ -32,18 +35,23 @@ public IEnumerable<object> GetAllContentTypes()
[HttpGet]
public IEnumerable<object> GetContentTypesByGuid([ModelBinder] Guid[] guids)
{
return Services.ContentTypeService.GetAllContentTypes()
.Where(x => guids == null || guids.Contains(x.Key))
.OrderBy(x => x.SortOrder)
.Select(x => new
{
id = x.Id,
guid = x.Key,
name = 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()
});
var contentTypes = Services.ContentTypeService.GetAllContentTypes(guids).OrderBy(x => x.SortOrder).ToList();
var blueprints = Services.ContentService.GetBlueprintsForContentTypes(contentTypes.Select(x => x.Id).ToArray()).ToArray();

// 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,
description = ct.Description,
guid = ct.Key,
key = ct.Key,
icon = string.IsNullOrWhiteSpace(ct.Icon) || ct.Icon == ".sprTreeFolder" ? "icon-document" : ct.Icon,
blueprints = blueprints.Where(bp => bp.ContentTypeId == ct.Id).ToDictionary(bp => bp.Id, bp => bp.Name)
});
}

[HttpGet]
Expand Down Expand Up @@ -80,5 +88,25 @@ public ContentItemDisplay GetContentTypeScaffoldByGuid(Guid guid)
var contentType = Services.ContentTypeService.GetContentType(guid);
return new ContentController().GetEmpty(contentType.Alias, -20);
}

[HttpGet]
[UseInternalActionFilter("Umbraco.Web.WebApi.Filters.OutgoingEditorModelEventAttribute", onActionExecuted: true)]
public ContentItemDisplay GetContentTypeScaffoldByBlueprintId(int blueprintId)
{
return new ContentController().GetEmpty(blueprintId, -20);
}

[HttpPost]
public SimpleNotificationModel CreateBlueprintFromContent([FromBody] JObject item, int userId = 0)
{
var blueprint = InnerContentHelper.ConvertInnerContentToBlueprint(item, userId);

Services.ContentService.SaveBlueprint(blueprint, userId);

return new SimpleNotificationModel(new Notification(
Services.TextService.Localize("blueprints/createdBlueprintHeading"),
Services.TextService.Localize("blueprints/createdBlueprintMessage", new[] { blueprint.Name }),
global::Umbraco.Web.UI.SpeechBubbleIcon.Success));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
/*
Inner Content - Doc Type Picker
*/
.inner-content__doctypepicker table input, .inner-content__doctypepicker table select {
/* Inner Content - Doc Type Picker */

.inner-content__doctypepicker table input,
.inner-content__doctypepicker table select {
width: 100%;
padding-right: 0;
}

.inner-content__doctypepicker table td.icon-navigation, .inner-content__doctypepicker i.inner-content__help-icon {
.inner-content__doctypepicker table td.icon-navigation,
.inner-content__doctypepicker i.inner-content__help-icon {
vertical-align: middle;
color: #CCC;
}

.inner-content__doctypepicker table td.icon-navigation:hover, .inner-content__doctypepicker i.inner-content__help-icon:hover {
.inner-content__doctypepicker table td.icon-navigation:hover,
.inner-content__doctypepicker i.inner-content__help-icon:hover {
color: #343434;
}

.inner-content__doctypepicker i.inner-content__help-icon {
margin-left: 10px;
}

.inner-content__doctypepicker table .td-min {
width: 1px;
}


/* Inner Content - Content Overlay Panel */

.inner-content-overlay > .umb-overlay-right > .umb-overlay__form > .umb-overlay-container {
padding: 0;
position: static;
Expand All @@ -31,3 +32,7 @@
.inner-content-dialog > .nav-tabs {
margin: -31px 0 0 20px;
}

.inner-content-pane {
margin: 30px 20px;
}
Loading

0 comments on commit e6cae23

Please sign in to comment.