Browse Source

Add default value method to FieldDto

pull/198/head
Derek Begnoche 8 years ago
parent
commit
d188c022de
  1. 2
      src/Squidex/app/features/content/pages/content/content-page.component.ts
  2. 49
      src/Squidex/app/shared/services/schemas.service.ts

2
src/Squidex/app/features/content/pages/content/content-page.component.ts

@ -262,7 +262,7 @@ export class ContentPageComponent implements CanComponentDeactivate, OnDestroy,
} else {
for (const field of this.schema.fields) {
if (field.properties.hasOwnProperty('defaultValue')) {
const defaultValue = (field.properties as any).defaultValue;
const defaultValue = field.defaultValue();
if (defaultValue) {
const fieldForm = <FormGroup>this.contentForm.get(field.name);
if (field.partitioning === 'language') {

49
src/Squidex/app/shared/services/schemas.service.ts

@ -317,6 +317,10 @@ export class FieldDto {
public createValidators(isOptional: boolean): ValidatorFn[] {
return this.properties.createValidators(isOptional);
}
public defaultValue(): any {
return this.properties.getDefaultValue();
}
}
export abstract class FieldPropertiesDto {
@ -333,6 +337,8 @@ export abstract class FieldPropertiesDto {
public abstract formatValue(value: any): string;
public abstract createValidators(isOptional: boolean): ValidatorFn[];
public abstract getDefaultValue(): any;
}
export class StringFieldPropertiesDto extends FieldPropertiesDto {
@ -387,6 +393,10 @@ export class StringFieldPropertiesDto extends FieldPropertiesDto {
return validators;
}
public getDefaultValue(): any {
return this.defaultValue;
}
}
export class NumberFieldPropertiesDto extends FieldPropertiesDto {
@ -435,6 +445,10 @@ export class NumberFieldPropertiesDto extends FieldPropertiesDto {
return validators;
}
public getDefaultValue(): any {
return this.defaultValue;
}
}
export class DateTimeFieldPropertiesDto extends FieldPropertiesDto {
@ -477,6 +491,17 @@ export class DateTimeFieldPropertiesDto extends FieldPropertiesDto {
return validators;
}
public getDefaultValue(): any {
if (this.calculatedDefaultValue != null) {
let now = new Date();
if (this.calculatedDefaultValue === 'Today') {
now = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
}
return now.toUTCString();
}
return this.defaultValue;
}
}
export class BooleanFieldPropertiesDto extends FieldPropertiesDto {
@ -506,6 +531,10 @@ export class BooleanFieldPropertiesDto extends FieldPropertiesDto {
return validators;
}
public getDefaultValue(): any {
return this.defaultValue;
}
}
export class GeolocationFieldPropertiesDto extends FieldPropertiesDto {
@ -534,6 +563,10 @@ export class GeolocationFieldPropertiesDto extends FieldPropertiesDto {
return validators;
}
public getDefaultValue(): any {
return null;
}
}
export class ReferencesFieldPropertiesDto extends FieldPropertiesDto {
@ -576,6 +609,10 @@ export class ReferencesFieldPropertiesDto extends FieldPropertiesDto {
return validators;
}
public getDefaultValue(): any {
return null;
}
}
export class AssetsFieldPropertiesDto extends FieldPropertiesDto {
@ -617,6 +654,10 @@ export class AssetsFieldPropertiesDto extends FieldPropertiesDto {
return validators;
}
public getDefaultValue(): any {
return null;
}
}
export class TagsFieldPropertiesDto extends FieldPropertiesDto {
@ -658,6 +699,10 @@ export class TagsFieldPropertiesDto extends FieldPropertiesDto {
return validators;
}
public getDefaultValue(): any {
return null;
}
}
export class JsonFieldPropertiesDto extends FieldPropertiesDto {
@ -685,6 +730,10 @@ export class JsonFieldPropertiesDto extends FieldPropertiesDto {
return validators;
}
public getDefaultValue(): any {
return null;
}
}
export class SchemaPropertiesDto {

Loading…
Cancel
Save