diff --git a/src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs b/src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs index c7a96fed8..4259f8a45 100644 --- a/src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs +++ b/src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; +using System.Linq; using Squidex.Core.Schemas; using Squidex.Infrastructure.Reflection; using Squidex.Read.Schemas.Repositories; @@ -20,11 +21,11 @@ namespace Squidex.Controllers.Api.Schemas.Models.Converters { { typeof(NumberFieldProperties), - p => SimpleMapper.Map((NumberFieldProperties)p, new NumberFieldPropertiesDto()) + p => Convert((NumberFieldProperties)p) }, { typeof(StringFieldProperties), - p => SimpleMapper.Map((StringFieldProperties)p, new StringFieldPropertiesDto()) + p => Convert((StringFieldProperties)p) } }; @@ -38,22 +39,41 @@ namespace Squidex.Controllers.Api.Schemas.Models.Converters dto.Fields = new List(); - foreach (var field in entity.Schema.Fields.Values) + foreach (var kvp in entity.Schema.Fields) { - var fieldPropertiesDto = Factories[field.RawProperties.GetType()](field.RawProperties); + var fieldPropertiesDto = + Factories[kvp.Value.RawProperties.GetType()](kvp.Value.RawProperties); - var fieldDto = new FieldDto - { - Name = field.Name, - IsHidden = field.IsHidden, - IsDisabled = field.IsDisabled, - Properties = fieldPropertiesDto - }; + var fieldDto = SimpleMapper.Map(kvp.Value, new FieldDto { FieldId = kvp.Key, Properties = fieldPropertiesDto }); dto.Fields.Add(fieldDto); } return dto; } + + private static FieldPropertiesDto Convert(StringFieldProperties source) + { + var result = SimpleMapper.Map(source, new StringFieldPropertiesDto()); + + if (source.AllowedValues != null) + { + result.AllowedValues = source.AllowedValues.ToArray(); + } + + return result; + } + + private static FieldPropertiesDto Convert(NumberFieldProperties source) + { + var result = SimpleMapper.Map(source, new NumberFieldPropertiesDto()); + + if (source.AllowedValues != null) + { + result.AllowedValues = source.AllowedValues.ToArray(); + } + + return result; + } } } diff --git a/src/Squidex/Controllers/Api/Schemas/Models/FieldDto.cs b/src/Squidex/Controllers/Api/Schemas/Models/FieldDto.cs index ff6ffbd93..5e8e8a519 100644 --- a/src/Squidex/Controllers/Api/Schemas/Models/FieldDto.cs +++ b/src/Squidex/Controllers/Api/Schemas/Models/FieldDto.cs @@ -12,6 +12,11 @@ namespace Squidex.Controllers.Api.Schemas.Models { public sealed class FieldDto { + /// + /// The id of the field. + /// + public long FieldId { get; set; } + /// /// The name of the field. Must be unique within the schema. /// diff --git a/src/Squidex/Controllers/Api/Schemas/Models/NumberFieldPropertiesDto.cs b/src/Squidex/Controllers/Api/Schemas/Models/NumberFieldPropertiesDto.cs index dd76e51f9..d72fa070b 100644 --- a/src/Squidex/Controllers/Api/Schemas/Models/NumberFieldPropertiesDto.cs +++ b/src/Squidex/Controllers/Api/Schemas/Models/NumberFieldPropertiesDto.cs @@ -6,6 +6,9 @@ // All rights reserved. // ========================================================================== +using System.Collections.Immutable; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; using NJsonSchema.Annotations; using Squidex.Core.Schemas; using Squidex.Infrastructure.Reflection; @@ -38,11 +41,19 @@ namespace Squidex.Controllers.Api.Schemas.Models /// /// The editor that is used to manage this field. /// + [JsonConverter(typeof(StringEnumConverter))] public NumberFieldEditor Editor { get; set; } public override FieldProperties ToProperties() { - return SimpleMapper.Map(this, new NumberFieldProperties()); + var result = SimpleMapper.Map(this, new NumberFieldProperties()); + + if (AllowedValues != null) + { + result.AllowedValues = ImmutableList.Create(AllowedValues); + } + + return result; } } } diff --git a/src/Squidex/Controllers/Api/Schemas/Models/StringFieldPropertiesDto.cs b/src/Squidex/Controllers/Api/Schemas/Models/StringFieldPropertiesDto.cs index 2490e11ef..15c2c5a70 100644 --- a/src/Squidex/Controllers/Api/Schemas/Models/StringFieldPropertiesDto.cs +++ b/src/Squidex/Controllers/Api/Schemas/Models/StringFieldPropertiesDto.cs @@ -6,6 +6,9 @@ // All rights reserved. // ========================================================================== +using System.Collections.Immutable; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; using NJsonSchema.Annotations; using Squidex.Core.Schemas; using Squidex.Infrastructure.Reflection; @@ -48,11 +51,19 @@ namespace Squidex.Controllers.Api.Schemas.Models /// /// The editor that is used to manage this field. /// + [JsonConverter(typeof(StringEnumConverter))] public StringFieldEditor Editor { get; set; } public override FieldProperties ToProperties() { - return SimpleMapper.Map(this, new StringFieldProperties()); + var result = SimpleMapper.Map(this, new StringFieldProperties()); + + if (AllowedValues != null) + { + result.AllowedValues = ImmutableList.Create(AllowedValues); + } + + return result; } } } 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 3cae35de4..d4fb5e795 100644 --- a/src/Squidex/app/features/schemas/pages/schema/field.component.html +++ b/src/Squidex/app/features/schemas/pages/schema/field.component.html @@ -1,17 +1,48 @@ -
+
-
- {{field.name}} +
+ + + + {{displayName}} + {{field.properties.hints}} + +
+
+
+ Enabled + Disabled +
- @@ -38,7 +69,7 @@
-
+
@@ -80,24 +111,24 @@
-
+
- +
- +
-
+
- +
- +
diff --git a/src/Squidex/app/features/schemas/pages/schema/field.component.scss b/src/Squidex/app/features/schemas/pages/schema/field.component.scss index f88dcd70b..9901dade6 100644 --- a/src/Squidex/app/features/schemas/pages/schema/field.component.scss +++ b/src/Squidex/app/features/schemas/pages/schema/field.component.scss @@ -7,6 +7,31 @@ $field-header: #e7ebef; padding: 0; } +.dropdown { + & { + display: inline-block; + } + + &-menu { + @include absolute(100%, 0, auto, auto); + } + + &-item { + cursor: pointer; + } +} + +.btn-simple { + & { + color: $color-border-dark; + } + + &:hover, + &.active { + color: $color-text; + } +} + .field { &-summary { padding: 15px 20px; @@ -14,11 +39,11 @@ $field-header: #e7ebef; } &-icon { - color: darken($color-border, 15%); + margin-right: 1rem; + color: $color-border-dark; font-size: 1.2rem; font-weight: normal; vertical-align: middle; - margin-right: 1rem; } &-edit-button { @@ -37,6 +62,21 @@ $field-header: #e7ebef; } } + &-name { + @include truncate; + } + + &-hidden { + color: $color-border-dark; + } + + &-hints { + color: lighten($color-text, 50%); + font-weight: normal; + font-size: .95rem; + margin-left: .3rem; + } + &-details { & { position: relative; @@ -59,6 +99,12 @@ $field-header: #e7ebef; padding: 15px 20px; } } + + .tag { + @include opacity(.9); + min-width: 60px; + max-width: 90px; + } } .nav-field-tabs { 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 f511d5ed3..545b536ee 100644 --- a/src/Squidex/app/features/schemas/pages/schema/field.component.ts +++ b/src/Squidex/app/features/schemas/pages/schema/field.component.ts @@ -11,7 +11,8 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { createProperties, fadeAnimation, - FieldDto + FieldDto, + ModalView } from 'shared'; @Component({ @@ -23,17 +24,36 @@ import { ] }) export class FieldComponent implements OnInit { - private oldValue: any; + public dropdown = new ModalView(false, true); @Input() public field: FieldDto; + @Output() + public hidden = new EventEmitter(); + + @Output() + public shown = new EventEmitter(); + @Output() public saved = new EventEmitter(); + @Output() + public enabled = new EventEmitter(); + + @Output() + public disabled = new EventEmitter(); + + @Output() + public deleted = new EventEmitter(); + public isEditing: boolean = false; public selectedTab = 0; + public get displayName() { + return this.field.properties.label && this.field.properties.label.length > 0 ? this.field.properties.label : this.field.name; + } + public editForm: FormGroup = this.formBuilder.group({ label: ['', @@ -53,7 +73,7 @@ export class FieldComponent implements OnInit { } public ngOnInit() { - this.resetForm(this.field.properties); + this.resetForm(); } public save() { @@ -64,6 +84,7 @@ export class FieldComponent implements OnInit { const field = new FieldDto( + this.field.fieldId, this.field.name, this.field.isHidden, this.field.isHidden, @@ -74,7 +95,7 @@ export class FieldComponent implements OnInit { } public cancel() { - this.resetForm(this.oldValue); + this.resetForm(); } public toggleEditing() { @@ -85,20 +106,8 @@ export class FieldComponent implements OnInit { this.selectedTab = tab; } - private resetForm(properties: any) { - this.editForm.reset(); - - for (let property in properties) { - if (properties.hasOwnProperty(property)) { - const controlName = property + ''; - - if (this.editForm.contains(controlName)) { - this.editForm.get(controlName).setValue(properties[property]); - } - } - } - - this.oldValue = Object.assign({}, this.editForm.value); + private resetForm() { + this.editForm.reset(this.field.properties); this.isEditing = false; } 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 d52f2035a..7eb8a43b0 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 @@ -1,9 +1,9 @@ - +
-

{{schemaName | async}}

+

{{schemaName}}

@@ -13,7 +13,13 @@
- +