Refactors content model mapper to be re-used for media, added new base model class
to deal with content similarities like media. Renamed some service methods to be consistent.
This commit is contained in:
4
src/Umbraco.Web.UI.Client/build.copy.bat
Normal file
4
src/Umbraco.Web.UI.Client/build.copy.bat
Normal file
@@ -0,0 +1,4 @@
|
||||
xcopy build\belle\js\*.* ..\Umbraco.Web.UI\Umbraco\js /Y /F /E /D
|
||||
xcopy build\belle\assets\*.* ..\Umbraco.Web.UI\Umbraco\assets /Y /F /E /D
|
||||
xcopy build\belle\lib\*.* ..\Umbraco.Web.UI\Umbraco\lib /Y /F /E /D
|
||||
xcopy build\belle\views\*.* ..\Umbraco.Web.UI\Umbraco\views /Y /F /E /D
|
||||
1
src/Umbraco.Web.UI.Client/build.grunt.bat
Normal file
1
src/Umbraco.Web.UI.Client/build.grunt.bat
Normal file
@@ -0,0 +1 @@
|
||||
grunt.cmd build
|
||||
@@ -15,7 +15,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
|
||||
|
||||
/** internal method to get the api url */
|
||||
function getContentUrl(contentId) {
|
||||
return Umbraco.Sys.ServerVariables.contentApiBaseUrl + "GetContent?id=" + contentId;
|
||||
return Umbraco.Sys.ServerVariables.contentApiBaseUrl + "GetById?id=" + contentId;
|
||||
}
|
||||
/** internal method to get the api url */
|
||||
function getEmptyContentUrl(contentTypeAlias, parentId) {
|
||||
@@ -64,7 +64,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
|
||||
}
|
||||
|
||||
return {
|
||||
getContent: function (id) {
|
||||
getById: function (id) {
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
@@ -234,6 +234,10 @@ angular.module('umbraco.resources').factory('contentTypeResource', contentTypeRe
|
||||
**/
|
||||
function mediaResource($q, $http) {
|
||||
|
||||
/** internal method to get the api url */
|
||||
function getMediaUrl(contentId) {
|
||||
return Umbraco.Sys.ServerVariables.mediaApiBaseUrl + "GetById?id=" + contentId;
|
||||
}
|
||||
/** internal method to get the api url */
|
||||
function getRootMediaUrl() {
|
||||
return Umbraco.Sys.ServerVariables.mediaApiBaseUrl + "GetRootMedia";
|
||||
@@ -245,6 +249,30 @@ function mediaResource($q, $http) {
|
||||
}
|
||||
|
||||
return {
|
||||
getById: function (id) {
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
//go and get the data
|
||||
$http.get(getMediaUrl(id)).
|
||||
success(function (data, status, headers, config) {
|
||||
//set the first tab to active
|
||||
_.each(data.tabs, function (item) {
|
||||
item.active = false;
|
||||
});
|
||||
if (data.tabs.length > 0) {
|
||||
data.tabs[0].active = true;
|
||||
}
|
||||
|
||||
deferred.resolve(data);
|
||||
}).
|
||||
error(function (data, status, headers, config) {
|
||||
deferred.reject('Failed to retreive data for media id ' + id);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
rootMedia: function () {
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
@@ -7,7 +7,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
|
||||
|
||||
/** internal method to get the api url */
|
||||
function getContentUrl(contentId) {
|
||||
return Umbraco.Sys.ServerVariables.contentApiBaseUrl + "GetContent?id=" + contentId;
|
||||
return Umbraco.Sys.ServerVariables.contentApiBaseUrl + "GetById?id=" + contentId;
|
||||
}
|
||||
/** internal method to get the api url */
|
||||
function getEmptyContentUrl(contentTypeAlias, parentId) {
|
||||
@@ -56,7 +56,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
|
||||
}
|
||||
|
||||
return {
|
||||
getContent: function (id) {
|
||||
getById: function (id) {
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
**/
|
||||
function mediaResource($q, $http) {
|
||||
|
||||
/** internal method to get the api url */
|
||||
function getMediaUrl(contentId) {
|
||||
return Umbraco.Sys.ServerVariables.mediaApiBaseUrl + "GetById?id=" + contentId;
|
||||
}
|
||||
/** internal method to get the api url */
|
||||
function getRootMediaUrl() {
|
||||
return Umbraco.Sys.ServerVariables.mediaApiBaseUrl + "GetRootMedia";
|
||||
@@ -16,6 +20,30 @@ function mediaResource($q, $http) {
|
||||
}
|
||||
|
||||
return {
|
||||
getById: function (id) {
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
//go and get the data
|
||||
$http.get(getMediaUrl(id)).
|
||||
success(function (data, status, headers, config) {
|
||||
//set the first tab to active
|
||||
_.each(data.tabs, function (item) {
|
||||
item.active = false;
|
||||
});
|
||||
if (data.tabs.length > 0) {
|
||||
data.tabs[0].active = true;
|
||||
}
|
||||
|
||||
deferred.resolve(data);
|
||||
}).
|
||||
error(function (data, status, headers, config) {
|
||||
deferred.reject('Failed to retreive data for media id ' + id);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
rootMedia: function () {
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
angular.module("umbraco")
|
||||
.controller("Umbraco.Editors.ContentEditController",
|
||||
angular.module("umbraco")
|
||||
.controller("Umbraco.Editors.ContentEditController",
|
||||
function ($scope, $routeParams, contentResource, notificationsService) {
|
||||
|
||||
|
||||
if ($routeParams.create) {
|
||||
|
||||
contentResource.getContentScaffold($routeParams.id, $routeParams.doctype)
|
||||
@@ -10,22 +10,22 @@ angular.module("umbraco")
|
||||
});
|
||||
}
|
||||
else {
|
||||
contentResource.getContent($routeParams.id)
|
||||
contentResource.getById($routeParams.id)
|
||||
.then(function (data) {
|
||||
$scope.content = data;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
$scope.saveAndPublish = function (cnt) {
|
||||
cnt.publishDate = new Date();
|
||||
contentResource.publishContent(cnt);
|
||||
cnt.publishDate = new Date();
|
||||
contentResource.publishContent(cnt);
|
||||
notificationsService.success("Published", "Content has been saved and published");
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
$scope.save = function (cnt) {
|
||||
cnt.updateDate = new Date();
|
||||
contentResource.saveContent(cnt);
|
||||
cnt.updateDate = new Date();
|
||||
contentResource.saveContent(cnt);
|
||||
notificationsService.success("Saved", "Content has been saved");
|
||||
};
|
||||
});
|
||||
@@ -1,22 +0,0 @@
|
||||
function mediaEditController($scope, $routeParams, contentResource, notificationsService) {
|
||||
if ($routeParams.create)
|
||||
$scope.content = contentResource.getContentScaffold($routeParams.id, $routeParams.doctype);
|
||||
else
|
||||
$scope.content = contentResource.getContent($routeParams.id);
|
||||
|
||||
|
||||
$scope.saveAndPublish = function (cnt) {
|
||||
cnt.publishDate = new Date();
|
||||
contentResource.publishContent(cnt);
|
||||
notificationsService.success("Published", "Content has been saved and published");
|
||||
};
|
||||
|
||||
$scope.save = function (cnt) {
|
||||
cnt.updateDate = new Date();
|
||||
contentResource.saveContent(cnt);
|
||||
notificationsService.success("Saved", "Content has been saved");
|
||||
};
|
||||
}
|
||||
|
||||
angular.module("umbraco")
|
||||
.controller("Umbraco.Editors.MediaEditController", mediaEditController);
|
||||
@@ -0,0 +1,25 @@
|
||||
function mediaEditController($scope, $routeParams, mediaResource, notificationsService) {
|
||||
|
||||
if ($routeParams.create) {
|
||||
|
||||
mediaResource.getContentScaffold($routeParams.id, $routeParams.doctype)
|
||||
.then(function (data) {
|
||||
$scope.content = data;
|
||||
});
|
||||
}
|
||||
else {
|
||||
mediaResource.getById($routeParams.id)
|
||||
.then(function (data) {
|
||||
$scope.content = data;
|
||||
});
|
||||
}
|
||||
|
||||
$scope.save = function (cnt) {
|
||||
cnt.updateDate = new Date();
|
||||
contentResource.saveContent(cnt);
|
||||
notificationsService.success("Saved", "Media has been saved");
|
||||
};
|
||||
}
|
||||
|
||||
angular.module("umbraco")
|
||||
.controller("Umbraco.Editors.MediaEditController", mediaEditController);
|
||||
@@ -58,7 +58,7 @@ namespace Umbraco.Web.Editors
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public ContentItemDisplay GetContent(int id)
|
||||
public ContentItemDisplay GetById(int id)
|
||||
{
|
||||
var foundContent = Services.ContentService.GetById(id);
|
||||
if (foundContent == null)
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Models.Mapping;
|
||||
using Umbraco.Web.Mvc;
|
||||
@@ -43,13 +46,32 @@ namespace Umbraco.Web.Editors
|
||||
_mediaModelMapper = mediaModelMapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content json for the content id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public MediaItemDisplay GetById(int id)
|
||||
{
|
||||
var foundContent = Services.MediaService.GetById(id);
|
||||
if (foundContent == null)
|
||||
{
|
||||
ModelState.AddModelError("id", string.Format("media with id: {0} was not found", id));
|
||||
var errorResponse = Request.CreateErrorResponse(
|
||||
HttpStatusCode.NotFound,
|
||||
ModelState);
|
||||
throw new HttpResponseException(errorResponse);
|
||||
}
|
||||
return _mediaModelMapper.ToMediaItemDisplay(foundContent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the root media objects
|
||||
/// </summary>
|
||||
public IEnumerable<ContentItemBasic<ContentPropertyBasic>> GetRootMedia()
|
||||
{
|
||||
return Services.MediaService.GetRootMedia()
|
||||
.Select(x => _mediaModelMapper.ToMediaItemSimple(x));
|
||||
.Select(x => _mediaModelMapper.ToContentItemSimple(x));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -58,7 +80,7 @@ namespace Umbraco.Web.Editors
|
||||
public IEnumerable<ContentItemBasic<ContentPropertyBasic>> GetChildren(int parentId)
|
||||
{
|
||||
return Services.MediaService.GetChildren(parentId)
|
||||
.Select(x => _mediaModelMapper.ToMediaItemSimple(x));
|
||||
.Select(x => _mediaModelMapper.ToContentItemSimple(x));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using System.Linq;
|
||||
|
||||
namespace Umbraco.Web.Models.ContentEditing
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A model representing a content item to be displayed in the back office
|
||||
/// </summary>
|
||||
public class ContentItemDisplay : ContentItemBasic<ContentPropertyDisplay>
|
||||
public class ContentItemDisplay : TabbedContentItem<ContentPropertyDisplay>
|
||||
{
|
||||
public ContentItemDisplay()
|
||||
{
|
||||
Tabs = new List<Tab<ContentPropertyDisplay>>();
|
||||
}
|
||||
|
||||
|
||||
[DataMember(Name = "publishDate")]
|
||||
public DateTime? PublishDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines the tabs containing display properties
|
||||
/// </summary>
|
||||
[DataMember(Name = "tabs")]
|
||||
public IEnumerable<Tab<ContentPropertyDisplay>> Tabs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Override the properties property to ensure we don't serialize this
|
||||
/// and to simply return the properties based on the properties in the tabs collection
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This property cannot be set
|
||||
/// </remarks>
|
||||
[JsonIgnore]
|
||||
public override IEnumerable<ContentPropertyDisplay> Properties
|
||||
{
|
||||
get { return Tabs.SelectMany(x => x.Properties); }
|
||||
set { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
13
src/Umbraco.Web/Models/ContentEditing/MediaItemDisplay.cs
Normal file
13
src/Umbraco.Web/Models/ContentEditing/MediaItemDisplay.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Umbraco.Web.Models.ContentEditing
|
||||
{
|
||||
/// <summary>
|
||||
/// A model representing a content item to be displayed in the back office
|
||||
/// </summary>
|
||||
public class MediaItemDisplay : TabbedContentItem<ContentPropertyDisplay>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
37
src/Umbraco.Web/Models/ContentEditing/TabbedContentItem.cs
Normal file
37
src/Umbraco.Web/Models/ContentEditing/TabbedContentItem.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Umbraco.Web.Models.ContentEditing
|
||||
{
|
||||
public abstract class TabbedContentItem<T> : ContentItemBasic<T>
|
||||
where T : ContentPropertyBasic
|
||||
{
|
||||
protected TabbedContentItem()
|
||||
{
|
||||
Tabs = new List<Tab<T>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines the tabs containing display properties
|
||||
/// </summary>
|
||||
[DataMember(Name = "tabs")]
|
||||
public IEnumerable<Tab<T>> Tabs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Override the properties property to ensure we don't serialize this
|
||||
/// and to simply return the properties based on the properties in the tabs collection
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This property cannot be set
|
||||
/// </remarks>
|
||||
[JsonIgnore]
|
||||
public override IEnumerable<T> Properties
|
||||
{
|
||||
get { return Tabs.SelectMany(x => x.Properties); }
|
||||
set { throw new NotImplementedException(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,142 +10,111 @@ using Umbraco.Web.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
internal class ContentModelMapper
|
||||
internal class BaseContentModelMapper
|
||||
{
|
||||
private readonly ApplicationContext _applicationContext;
|
||||
private readonly ProfileModelMapper _profileMapper;
|
||||
protected ApplicationContext ApplicationContext { get; private set; }
|
||||
protected ProfileModelMapper ProfileMapper { get; private set; }
|
||||
|
||||
public ContentModelMapper(ApplicationContext applicationContext, ProfileModelMapper profileMapper)
|
||||
public BaseContentModelMapper(ApplicationContext applicationContext, ProfileModelMapper profileMapper)
|
||||
{
|
||||
_applicationContext = applicationContext;
|
||||
_profileMapper = profileMapper;
|
||||
ApplicationContext = applicationContext;
|
||||
ProfileMapper = profileMapper;
|
||||
}
|
||||
|
||||
private ContentPropertyDisplay ToContentPropertyDisplay(Property property)
|
||||
internal ContentItemDto ToContentItemDto(IContentBase content)
|
||||
{
|
||||
return CreateProperty<ContentPropertyDisplay>(property, (display, originalProp, propEditor) =>
|
||||
{
|
||||
//set the display properties after mapping
|
||||
display.Alias = originalProp.Alias;
|
||||
display.Description = originalProp.PropertyType.Description;
|
||||
display.Label = property.PropertyType.Name;
|
||||
display.Config = _applicationContext.Services.DataTypeService.GetPreValuesByDataTypeId(property.PropertyType.DataTypeDefinitionId);
|
||||
display.View = propEditor.ValueEditor.View;
|
||||
});
|
||||
return CreateContent<ContentItemDto, ContentPropertyDto>(content, null, (propertyDto, originalProperty, propEditor) =>
|
||||
{
|
||||
propertyDto.Alias = originalProperty.Alias;
|
||||
propertyDto.Description = originalProperty.PropertyType.Description;
|
||||
propertyDto.Label = originalProperty.PropertyType.Name;
|
||||
propertyDto.DataType = ApplicationContext.Services.DataTypeService.GetDataTypeDefinitionById(originalProperty.PropertyType.DataTypeDefinitionId);
|
||||
propertyDto.PropertyEditor = PropertyEditorResolver.Current.GetById(originalProperty.PropertyType.DataTypeId);
|
||||
});
|
||||
}
|
||||
|
||||
public ContentItemDisplay ToContentItemDisplay(IContent content)
|
||||
internal ContentItemBasic<ContentPropertyBasic> ToContentItemSimple(IContentBase content)
|
||||
{
|
||||
return CreateContent<ContentItemBasic<ContentPropertyBasic>, ContentPropertyBasic>(content, null, null);
|
||||
}
|
||||
|
||||
protected IList<Tab<ContentPropertyDisplay>> GetTabs(IContentBase content)
|
||||
{
|
||||
//create the list of tabs for properties assigned to tabs.
|
||||
var tabs = content.PropertyGroups.Select(propertyGroup =>
|
||||
{
|
||||
//get the properties for the current tab
|
||||
var propertiesForTab = content.GetPropertiesForGroup(propertyGroup).ToArray();
|
||||
|
||||
//convert the properties to ContentPropertyDisplay objects
|
||||
var displayProperties = propertiesForTab
|
||||
.Select(ToContentPropertyDisplay);
|
||||
|
||||
//return the tab with the tab properties
|
||||
return new Tab<ContentPropertyDisplay>
|
||||
{
|
||||
//get the properties for the current tab
|
||||
var propertiesForTab = content.GetPropertiesForGroup(propertyGroup).ToArray();
|
||||
|
||||
//convert the properties to ContentPropertyDisplay objects
|
||||
var displayProperties = propertiesForTab
|
||||
.Select(ToContentPropertyDisplay);
|
||||
|
||||
//return the tab with the tab properties
|
||||
return new Tab<ContentPropertyDisplay>
|
||||
{
|
||||
Id = propertyGroup.Id,
|
||||
Alias = propertyGroup.Name,
|
||||
Label = propertyGroup.Name,
|
||||
Properties = displayProperties
|
||||
};
|
||||
}).ToList();
|
||||
Id = propertyGroup.Id,
|
||||
Alias = propertyGroup.Name,
|
||||
Label = propertyGroup.Name,
|
||||
Properties = displayProperties
|
||||
};
|
||||
}).ToList();
|
||||
|
||||
//now add the generic properties tab for any properties that don't belong to a tab
|
||||
var orphanProperties = content.GetNonGroupedProperties();
|
||||
|
||||
//now add the generic properties tab
|
||||
tabs.Add(new Tab<ContentPropertyDisplay>
|
||||
{
|
||||
Id = 0,
|
||||
Label = "Generic properties",
|
||||
Alias = "Generic properties",
|
||||
Properties = orphanProperties.Select(ToContentPropertyDisplay).ToArray()
|
||||
});
|
||||
|
||||
var result = CreateContent<ContentItemDisplay, ContentPropertyDisplay>(content, (display, originalContent) =>
|
||||
{
|
||||
//set display props after the normal properties are alraedy mapped
|
||||
display.Name = originalContent.Name;
|
||||
display.Tabs = tabs;
|
||||
//look up the published version of this item if it is not published
|
||||
if (content.Published)
|
||||
{
|
||||
display.PublishDate = content.UpdateDate;
|
||||
}
|
||||
else if (content.HasPublishedVersion())
|
||||
{
|
||||
var published = _applicationContext.Services.ContentService.GetPublishedVersion(content.Id);
|
||||
display.PublishDate = published.UpdateDate;
|
||||
}
|
||||
else
|
||||
{
|
||||
display.PublishDate = null;
|
||||
}
|
||||
|
||||
}, null, false);
|
||||
{
|
||||
Id = 0,
|
||||
Label = "Generic properties",
|
||||
Alias = "Generic properties",
|
||||
Properties = orphanProperties.Select(ToContentPropertyDisplay).ToArray()
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
internal ContentItemDto ToContentItemDto(IContent content)
|
||||
{
|
||||
return CreateContent<ContentItemDto, ContentPropertyDto>(content, null, (propertyDto, originalProperty, propEditor) =>
|
||||
{
|
||||
propertyDto.Alias = originalProperty.Alias;
|
||||
propertyDto.Description = originalProperty.PropertyType.Description;
|
||||
propertyDto.Label = originalProperty.PropertyType.Name;
|
||||
propertyDto.DataType = _applicationContext.Services.DataTypeService.GetDataTypeDefinitionById(originalProperty.PropertyType.DataTypeDefinitionId);
|
||||
propertyDto.PropertyEditor = PropertyEditorResolver.Current.GetById(originalProperty.PropertyType.DataTypeId);
|
||||
});
|
||||
}
|
||||
|
||||
internal ContentItemBasic<ContentPropertyBasic> ToContentItemSimple(IContent content)
|
||||
{
|
||||
return CreateContent<ContentItemBasic<ContentPropertyBasic>, ContentPropertyBasic>(content, null, null);
|
||||
return tabs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new content item
|
||||
/// </summary>
|
||||
/// <typeparam name="TContent"></typeparam>
|
||||
/// <typeparam name="TContentProperty"></typeparam>
|
||||
/// <param name="content"></param>
|
||||
/// <param name="contentCreatedCallback"></param>
|
||||
/// <param name="propertyCreatedCallback"></param>
|
||||
/// <param name="createProperties"></param>
|
||||
/// <returns></returns>
|
||||
private TContent CreateContent<TContent, TContentProperty>(IContent content,
|
||||
Action<TContent, IContent> contentCreatedCallback = null,
|
||||
Action<TContentProperty, Property, PropertyEditor> propertyCreatedCallback = null,
|
||||
protected TContent CreateContent<TContent, TContentProperty>(IContentBase content,
|
||||
Action<TContent, IContentBase> contentCreatedCallback = null,
|
||||
Action<TContentProperty, Property, PropertyEditor> propertyCreatedCallback = null,
|
||||
bool createProperties = true)
|
||||
where TContent : ContentItemBasic<TContentProperty>, new()
|
||||
where TContentProperty : ContentPropertyBasic, new()
|
||||
{
|
||||
var result = new TContent
|
||||
{
|
||||
Id = content.Id,
|
||||
Owner = _profileMapper.ToBasicUser(content.GetCreatorProfile()),
|
||||
Updator = _profileMapper.ToBasicUser(content.GetWriterProfile()),
|
||||
ParentId = content.ParentId,
|
||||
UpdateDate = content.UpdateDate,
|
||||
CreateDate = content.CreateDate,
|
||||
ContentTypeAlias = content.ContentType.Alias,
|
||||
Icon = content.ContentType.Icon,
|
||||
Name = content.Name
|
||||
};
|
||||
{
|
||||
Id = content.Id,
|
||||
Owner = ProfileMapper.ToBasicUser(content.GetCreatorProfile()),
|
||||
|
||||
ParentId = content.ParentId,
|
||||
UpdateDate = content.UpdateDate,
|
||||
CreateDate = content.CreateDate,
|
||||
Name = content.Name
|
||||
};
|
||||
if (createProperties)
|
||||
result.Properties = content.Properties.Select(p => CreateProperty(p, propertyCreatedCallback)).ToArray();
|
||||
if (contentCreatedCallback != null)
|
||||
if (contentCreatedCallback != null)
|
||||
contentCreatedCallback(result, content);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected ContentPropertyDisplay ToContentPropertyDisplay(Property property)
|
||||
{
|
||||
return CreateProperty<ContentPropertyDisplay>(property, (display, originalProp, propEditor) =>
|
||||
{
|
||||
//set the display properties after mapping
|
||||
display.Alias = originalProp.Alias;
|
||||
display.Description = originalProp.PropertyType.Description;
|
||||
display.Label = property.PropertyType.Name;
|
||||
display.Config = ApplicationContext.Services.DataTypeService.GetPreValuesByDataTypeId(property.PropertyType.DataTypeDefinitionId);
|
||||
if (propEditor != null)
|
||||
{
|
||||
display.View = propEditor.ValueEditor.View;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the property with the basic property values mapped
|
||||
/// </summary>
|
||||
@@ -153,8 +122,8 @@ namespace Umbraco.Web.Models.Mapping
|
||||
/// <param name="property"></param>
|
||||
/// <param name="callback"></param>
|
||||
/// <returns></returns>
|
||||
private static TContentProperty CreateProperty<TContentProperty>(
|
||||
Property property,
|
||||
protected static TContentProperty CreateProperty<TContentProperty>(
|
||||
Property property,
|
||||
Action<TContentProperty, Property, PropertyEditor> callback = null)
|
||||
where TContentProperty : ContentPropertyBasic, new()
|
||||
{
|
||||
@@ -178,13 +147,58 @@ namespace Umbraco.Web.Models.Mapping
|
||||
return legacyResult;
|
||||
}
|
||||
var result = new TContentProperty
|
||||
{
|
||||
Id = property.Id,
|
||||
Value = editor.ValueEditor.SerializeValue(property.Value),
|
||||
Alias = property.Alias
|
||||
};
|
||||
{
|
||||
Id = property.Id,
|
||||
Value = editor.ValueEditor.SerializeValue(property.Value),
|
||||
Alias = property.Alias
|
||||
};
|
||||
if (callback != null) callback(result, property, editor);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
internal class ContentModelMapper : BaseContentModelMapper
|
||||
{
|
||||
|
||||
public ContentModelMapper(ApplicationContext applicationContext, ProfileModelMapper profileMapper)
|
||||
: base(applicationContext, profileMapper)
|
||||
{
|
||||
}
|
||||
|
||||
public ContentItemDisplay ToContentItemDisplay(IContent content)
|
||||
{
|
||||
//create the list of tabs for properties assigned to tabs.
|
||||
var tabs = GetTabs(content);
|
||||
|
||||
var result = CreateContent<ContentItemDisplay, ContentPropertyDisplay>(content, (display, originalContent) =>
|
||||
{
|
||||
//fill in the rest
|
||||
display.Updator = ProfileMapper.ToBasicUser(content.GetWriterProfile());
|
||||
display.ContentTypeAlias = content.ContentType.Alias;
|
||||
display.Icon = content.ContentType.Icon;
|
||||
|
||||
//set display props after the normal properties are alraedy mapped
|
||||
display.Name = originalContent.Name;
|
||||
display.Tabs = tabs;
|
||||
//look up the published version of this item if it is not published
|
||||
if (content.Published)
|
||||
{
|
||||
display.PublishDate = content.UpdateDate;
|
||||
}
|
||||
else if (content.HasPublishedVersion())
|
||||
{
|
||||
var published = ApplicationContext.Services.ContentService.GetPublishedVersion(content.Id);
|
||||
display.PublishDate = published.UpdateDate;
|
||||
}
|
||||
else
|
||||
{
|
||||
display.PublishDate = null;
|
||||
}
|
||||
|
||||
}, null, false);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,98 +10,31 @@ using Umbraco.Web.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
internal class MediaModelMapper
|
||||
internal class MediaModelMapper : BaseContentModelMapper
|
||||
{
|
||||
private readonly ApplicationContext _applicationContext;
|
||||
private readonly ProfileModelMapper _profileMapper;
|
||||
|
||||
public MediaModelMapper(ApplicationContext applicationContext, ProfileModelMapper profileMapper)
|
||||
: base(applicationContext, profileMapper)
|
||||
{
|
||||
_applicationContext = applicationContext;
|
||||
_profileMapper = profileMapper;
|
||||
}
|
||||
|
||||
internal ContentItemBasic<ContentPropertyBasic> ToMediaItemSimple(IMedia media)
|
||||
{
|
||||
return CreateMedia<ContentItemBasic<ContentPropertyBasic>, ContentPropertyBasic>(media, null, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new content item
|
||||
/// </summary>
|
||||
/// <typeparam name="TContent"></typeparam>
|
||||
/// <typeparam name="TContentProperty"></typeparam>
|
||||
/// <param name="media"></param>
|
||||
/// <param name="contentCreatedCallback"></param>
|
||||
/// <param name="propertyCreatedCallback"></param>
|
||||
/// <param name="createProperties"></param>
|
||||
/// <returns></returns>
|
||||
private TContent CreateMedia<TContent, TContentProperty>(IMedia media,
|
||||
Action<TContent, IMedia> contentCreatedCallback = null,
|
||||
Action<TContentProperty, Property, PropertyEditor> propertyCreatedCallback = null,
|
||||
bool createProperties = true)
|
||||
where TContent : ContentItemBasic<TContentProperty>, new()
|
||||
where TContentProperty : ContentPropertyBasic, new()
|
||||
{
|
||||
var result = new TContent
|
||||
{
|
||||
Id = media.Id,
|
||||
Owner = _profileMapper.ToBasicUser(media.GetCreatorProfile()),
|
||||
Updator = null,
|
||||
ParentId = media.ParentId,
|
||||
UpdateDate = media.UpdateDate,
|
||||
CreateDate = media.CreateDate,
|
||||
ContentTypeAlias = media.ContentType.Alias,
|
||||
Icon = media.ContentType.Icon,
|
||||
Name = media.Name
|
||||
};
|
||||
if (createProperties)
|
||||
result.Properties = media.Properties.Select(p => CreateProperty(p, propertyCreatedCallback)).ToArray();
|
||||
if (contentCreatedCallback != null)
|
||||
contentCreatedCallback(result, media);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the property with the basic property values mapped
|
||||
/// </summary>
|
||||
/// <typeparam name="TContentProperty"></typeparam>
|
||||
/// <param name="property"></param>
|
||||
/// <param name="callback"></param>
|
||||
/// <returns></returns>
|
||||
private static TContentProperty CreateProperty<TContentProperty>(
|
||||
Property property,
|
||||
Action<TContentProperty, Property, PropertyEditor> callback = null)
|
||||
where TContentProperty : ContentPropertyBasic, new()
|
||||
public MediaItemDisplay ToMediaItemDisplay(IMedia media)
|
||||
{
|
||||
var editor = PropertyEditorResolver.Current.GetById(property.PropertyType.DataTypeId);
|
||||
if (editor == null)
|
||||
//create the list of tabs for properties assigned to tabs.
|
||||
var tabs = GetTabs(media);
|
||||
|
||||
var result = CreateContent<MediaItemDisplay, ContentPropertyDisplay>(media, (display, originalContent) =>
|
||||
{
|
||||
//TODO: Remove this check as we shouldn't support this at all!
|
||||
var legacyEditor = DataTypesResolver.Current.GetById(property.PropertyType.DataTypeId);
|
||||
if (legacyEditor == null)
|
||||
{
|
||||
throw new NullReferenceException("The property editor with id " + property.PropertyType.DataTypeId + " does not exist");
|
||||
}
|
||||
//fill in the rest
|
||||
display.ContentTypeAlias = media.ContentType.Alias;
|
||||
display.Icon = media.ContentType.Icon;
|
||||
|
||||
var legacyResult = new TContentProperty
|
||||
{
|
||||
Id = property.Id,
|
||||
Value = property.Value.ToString(),
|
||||
Alias = property.Alias
|
||||
};
|
||||
if (callback != null) callback(legacyResult, property, null);
|
||||
return legacyResult;
|
||||
//set display props after the normal properties are alraedy mapped
|
||||
display.Name = originalContent.Name;
|
||||
display.Tabs = tabs;
|
||||
}, null, false);
|
||||
|
||||
}
|
||||
var result = new TContentProperty
|
||||
{
|
||||
Id = property.Id,
|
||||
Value = editor.ValueEditor.SerializeValue(property.Value),
|
||||
Alias = property.Alias
|
||||
};
|
||||
if (callback != null) callback(result, property, editor);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,7 +297,9 @@
|
||||
<Compile Include="HttpCookieExtensions.cs" />
|
||||
<Compile Include="Models\ContentEditing\ContentSaveAction.cs" />
|
||||
<Compile Include="Models\ContentEditing\ContentTypeBasic.cs" />
|
||||
<Compile Include="Models\ContentEditing\MediaItemDisplay.cs" />
|
||||
<Compile Include="Models\ContentEditing\Tab.cs" />
|
||||
<Compile Include="Models\ContentEditing\TabbedContentItem.cs" />
|
||||
<Compile Include="Models\ContentEditing\UserBasic.cs" />
|
||||
<Compile Include="Models\Mapping\ContentModelMapper.cs" />
|
||||
<Compile Include="FormDataCollectionExtensions.cs" />
|
||||
|
||||
Reference in New Issue
Block a user