Browse Source

More default values.

pull/596/head
Sebastian 5 years ago
parent
commit
733bfa50fd
  1. 1
      backend/i18n/frontend_en.json
  2. 1
      backend/i18n/frontend_it.json
  3. 1
      backend/i18n/frontend_nl.json
  4. 1
      backend/i18n/source/frontend_en.json
  5. 2
      backend/src/Squidex.Domain.Apps.Core.Model/Schemas/AssetsFieldProperties.cs
  6. 2
      backend/src/Squidex.Domain.Apps.Core.Model/Schemas/ReferencesFieldProperties.cs
  7. 2
      backend/src/Squidex.Domain.Apps.Core.Model/Schemas/TagsFieldProperties.cs
  8. 18
      backend/src/Squidex.Domain.Apps.Core.Operations/DefaultValues/DefaultValueFactory.cs
  9. 5
      backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/Fields/AssetsFieldPropertiesDto.cs
  10. 5
      backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/Fields/ReferencesFieldPropertiesDto.cs
  11. 5
      backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/Fields/TagsFieldPropertiesDto.cs
  12. 24
      backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/DefaultValues/DefaultValuesTests.cs
  13. 15
      frontend/app/features/content/pages/content/content-history-page.component.html
  14. 8
      frontend/app/features/schemas/pages/schema/fields/types/assets-validation.component.html
  15. 3
      frontend/app/features/schemas/pages/schema/fields/types/assets-validation.component.ts
  16. 2
      frontend/app/features/schemas/pages/schema/fields/types/number-validation.component.html
  17. 8
      frontend/app/features/schemas/pages/schema/fields/types/number-validation.component.ts
  18. 8
      frontend/app/features/schemas/pages/schema/fields/types/references-validation.component.html
  19. 3
      frontend/app/features/schemas/pages/schema/fields/types/references-validation.component.ts
  20. 18
      frontend/app/features/schemas/pages/schema/fields/types/string-validation.component.html
  21. 4
      frontend/app/features/schemas/pages/schema/fields/types/string-validation.component.ts
  22. 8
      frontend/app/features/schemas/pages/schema/fields/types/tags-validation.component.html
  23. 3
      frontend/app/features/schemas/pages/schema/fields/types/tags-validation.component.ts
  24. 8
      frontend/app/features/settings/pages/roles/role.component.ts
  25. 1
      frontend/app/framework/angular/forms/editors/tag-editor.component.html
  26. 23
      frontend/app/framework/angular/forms/editors/tag-editor.component.scss
  27. 15
      frontend/app/shared/components/assets/asset-dialog.component.html
  28. 3
      frontend/app/shared/services/schemas.types.ts
  29. 36
      frontend/app/shared/state/contents.forms.spec.ts
  30. 12
      frontend/app/shared/state/contents.forms.visitors.ts

1
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",

1
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",

1
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",

1
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",

2
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; }

2
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

2
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; }

18
backend/src/Squidex.Domain.Apps.Core.Operations/DefaultValues/DefaultValueFactory.cs

@ -36,7 +36,7 @@ namespace Squidex.Domain.Apps.Core.DefaultValues
public IJsonValue Visit(IField<AssetsFieldProperties> field)
{
return JsonValue.Array();
return Array(field.Properties.DefaultValue);
}
public IJsonValue Visit(IField<BooleanFieldProperties> field)
@ -61,7 +61,7 @@ namespace Squidex.Domain.Apps.Core.DefaultValues
public IJsonValue Visit(IField<ReferencesFieldProperties> field)
{
return JsonValue.Array();
return Array(field.Properties.DefaultValue);
}
public IJsonValue Visit(IField<StringFieldProperties> field)
@ -71,7 +71,7 @@ namespace Squidex.Domain.Apps.Core.DefaultValues
public IJsonValue Visit(IField<TagsFieldProperties> field)
{
return JsonValue.Array();
return Array(field.Properties.DefaultValue);
}
public IJsonValue Visit(IField<UIFieldProperties> 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();
}
}
}
}

5
backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/Fields/AssetsFieldPropertiesDto.cs

@ -19,6 +19,11 @@ namespace Squidex.Areas.Api.Controllers.Schemas.Models.Fields
/// </summary>
public AssetPreviewMode PreviewMode { get; set; }
/// <summary>
/// The default value as a list of asset ids.
/// </summary>
public string[]? DefaultValue { get; set; }
/// <summary>
/// The minimum allowed items for the field value.
/// </summary>

5
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
{
/// <summary>
/// The default value as a list of content ids.
/// </summary>
public string[]? DefaultValue { get; set; }
/// <summary>
/// The minimum allowed items for the field value.
/// </summary>

5
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
{
/// <summary>
/// The default value.
/// </summary>
public string[]? DefaultValue { get; set; }
/// <summary>
/// The minimum allowed items for the field value.
/// </summary>

24
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)

15
frontend/app/features/content/pages/content/content-history-page.component.html

@ -4,6 +4,21 @@
</ng-container>
<ng-container content>
<div class="section mb-4">
<label for="id">{{ 'common.id' | sqxTranslate }}</label>
<div class="row no-gutters">
<div class="col">
<input readonly class="form-control" name="id" id="id" value="{{content.id}}" #inputId>
</div>
<div class="col-auto">
<button type="button" class="btn btn-text" [sqxCopy]="inputId">
<i class="icon-copy"></i>
</button>
</div>
</div>
</div>
<div class="section mb-4" *ngIf="content.canDraftCreate || content.canDraftDelete">
<ng-container *ngIf="!content.newStatus; else newVersion">
<button class="btn btn-success btn-block" (click)="createDraft() ">

8
frontend/app/features/schemas/pages/schema/fields/types/assets-validation.component.html

@ -107,4 +107,12 @@
<sqx-tag-editor formControlName="allowedExtensions"></sqx-tag-editor>
</div>
</div>
<div class="form-group row">
<label class="col-3 col-form-label">{{ 'schemas.field.defaultValue' | sqxTranslate }}</label>
<div class="col-6">
<sqx-tag-editor formControlName="defaultValue"></sqx-tag-editor>
</div>
</div>
</div>

3
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));
}
}

2
frontend/app/features/schemas/pages/schema/fields/types/number-validation.component.html

@ -23,7 +23,7 @@
</div>
</div>
<div class="form-group row" *ngIf="showDefaultValue | async">
<div class="form-group row">
<label class="col-3 col-form-label" for="{{field.fieldId}}_fieldDefaultValue">{{ 'schemas.field.defaultValue' | sqxTranslate }}</label>
<div class="col-6">

8
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<boolean>;
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']);
}
}

8
frontend/app/features/schemas/pages/schema/fields/types/references-validation.component.html

@ -31,5 +31,13 @@
<input type="number" class="form-control" formControlName="maxItems" placeholder="{{ 'schemas.fieldTypes.references.countMax' | sqxTranslate }}">
</div>
</div>
<div class="form-group row">
<label class="col-3 col-form-label">{{ 'schemas.field.defaultValue' | sqxTranslate }}</label>
<div class="col-6">
<sqx-tag-editor formControlName="defaultValue"></sqx-tag-editor>
</div>
</div>
</div>

3
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));
}
}

18
frontend/app/features/schemas/pages/schema/fields/types/string-validation.component.html

@ -54,18 +54,10 @@
</div>
</div>
<div class="form-group row" *ngIf="showDefaultValue | async">
<label class="col-3 col-form-label" for="{{field.fieldId}}_fieldDefaultValue">{{ 'schemas.field.defaultValue' | sqxTranslate }}</label>
<div class="col-6">
<input type="text" class="form-control" id="{{field.fieldId}}_fieldDefaultValue" formControlName="defaultValue">
</div>
</div>
<div class="form-group row">
<div class="col-7 offset-3">
<sqx-form-hint>
{{ 'schemas.fieldTypes.string.wordHint' | sqxTranslate}}
{{ 'schemas.fieldTypes.string.wordHint' | sqxTranslate}}
</sqx-form-hint>
</div>
</div>
@ -102,4 +94,12 @@
<input type="number" class="form-control" formControlName="maxWords" placeholder="{{ 'schemas.fieldTypes.string.wordsMax' | sqxTranslate }}">
</div>
</div>
<div class="form-group row">
<label class="col-3 col-form-label" for="{{field.fieldId}}_fieldDefaultValue">{{ 'schemas.field.defaultValue' | sqxTranslate }}</label>
<div class="col-6">
<input type="text" class="form-control" id="{{field.fieldId}}_fieldDefaultValue" formControlName="defaultValue">
</div>
</div>
</div>

4
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<boolean>;
public showPatternMessage: Observable<boolean>;
public showPatternSuggestions: Observable<boolean>;
@ -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']);

8
frontend/app/features/schemas/pages/schema/fields/types/tags-validation.component.html

@ -11,4 +11,12 @@
<input type="number" class="form-control" formControlName="maxItems" placeholder="{{ 'schemas.fieldTypes.tags.countMax' | sqxTranslate }}">
</div>
</div>
<div class="form-group row">
<label class="col-3 col-form-label">{{ 'schemas.field.defaultValue' | sqxTranslate }}</label>
<div class="col-6">
<sqx-tag-editor formControlName="defaultValue"></sqx-tag-editor>
</div>
</div>
</div>

3
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));
}
}

8
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<Property> = [{
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
}];

1
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"

23
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%);
}
}

15
frontend/app/shared/components/assets/asset-dialog.component.html

@ -51,6 +51,21 @@
<ng-container *ngSwitchCase="'i18n:assets.tabMetadata'">
<div class="metadata">
<sqx-form-error [error]="annotateForm.error | async"></sqx-form-error>
<div class="form-group no-gutters">
<label for="id">{{ 'common.id' | sqxTranslate }}</label>
<div class="row no-gutters">
<div class="col">
<input readonly class="form-control" name="id" id="id" value="{{asset.id}}" #inputId>
</div>
<div class="col-auto">
<button type="button" class="btn btn-text" [sqxCopy]="inputId">
<i class="icon-copy"></i>
</button>
</div>
</div>
</div>
<div class="form-group">
<label for="fileName">{{ 'common.name' | sqxTranslate }}</label>

3
frontend/app/shared/services/schemas.types.ts

@ -179,6 +179,7 @@ export class AssetsFieldPropertiesDto extends FieldPropertiesDto {
public readonly fieldType = 'Assets';
public readonly previewMode: AssetPreviewMode;
public readonly defaultValue?: ReadonlyArray<string>;
public readonly allowDuplicates?: boolean;
public readonly allowedExtensions?: ReadonlyArray<string>;
public readonly resolveFirst: boolean;
@ -325,6 +326,7 @@ export class ReferencesFieldPropertiesDto extends FieldPropertiesDto {
public readonly fieldType = 'References';
public readonly allowDuplicates?: boolean;
public readonly defaultValue?: ReadonlyArray<string>;
public readonly editor: ReferencesFieldEditor = 'List';
public readonly maxItems?: number;
public readonly minItems?: number;
@ -405,6 +407,7 @@ export class TagsFieldPropertiesDto extends FieldPropertiesDto {
public readonly fieldType = 'Tags';
public readonly allowedValues?: ReadonlyArray<string>;
public readonly defaultValue?: ReadonlyArray<string>;
public readonly editor: TagsFieldEditor = 'Tags';
public readonly maxItems?: number;
public readonly minItems?: number;

36
frontend/app/shared/state/contents.forms.spec.ts

@ -151,7 +151,7 @@ describe('ArrayField', () => {
expect(FieldFormatter.format(field, 1)).toBe('0 Items');
});
it('should return null for default properties', () => {
it('should return default value as null', () => {
expect(FieldDefaultValue.get(field)).toBeNull();
});
});
@ -179,8 +179,10 @@ describe('AssetsField', () => {
expect(FieldFormatter.format(field, 1)).toBe('0 Assets');
});
it('should return null for default properties', () => {
expect(FieldDefaultValue.get(field)).toBeNull();
it('should return default value from properties', () => {
const field2 = createField({ properties: createProperties('Assets', { defaultValue: ['1', '2'] }) });
expect(FieldDefaultValue.get(field2)).toEqual(['1', '2']);
});
});
@ -203,8 +205,10 @@ describe('TagsField', () => {
expect(FieldFormatter.format(field, 1)).toBe('');
});
it('should return null for default properties', () => {
expect(FieldDefaultValue.get(field)).toBeNull();
it('should return default value from properties', () => {
const field2 = createField({ properties: createProperties('Tags', { defaultValue: ['1', '2'] }) });
expect(FieldDefaultValue.get(field2)).toEqual(['1', '2']);
});
});
@ -227,7 +231,7 @@ describe('BooleanField', () => {
expect(FieldFormatter.format(field, false)).toBe('No');
});
it('should return default value for default properties', () => {
it('should return default value from properties', () => {
const field2 = createField({ properties: createProperties('Boolean', { editor: 'Checkbox', defaultValue: true }) });
expect(FieldDefaultValue.get(field2)).toBeTruthy();
@ -277,19 +281,19 @@ describe('DateTimeField', () => {
expect(FieldFormatter.format(field2, '2017-12-12T16:00:00Z')).toBe('12/12/2017, 4:00:00 PM');
});
it('should return default for DateFieldProperties', () => {
it('should return default from properties value', () => {
const field2 = createField({ properties: createProperties('DateTime', { editor: 'DateTime', defaultValue: '2017-10-12T16:00:00Z' }) });
expect(FieldDefaultValue.get(field2)).toEqual('2017-10-12T16:00:00Z');
});
it('should return calculated date when Today for DateFieldProperties', () => {
it('should return default from Today', () => {
const field2 = createField({ properties: createProperties('DateTime', { editor: 'DateTime', calculatedDefaultValue: 'Today' }) });
expect(FieldDefaultValue.get(field2, now)).toEqual('2017-10-12T00:00:00Z');
});
it('should return calculated date when Now for DateFieldProperties', () => {
it('should return default value from Today', () => {
const field2 = createField({ properties: createProperties('DateTime', { editor: 'DateTime', calculatedDefaultValue: 'Now' }) });
expect(FieldDefaultValue.get(field2, now)).toEqual('2017-10-12T16:30:10Z');
@ -311,7 +315,7 @@ describe('GeolocationField', () => {
expect(FieldFormatter.format(field, { latitude: 42, longitude: 3.14 })).toBe('3.14, 42');
});
it('should return null for default properties', () => {
it('should return default value as null', () => {
expect(FieldDefaultValue.get(field)).toBeNull();
});
});
@ -331,7 +335,7 @@ describe('JsonField', () => {
expect(FieldFormatter.format(field, {})).toBe('<Json />');
});
it('should return null for default properties', () => {
it('should return default value as null', () => {
expect(FieldDefaultValue.get(field)).toBeNull();
});
});
@ -381,7 +385,7 @@ describe('NumberField', () => {
expect(FieldFormatter.format(field2, 3, false)).toEqual('3');
});
it('should return default value for default properties', () => {
it('should return default value from properties', () => {
const field2 = createField({ properties: createProperties('Number', { defaultValue: 13 }) });
expect(FieldDefaultValue.get(field2)).toEqual(13);
@ -411,8 +415,10 @@ describe('ReferencesField', () => {
expect(FieldFormatter.format(field, 1)).toBe('0 References');
});
it('should return null for default properties', () => {
expect(FieldDefaultValue.get(field)).toBeNull();
it('should return default value from properties', () => {
const field2 = createField({ properties: createProperties('References', { defaultValue: ['1', '2'] }) });
expect(FieldDefaultValue.get(field2)).toEqual(['1', '2']);
});
});
@ -449,7 +455,7 @@ describe('StringField', () => {
expect(FieldFormatter.format(field2, 'https://images.com/123?x', true)).toBe('https://images.com/123?x');
});
it('should return default value for default properties', () => {
it('should return default value from properties', () => {
const field2 = createField({ properties: createProperties('String', { defaultValue: 'MyDefault' }) });
expect(FieldDefaultValue.get(field2)).toEqual('MyDefault');

12
frontend/app/shared/state/contents.forms.visitors.ts

@ -368,8 +368,8 @@ export class FieldDefaultValue implements FieldPropertiesVisitor<any> {
return null;
}
public visitAssets(_: AssetsFieldPropertiesDto): any {
return null;
public visitAssets(properties: AssetsFieldPropertiesDto): any {
return properties.defaultValue;
}
public visitBoolean(properties: BooleanFieldPropertiesDto): any {
@ -388,16 +388,16 @@ export class FieldDefaultValue implements FieldPropertiesVisitor<any> {
return properties.defaultValue;
}
public visitReferences(_: ReferencesFieldPropertiesDto): any {
return null;
public visitReferences(properties: ReferencesFieldPropertiesDto): any {
return properties.defaultValue;
}
public visitString(properties: StringFieldPropertiesDto): any {
return properties.defaultValue;
}
public visitTags(_: TagsFieldPropertiesDto): any {
return null;
public visitTags(properties: TagsFieldPropertiesDto): any {
return properties.defaultValue;
}
public visitUI(_: UIFieldPropertiesDto): any {

Loading…
Cancel
Save