Implement content apps code config and manifest

This commit is contained in:
Stephan
2018-09-20 17:22:39 +02:00
parent 7f45727936
commit d6775aa79a
25 changed files with 552 additions and 200 deletions

View File

@@ -1,56 +1,26 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using AutoMapper;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Core.Models.ContentEditing;
using Umbraco.Web.ContentApps;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
// injected into ContentMapperProfile,
// maps ContentApps when mapping IContent to ContentItemDisplay
internal class ContentAppResolver : IValueResolver<IContent, ContentItemDisplay, IEnumerable<ContentApp>>
{
private readonly ContentApp _contentApp = new ContentApp
{
Alias = "umbContent",
Name = "Content",
Icon = "icon-document",
View = "views/content/apps/content/content.html"
};
private readonly ContentAppDefinitionCollection _contentAppDefinitions;
private readonly ContentApp _infoApp = new ContentApp
public ContentAppResolver(ContentAppDefinitionCollection contentAppDefinitions)
{
Alias = "umbInfo",
Name = "Info",
Icon = "icon-info",
View = "views/content/apps/info/info.html"
};
private readonly IDataTypeService _dataTypeService;
private readonly PropertyEditorCollection _propertyEditorCollection;
public ContentAppResolver(IDataTypeService dataTypeService, PropertyEditorCollection propertyEditorCollection)
{
_dataTypeService = dataTypeService ?? throw new ArgumentNullException(nameof(dataTypeService));
_propertyEditorCollection = propertyEditorCollection ?? throw new ArgumentNullException(nameof(propertyEditorCollection));
_contentAppDefinitions = contentAppDefinitions;
}
public IEnumerable<ContentApp> Resolve(IContent source, ContentItemDisplay destination, IEnumerable<ContentApp> destMember, ResolutionContext context)
{
var apps = new List<ContentApp>();
if (source.ContentType.IsContainer)
{
//If it's a container then add the list view app and view model
apps.AppendListViewApp(_dataTypeService, _propertyEditorCollection, source.ContentType.Alias, "content");
}
apps.Add(_contentApp);
apps.Add(_infoApp);
return apps;
return _contentAppDefinitions.GetContentAppsFor(source);
}
}
}
}

View File

@@ -1,77 +0,0 @@
using System;
using System.Collections.Generic;
using AutoMapper;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
internal static class ContentAppResolverExtensions
{
/// <summary>
/// Helper method to append a list view app to the content app collection
/// </summary>
/// <param name="resolver"></param>
public static void AppendListViewApp(
this ICollection<ContentApp> list,
IDataTypeService dataTypeService, PropertyEditorCollection propertyEditors,
string contentTypeAlias, string entityType)
{
var listViewApp = new ContentApp
{
Alias = "umbListView",
Name = "Child items",
Icon = "icon-list",
View = "views/content/apps/listview/listview.html"
};
var customDtdName = Core.Constants.Conventions.DataTypes.ListViewPrefix + contentTypeAlias;
var dtdId = Core.Constants.DataTypes.DefaultContentListView;
//first try to get the custom one if there is one
var dt = dataTypeService.GetDataType(customDtdName)
?? dataTypeService.GetDataType(dtdId);
if (dt == null)
{
throw new InvalidOperationException("No list view data type was found for this document type, ensure that the default list view data types exists and/or that your custom list view data type exists");
}
var editor = propertyEditors[dt.EditorAlias];
if (editor == null)
{
throw new NullReferenceException("The property editor with alias " + dt.EditorAlias + " does not exist");
}
var listViewConfig = editor.GetConfigurationEditor().ToConfigurationEditor(dt.Configuration);
//add the entity type to the config
listViewConfig["entityType"] = entityType;
//Override Tab Label if tabName is provided
if (listViewConfig.ContainsKey("tabName"))
{
var configTabName = listViewConfig["tabName"];
if (configTabName != null && string.IsNullOrWhiteSpace(configTabName.ToString()) == false)
listViewApp.Name = configTabName.ToString();
}
//This is the view model used for the list view app
listViewApp.ViewModel = new List<ContentPropertyDisplay>
{
new ContentPropertyDisplay
{
Alias = $"{Core.Constants.PropertyEditors.InternalGenericPropertiesPrefix}containerView",
Label = "",
Value = null,
View = editor.GetValueEditor().View,
HideLabel = true,
Config = listViewConfig
}
};
list.Add(listViewApp);
}
}
}

View File

@@ -1,57 +1,26 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using AutoMapper;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Core.Models.ContentEditing;
using Umbraco.Web.ContentApps;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
// injected into ContentMapperProfile,
// maps ContentApps when mapping IMedia to MediaItemDisplay
internal class MediaAppResolver : IValueResolver<IMedia, MediaItemDisplay, IEnumerable<ContentApp>>
{
private static readonly ContentApp _contentApp = new ContentApp
{
Alias = "umbContent",
Name = "Content",
Icon = "icon-document",
View = "views/media/apps/content/content.html"
};
private readonly ContentAppDefinitionCollection _contentAppDefinitions;
private static readonly ContentApp _infoApp = new ContentApp
public MediaAppResolver(ContentAppDefinitionCollection contentAppDefinitions)
{
Alias = "umbInfo",
Name = "Info",
Icon = "icon-info",
View = "views/media/apps/info/info.html"
};
private readonly IDataTypeService _dataTypeService;
private readonly PropertyEditorCollection _propertyEditorCollection;
public MediaAppResolver(IDataTypeService dataTypeService, PropertyEditorCollection propertyEditorCollection)
{
_dataTypeService = dataTypeService ?? throw new ArgumentNullException(nameof(dataTypeService));
_propertyEditorCollection = propertyEditorCollection ?? throw new ArgumentNullException(nameof(propertyEditorCollection));
_contentAppDefinitions = contentAppDefinitions;
}
public IEnumerable<ContentApp> Resolve(IMedia source, MediaItemDisplay destination, IEnumerable<ContentApp> destMember, ResolutionContext context)
{
var apps = new List<ContentApp>();
if (source.ContentType.IsContainer || source.ContentType.Alias == Core.Constants.Conventions.MediaTypes.Folder)
{
apps.AppendListViewApp(_dataTypeService, _propertyEditorCollection, source.ContentType.Alias, "media");
}
else
{
apps.Add(_contentApp);
}
apps.Add(_infoApp);
return apps;
return _contentAppDefinitions.GetContentAppsFor(source);
}
}
}