Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

81 lines
2.4 KiB

/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnChanges, QueryList, SimpleChanges, ViewChildren } from '@angular/core';
import { AppLanguageDto, ComponentFieldPropertiesDto, ComponentForm, EditContentForm, FieldDto, FieldSection, ModalModel, ResourceOwner, SchemaDto, Types } from '@app/shared';
import { ComponentSectionComponent } from './component-section.component';
@Component({
selector: 'sqx-component[form][formContext][formLevel][formModel][language][languages]',
styleUrls: ['./component.component.scss'],
templateUrl: './component.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ComponentComponent extends ResourceOwner implements OnChanges {
@Input()
public canUnset?: boolean | null;
@Input()
public form!: EditContentForm;
@Input()
public formContext!: any;
@Input()
public formLevel!: number;
@Input()
public formModel!: ComponentForm;
@Input()
public language!: AppLanguageDto;
@Input()
public languages!: ReadonlyArray<AppLanguageDto>;
@ViewChildren(ComponentSectionComponent)
public sections!: QueryList<ComponentSectionComponent>;
public schemasDropdown = new ModalModel();
public schemasList: ReadonlyArray<SchemaDto> = [];
constructor(
private readonly changeDetector: ChangeDetectorRef,
) {
super();
}
public ngOnChanges(changes: SimpleChanges) {
if (changes['formModel']) {
this.unsubscribeAll();
this.own(
this.formModel.form.valueChanges
.subscribe(() => {
this.changeDetector.detectChanges();
}));
if (Types.is(this.formModel.field.properties, ComponentFieldPropertiesDto)) {
this.schemasList = this.formModel.field.properties.schemaIds?.map(x => this.formModel.globals.schemas[x]).filter(x => !!x) || [];
}
}
}
public reset() {
this.sections.forEach(section => {
section.reset();
});
}
public setSchema(schema: SchemaDto) {
this.formModel.selectSchema(schema.id);
}
public trackBySection(_index: number, section: FieldSection<FieldDto, any>) {
return section.separator?.fieldId;
}
}