Add the remaining properties to document type (minus list view info, still pending)

This commit is contained in:
kjac
2023-02-04 12:03:43 +01:00
parent 43c10a7fc0
commit 8c2fa7274c
7 changed files with 79 additions and 0 deletions

View File

@@ -1,8 +1,10 @@
using Umbraco.Cms.Api.Management.Mapping.ContentType;
using Umbraco.Cms.Api.Management.ViewModels.ContentType;
using Umbraco.Cms.Api.Management.ViewModels.DocumentType;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models;
using Umbraco.Extensions;
using ContentTypeSort = Umbraco.Cms.Api.Management.ViewModels.ContentType.ContentTypeSort;
namespace Umbraco.Cms.Api.Management.Mapping.DocumentType;
@@ -18,10 +20,42 @@ public class DocumentTypeMapDefinition : ContentTypeMapDefinition<IContentType,
target.Alias = source.Alias;
target.Name = source.Name ?? string.Empty;
target.Description = source.Description;
target.Icon = source.Icon ?? string.Empty;
target.AllowedAsRoot = source.AllowedAsRoot;
target.VariesByCulture = source.VariesByCulture();
target.IsElement = source.IsElement;
target.Containers = MapPropertyTypeContainers(source);
target.Properties = MapPropertyTypes(source);
if (source.AllowedContentTypes != null)
{
target.AllowedContentTypes = source.AllowedContentTypes.Select(contentTypeSort
=> new ContentTypeSort { Key = contentTypeSort.Key, SortOrder = contentTypeSort.SortOrder });
}
if (source.AllowedTemplates != null)
{
target.AllowedTemplateKeys = source.AllowedTemplates.Select(template => template.Key);
}
target.DefaultTemplateKey = source.DefaultTemplate?.Key;
if (source.HistoryCleanup != null)
{
target.Cleanup = new ContentTypeCleanup
{
PreventCleanup = source.HistoryCleanup.PreventCleanup,
KeepAllVersionsNewerThanDays = source.HistoryCleanup.KeepAllVersionsNewerThanDays,
KeepLatestVersionPerDayForDays = source.HistoryCleanup.KeepLatestVersionPerDayForDays
};
}
target.Compositions = source.ContentTypeComposition.Select(contentType => new ContentTypeComposition
{
Key = contentType.Key,
CompositionType = contentType.Id == source.ParentId
? ContentTypeCompositionType.Inheritance
: ContentTypeCompositionType.Composition
}).ToArray();
}
}

View File

@@ -0,0 +1,10 @@
namespace Umbraco.Cms.Api.Management.ViewModels.ContentType;
public class ContentTypeCleanup
{
public bool PreventCleanup { get; init; }
public int? KeepAllVersionsNewerThanDays { get; init; }
public int? KeepLatestVersionPerDayForDays { get; init; }
}

View File

@@ -0,0 +1,8 @@
namespace Umbraco.Cms.Api.Management.ViewModels.ContentType;
public class ContentTypeComposition
{
public required Guid Key { get; init; }
public required ContentTypeCompositionType CompositionType { get; init; }
}

View File

@@ -0,0 +1,7 @@
namespace Umbraco.Cms.Api.Management.ViewModels.ContentType;
public enum ContentTypeCompositionType
{
Composition,
Inheritance
}

View File

@@ -0,0 +1,8 @@
namespace Umbraco.Cms.Api.Management.ViewModels.ContentType;
public class ContentTypeSort
{
public required Guid Key { get; init; }
public required int SortOrder { get; init; }
}

View File

@@ -12,6 +12,8 @@ public abstract class ContentTypeViewModelBase<TPropertyType, TPropertyTypeConta
public string? Description { get; set; }
public string Icon { get; set; } = string.Empty;
public bool AllowedAsRoot { get; set; }
public bool VariesByCulture { get; set; }
@@ -21,4 +23,8 @@ public abstract class ContentTypeViewModelBase<TPropertyType, TPropertyTypeConta
public IEnumerable<TPropertyType> Properties { get; set; } = Array.Empty<TPropertyType>();
public IEnumerable<TPropertyTypeContainer> Containers { get; set; } = Array.Empty<TPropertyTypeContainer>();
public IEnumerable<ContentTypeSort> AllowedContentTypes { get; set; } = Array.Empty<ContentTypeSort>();
public IEnumerable<ContentTypeComposition> Compositions { get; set; } = Array.Empty<ContentTypeComposition>();
}

View File

@@ -4,4 +4,10 @@ namespace Umbraco.Cms.Api.Management.ViewModels.DocumentType;
public class DocumentTypeViewModel : ContentTypeViewModelBase<DocumentTypePropertyTypeViewModel, DocumentTypePropertyTypeContainerViewModel>
{
public IEnumerable<Guid> AllowedTemplateKeys { get; set; } = Array.Empty<Guid>();
public Guid? DefaultTemplateKey { get; set; }
// FIXME: either move this to base level or rename to DocumentTypeCleanup
public ContentTypeCleanup Cleanup { get; set; } = new();
}