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 #112 from umco/develop
Browse files Browse the repository at this point in the history
Preparing v0.6.0-beta release
  • Loading branch information
leekelleher authored Aug 3, 2018
2 parents e80d101 + 611c991 commit 5275b46
Show file tree
Hide file tree
Showing 27 changed files with 544 additions and 164 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ To clone it locally click the "Clone in Windows" button above or run the followi

For details on how to use the Doc Type Grid Editor package, please refer to our [Developers Guide](docs/developers-guide.md) documentation.

A PDF download is also available: [Doc Type Grid Editor - Developers Guide v1.0.pdf](docs/Doc-Type-Grid-Editor--Developers-Guide-v1.0.pdf)

---

## Known Issues
Expand Down Expand Up @@ -89,6 +87,7 @@ Have a question?
### Special thanks

* Thanks to [Jeavon Leopold](https://github.com/Jeavon) for being a rockstar and adding AppVeyor & NuGet support.
* Thanks to [Dave Woestenborghs](https://github.com/dawoe) for helping solve showstopper issues.


## License
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
image: Visual Studio 2017

# version format
version: 0.5.0.{build}
version: 0.6.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
init:
- set UMBRACO_PACKAGE_PRERELEASE_SUFFIX=
- set UMBRACO_PACKAGE_PRERELEASE_SUFFIX=beta

cache:
- src\packages -> **\packages.config # preserve "packages" directory in the root of build folder but will reset it if packages.config is modified
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 6 additions & 6 deletions docs/developers-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

1. [Introduction](#introduction)
2. [Getting Set Up](#getting-set-up)
* [System Requirements](#system-requirements)
a. [System Requirements](#system-requirements)
3. [Configuring The Doc Type Grid Editor](#configuring-the-doc-type-grid-editor)
4. [Hooking Up The Doc Type Grid Editor](#hooking-up-the-doc-type-grid-editor)
5. [Rendering a Doc Type Grid Editor](#rendering-a-doc-type-grid-editor)
* [Rendering Alternative Preview Content](#rendering-alternative-preview-content)
* [DocTypeGridEditorSurfaceController](#doctypegrideditorsurfacecontroller)
a. [Rendering Alternative Preview Content](#rendering-alternative-preview-content)
b. [DocTypeGridEditorSurfaceController](#doctypegrideditorsurfacecontroller)
6. [Useful Links](#useful-links)

---
Expand Down Expand Up @@ -82,7 +82,7 @@ The **Doc Type Grid Editor** supports 3 config options, all of which are optiona

| Member | Type | Description |
|-----------------|----------|-------------|
| AllowedDocTypes | String[] | An array of doc type aliases of which should be allowed to be selected in the grid editor. Strings can be REGEX patterns to allow matching groups of doc types in a single entry. e.g. "Widget$" will match all doc types with an alias ending in "Widget". |
| AllowedDocTypes | String[] | An array of doc type aliases of which should be allowed to be selected in the grid editor. Strings can be REGEX patterns to allow matching groups of doc types in a single entry. e.g. "Widget$" will match all doc types with an alias ending in "Widget". However if a single doc type is matched, (aka **Single Doc Type Mode**), then dropdown selection stage (in the DTGE panel) will be skipped. |
| EnablePreview | Boolean | Enables rendering a preview of the grid cell in the grid editor. |
| ViewPath | String | Set's an alternative view path for where the **Doc Type Grid Editor** should look for views when rendering. Defaults to `~/Views/Partials/` |

Expand Down Expand Up @@ -139,11 +139,11 @@ Because we treat your data as a standard `IPublishedContent` entity, that means

#### Rendering Alternative Preview Content

If your front end view is rather complex, you may decide that you want to feed the back office preview an alternative, less complex view. To do this, within your Razor view/partial, simply check for a querystring parameter `dtgePreview` being set to "1" to detect being in preview mode to provide an alternative view.
If your front end view is rather complex, you may decide that you want to feed the back office preview an alternative, less complex view. To do this, within your Razor view/partial, check for a RouteData parameter `dtgePreview` being set to true to detect being in preview mode to provide an alternative view.

```
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@if (Request.QueryString["dtgePreview"] == "1")
@if (ViewContext.RouteData.Values["dtgePreview"])
{
// Render preview view
}
Expand Down
15 changes: 0 additions & 15 deletions src/Our.Umbraco.DocTypeGridEditor/Bootstrap.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
using System;
using System.Web.Mvc;
using Newtonsoft.Json;
using Our.Umbraco.DocTypeGridEditor.Web.Attributes;
using Our.Umbraco.DocTypeGridEditor.Web.Mvc;
using Umbraco.Core;
using Umbraco.Core.Sync;
using Umbraco.Web.Cache;
using Umbraco.Web.Routing;

namespace Our.Umbraco.DocTypeGridEditor
{
internal class Bootstrap : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
GlobalFilters.Filters.Add(new DocTypeGridEditorPreviewAttribute());

if (DefaultDocTypeGridEditorSurfaceControllerResolver.HasCurrent == false)
{
DefaultDocTypeGridEditorSurfaceControllerResolver.Current = new DefaultDocTypeGridEditorSurfaceControllerResolver();
Expand Down Expand Up @@ -63,16 +58,6 @@ protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplica
}
}
};

PublishedContentRequest.Prepared += (sender, e) =>
{
// Check if it's a dtgePreview request and is set to redirect.
// If so reset the redirect url to an empty string to stop the redirect happening in preview mode.
if (sender is PublishedContentRequest request && request.Uri.Query.InvariantContains("dtgePreview") && request.IsRedirect)
{
request.SetRedirect(string.Empty);
}
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Services;

namespace Our.Umbraco.DocTypeGridEditor.Extensions
Expand All @@ -8,9 +9,11 @@ internal static class ContentTypeServiceExtensions
{
public static string GetAliasByGuid(this IContentTypeService contentTypeService, Guid id)
{
return (string)ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem(
return ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem<string>(
string.Concat("Our.Umbraco.DocTypeGridEditor.Web.Extensions.ContentTypeServiceExtensions.GetAliasById_", id),
() => ApplicationContext.Current.DatabaseContext.Database
() => ApplicationContext.Current
.DatabaseContext
.Database
.ExecuteScalar<string>("SELECT [cmsContentType].[alias] FROM [cmsContentType] INNER JOIN [umbracoNode] ON [cmsContentType].[nodeId] = [umbracoNode].[id] WHERE [umbracoNode].[uniqueID] = @0", id));
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ private static IEnumerable<JsonDbRow> GetPropertyDataRows(string docTypeAlias)
public class ContentTypeContainer
{
public PublishedContentType PublishedContentType { get; set; }

public IContentType ContentType { get; set; }
}
}
125 changes: 125 additions & 0 deletions src/Our.Umbraco.DocTypeGridEditor/Models/UnpublishedContent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Web.Models;

namespace Our.Umbraco.DocTypeGridEditor.Models
{
internal class UnpublishedContent : PublishedContentWithKeyBase
{
private readonly IContent content;

private readonly Lazy<IEnumerable<IPublishedContent>> children;
private readonly Lazy<PublishedContentType> contentType;
private readonly Lazy<string> creatorName;
private readonly Lazy<IPublishedContent> parent;
private readonly Lazy<Dictionary<string, IPublishedProperty>> properties;
private readonly Lazy<string> urlName;
private readonly Lazy<string> writerName;

public UnpublishedContent(int id, ServiceContext serviceContext)
: this(serviceContext.ContentService.GetById(id), serviceContext)
{ }

public UnpublishedContent(IContent content, ServiceContext serviceContext)
: base()
{
Mandate.ParameterNotNull(content, nameof(content));
Mandate.ParameterNotNull(serviceContext, nameof(serviceContext));

var userService = new Lazy<IUserService>(() => serviceContext.UserService);

this.content = content;

this.children = new Lazy<IEnumerable<IPublishedContent>>(() => this.content.Children().Select(x => new UnpublishedContent(x, serviceContext)).ToList());
this.contentType = new Lazy<PublishedContentType>(() => PublishedContentType.Get(this.ItemType, this.DocumentTypeAlias));
this.creatorName = new Lazy<string>(() => this.content.GetCreatorProfile(userService.Value).Name);
this.parent = new Lazy<IPublishedContent>(() => new UnpublishedContent(this.content.Parent(), serviceContext));
this.properties = new Lazy<Dictionary<string, IPublishedProperty>>(() => MapProperties(PropertyEditorResolver.Current, serviceContext));
this.urlName = new Lazy<string>(() => this.content.Name.ToUrlSegment());
this.writerName = new Lazy<string>(() => this.content.GetWriterProfile(userService.Value).Name);
}

public override Guid Key => this.content.Key;

public override PublishedItemType ItemType => PublishedItemType.Content;

public override int Id => this.content.Id;

public override int TemplateId => this.content.Template?.Id ?? default(int);

public override int SortOrder => this.content.SortOrder;

public override string Name => this.content.Name;

public override string UrlName => this.urlName.Value;

public override string DocumentTypeAlias => this.content.ContentType?.Alias;

public override int DocumentTypeId => this.content.ContentType?.Id ?? default(int);

public override string WriterName => this.writerName.Value;

public override string CreatorName => this.creatorName.Value;

public override int WriterId => this.content.WriterId;

public override int CreatorId => this.content.CreatorId;

public override string Path => this.content.Path;

public override DateTime CreateDate => this.content.CreateDate;

public override DateTime UpdateDate => this.content.UpdateDate;

public override Guid Version => this.content.Version;

public override int Level => this.content.Level;

public override bool IsDraft => true;

public override IPublishedContent Parent => this.parent.Value;

public override IEnumerable<IPublishedContent> Children => this.children.Value;

public override PublishedContentType ContentType => this.contentType.Value;

public override ICollection<IPublishedProperty> Properties => this.properties.Value.Values;

public override IPublishedProperty GetProperty(string alias)
{
return this.properties.Value.TryGetValue(alias, out IPublishedProperty property) ? property : null;
}

private Dictionary<string, IPublishedProperty> MapProperties(PropertyEditorResolver resolver, ServiceContext services)
{
var contentType = this.contentType.Value;
var properties = this.content.Properties;

var items = new Dictionary<string, IPublishedProperty>(StringComparer.InvariantCultureIgnoreCase);

foreach (var propertyType in contentType.PropertyTypes)
{
var property = properties.FirstOrDefault(x => x.Alias.InvariantEquals(propertyType.PropertyTypeAlias));
var value = property?.Value;
if (value != null)
{
var propertyEditor = resolver.GetByAlias(propertyType.PropertyEditorAlias);
if (propertyEditor != null)
{
value = propertyEditor.ValueEditor.ConvertDbToString(property, property.PropertyType, services.DataTypeService);
}
}

items.Add(propertyType.PropertyTypeAlias, new UnpublishedProperty(propertyType, value));
}

return items;
}
}
}
38 changes: 38 additions & 0 deletions src/Our.Umbraco.DocTypeGridEditor/Models/UnpublishedProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;

namespace Our.Umbraco.DocTypeGridEditor.Models
{
internal class UnpublishedProperty : IPublishedProperty
{
private readonly PublishedPropertyType propertyType;
private readonly object dataValue;
private readonly Lazy<bool> hasValue;
private readonly Lazy<object> sourceValue;
private readonly Lazy<object> objectValue;
private readonly Lazy<object> xpathValue;

public UnpublishedProperty(PublishedPropertyType propertyType, object value)
{
this.propertyType = propertyType;

this.dataValue = value;
this.hasValue = new Lazy<bool>(() => value != null && value.ToString().Trim().Length > 0);

this.sourceValue = new Lazy<object>(() => this.propertyType.ConvertDataToSource(this.dataValue, true));
this.objectValue = new Lazy<object>(() => this.propertyType.ConvertSourceToObject(this.sourceValue.Value, true));
this.xpathValue = new Lazy<object>(() => this.propertyType.ConvertSourceToXPath(this.sourceValue.Value, true));
}

public string PropertyTypeAlias => this.propertyType.PropertyTypeAlias;

public bool HasValue => this.hasValue.Value;

public object DataValue => this.dataValue;

public object Value => this.objectValue.Value;

public object XPathValue => this.xpathValue.Value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
Expand All @@ -94,21 +96,24 @@
<ItemGroup>
<Compile Include="Bootstrap.cs" />
<Compile Include="Extensions\JsonExtensions.cs" />
<Compile Include="Extensions\ViewEnginesCollectionExtensions.cs" />
<Compile Include="Helpers\DocTypeGridEditorHelper.cs" />
<Compile Include="Helpers\XmlHelper.cs" />
<Compile Include="Models\DetachedPublishedContent.cs" />
<Compile Include="Models\DetachedPublishedProperty.cs" />
<Compile Include="Models\JsonDbRow.cs" />
<Compile Include="Models\UnpublishedContent.cs" />
<Compile Include="Models\UnpublishedProperty.cs" />
<Compile Include="PackageActions\AddObjectToJsonArray.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\VersionInfo.cs" />
<Compile Include="Web\Attributes\DocTypeGridEditorPreviewAttribute.cs" />
<Compile Include="Web\Controllers\DocTypeGridEditorApiController.cs" />
<Compile Include="Extensions\ContentTypeServiceExtensions.cs" />
<Compile Include="Web\Controllers\DocTypeGridEditorSurfaceController.cs" />
<Compile Include="Web\Extensions\HtmlHelperExtensions.cs" />
<Compile Include="Web\Helpers\SurfaceControllerHelper.cs" />
<Compile Include="Web\Helpers\ViewHelper.cs" />
<Compile Include="Web\Models\PreviewData.cs" />
<Compile Include="Web\Models\PreviewModel.cs" />
<Compile Include="Web\Mvc\DefaultDocTypeGridEditorSurfaceControllerResolver.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -125,6 +130,9 @@
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Js\doctypegrideditor.services.js" />
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Js\doctypegrideditor.resources.js" />
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Js\doctypegrideditor.controllers.js" />
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Lang\da-DK.xml" />
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Lang\en-GB.xml" />
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Lang\en-US.xml" />
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Views\doctypegrideditor.dialog.html" />
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Views\doctypegrideditor.html" />
</ItemGroup>
Expand Down
Loading

0 comments on commit 5275b46

Please sign in to comment.