From 733bfa50fd5fe0d47a557bc1f0575bcd5a3d9d71 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 1 Nov 2020 21:51:46 +0100 Subject: [PATCH] More default values. --- backend/i18n/frontend_en.json | 1 + backend/i18n/frontend_it.json | 1 + backend/i18n/frontend_nl.json | 1 + backend/i18n/source/frontend_en.json | 1 + .../Schemas/AssetsFieldProperties.cs | 2 ++ .../Schemas/ReferencesFieldProperties.cs | 2 ++ .../Schemas/TagsFieldProperties.cs | 2 ++ .../DefaultValues/DefaultValueFactory.cs | 18 ++++++++-- .../Models/Fields/AssetsFieldPropertiesDto.cs | 5 +++ .../Fields/ReferencesFieldPropertiesDto.cs | 5 +++ .../Models/Fields/TagsFieldPropertiesDto.cs | 5 +++ .../DefaultValues/DefaultValuesTests.cs | 24 +++++++++++-- .../content-history-page.component.html | 15 ++++++++ .../types/assets-validation.component.html | 8 +++++ .../types/assets-validation.component.ts | 3 ++ .../types/number-validation.component.html | 2 +- .../types/number-validation.component.ts | 8 +---- .../references-validation.component.html | 8 +++++ .../types/references-validation.component.ts | 3 ++ .../types/string-validation.component.html | 18 +++++----- .../types/string-validation.component.ts | 4 --- .../types/tags-validation.component.html | 8 +++++ .../fields/types/tags-validation.component.ts | 3 ++ .../settings/pages/roles/role.component.ts | 8 ++--- .../forms/editors/tag-editor.component.html | 1 + .../forms/editors/tag-editor.component.scss | 23 +++++++++--- .../assets/asset-dialog.component.html | 15 ++++++++ frontend/app/shared/services/schemas.types.ts | 3 ++ .../app/shared/state/contents.forms.spec.ts | 36 +++++++++++-------- .../shared/state/contents.forms.visitors.ts | 12 +++---- 30 files changed, 190 insertions(+), 55 deletions(-) diff --git a/backend/i18n/frontend_en.json b/backend/i18n/frontend_en.json index 183e05c56..92356969a 100644 --- a/backend/i18n/frontend_en.json +++ b/backend/i18n/frontend_en.json @@ -257,6 +257,7 @@ "common.history": "History", "common.httpConflict": "Failed to make the update. Another user has made a change. Please reload.", "common.httpLimit": "You have exceeded the maximum limit of API calls.", + "common.id": "Identity", "common.label": "Label", "common.language": "Language", "common.languages": "Languages", diff --git a/backend/i18n/frontend_it.json b/backend/i18n/frontend_it.json index 6c19502d0..0ff1310d0 100644 --- a/backend/i18n/frontend_it.json +++ b/backend/i18n/frontend_it.json @@ -257,6 +257,7 @@ "common.history": "Cronologia", "common.httpConflict": "Non รจ stato possibile effettuare l'aggiornamento. Un altro utente ha fatto delle modifiche. Per favore ricarica.", "common.httpLimit": "Hai superato il limite massimo di chiamate API.", + "common.id": "Identity", "common.label": "Etichetta", "common.language": "Language", "common.languages": "Lingue", diff --git a/backend/i18n/frontend_nl.json b/backend/i18n/frontend_nl.json index b8245f6e4..e0bef07f8 100644 --- a/backend/i18n/frontend_nl.json +++ b/backend/i18n/frontend_nl.json @@ -257,6 +257,7 @@ "common.history": "Geschiedenis", "common.httpConflict": "De update is mislukt. Een andere gebruiker heeft een wijziging aangebracht. Laad opnieuw.", "common.httpLimit": "Je hebt de maximale limiet van API-aanroepen overschreden.", + "common.id": "Identity", "common.label": "Label", "common.language": "Language", "common.languages": "Talen", diff --git a/backend/i18n/source/frontend_en.json b/backend/i18n/source/frontend_en.json index 183e05c56..92356969a 100644 --- a/backend/i18n/source/frontend_en.json +++ b/backend/i18n/source/frontend_en.json @@ -257,6 +257,7 @@ "common.history": "History", "common.httpConflict": "Failed to make the update. Another user has made a change. Please reload.", "common.httpLimit": "You have exceeded the maximum limit of API calls.", + "common.id": "Identity", "common.label": "Label", "common.language": "Language", "common.languages": "Languages", diff --git a/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/AssetsFieldProperties.cs b/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/AssetsFieldProperties.cs index e5087a2ba..6ef5f8a10 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/AssetsFieldProperties.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/AssetsFieldProperties.cs @@ -14,6 +14,8 @@ namespace Squidex.Domain.Apps.Core.Schemas { public AssetPreviewMode PreviewMode { get; set; } + public string[]? DefaultValue { get; set; } + public int? MinItems { get; set; } public int? MaxItems { get; set; } diff --git a/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/ReferencesFieldProperties.cs b/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/ReferencesFieldProperties.cs index af1585cc7..e28d89a13 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/ReferencesFieldProperties.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/ReferencesFieldProperties.cs @@ -23,6 +23,8 @@ namespace Squidex.Domain.Apps.Core.Schemas public bool AllowDuplicates { get; set; } + public string[]? DefaultValue { get; set; } + public ReferencesFieldEditor Editor { get; set; } public DomainId SchemaId diff --git a/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/TagsFieldProperties.cs b/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/TagsFieldProperties.cs index 83a7eb8e3..772ae01b6 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/TagsFieldProperties.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/TagsFieldProperties.cs @@ -18,6 +18,8 @@ namespace Squidex.Domain.Apps.Core.Schemas public int? MaxItems { get; set; } + public string[]? DefaultValue { get; set; } + public TagsFieldEditor Editor { get; set; } public TagsFieldNormalization Normalization { get; set; } diff --git a/backend/src/Squidex.Domain.Apps.Core.Operations/DefaultValues/DefaultValueFactory.cs b/backend/src/Squidex.Domain.Apps.Core.Operations/DefaultValues/DefaultValueFactory.cs index 0b55ddf57..83d449787 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Operations/DefaultValues/DefaultValueFactory.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Operations/DefaultValues/DefaultValueFactory.cs @@ -36,7 +36,7 @@ namespace Squidex.Domain.Apps.Core.DefaultValues public IJsonValue Visit(IField field) { - return JsonValue.Array(); + return Array(field.Properties.DefaultValue); } public IJsonValue Visit(IField field) @@ -61,7 +61,7 @@ namespace Squidex.Domain.Apps.Core.DefaultValues public IJsonValue Visit(IField field) { - return JsonValue.Array(); + return Array(field.Properties.DefaultValue); } public IJsonValue Visit(IField field) @@ -71,7 +71,7 @@ namespace Squidex.Domain.Apps.Core.DefaultValues public IJsonValue Visit(IField field) { - return JsonValue.Array(); + return Array(field.Properties.DefaultValue); } public IJsonValue Visit(IField field) @@ -93,5 +93,17 @@ namespace Squidex.Domain.Apps.Core.DefaultValues return JsonValue.Create(field.Properties.DefaultValue); } + + private IJsonValue Array(string[]? values) + { + if (values != null) + { + return JsonValue.Array(values); + } + else + { + return JsonValue.Array(); + } + } } } diff --git a/backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/Fields/AssetsFieldPropertiesDto.cs b/backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/Fields/AssetsFieldPropertiesDto.cs index 76912088b..eec8c2b30 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/Fields/AssetsFieldPropertiesDto.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/Fields/AssetsFieldPropertiesDto.cs @@ -19,6 +19,11 @@ namespace Squidex.Areas.Api.Controllers.Schemas.Models.Fields /// public AssetPreviewMode PreviewMode { get; set; } + /// + /// The default value as a list of asset ids. + /// + public string[]? DefaultValue { get; set; } + /// /// The minimum allowed items for the field value. /// diff --git a/backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/Fields/ReferencesFieldPropertiesDto.cs b/backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/Fields/ReferencesFieldPropertiesDto.cs index eb8034af9..807b645ca 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/Fields/ReferencesFieldPropertiesDto.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/Fields/ReferencesFieldPropertiesDto.cs @@ -14,6 +14,11 @@ namespace Squidex.Areas.Api.Controllers.Schemas.Models.Fields { public sealed class ReferencesFieldPropertiesDto : FieldPropertiesDto { + /// + /// The default value as a list of content ids. + /// + public string[]? DefaultValue { get; set; } + /// /// The minimum allowed items for the field value. /// diff --git a/backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/Fields/TagsFieldPropertiesDto.cs b/backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/Fields/TagsFieldPropertiesDto.cs index 202fd9a5e..70ca5d043 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/Fields/TagsFieldPropertiesDto.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/Fields/TagsFieldPropertiesDto.cs @@ -13,6 +13,11 @@ namespace Squidex.Areas.Api.Controllers.Schemas.Models.Fields { public sealed class TagsFieldPropertiesDto : FieldPropertiesDto { + /// + /// The default value. + /// + public string[]? DefaultValue { get; set; } + /// /// The minimum allowed items for the field value. /// diff --git a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/DefaultValues/DefaultValuesTests.cs b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/DefaultValues/DefaultValuesTests.cs index 2f50023f9..14a394696 100644 --- a/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/DefaultValues/DefaultValuesTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/DefaultValues/DefaultValuesTests.cs @@ -90,6 +90,16 @@ namespace Squidex.Domain.Apps.Core.Operations.DefaultValues Assert.Equal(JsonValue.Array(), DefaultValueFactory.CreateDefaultValue(field, now)); } + [Fact] + public void Should_get_default_value_from_assets_field_when_set() + { + var field = + Fields.Assets(1, "1", Partitioning.Invariant, + new AssetsFieldProperties { DefaultValue = new[] { "1", "2" } }); + + Assert.Equal(JsonValue.Array("1", "2"), DefaultValueFactory.CreateDefaultValue(field, now)); + } + [Fact] public void Should_get_default_value_from_boolean_field() { @@ -170,6 +180,16 @@ namespace Squidex.Domain.Apps.Core.Operations.DefaultValues Assert.Equal(JsonValue.Array(), DefaultValueFactory.CreateDefaultValue(field, now)); } + [Fact] + public void Should_get_default_value_from_references_field_when_set() + { + var field = + Fields.References(1, "1", Partitioning.Invariant, + new ReferencesFieldProperties { DefaultValue = new[] { "1", "2" } }); + + Assert.Equal(JsonValue.Array("1", "2"), DefaultValueFactory.CreateDefaultValue(field, now)); + } + [Fact] public void Should_get_default_value_from_string_field() { @@ -185,9 +205,9 @@ namespace Squidex.Domain.Apps.Core.Operations.DefaultValues { var field = Fields.Tags(1, "1", Partitioning.Invariant, - new TagsFieldProperties()); + new TagsFieldProperties { DefaultValue = new[] { "tag1", "tag2" } }); - Assert.Equal(JsonValue.Array(), DefaultValueFactory.CreateDefaultValue(field, now)); + Assert.Equal(JsonValue.Array("tag1", "tag2"), DefaultValueFactory.CreateDefaultValue(field, now)); } private Instant FutureDays(int days) diff --git a/frontend/app/features/content/pages/content/content-history-page.component.html b/frontend/app/features/content/pages/content/content-history-page.component.html index 9b009c7f1..66fb9d1f5 100644 --- a/frontend/app/features/content/pages/content/content-history-page.component.html +++ b/frontend/app/features/content/pages/content/content-history-page.component.html @@ -4,6 +4,21 @@ +
+ + +
+
+ +
+
+ +
+
+
+
+ +
+ + +
+ +
+
\ No newline at end of file diff --git a/frontend/app/features/schemas/pages/schema/fields/types/assets-validation.component.ts b/frontend/app/features/schemas/pages/schema/fields/types/assets-validation.component.ts index d771f8f70..7067f6b7b 100644 --- a/frontend/app/features/schemas/pages/schema/fields/types/assets-validation.component.ts +++ b/frontend/app/features/schemas/pages/schema/fields/types/assets-validation.component.ts @@ -63,5 +63,8 @@ export class AssetsValidationComponent implements OnInit { this.fieldForm.setControl('allowDuplicates', new FormControl(this.properties.allowDuplicates)); + + this.fieldForm.setControl('defaultValue', + new FormControl(this.properties.defaultValue)); } } \ No newline at end of file diff --git a/frontend/app/features/schemas/pages/schema/fields/types/number-validation.component.html b/frontend/app/features/schemas/pages/schema/fields/types/number-validation.component.html index 0a19a5337..2c10cf17e 100644 --- a/frontend/app/features/schemas/pages/schema/fields/types/number-validation.component.html +++ b/frontend/app/features/schemas/pages/schema/fields/types/number-validation.component.html @@ -23,7 +23,7 @@ -
+
diff --git a/frontend/app/features/schemas/pages/schema/fields/types/number-validation.component.ts b/frontend/app/features/schemas/pages/schema/fields/types/number-validation.component.ts index b414830f0..b32cf0e83 100644 --- a/frontend/app/features/schemas/pages/schema/fields/types/number-validation.component.ts +++ b/frontend/app/features/schemas/pages/schema/fields/types/number-validation.component.ts @@ -7,8 +7,7 @@ import { Component, Input, OnInit } from '@angular/core'; import { FormControl, FormGroup } from '@angular/forms'; -import { FieldDto, hasNoValue$, NumberFieldPropertiesDto, RootFieldDto, Types } from '@app/shared'; -import { Observable } from 'rxjs'; +import { FieldDto, NumberFieldPropertiesDto, RootFieldDto, Types } from '@app/shared'; @Component({ selector: 'sqx-number-validation', @@ -27,8 +26,6 @@ export class NumberValidationComponent implements OnInit { public showUnique: boolean; - public showDefaultValue: Observable; - public ngOnInit() { this.showUnique = Types.is(this.field, RootFieldDto) && !this.field.isLocalizable; @@ -45,8 +42,5 @@ export class NumberValidationComponent implements OnInit { this.fieldForm.setControl('defaultValue', new FormControl(this.properties.defaultValue)); - - this.showDefaultValue = - hasNoValue$(this.fieldForm.controls['isRequired']); } } \ No newline at end of file diff --git a/frontend/app/features/schemas/pages/schema/fields/types/references-validation.component.html b/frontend/app/features/schemas/pages/schema/fields/types/references-validation.component.html index d63e0be54..f1b6674d6 100644 --- a/frontend/app/features/schemas/pages/schema/fields/types/references-validation.component.html +++ b/frontend/app/features/schemas/pages/schema/fields/types/references-validation.component.html @@ -31,5 +31,13 @@
+ +
+ + +
+ +
+
diff --git a/frontend/app/features/schemas/pages/schema/fields/types/references-validation.component.ts b/frontend/app/features/schemas/pages/schema/fields/types/references-validation.component.ts index 232d033de..cae1275b5 100644 --- a/frontend/app/features/schemas/pages/schema/fields/types/references-validation.component.ts +++ b/frontend/app/features/schemas/pages/schema/fields/types/references-validation.component.ts @@ -41,5 +41,8 @@ export class ReferencesValidationComponent implements OnInit { this.fieldForm.setControl('schemaIds', new FormControl(this.properties.schemaIds)); + + this.fieldForm.setControl('defaultValue', + new FormControl(this.properties.defaultValue)); } } \ No newline at end of file diff --git a/frontend/app/features/schemas/pages/schema/fields/types/string-validation.component.html b/frontend/app/features/schemas/pages/schema/fields/types/string-validation.component.html index c960df2dc..de0281e42 100644 --- a/frontend/app/features/schemas/pages/schema/fields/types/string-validation.component.html +++ b/frontend/app/features/schemas/pages/schema/fields/types/string-validation.component.html @@ -54,18 +54,10 @@ -
- - -
- -
-
-
- {{ 'schemas.fieldTypes.string.wordHint' | sqxTranslate}} + {{ 'schemas.fieldTypes.string.wordHint' | sqxTranslate}}
@@ -102,4 +94,12 @@ + +
+ + +
+ +
+
\ No newline at end of file diff --git a/frontend/app/features/schemas/pages/schema/fields/types/string-validation.component.ts b/frontend/app/features/schemas/pages/schema/fields/types/string-validation.component.ts index 0f05f422c..eb3c1d744 100644 --- a/frontend/app/features/schemas/pages/schema/fields/types/string-validation.component.ts +++ b/frontend/app/features/schemas/pages/schema/fields/types/string-validation.component.ts @@ -33,7 +33,6 @@ export class StringValidationComponent extends ResourceOwner implements OnChange public contentTypes = STRING_CONTENT_TYPES; - public showDefaultValue: Observable; public showPatternMessage: Observable; public showPatternSuggestions: Observable; @@ -80,9 +79,6 @@ export class StringValidationComponent extends ResourceOwner implements OnChange this.fieldForm.setControl('defaultValue', new FormControl(this.properties.defaultValue)); - this.showDefaultValue = - hasNoValue$(this.fieldForm.controls['isRequired']); - this.showPatternSuggestions = hasNoValue$(this.fieldForm.controls['pattern']); diff --git a/frontend/app/features/schemas/pages/schema/fields/types/tags-validation.component.html b/frontend/app/features/schemas/pages/schema/fields/types/tags-validation.component.html index a1c6d8225..571e6303c 100644 --- a/frontend/app/features/schemas/pages/schema/fields/types/tags-validation.component.html +++ b/frontend/app/features/schemas/pages/schema/fields/types/tags-validation.component.html @@ -11,4 +11,12 @@ + +
+ + +
+ +
+
\ No newline at end of file diff --git a/frontend/app/features/schemas/pages/schema/fields/types/tags-validation.component.ts b/frontend/app/features/schemas/pages/schema/fields/types/tags-validation.component.ts index 5f5df516f..0ba07f3d2 100644 --- a/frontend/app/features/schemas/pages/schema/fields/types/tags-validation.component.ts +++ b/frontend/app/features/schemas/pages/schema/fields/types/tags-validation.component.ts @@ -30,5 +30,8 @@ export class TagsValidationComponent implements OnInit { this.fieldForm.setControl('minItems', new FormControl(this.properties.minItems)); + + this.fieldForm.setControl('defaultValue', + new FormControl(this.properties.defaultValue)); } } \ No newline at end of file diff --git a/frontend/app/features/settings/pages/roles/role.component.ts b/frontend/app/features/settings/pages/roles/role.component.ts index 30bbaa136..94e29cdf8 100644 --- a/frontend/app/features/settings/pages/roles/role.component.ts +++ b/frontend/app/features/settings/pages/roles/role.component.ts @@ -19,16 +19,16 @@ const DESCRIPTIONS = { type Property = { name: string, key: string }; const SIMPLE_PROPERTIES: ReadonlyArray = [{ - name: 'roles.properties.hideSchemas', + name: 'i18n:roles.properties.hideSchemas', key: Settings.AppProperties.HIDE_SCHEMAS }, { - name: 'roles.properties.hideAssets', + name: 'i18n:roles.properties.hideAssets', key: Settings.AppProperties.HIDE_ASSETS }, { - name: 'roles.properties.hideSettings', + name: 'i18n:roles.properties.hideSettings', key: Settings.AppProperties.HIDE_SETTINGS }, { - name: 'roles.properties.hideAPI', + name: 'i18n:roles.properties.hideAPI', key: Settings.AppProperties.HIDE_API }]; diff --git a/frontend/app/framework/angular/forms/editors/tag-editor.component.html b/frontend/app/framework/angular/forms/editors/tag-editor.component.html index b6571521d..e45bad2a3 100644 --- a/frontend/app/framework/angular/forms/editors/tag-editor.component.html +++ b/frontend/app/framework/angular/forms/editors/tag-editor.component.html @@ -3,6 +3,7 @@ [class.blank]="styleBlank" [class.singleline]="singleLine" [class.readonly]="readonly" + [class.suggested]="suggestionsSorted.length > 0" [class.multiline]="!singleLine" [class.focus]="snapshot.hasFocus" [class.disabled]="snapshot.isDisabled" diff --git a/frontend/app/framework/angular/forms/editors/tag-editor.component.scss b/frontend/app/framework/angular/forms/editors/tag-editor.component.scss index 0670aa950..2c2e14fbf 100644 --- a/frontend/app/framework/angular/forms/editors/tag-editor.component.scss +++ b/frontend/app/framework/angular/forms/editors/tag-editor.component.scss @@ -14,15 +14,17 @@ $inner-height: 1.75rem; .form-control { & { cursor: text; + padding: .25rem; padding-bottom: 0; - padding-left: .25rem; - padding-right: 2rem; - padding-top: .25rem; position: relative; text-align: left; text-decoration: none; } + &.suggested { + padding-right: 2rem; + } + &.disabled { cursor: inherit; } @@ -63,6 +65,13 @@ $inner-height: 1.75rem; .multiline { height: auto; + overflow-x: hidden; + overflow-y: hidden; + + .item { + @include truncate; + display: inline-block; + } } div { @@ -131,10 +140,16 @@ div { margin-bottom: .25rem; margin-right: 2px; padding: 1px .5rem; + padding-right: 1.5rem; + position: relative; vertical-align: top; white-space: nowrap; } + .icon-close { + @include absolute(.6125rem, .5rem); + } + &.disabled { pointer-events: none; @@ -144,7 +159,7 @@ div { } &:hover { - background: $color-theme-blue-dark; + background: darken($color-input, 10%); } } diff --git a/frontend/app/shared/components/assets/asset-dialog.component.html b/frontend/app/shared/components/assets/asset-dialog.component.html index 451c6183d..dcb949266 100644 --- a/frontend/app/shared/components/assets/asset-dialog.component.html +++ b/frontend/app/shared/components/assets/asset-dialog.component.html @@ -51,6 +51,21 @@