Skip to content
This repository has been archived by the owner on Feb 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #69 from umco/develop
Browse files Browse the repository at this point in the history
Release 0.4.0
  • Loading branch information
leekelleher authored Mar 18, 2017
2 parents fb22f57 + 86f6bd7 commit 2ddb60e
Show file tree
Hide file tree
Showing 19 changed files with 335 additions and 156 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Doc Type Grid Editor

[![Build status](https://img.shields.io/appveyor/ci/leekelleher/umbraco-doc-type-grid-editor.svg)](https://ci.appveyor.com/project/leekelleher/umbraco-doc-type-grid-editor)
[![Build status](https://img.shields.io/appveyor/ci/UMCO/umbraco-doc-type-grid-editor.svg)](https://ci.appveyor.com/project/UMCO/umbraco-doc-type-grid-editor)
[![NuGet release](https://img.shields.io/nuget/v/Our.Umbraco.DocTypeGridEditor.svg)](https://www.nuget.org/packages/Our.Umbraco.DocTypeGridEditor)
[![Our Umbraco project page](https://img.shields.io/badge/our-umbraco-orange.svg)](https://our.umbraco.org/projects/backoffice-extensions/doc-type-grid-editor)
[![Chat on Gitter](https://img.shields.io/badge/gitter-join_chat-green.svg)](https://gitter.im/leekelleher/umbraco-doc-type-grid-editor)
Expand All @@ -13,7 +13,7 @@ A grid editor for Umbraco 7 that allows you to use Doc Types as a blue print for

### Installation

> *Note:* Doc Type Grid Editor has been developed against **Umbraco v7.2.0** and will support that version and above.
> *Note:* Doc Type Grid Editor has been developed against **Umbraco v7.3.0** and will support that version and above.
Doc Type Grid Editor can be installed from either Our Umbraco package repository, or build manually from the source-code.

Expand Down Expand Up @@ -55,12 +55,12 @@ A PDF download is also available: [Doc Type Grid Editor - Developers Guide v1.0.

## Known Issues

Please be aware that not all property-editors will work within Doc Type Grid Editor. The following property-editors are known to have compatibility issues:
Please be aware that not all property-editors will work within Doc Type Grid Editor. The following Umbraco core property-editors are known to have compatibility issues:

* Upload (default Umbraco core)
* Image Cropper (default Umbraco core)
* Macro Container (default Umbraco core)
* Tags (default Umbraco core)
* Image Cropper
* Macro Container
* Tags
* Upload

---

Expand Down
8 changes: 4 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# version format
version: 0.3.0.{build}
version: 0.4.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 All @@ -22,15 +22,15 @@ deploy:
server: https://www.myget.org/F/umbraco-packages/
symbol_server: https://nuget.symbolsource.org/MyGet/umbraco-packages
api_key:
secure: Q1/4K8VSwr7BjwmKDTef8y5lOc7S+jK9ELuWy67y6OVRpjxmnF9M3Gfs1kT+ir8x
secure: 36/Ax5O+e6wENlhoTwgvoEBZV3FG4XjF429SNTej2qsGTAL+cdfA1kT/tm1St8vx
artifact: /.*\.nupkg/
on:
branch: develop

# GitHub Deployment for releases
- provider: GitHub
auth_token:
secure: pEozEGTqJutQwOidJU6BTB+Ix0NV4vrUnomhfeqheVz4RNwfxjEYLoqR4XabhlPz
secure: yDxrRTveSScJA35MQTOaLYVjoPKFKl2bHBkG+JMZjiN0r7AfuUCxVU3CgW8Imu4h
artifact: /.*\.zip/ # upload all Zip packages to release assets
draft: false
prerelease: false
Expand All @@ -42,7 +42,7 @@ deploy:
- provider: NuGet
server:
api_key:
secure: CGzDKxw4QI/z2VSe9ceiYlIabqGXHolgBgVNWWZjVAJ2V5WLF11IFdlp9r5Qp+Sw
secure: eSLiOXbGVrxSG+X7PV6qTTUZ5VzS9EFj5+EufaWPfd+QXkF6gc8rZ4mGoHIVp/fL
artifact: /.*\.nupkg/
on:
branch: master
Expand Down
8 changes: 4 additions & 4 deletions build/package.proj
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
<PropertyGroup>
<ProjectName>Our.Umbraco.DocTypeGridEditor</ProjectName>
<PackageName>Doc Type Grid Editor</PackageName>
<MinUmbracoVersion>7.2.0</MinUmbracoVersion>
<Readme>Doc Type Grid Editor is an advanced grid editor for the new Umbraco v7.2 Grid</Readme>
<MinUmbracoVersion>7.3.0</MinUmbracoVersion>
<Readme>Doc Type Grid Editor is an advanced grid editor for Umbraco 7</Readme>
<AuthorName>Matt Brailsford, Lee Kelleher</AuthorName>
<AuthorUrl>https://github.com/leekelleher/umbraco-doc-type-grid-editor/graphs/contributors</AuthorUrl>
<AuthorUrl>https://github.com/umco/umbraco-doc-type-grid-editor/graphs/contributors</AuthorUrl>
<PackageLicenseName>MIT license</PackageLicenseName>
<PackageLicenseUrl>http://opensource.org/licenses/MIT</PackageLicenseUrl>
<ProjectUrl>https://github.com/leekelleher/umbraco-doc-type-grid-editor</ProjectUrl>
<ProjectUrl>https://github.com/umco/umbraco-doc-type-grid-editor</ProjectUrl>
</PropertyGroup>

<!-- NUGET ONLY PROPERTIES -->
Expand Down
3 changes: 1 addition & 2 deletions src/Our.Umbraco.DocTypeGridEditor.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Expand Down
27 changes: 23 additions & 4 deletions src/Our.Umbraco.DocTypeGridEditor/Bootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,40 @@ protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplic
{
GlobalFilters.Filters.Add(new DocTypeGridEditorPreviewAttribute());

DefaultDocTypeGridEditorSurfaceControllerResolver.Current = new DefaultDocTypeGridEditorSurfaceControllerResolver();
if (!DefaultDocTypeGridEditorSurfaceControllerResolver.HasCurrent)
{
DefaultDocTypeGridEditorSurfaceControllerResolver.Current = new DefaultDocTypeGridEditorSurfaceControllerResolver();
}
}

protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
DataTypeService.Saved += ExpireCache;
DataTypeService.Saved += ExpireDataTypeCache;
ContentTypeService.SavedContentType += ExpireContentTypeCache;
}

private void ExpireCache(IDataTypeService sender, SaveEventArgs<IDataTypeDefinition> e)
private void ExpireDataTypeCache(IDataTypeService sender, SaveEventArgs<IDataTypeDefinition> e)
{
foreach (var dataType in e.SavedEntities)
{
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(
string.Concat("Our.Umbraco.DocTypeGridEditor.Web.Extensions.ContentTypeServiceExtensions.GetAliasById_", dataType.Key));

ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(
string.Concat("Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetPreValuesCollectionByDataTypeId_", dataType.Id));
}
}

private void ExpireContentTypeCache(IContentTypeService sender, SaveEventArgs<IContentType> e)
{
foreach (var contentType in e.SavedEntities)
{
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(
string.Concat("Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetContentTypesByAlias_", contentType.Alias));

ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(
string.Concat("Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetContentTypeAliasByGuid_", contentType.Key));
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Web.Mvc;
using Umbraco.Core.Logging;

namespace Our.Umbraco.DocTypeGridEditor.Extensions
{
Expand All @@ -17,8 +16,6 @@ public static bool ViewExists(
if (result.View != null)
return true;

LogHelper.Info<ViewEngineCollection>("[DocTypeGridEditor] No view file found with the name '{0}'", () => viewName);

return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ public static IPublishedContent ConvertValueToContent(string id, string contentT
if (string.IsNullOrWhiteSpace(contentTypeAlias))
return null;

if (dataJson == null)
return null;

if (UmbracoContext.Current == null)
return ConvertValue(id, contentTypeAlias, dataJson);

return (IPublishedContent)ApplicationContext.Current.ApplicationCache.RequestCache.GetCacheItem(
string.Concat("DocTypeGridEditorHelper.ConvertValueToContent_", id, "_", contentTypeAlias),
string.Concat("Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.ConvertValueToContent_", id, "_", contentTypeAlias),
() =>
{
return ConvertValue(id, contentTypeAlias, dataJson);
Expand All @@ -41,22 +44,17 @@ public static IPublishedContent ConvertValueToContent(string id, string contentT

private static IPublishedContent ConvertValue(string id, string contentTypeAlias, string dataJson)
{
using (var timer = DisposableTimer.DebugDuration<DocTypeGridEditorHelper>(string.Format("ConvertValueToContent ({0}, {1})", id, contentTypeAlias)))
using (var timer = ApplicationContext.Current.ProfilingLogger.DebugDuration<DocTypeGridEditorHelper>(string.Format("ConvertValue ({0}, {1})", id, contentTypeAlias)))
{
Guid contentTypeGuid;
if (Guid.TryParse(contentTypeAlias, out contentTypeGuid))
contentTypeAlias = Services.ContentTypeService.GetAliasByGuid(contentTypeGuid);

var publishedContentType = PublishedContentType.Get(PublishedItemType.Content, contentTypeAlias);
var contentType = ApplicationContext.Current.Services.ContentTypeService.GetContentType(contentTypeAlias);
var contentTypes = GetContentTypesByAlias(contentTypeAlias);
var properties = new List<IPublishedProperty>();

// Convert all the properties
var data = JsonConvert.DeserializeObject(dataJson);
var propValues = ((JObject)data).ToObject<Dictionary<string, object>>();
foreach (var jProp in propValues)
{
var propType = publishedContentType.GetPropertyType(jProp.Key);
var propType = contentTypes.PublishedContentType.GetPropertyType(jProp.Key);
if (propType != null)
{
/* Because we never store the value in the database, we never run the property editors
Expand All @@ -65,8 +63,7 @@ private static IPublishedContent ConvertValue(string id, string contentTypeAlias
* we go on to convert the value for the view.
*/
var propEditor = PropertyEditorResolver.Current.GetByAlias(propType.PropertyEditorAlias);
var propPreValues = Services.DataTypeService.GetPreValuesCollectionByDataTypeId(
propType.DataTypeId);
var propPreValues = GetPreValuesCollectionByDataTypeId(propType.DataTypeId);

var contentPropData = new ContentPropertyData(
jProp.Value,
Expand All @@ -78,7 +75,7 @@ private static IPublishedContent ConvertValue(string id, string contentTypeAlias
/* Now that we have the DB stored value, we actually need to then convert it into it's
* XML serialized state as expected by the published property by calling ConvertDbToString
*/
var propType2 = contentType.CompositionPropertyTypes.Single(x => x.Alias.InvariantEquals(propType.PropertyTypeAlias));
var propType2 = contentTypes.ContentType.CompositionPropertyTypes.Single(x => x.Alias.InvariantEquals(propType.PropertyTypeAlias));

Property prop2 = null;
try
Expand All @@ -91,15 +88,14 @@ private static IPublishedContent ConvertValue(string id, string contentTypeAlias
*/
prop2 = new Property(propType2, newValue);
}
catch(Exception ex)
catch (Exception ex)
{
LogHelper.Error<DocTypeGridEditorHelper>("[DocTypeGridEditor] Error creating Property object.", ex);
}

if (prop2 != null)
{
var newValue2 = propEditor.ValueEditor.ConvertDbToString(prop2, propType2,
ApplicationContext.Current.Services.DataTypeService);
var newValue2 = propEditor.ValueEditor.ConvertDbToString(prop2, propType2, Services.DataTypeService);

properties.Add(new DetachedPublishedProperty(propType, newValue2));
}
Expand All @@ -118,11 +114,46 @@ private static IPublishedContent ConvertValue(string id, string contentTypeAlias
var containerNode = pcr != null && pcr.HasPublishedContent ? pcr.PublishedContent : null;

return new DetachedPublishedContent(nameObj != null ? nameObj.ToString() : null,
publishedContentType,
contentTypes.PublishedContentType,
properties.ToArray(),
containerNode);
}

}

private static PreValueCollection GetPreValuesCollectionByDataTypeId(int dataTypeId)
{
return (PreValueCollection)ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem(
string.Concat("Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetPreValuesCollectionByDataTypeId_", dataTypeId),
() => Services.DataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeId));
}

private static ContentTypeContainer GetContentTypesByAlias(string contentTypeAlias)
{
Guid contentTypeGuid;
if (Guid.TryParse(contentTypeAlias, out contentTypeGuid))
contentTypeAlias = GetContentTypeAliasByGuid(contentTypeGuid);

return (ContentTypeContainer)ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem(
string.Concat("Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetContentTypesByAlias_", contentTypeAlias),
() => new ContentTypeContainer
{
PublishedContentType = PublishedContentType.Get(PublishedItemType.Content, contentTypeAlias),
ContentType = Services.ContentTypeService.GetContentType(contentTypeAlias)
});
}

private static string GetContentTypeAliasByGuid(Guid contentTypeGuid)
{
return (string)ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem(
string.Concat("Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetContentTypeAliasByGuid_", contentTypeGuid),
() => Services.ContentTypeService.GetAliasByGuid(contentTypeGuid));
}
}

public class ContentTypeContainer
{
public PublishedContentType PublishedContentType { get; set; }
public IContentType ContentType { get; set; }
}
}
Loading

0 comments on commit 2ddb60e

Please sign in to comment.