mirror of https://github.com/Squidex/squidex.git
17 changed files with 528 additions and 455 deletions
@ -0,0 +1,30 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|||
|
|||
import { Form, ValidatorsEx } from '@app/framework'; |
|||
|
|||
const FALLBACK_NAME = 'my-app'; |
|||
|
|||
export class CreateAppForm extends Form<FormGroup> { |
|||
public appName = |
|||
this.form.controls['name'].valueChanges.map(n => n || FALLBACK_NAME) |
|||
.startWith(FALLBACK_NAME); |
|||
|
|||
constructor(formBuilder: FormBuilder) { |
|||
super(formBuilder.group({ |
|||
name: ['', |
|||
[ |
|||
Validators.required, |
|||
Validators.maxLength(40), |
|||
ValidatorsEx.pattern('[a-z0-9]+(\-[a-z0-9]+)*', 'Name can contain lower case letters (a-z), numbers and dashes (not at the end).') |
|||
] |
|||
] |
|||
})); |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|||
|
|||
import { Form } from '@app/framework'; |
|||
|
|||
export class RenameAssetForm extends Form<FormGroup> { |
|||
constructor(formBuilder: FormBuilder) { |
|||
super(formBuilder.group({ |
|||
name: ['', |
|||
[ |
|||
Validators.required |
|||
] |
|||
] |
|||
})); |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|||
|
|||
import { Form, ValidatorsEx } from '@app/framework'; |
|||
|
|||
export class RenameClientForm extends Form<FormGroup> { |
|||
constructor(formBuilder: FormBuilder) { |
|||
super(formBuilder.group({ |
|||
name: ['', |
|||
[ |
|||
Validators.required |
|||
] |
|||
] |
|||
})); |
|||
} |
|||
} |
|||
|
|||
export class AttachClientForm extends Form<FormGroup> { |
|||
public hasNoName = |
|||
this.form.controls['name'].valueChanges.startWith('').map(x => !x || x.length === 0); |
|||
|
|||
constructor(formBuilder: FormBuilder) { |
|||
super(formBuilder.group({ |
|||
name: ['', |
|||
[ |
|||
Validators.maxLength(40), |
|||
ValidatorsEx.pattern('[a-z0-9]+(\-[a-z0-9]+)*', 'Name can contain lower case letters (a-z), numbers and dashes (not at the end).') |
|||
] |
|||
] |
|||
})); |
|||
} |
|||
} |
|||
@ -0,0 +1,196 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
|
|||
// tslint:disable:prefer-for-of
|
|||
|
|||
import { FormArray, FormControl, FormGroup } from '@angular/forms'; |
|||
|
|||
import { |
|||
ErrorDto, |
|||
Form, |
|||
ImmutableArray, |
|||
Types |
|||
} from '@app/framework'; |
|||
|
|||
import { AppLanguageDto } from './../services/app-languages.service'; |
|||
import { fieldInvariant, RootFieldDto, SchemaDetailsDto } from './../services/schemas.service'; |
|||
|
|||
export class EditContentForm extends Form<FormGroup> { |
|||
constructor( |
|||
private readonly schema: SchemaDetailsDto, |
|||
private readonly languages: ImmutableArray<AppLanguageDto> |
|||
) { |
|||
super(new FormGroup({})); |
|||
|
|||
for (const field of schema.fields) { |
|||
const fieldForm = new FormGroup({}); |
|||
const fieldDefault = field.defaultValue(); |
|||
|
|||
const createControl = (isOptional: boolean) => { |
|||
if (field.properties.fieldType === 'Array') { |
|||
return new FormArray([], field.createValidators(isOptional)); |
|||
} else { |
|||
return new FormControl(fieldDefault, field.createValidators(isOptional)); |
|||
} |
|||
}; |
|||
|
|||
if (field.isLocalizable) { |
|||
for (let language of this.languages.values) { |
|||
fieldForm.setControl(language.iso2Code, createControl(language.isOptional)); |
|||
} |
|||
} else { |
|||
fieldForm.setControl(fieldInvariant, createControl(false)); |
|||
} |
|||
|
|||
this.form.setControl(field.name, fieldForm); |
|||
} |
|||
|
|||
this.enableContentForm(); |
|||
} |
|||
|
|||
public removeArrayItem(field: RootFieldDto, language: AppLanguageDto, index: number) { |
|||
this.findArrayItemForm(field, language).removeAt(index); |
|||
} |
|||
|
|||
public insertArrayItem(field: RootFieldDto, language: AppLanguageDto) { |
|||
if (field.nested.length > 0) { |
|||
const formControl = this.findArrayItemForm(field, language); |
|||
|
|||
this.addArrayItem(field, language, formControl); |
|||
} |
|||
} |
|||
|
|||
private addArrayItem(field: RootFieldDto, language: AppLanguageDto | null, formControl: FormArray) { |
|||
const formItem = new FormGroup({}); |
|||
|
|||
let isOptional = field.isLocalizable && language !== null && language.isOptional; |
|||
|
|||
for (let nested of field.nested) { |
|||
const nestedDefault = field.defaultValue(); |
|||
|
|||
formItem.setControl(nested.name, new FormControl(nestedDefault, nested.createValidators(isOptional))); |
|||
} |
|||
|
|||
formControl.push(formItem); |
|||
} |
|||
|
|||
private findArrayItemForm(field: RootFieldDto, language: AppLanguageDto): FormArray { |
|||
const fieldForm = this.form.get(field.name)!; |
|||
|
|||
if (field.isLocalizable) { |
|||
return <FormArray>fieldForm.get(language.iso2Code)!; |
|||
} else { |
|||
return <FormArray>fieldForm.get(fieldInvariant); |
|||
} |
|||
} |
|||
|
|||
public submitCompleted(newValue?: any) { |
|||
super.submitCompleted(newValue); |
|||
|
|||
this.enableContentForm(); |
|||
} |
|||
|
|||
public submitFailed(error?: string | ErrorDto) { |
|||
super.submitFailed(error); |
|||
|
|||
this.enableContentForm(); |
|||
} |
|||
|
|||
public loadData(value: any, isArchive: boolean) { |
|||
for (let field of this.schema.fields) { |
|||
if (field.properties.fieldType === 'Array' && field.nested.length > 0) { |
|||
const fieldValue = value ? value[field.name] || {} : {}; |
|||
const fieldForm = <FormGroup>this.form.get(field.name)!; |
|||
|
|||
const addControls = (key: string, language: AppLanguageDto | null) => { |
|||
const languageValue = fieldValue[key]; |
|||
const languageForm = new FormArray([]); |
|||
|
|||
if (Types.isArray(languageValue)) { |
|||
for (let i = 0; i < languageValue.length; i++) { |
|||
this.addArrayItem(field, language, languageForm); |
|||
} |
|||
} |
|||
|
|||
fieldForm.setControl(key, languageForm); |
|||
}; |
|||
|
|||
if (field.isLocalizable) { |
|||
for (let language of this.languages.values) { |
|||
addControls(language.iso2Code, language); |
|||
} |
|||
} else { |
|||
addControls(fieldInvariant, null); |
|||
} |
|||
} |
|||
} |
|||
|
|||
super.load(value); |
|||
|
|||
if (isArchive) { |
|||
this.form.disable(); |
|||
} else { |
|||
this.enableContentForm(); |
|||
} |
|||
} |
|||
|
|||
private enableContentForm() { |
|||
if (this.schema.fields.length === 0) { |
|||
this.form.enable(); |
|||
} else { |
|||
for (const field of this.schema.fields) { |
|||
const fieldForm = this.form.controls[field.name]; |
|||
|
|||
if (field.isDisabled) { |
|||
fieldForm.disable(); |
|||
} else { |
|||
fieldForm.enable(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
export class PatchContentForm extends Form<FormGroup> { |
|||
constructor( |
|||
private readonly schema: SchemaDetailsDto, |
|||
private readonly language: AppLanguageDto |
|||
) { |
|||
super(new FormGroup({})); |
|||
|
|||
for (let field of this.schema.listFields) { |
|||
if (field.properties && field.properties['inlineEditable']) { |
|||
this.form.setControl(field.name, new FormControl(undefined, field.createValidators(this.language.isOptional))); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public submit() { |
|||
const result = super.submit(); |
|||
|
|||
if (result) { |
|||
const request = {}; |
|||
|
|||
for (let field of this.schema.listFields) { |
|||
if (field.properties['inlineEditable']) { |
|||
const value = result[field.name]; |
|||
|
|||
if (field.isLocalizable) { |
|||
request[field.name] = { [this.language.iso2Code]: value }; |
|||
} else { |
|||
request[field.name] = { iv: value }; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return request; |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|||
|
|||
import { Form } from '@app/framework'; |
|||
|
|||
export class AssignContributorForm extends Form<FormGroup> { |
|||
public hasNoUser = |
|||
this.form.controls['user'].valueChanges.startWith(null).map(x => !x); |
|||
|
|||
constructor(formBuilder: FormBuilder) { |
|||
super(formBuilder.group({ |
|||
user: [null, |
|||
[ |
|||
Validators.required |
|||
] |
|||
] |
|||
})); |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|||
|
|||
import { Form } from '@app/framework'; |
|||
|
|||
export class EditLanguageForm extends Form<FormGroup> { |
|||
constructor(formBuilder: FormBuilder) { |
|||
super(formBuilder.group({ |
|||
isMaster: false, |
|||
isOptional: false |
|||
})); |
|||
|
|||
this.form.controls['isMaster'].valueChanges |
|||
.subscribe(value => { |
|||
if (value) { |
|||
this.form.controls['isOptional'].setValue(false); |
|||
} |
|||
}); |
|||
|
|||
this.form.controls['isOptional'].valueChanges |
|||
.subscribe(value => { |
|||
if (value) { |
|||
this.form.controls['isMaster'].setValue(false); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
|
|||
export class AddLanguageForm extends Form<FormGroup> { |
|||
constructor(formBuilder: FormBuilder) { |
|||
super(formBuilder.group({ |
|||
language: [null, |
|||
[ |
|||
Validators.required |
|||
] |
|||
] |
|||
})); |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|||
|
|||
import { Form, ValidatorsEx } from '@app/framework'; |
|||
|
|||
export class EditPatternForm extends Form<FormGroup> { |
|||
constructor(formBuilder: FormBuilder) { |
|||
super(formBuilder.group({ |
|||
name: ['', |
|||
[ |
|||
Validators.required, |
|||
Validators.maxLength(100), |
|||
ValidatorsEx.pattern('[A-z0-9]+[A-z0-9\- ]*[A-z0-9]', 'Name can only contain letters, numbers, dashes and spaces.') |
|||
] |
|||
], |
|||
pattern: ['', |
|||
[ |
|||
Validators.required |
|||
] |
|||
], |
|||
message: ['', |
|||
[ |
|||
Validators.maxLength(1000) |
|||
] |
|||
] |
|||
})); |
|||
} |
|||
} |
|||
@ -0,0 +1,128 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|||
|
|||
import { Form, ValidatorsEx } from '@app/framework'; |
|||
|
|||
import { createProperties } from './../services/schemas.service'; |
|||
|
|||
const FALLBACK_NAME = 'my-schema'; |
|||
|
|||
export class CreateCategoryForm extends Form<FormGroup> { |
|||
constructor(formBuilder: FormBuilder) { |
|||
super(formBuilder.group({ |
|||
name: [''] |
|||
})); |
|||
} |
|||
} |
|||
|
|||
export class CreateSchemaForm extends Form<FormGroup> { |
|||
public schemaName = |
|||
this.form.controls['name'].valueChanges.map(n => n || FALLBACK_NAME) |
|||
.startWith(FALLBACK_NAME); |
|||
|
|||
constructor(formBuilder: FormBuilder) { |
|||
super(formBuilder.group({ |
|||
name: ['', |
|||
[ |
|||
Validators.required, |
|||
Validators.maxLength(40), |
|||
ValidatorsEx.pattern('[a-z0-9]+(\-[a-z0-9]+)*', 'Name can contain lower case letters (a-z), numbers and dashes only (not at the end).') |
|||
] |
|||
], |
|||
import: {} |
|||
})); |
|||
} |
|||
} |
|||
|
|||
export class EditScriptsForm extends Form<FormGroup> { |
|||
constructor(formBuilder: FormBuilder) { |
|||
super(formBuilder.group({ |
|||
scriptQuery: '', |
|||
scriptCreate: '', |
|||
scriptUpdate: '', |
|||
scriptDelete: '', |
|||
scriptChange: '' |
|||
})); |
|||
} |
|||
} |
|||
|
|||
export class EditFieldForm extends Form<FormGroup> { |
|||
constructor(formBuilder: FormBuilder) { |
|||
super(formBuilder.group({ |
|||
label: ['', |
|||
[ |
|||
Validators.maxLength(100) |
|||
] |
|||
], |
|||
hints: ['', |
|||
[ |
|||
Validators.maxLength(1000) |
|||
] |
|||
], |
|||
placeholder: ['', |
|||
[ |
|||
Validators.maxLength(1000) |
|||
] |
|||
], |
|||
editorUrl: null, |
|||
isRequired: false, |
|||
isListField: false |
|||
})); |
|||
} |
|||
} |
|||
|
|||
export class EditSchemaForm extends Form<FormGroup> { |
|||
constructor(formBuilder: FormBuilder) { |
|||
super(formBuilder.group({ |
|||
label: ['', |
|||
[ |
|||
Validators.maxLength(100) |
|||
] |
|||
], |
|||
hints: ['', |
|||
[ |
|||
Validators.maxLength(1000) |
|||
] |
|||
] |
|||
})); |
|||
} |
|||
} |
|||
|
|||
export class AddFieldForm extends Form<FormGroup> { |
|||
constructor(formBuilder: FormBuilder) { |
|||
super(formBuilder.group({ |
|||
type: ['String', |
|||
[ |
|||
Validators.required |
|||
] |
|||
], |
|||
name: ['', |
|||
[ |
|||
Validators.required, |
|||
Validators.maxLength(40), |
|||
ValidatorsEx.pattern('[a-zA-Z0-9]+(\\-[a-zA-Z0-9]+)*', 'Name must be a valid javascript name in camel case.') |
|||
] |
|||
], |
|||
isLocalizable: false |
|||
})); |
|||
} |
|||
|
|||
public submit() { |
|||
const value = super.submit(); |
|||
|
|||
if (value) { |
|||
const properties = createProperties(value.type); |
|||
const partitioning = value.isLocalizable ? 'language' : 'invariant'; |
|||
|
|||
return { name: value.name, partitioning, properties }; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue