diff --git a/src/Squidex.Core/Schemas/NumberFieldEditor.cs b/src/Squidex.Core/Schemas/NumberFieldEditor.cs new file mode 100644 index 000000000..8e54de235 --- /dev/null +++ b/src/Squidex.Core/Schemas/NumberFieldEditor.cs @@ -0,0 +1,17 @@ +// ========================================================================== +// NumberFieldEditor.cs +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex Group +// All rights reserved. +// ========================================================================== + +namespace Squidex.Core.Schemas +{ + public enum NumberFieldEditor + { + Input, + Radio, + Dropdown + } +} diff --git a/src/Squidex.Core/Schemas/NumberFieldProperties.cs b/src/Squidex.Core/Schemas/NumberFieldProperties.cs index f58b8fac1..3a1d7ebc9 100644 --- a/src/Squidex.Core/Schemas/NumberFieldProperties.cs +++ b/src/Squidex.Core/Schemas/NumberFieldProperties.cs @@ -19,6 +19,7 @@ namespace Squidex.Core.Schemas private double? minValue; private double? defaultValue; private ImmutableList allowedValues; + private NumberFieldEditor editor; public double? MaxValue { @@ -64,14 +65,35 @@ namespace Squidex.Core.Schemas } } + public NumberFieldEditor Editor + { + get { return editor; } + set + { + ThrowIfFrozen(); + + editor = value; + } + } + protected override IEnumerable ValidateCore() { + if (!Editor.IsEnumValue()) + { + yield return new ValidationError("Editor ist not a valid value", nameof(Editor)); + } + + if ((Editor == NumberFieldEditor.Radio || Editor == NumberFieldEditor.Dropdown) && (AllowedValues == null || AllowedValues.Count == 0)) + { + yield return new ValidationError("Radio buttons or dropdown list need allowed values", nameof(AllowedValues)); + } + if (MaxValue.HasValue && MinValue.HasValue && MinValue.Value >= MaxValue.Value) { yield return new ValidationError("Max value must be greater than min value", nameof(MinValue), nameof(MaxValue)); } - if (AllowedValues != null && (MinValue.HasValue || MaxValue.HasValue)) + if (AllowedValues != null && AllowedValues.Count > 0 && (MinValue.HasValue || MaxValue.HasValue)) { yield return new ValidationError("Either or allowed values or range can be defined", nameof(AllowedValues), diff --git a/src/Squidex.Core/Schemas/StringFieldEditor.cs b/src/Squidex.Core/Schemas/StringFieldEditor.cs new file mode 100644 index 000000000..eaf901d0a --- /dev/null +++ b/src/Squidex.Core/Schemas/StringFieldEditor.cs @@ -0,0 +1,18 @@ +// ========================================================================== +// StringFieldEditor.cs +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex Group +// All rights reserved. +// ========================================================================== + +namespace Squidex.Core.Schemas +{ + public enum StringFieldEditor + { + Input, + TextArea, + Radio, + Dropdown + } +} diff --git a/src/Squidex.Core/Schemas/StringFieldProperties.cs b/src/Squidex.Core/Schemas/StringFieldProperties.cs index 1bb2b27ef..b6aaad274 100644 --- a/src/Squidex.Core/Schemas/StringFieldProperties.cs +++ b/src/Squidex.Core/Schemas/StringFieldProperties.cs @@ -23,6 +23,7 @@ namespace Squidex.Core.Schemas private string pattern; private string patternMessage; private ImmutableList allowedValues; + private StringFieldEditor editor; public int? MinLength { @@ -79,8 +80,29 @@ namespace Squidex.Core.Schemas } } + public StringFieldEditor Editor + { + get { return editor; } + set + { + ThrowIfFrozen(); + + editor = value; + } + } + protected override IEnumerable ValidateCore() { + if (!Editor.IsEnumValue()) + { + yield return new ValidationError("Editor ist not a valid value", nameof(Editor)); + } + + if ((Editor == StringFieldEditor.Radio || Editor == StringFieldEditor.Dropdown) && (AllowedValues == null || AllowedValues.Count == 0)) + { + yield return new ValidationError("Radio buttons or dropdown list need allowed values", nameof(AllowedValues)); + } + if (MaxLength.HasValue && MinLength.HasValue && MinLength.Value >= MaxLength.Value) { yield return new ValidationError("Max length must be greater than min length", nameof(MinLength), nameof(MaxLength)); diff --git a/src/Squidex/Controllers/Api/Schemas/Models/NumberFieldPropertiesDto.cs b/src/Squidex/Controllers/Api/Schemas/Models/NumberFieldPropertiesDto.cs index 6cd058220..dd76e51f9 100644 --- a/src/Squidex/Controllers/Api/Schemas/Models/NumberFieldPropertiesDto.cs +++ b/src/Squidex/Controllers/Api/Schemas/Models/NumberFieldPropertiesDto.cs @@ -35,6 +35,11 @@ namespace Squidex.Controllers.Api.Schemas.Models /// public double[] AllowedValues { get; set; } + /// + /// The editor that is used to manage this field. + /// + public NumberFieldEditor Editor { get; set; } + public override FieldProperties ToProperties() { return SimpleMapper.Map(this, new NumberFieldProperties()); diff --git a/src/Squidex/Controllers/Api/Schemas/Models/StringFieldPropertiesDto.cs b/src/Squidex/Controllers/Api/Schemas/Models/StringFieldPropertiesDto.cs index 7829f5dd0..2490e11ef 100644 --- a/src/Squidex/Controllers/Api/Schemas/Models/StringFieldPropertiesDto.cs +++ b/src/Squidex/Controllers/Api/Schemas/Models/StringFieldPropertiesDto.cs @@ -45,6 +45,11 @@ namespace Squidex.Controllers.Api.Schemas.Models /// public string[] AllowedValues { get; set; } + /// + /// The editor that is used to manage this field. + /// + public StringFieldEditor Editor { get; set; } + public override FieldProperties ToProperties() { return SimpleMapper.Map(this, new StringFieldProperties()); diff --git a/src/Squidex/app/features/schemas/declarations.ts b/src/Squidex/app/features/schemas/declarations.ts index 926cf40ee..023e83738 100644 --- a/src/Squidex/app/features/schemas/declarations.ts +++ b/src/Squidex/app/features/schemas/declarations.ts @@ -5,6 +5,8 @@ * Copyright (c) Sebastian Stehle. All rights reserved */ +export * from './pages/schema/types/number-ui.component'; +export * from './pages/schema/types/number-validation.component'; export * from './pages/schema/types/string-ui.component'; export * from './pages/schema/types/string-validation.component'; export * from './pages/schema/field.component'; diff --git a/src/Squidex/app/features/schemas/module.ts b/src/Squidex/app/features/schemas/module.ts index 3074a42e8..807fee8f7 100644 --- a/src/Squidex/app/features/schemas/module.ts +++ b/src/Squidex/app/features/schemas/module.ts @@ -12,6 +12,8 @@ import { SqxFrameworkModule, SqxSharedModule } from 'shared'; import { FieldComponent, + NumberUIComponent, + NumberValidationComponent, SchemaFormComponent, SchemaPageComponent, SchemasPageComponent, @@ -42,6 +44,8 @@ const routes: Routes = [ ], declarations: [ FieldComponent, + NumberUIComponent, + NumberValidationComponent, SchemaFormComponent, SchemaPageComponent, SchemasPageComponent, 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 87c825783..3cae35de4 100644 --- a/src/Squidex/app/features/schemas/pages/schema/field.component.html +++ b/src/Squidex/app/features/schemas/pages/schema/field.component.html @@ -2,7 +2,7 @@
- {{field.name}} + {{field.name}}
@@ -28,7 +28,7 @@ Validation @@ -43,9 +43,9 @@
-
+
- + Label can not have more than 100 characters.
@@ -63,9 +63,9 @@
-
+
- + Hints can not have more than 100 characters.
@@ -83,10 +83,10 @@
- asdsad +
- +
@@ -94,10 +94,10 @@
- asdsad +
- +
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 44ce3aa4a..56f5b8fe4 100644 --- a/src/Squidex/app/features/schemas/pages/schema/field.component.scss +++ b/src/Squidex/app/features/schemas/pages/schema/field.component.scss @@ -13,6 +13,14 @@ $field-header: #e7ebef; line-height: 40px; } + &-icon { + color: darken($color-border, 15%); + font-size: 1.2rem; + font-weight: normal; + vertical-align: middle; + margin-right: 1rem; + } + &-edit-button { & { color: $color-theme-blue; 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 f6e24b32a..38c2bafb6 100644 --- a/src/Squidex/app/features/schemas/pages/schema/field.component.ts +++ b/src/Squidex/app/features/schemas/pages/schema/field.component.ts @@ -7,16 +7,13 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; -import { Observable} from 'rxjs'; + import { createProperties, fadeAnimation, - FieldDto, - FieldPropertiesDto + FieldDto } from 'shared'; -const ESCAPE_KEY = 27; - @Component({ selector: 'sqx-field', styleUrls: ['./field.component.scss'], @@ -34,8 +31,8 @@ export class FieldComponent implements OnInit { @Output() public saved = new EventEmitter(); - public isEditing: boolean = false; - public selectedTab = 0; + public isEditing: boolean = true; + public selectedTab = 2; public editForm: FormGroup = this.formBuilder.group({ @@ -102,8 +99,6 @@ export class FieldComponent implements OnInit { } this.oldValue = Object.assign({}, this.editForm.value); - - 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 aaed5b356..d52f2035a 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 @@ -24,15 +24,15 @@
-
+
- + Name is required. - + Name can not have more than 40 characters. - + Name can contain lower case letters (a-z), numbers and dashes (not at the end).
diff --git a/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts b/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts index 44bceff0d..75db9e310 100644 --- a/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts +++ b/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts @@ -21,7 +21,6 @@ import { MessageBus, NotificationService, NumberFieldPropertiesDto, - SchemaDetailsDto, SchemasService, StringFieldPropertiesDto, UsersProviderService diff --git a/src/Squidex/app/features/schemas/pages/schema/types/number-ui.component.html b/src/Squidex/app/features/schemas/pages/schema/types/number-ui.component.html new file mode 100644 index 000000000..7eed595c4 --- /dev/null +++ b/src/Squidex/app/features/schemas/pages/schema/types/number-ui.component.html @@ -0,0 +1,55 @@ +
+
+ + +
+
+
+ + Placeholder can not have more than 100 characters. + +
+
+ + + + + Define the placeholder for the input control. + +
+
+
+ + +
+ + + +
+
+
+ + +
+ +
+
+
\ No newline at end of file diff --git a/src/Squidex/app/features/schemas/pages/schema/types/number-ui.component.scss b/src/Squidex/app/features/schemas/pages/schema/types/number-ui.component.scss new file mode 100644 index 000000000..fbb752506 --- /dev/null +++ b/src/Squidex/app/features/schemas/pages/schema/types/number-ui.component.scss @@ -0,0 +1,2 @@ +@import '_vars'; +@import '_mixins'; \ No newline at end of file diff --git a/src/Squidex/app/features/schemas/pages/schema/types/number-ui.component.ts b/src/Squidex/app/features/schemas/pages/schema/types/number-ui.component.ts new file mode 100644 index 000000000..7f05c49ac --- /dev/null +++ b/src/Squidex/app/features/schemas/pages/schema/types/number-ui.component.ts @@ -0,0 +1,47 @@ +/* + * Squidex Headless CMS + * + * @license + * Copyright (c) Sebastian Stehle. All rights reserved + */ + +import { Component, Input, OnInit } from '@angular/core'; +import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { Observable } from 'rxjs'; + +import { fadeAnimation, FloatConverter } from 'shared'; + +@Component({ + selector: 'sqx-number-ui', + styleUrls: ['number-ui.component.scss'], + templateUrl: 'number-ui.component.html', + animations: [ + fadeAnimation + ] +}) +export class NumberUIComponent implements OnInit { + @Input() + public editForm: FormGroup; + + public converter = new FloatConverter(); + + public hideAllowedValues: Observable; + + public ngOnInit() { + this.editForm.addControl('editor', + new FormControl('Input', [ + Validators.required + ])); + this.editForm.addControl('placeholder', + new FormControl('', [ + Validators.maxLength(100) + ])); + this.editForm.addControl('allowedValues', + new FormControl(undefined, [])); + + this.hideAllowedValues = + Observable.of(false) + .merge(this.editForm.get('editor').valueChanges) + .map(x => !x || x === 'Input' || x === 'Textarea'); + } +} \ No newline at end of file diff --git a/src/Squidex/app/features/schemas/pages/schema/types/number-validation.component.html b/src/Squidex/app/features/schemas/pages/schema/types/number-validation.component.html new file mode 100644 index 000000000..8fe6c59ec --- /dev/null +++ b/src/Squidex/app/features/schemas/pages/schema/types/number-validation.component.html @@ -0,0 +1,30 @@ +
+
+ + +
+ +
+
+ +
+ + +
+ + + +
+
+ +
+
+ +
+ + +
+ +
+
+
\ No newline at end of file diff --git a/src/Squidex/app/features/schemas/pages/schema/types/number-validation.component.scss b/src/Squidex/app/features/schemas/pages/schema/types/number-validation.component.scss new file mode 100644 index 000000000..052895cb8 --- /dev/null +++ b/src/Squidex/app/features/schemas/pages/schema/types/number-validation.component.scss @@ -0,0 +1,16 @@ +@import '_vars'; +@import '_mixins'; + +.minlength { + &-col { + position: relative; + } + + &-label { + @include absolute(0, -4px, auto, auto); + } +} + +.form-check-input { + margin: 0; +} \ No newline at end of file diff --git a/src/Squidex/app/features/schemas/pages/schema/types/number-validation.component.ts b/src/Squidex/app/features/schemas/pages/schema/types/number-validation.component.ts new file mode 100644 index 000000000..e4609291c --- /dev/null +++ b/src/Squidex/app/features/schemas/pages/schema/types/number-validation.component.ts @@ -0,0 +1,40 @@ +/* + * Squidex Headless CMS + * + * @license + * Copyright (c) Sebastian Stehle. All rights reserved + */ + +import { Component, Input, OnInit } from '@angular/core'; +import { FormControl, FormGroup } from '@angular/forms'; +import { Observable } from 'rxjs'; + +@Component({ + selector: 'sqx-number-validation', + styleUrls: ['number-validation.component.scss'], + templateUrl: 'number-validation.component.html' +}) +export class NumberValidationComponent implements OnInit { + @Input() + public editForm: FormGroup; + + public hideDefaultValue: Observable; + + public ngOnInit() { + this.editForm.addControl('maxValue', + new FormControl()); + this.editForm.addControl('minValue', + new FormControl()); + this.editForm.addControl('pattern', + new FormControl()); + this.editForm.addControl('patternMessage', + new FormControl()); + this.editForm.addControl('defaultValue', + new FormControl()); + + this.hideDefaultValue = + Observable.of(false) + .merge(this.editForm.get('isRequired').valueChanges) + .map(x => !!x); + } +} \ No newline at end of file diff --git a/src/Squidex/app/features/schemas/pages/schema/types/string-ui.component.html b/src/Squidex/app/features/schemas/pages/schema/types/string-ui.component.html index 3c6d92658..b46b31457 100644 --- a/src/Squidex/app/features/schemas/pages/schema/types/string-ui.component.html +++ b/src/Squidex/app/features/schemas/pages/schema/types/string-ui.component.html @@ -3,9 +3,9 @@
-
+
- + Placeholder can not have more than 100 characters.
@@ -18,4 +18,45 @@
+
+ + +
+ + + + +
+
+
+ + +
+ +
+
\ No newline at end of file diff --git a/src/Squidex/app/features/schemas/pages/schema/types/string-ui.component.ts b/src/Squidex/app/features/schemas/pages/schema/types/string-ui.component.ts index 86bb184a0..88df64f6c 100644 --- a/src/Squidex/app/features/schemas/pages/schema/types/string-ui.component.ts +++ b/src/Squidex/app/features/schemas/pages/schema/types/string-ui.component.ts @@ -7,8 +7,9 @@ import { Component, Input, OnInit } from '@angular/core'; import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { Observable } from 'rxjs'; -import { fadeAnimation, StringFieldPropertiesDto } from 'shared'; +import { fadeAnimation } from 'shared'; @Component({ selector: 'sqx-string-ui', @@ -22,13 +23,23 @@ export class StringUIComponent implements OnInit { @Input() public editForm: FormGroup; - @Input() - public properties: StringFieldPropertiesDto; + public hideAllowedValues: Observable; public ngOnInit() { + this.editForm.addControl('editor', + new FormControl('Input', [ + Validators.required + ])); this.editForm.addControl('placeholder', new FormControl('', [ Validators.maxLength(100) ])); + this.editForm.addControl('allowedValues', + new FormControl(10, [])); + + this.hideAllowedValues = + Observable.of(false) + .merge(this.editForm.get('editor').valueChanges) + .map(x => !x || x === 'Input' || x === 'Textarea'); } } \ No newline at end of file diff --git a/src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.html b/src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.html index a67604728..0e91328fd 100644 --- a/src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.html +++ b/src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.html @@ -1,6 +1,6 @@
- +
diff --git a/src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.ts b/src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.ts index b4cd85a2a..93fa236e5 100644 --- a/src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.ts +++ b/src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.ts @@ -9,8 +9,6 @@ import { Component, Input, OnInit } from '@angular/core'; import { FormControl, FormGroup } from '@angular/forms'; import { Observable } from 'rxjs'; -import { StringFieldPropertiesDto } from 'shared'; - @Component({ selector: 'sqx-string-validation', styleUrls: ['string-validation.component.scss'], @@ -20,9 +18,6 @@ export class StringValidationComponent implements OnInit { @Input() public editForm: FormGroup; - @Input() - public properties: StringFieldPropertiesDto; - public hidePatternMessage: Observable; public hideDefaultValue: Observable; diff --git a/src/Squidex/app/features/schemas/pages/schemas/schema-form.component.html b/src/Squidex/app/features/schemas/pages/schemas/schema-form.component.html index 348e7dcbb..f4cad156c 100644 --- a/src/Squidex/app/features/schemas/pages/schemas/schema-form.component.html +++ b/src/Squidex/app/features/schemas/pages/schemas/schema-form.component.html @@ -8,15 +8,15 @@
-
+
- + Name is required. - + Name can not have more than 40 characters. - + Name can contain lower case letters (a-z), numbers and dashes only (not at the end).
diff --git a/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts b/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts index f42cd81cc..2fd5de835 100644 --- a/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts +++ b/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts @@ -5,8 +5,8 @@ * Copyright (c) Sebastian Stehle. All rights reserved */ -import { Component, OnInit } from '@angular/core'; -import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; +import { Component } from '@angular/core'; +import { FormBuilder, FormControl } from '@angular/forms'; import { BehaviorSubject, Observable } from 'rxjs'; import { @@ -21,8 +21,6 @@ import { UsersProviderService } from 'shared'; -const FALLBACK_NAME = 'my-schema'; - @Component({ selector: 'sqx-schemas-page', styleUrls: ['./schemas-page.component.scss'], diff --git a/src/Squidex/app/features/settings/pages/clients/client.component.html b/src/Squidex/app/features/settings/pages/clients/client.component.html index b5ef2c38c..fde0877f0 100644 --- a/src/Squidex/app/features/settings/pages/clients/client.component.html +++ b/src/Squidex/app/features/settings/pages/clients/client.component.html @@ -15,9 +15,9 @@
-
+
- + Name is required.
diff --git a/src/Squidex/app/features/settings/pages/clients/clients-page.component.html b/src/Squidex/app/features/settings/pages/clients/clients-page.component.html index 723f232f2..284482b7a 100644 --- a/src/Squidex/app/features/settings/pages/clients/clients-page.component.html +++ b/src/Squidex/app/features/settings/pages/clients/clients-page.component.html @@ -22,15 +22,15 @@