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.
 
 
 
 
 

89 lines
2.6 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 { Observable } from 'rxjs';
import { AppLanguageDto, ComponentFieldPropertiesDto, ComponentForm, disabled$, EditContentForm, FieldDto, FieldSection, ModalModel, ResourceOwner, SchemaDto, Types } from '@app/shared';
import { ComponentSectionComponent } from './component-section.component';
@Component({
selector: 'sqx-component[form][formContext][formLevel][formModel][isComparing][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 isComparing = false;
@Input()
public language!: AppLanguageDto;
@Input()
public languages!: ReadonlyArray<AppLanguageDto>;
@ViewChildren(ComponentSectionComponent)
public sections!: QueryList<ComponentSectionComponent>;
public schemasDropdown = new ModalModel();
public schemasList: ReadonlyArray<SchemaDto> = [];
public isDisabled?: Observable<boolean>;
constructor(
private readonly changeDetector: ChangeDetectorRef,
) {
super();
}
public ngOnChanges(changes: SimpleChanges) {
if (changes['formModel']) {
this.unsubscribeAll();
this.isDisabled = disabled$(this.formModel.form);
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]).defined() || [];
}
}
}
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;
}
}