diff --git a/src/Squidex.Events/Schemas/FieldAdded.cs b/src/Squidex.Events/Schemas/FieldAdded.cs index b9fd27b38..4538c7caa 100644 --- a/src/Squidex.Events/Schemas/FieldAdded.cs +++ b/src/Squidex.Events/Schemas/FieldAdded.cs @@ -16,7 +16,7 @@ namespace Squidex.Events.Schemas { public string Name { get; set; } - public bool IsLocalizable { get; set; } + public string Partitioning { get; set; } public FieldProperties Properties { get; set; } } diff --git a/src/Squidex.Events/Schemas/Utils/SchemaEventDispatcher.cs b/src/Squidex.Events/Schemas/Utils/SchemaEventDispatcher.cs index c63e2a0c0..2cee64c9e 100644 --- a/src/Squidex.Events/Schemas/Utils/SchemaEventDispatcher.cs +++ b/src/Squidex.Events/Schemas/Utils/SchemaEventDispatcher.cs @@ -6,6 +6,7 @@ // All rights reserved. // ========================================================================== +using System; using Squidex.Core; using Squidex.Core.Schemas; @@ -17,8 +18,8 @@ namespace Squidex.Events.Schemas.Utils { public static Schema Dispatch(FieldAdded @event, Schema schema, FieldRegistry registry) { - var partitioning = - @event.IsLocalizable ? + var partitioning = + string.Equals(@event.Partitioning, "language", StringComparison.OrdinalIgnoreCase) ? Partitioning.Language : Partitioning.Invariant; diff --git a/src/Squidex.Write/Schemas/Commands/AddField.cs b/src/Squidex.Write/Schemas/Commands/AddField.cs index 6bb99b5c9..b487a89a4 100644 --- a/src/Squidex.Write/Schemas/Commands/AddField.cs +++ b/src/Squidex.Write/Schemas/Commands/AddField.cs @@ -16,10 +16,17 @@ namespace Squidex.Write.Schemas.Commands { public string Name { get; set; } + public string Partitioning { get; set; } + public FieldProperties Properties { get; set; } public void Validate(IList errors) { + if (Partitioning != null && Partitioning != "language") + { + errors.Add(new ValidationError("Partitioning must be invariant or language.", nameof(Partitioning))); + } + if (!Name.IsPropertyName()) { errors.Add(new ValidationError("Name must be a valid property name", nameof(Name))); diff --git a/src/Squidex/Controllers/Api/Schemas/Models/AddFieldDto.cs b/src/Squidex/Controllers/Api/Schemas/Models/AddFieldDto.cs index 04f5eab7d..e98fba456 100644 --- a/src/Squidex/Controllers/Api/Schemas/Models/AddFieldDto.cs +++ b/src/Squidex/Controllers/Api/Schemas/Models/AddFieldDto.cs @@ -20,9 +20,9 @@ namespace Squidex.Controllers.Api.Schemas.Models public string Name { get; set; } /// - /// Determines if the field is localizable. + /// Determines the optional partitioning of the field. /// - public bool IsLocalizable { get; set; } + public string Partitioning { get; set; } /// /// The field properties. diff --git a/src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs b/src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs index d57b244f0..bcea41fcb 100644 --- a/src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs +++ b/src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs @@ -62,7 +62,13 @@ namespace Squidex.Controllers.Api.Schemas.Models.Converters foreach (var field in entity.Schema.Fields) { var fieldPropertiesDto = Factories[field.RawProperties.GetType()](field.RawProperties); - var fieldInstanceDto = SimpleMapper.Map(field, new FieldDto { FieldId = field.Id, Properties = fieldPropertiesDto }); + var fieldInstanceDto = SimpleMapper.Map(field, + new FieldDto + { + FieldId = field.Id, + Properties = fieldPropertiesDto, + Partitioning = field.Paritioning.Key + }); dto.Fields.Add(fieldInstanceDto); } diff --git a/src/Squidex/Controllers/Api/Schemas/Models/FieldDto.cs b/src/Squidex/Controllers/Api/Schemas/Models/FieldDto.cs index 5e8e8a519..7b1c97bd7 100644 --- a/src/Squidex/Controllers/Api/Schemas/Models/FieldDto.cs +++ b/src/Squidex/Controllers/Api/Schemas/Models/FieldDto.cs @@ -34,6 +34,12 @@ namespace Squidex.Controllers.Api.Schemas.Models /// public bool IsDisabled { get; set; } + /// + /// Defines the partitioning of the field. + /// + [Required] + public string Partitioning { get; set; } + /// /// The field properties. /// diff --git a/src/Squidex/Controllers/Api/Schemas/SchemaFieldsController.cs b/src/Squidex/Controllers/Api/Schemas/SchemaFieldsController.cs index 6e9a065f9..90fb2f9ea 100644 --- a/src/Squidex/Controllers/Api/Schemas/SchemaFieldsController.cs +++ b/src/Squidex/Controllers/Api/Schemas/SchemaFieldsController.cs @@ -51,7 +51,7 @@ namespace Squidex.Controllers.Api.Schemas [ProducesResponseType(typeof(ErrorDto), 400)] public async Task PostField(string app, string name, [FromBody] AddFieldDto request) { - var command = new AddField { Name = request.Name, Properties = request.Properties.ToProperties() }; + var command = new AddField { Name = request.Name, Partitioning = request.Partitioning, Properties = request.Properties.ToProperties() }; var context = await CommandBus.PublishAsync(command); diff --git a/src/Squidex/Pipeline/ApiExceptionFilterAttribute.cs b/src/Squidex/Pipeline/ApiExceptionFilterAttribute.cs index a57e20a54..536160366 100644 --- a/src/Squidex/Pipeline/ApiExceptionFilterAttribute.cs +++ b/src/Squidex/Pipeline/ApiExceptionFilterAttribute.cs @@ -64,7 +64,12 @@ namespace Squidex.Pipeline { if (!context.ModelState.IsValid) { - var errors = context.ModelState.Values.SelectMany(g => g.Errors).Select(e => new ValidationError(e.ErrorMessage)).ToList(); + var errors = + context.ModelState.SelectMany(m => + { + return m.Value.Errors.Where(e => !string.IsNullOrWhiteSpace(e.ErrorMessage)) + .Select(e => new ValidationError(e.ErrorMessage, m.Key)); + }).ToList(); throw new ValidationException("The model is not valid.", errors); } diff --git a/src/Squidex/app/features/content/pages/content/content-field.component.html b/src/Squidex/app/features/content/pages/content/content-field.component.html index eb74ff397..539997329 100644 --- a/src/Squidex/app/features/content/pages/content/content-field.component.html +++ b/src/Squidex/app/features/content/pages/content/content-field.component.html @@ -6,25 +6,25 @@ Disabled
-
+
-
-
- +
+
+
- +
- +
- @@ -32,7 +32,7 @@
@@ -41,26 +41,26 @@
- +
- +
- +
- +
-
@@ -69,28 +69,28 @@
- +
- +
- +
- +
- +
diff --git a/src/Squidex/app/features/content/pages/content/content-field.component.ts b/src/Squidex/app/features/content/pages/content/content-field.component.ts index a8bbd45da..2a88e4df6 100644 --- a/src/Squidex/app/features/content/pages/content/content-field.component.ts +++ b/src/Squidex/app/features/content/pages/content/content-field.component.ts @@ -28,11 +28,11 @@ export class ContentFieldComponent implements OnInit { @Input() public contentFormSubmitted: boolean; - public fieldLanguages: string[]; - public fieldLanguage: string; + public fieldPartitions: string[]; + public fieldPartition: string; public selectLanguage(language: AppLanguageDto) { - this.fieldLanguage = language.iso2Code; + this.fieldPartition = language.iso2Code; } public ngOnInit() { @@ -40,12 +40,12 @@ export class ContentFieldComponent implements OnInit { this.fieldForm.disable(); } - if (this.field.properties.isLocalizable) { - this.fieldLanguages = this.languages.map(t => t.iso2Code); - this.fieldLanguage = this.fieldLanguages[0]; + if (this.field.partitioning === 'language') { + this.fieldPartitions = this.languages.map(t => t.iso2Code); + this.fieldPartition = this.fieldPartitions[0]; } else { - this.fieldLanguages = ['iv']; - this.fieldLanguage = 'iv'; + this.fieldPartitions = ['iv']; + this.fieldPartition = 'iv'; } } } diff --git a/src/Squidex/app/features/content/pages/content/content-page.component.ts b/src/Squidex/app/features/content/pages/content/content-page.component.ts index 1a27f4276..177dbcc45 100644 --- a/src/Squidex/app/features/content/pages/content/content-page.component.ts +++ b/src/Squidex/app/features/content/pages/content/content-page.component.ts @@ -230,7 +230,7 @@ export class ContentPageComponent extends AppComponentBase implements CanCompone const group = new FormGroup({}); - if (field.properties.isLocalizable) { + if (field.partitioning === 'language') { for (let language of this.languages) { group.addControl(language.iso2Code, new FormControl(undefined, validators)); } @@ -263,7 +263,7 @@ export class ContentPageComponent extends AppComponentBase implements CanCompone const fieldValue = content.data[field.name] || {}; const fieldForm = this.contentForm.controls[field.name]; - if (field.properties.isLocalizable) { + if (field.partitioning === 'language') { for (let language of this.languages) { fieldForm.controls[language.iso2Code].setValue(fieldValue[language.iso2Code]); } diff --git a/src/Squidex/app/features/content/pages/contents/content-item.component.ts b/src/Squidex/app/features/content/pages/contents/content-item.component.ts index 661bd3420..a4a8c9bfa 100644 --- a/src/Squidex/app/features/content/pages/contents/content-item.component.ts +++ b/src/Squidex/app/features/content/pages/contents/content-item.component.ts @@ -85,7 +85,7 @@ export class ContentItemComponent extends AppComponentBase implements OnInit, On let value: any; - if (properties.isLocalizable) { + if (field.partitioning === 'language') { value = contentField[this.language.iso2Code]; } else { value = contentField['iv']; diff --git a/src/Squidex/app/features/schemas/pages/schema/field.component.html b/src/Squidex/app/features/schemas/pages/schema/field.component.html index 94b97b5ad..cf6f0ff19 100644 --- a/src/Squidex/app/features/schemas/pages/schema/field.component.html +++ b/src/Squidex/app/features/schemas/pages/schema/field.component.html @@ -64,7 +64,7 @@
- +
@@ -121,14 +121,6 @@
- -
-
- -
-
diff --git a/src/Squidex/app/features/schemas/pages/schema/field.component.ts b/src/Squidex/app/features/schemas/pages/schema/field.component.ts index 864f4ea15..907c80078 100644 --- a/src/Squidex/app/features/schemas/pages/schema/field.component.ts +++ b/src/Squidex/app/features/schemas/pages/schema/field.component.ts @@ -66,8 +66,7 @@ export class FieldComponent implements OnInit { Validators.maxLength(100) ]], isRequired: [false], - isListField: [false], - isLocalizable: [false] + isListField: [false] }); constructor( @@ -91,6 +90,7 @@ export class FieldComponent implements OnInit { this.field.name, this.field.isHidden, this.field.isHidden, + this.field.partitioning, properties); this.saving.emit(field); diff --git a/src/Squidex/app/features/schemas/pages/schema/schema-edit-form.component.html b/src/Squidex/app/features/schemas/pages/schema/schema-edit-form.component.html index 6fba0ec29..1b08e5bc2 100644 --- a/src/Squidex/app/features/schemas/pages/schema/schema-edit-form.component.html +++ b/src/Squidex/app/features/schemas/pages/schema/schema-edit-form.component.html @@ -22,7 +22,7 @@
- +
\ No newline at end of file diff --git a/src/Squidex/app/features/schemas/pages/schema/schema-page.component.html b/src/Squidex/app/features/schemas/pages/schema/schema-page.component.html index bf1356832..cf4806279 100644 --- a/src/Squidex/app/features/schemas/pages/schema/schema-page.component.html +++ b/src/Squidex/app/features/schemas/pages/schema/schema-page.component.html @@ -48,21 +48,35 @@