// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschränkt) // All rights reserved. Licensed under the MIT license. // ========================================================================== using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using Squidex.Domain.Apps.Entities.Schemas; using Squidex.Infrastructure.Reflection; using Squidex.Web; namespace Squidex.Areas.Api.Controllers.Schemas.Models { public sealed class SchemaDetailsDto : SchemaDto { private static readonly Dictionary EmptyPreviewUrls = new Dictionary(); /// /// The scripts. /// [Required] public SchemaScriptsDto Scripts { get; set; } = new SchemaScriptsDto(); /// /// The preview Urls. /// [Required] public Dictionary PreviewUrls { get; set; } = EmptyPreviewUrls; /// /// The name of fields that are used in content lists. /// [Required] public List FieldsInLists { get; set; } /// /// The name of fields that are used in content references. /// [Required] public List FieldsInReferences { get; set; } /// /// The list of fields. /// [Required] public List Fields { get; set; } public static SchemaDetailsDto FromSchemaWithDetails(ISchemaEntity schema, Resources resources) { var result = new SchemaDetailsDto(); SimpleMapper.Map(schema, result); SimpleMapper.Map(schema.SchemaDef, result); SimpleMapper.Map(schema.SchemaDef.Scripts, result.Scripts); SimpleMapper.Map(schema.SchemaDef.Properties, result.Properties); result.FieldsInLists = schema.SchemaDef.FieldsInLists.ToList(); result.FieldsInReferences = schema.SchemaDef.FieldsInReferences.ToList(); if (schema.SchemaDef.PreviewUrls.Count > 0) { result.PreviewUrls = new Dictionary(schema.SchemaDef.PreviewUrls); } result.Fields = new List(); foreach (var field in schema.SchemaDef.Fields) { result.Fields.Add(FieldDto.FromField(field)); } result.CreateLinks(resources); return result; } protected override void CreateLinks(Resources resources) { base.CreateLinks(resources); var allowUpdate = resources.CanUpdateSchema(Name); if (Fields != null) { foreach (var nested in Fields) { nested.CreateLinks(resources, Name, allowUpdate); } } } } }