mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
5.0 KiB
165 lines
5.0 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using Squidex.Infrastructure;
|
|
using System.Collections.Generic;
|
|
using NamedIdStatic = Squidex.Infrastructure.NamedId;
|
|
|
|
namespace Squidex.Domain.Apps.Core.Schemas
|
|
{
|
|
public static class FieldExtensions
|
|
{
|
|
public static NamedId<long> NamedId(this IField field)
|
|
{
|
|
return NamedIdStatic.Of(field.Id, field.Name);
|
|
}
|
|
|
|
public static Schema ReorderFields(this Schema schema, List<long> ids, long? parentId = null)
|
|
{
|
|
if (parentId != null)
|
|
{
|
|
return schema.UpdateField(parentId.Value, f =>
|
|
{
|
|
if (f is ArrayField arrayField)
|
|
{
|
|
return arrayField.ReorderFields(ids);
|
|
}
|
|
|
|
return f;
|
|
});
|
|
}
|
|
|
|
return schema.ReorderFields(ids);
|
|
}
|
|
|
|
public static Schema DeleteField(this Schema schema, long fieldId, long? parentId = null)
|
|
{
|
|
if (parentId != null)
|
|
{
|
|
return schema.UpdateField(parentId.Value, f =>
|
|
{
|
|
if (f is ArrayField arrayField)
|
|
{
|
|
return arrayField.DeleteField(fieldId);
|
|
}
|
|
|
|
return f;
|
|
});
|
|
}
|
|
|
|
return schema.DeleteField(fieldId);
|
|
}
|
|
|
|
public static Schema LockField(this Schema schema, long fieldId, long? parentId = null)
|
|
{
|
|
if (parentId != null)
|
|
{
|
|
return schema.UpdateField(parentId.Value, f =>
|
|
{
|
|
if (f is ArrayField arrayField)
|
|
{
|
|
return arrayField.UpdateField(fieldId, n => n.Lock());
|
|
}
|
|
|
|
return f;
|
|
});
|
|
}
|
|
|
|
return schema.UpdateField(fieldId, f => f.Lock());
|
|
}
|
|
|
|
public static Schema HideField(this Schema schema, long fieldId, long? parentId = null)
|
|
{
|
|
if (parentId != null)
|
|
{
|
|
return schema.UpdateField(parentId.Value, f =>
|
|
{
|
|
if (f is ArrayField arrayField)
|
|
{
|
|
return arrayField.UpdateField(fieldId, n => n.Hide());
|
|
}
|
|
|
|
return f;
|
|
});
|
|
}
|
|
|
|
return schema.UpdateField(fieldId, f => f.Hide());
|
|
}
|
|
|
|
public static Schema ShowField(this Schema schema, long fieldId, long? parentId = null)
|
|
{
|
|
if (parentId != null)
|
|
{
|
|
return schema.UpdateField(parentId.Value, f =>
|
|
{
|
|
if (f is ArrayField arrayField)
|
|
{
|
|
return arrayField.UpdateField(fieldId, n => n.Show());
|
|
}
|
|
|
|
return f;
|
|
});
|
|
}
|
|
|
|
return schema.UpdateField(fieldId, f => f.Show());
|
|
}
|
|
|
|
public static Schema EnableField(this Schema schema, long fieldId, long? parentId = null)
|
|
{
|
|
if (parentId != null)
|
|
{
|
|
return schema.UpdateField(parentId.Value, f =>
|
|
{
|
|
if (f is ArrayField arrayField)
|
|
{
|
|
return arrayField.UpdateField(fieldId, n => n.Enable());
|
|
}
|
|
|
|
return f;
|
|
});
|
|
}
|
|
|
|
return schema.UpdateField(fieldId, f => f.Enable());
|
|
}
|
|
|
|
public static Schema DisableField(this Schema schema, long fieldId, long? parentId = null)
|
|
{
|
|
if (parentId != null)
|
|
{
|
|
return schema.UpdateField(parentId.Value, f =>
|
|
{
|
|
if (f is ArrayField arrayField)
|
|
{
|
|
return arrayField.UpdateField(fieldId, n => n.Disable());
|
|
}
|
|
|
|
return f;
|
|
});
|
|
}
|
|
|
|
return schema.UpdateField(fieldId, f => f.Disable());
|
|
}
|
|
|
|
public static Schema UpdateField(this Schema schema, long fieldId, FieldProperties properties, long? parentId = null)
|
|
{
|
|
if (parentId != null)
|
|
{
|
|
return schema.UpdateField(parentId.Value, f =>
|
|
{
|
|
if (f is ArrayField arrayField)
|
|
{
|
|
return arrayField.UpdateField(fieldId, n => n.Update(properties));
|
|
}
|
|
|
|
return f;
|
|
});
|
|
}
|
|
|
|
return schema.UpdateField(fieldId, f => f.Update(properties));
|
|
}
|
|
}
|
|
}
|
|
|