Browse Source

Persist collapsed for array editor.

pull/771/head
Sebastian 4 years ago
parent
commit
4dc0783e1e
  1. 6
      frontend/app/features/content/pages/content/editor/content-section.component.ts
  2. 2
      frontend/app/features/content/shared/forms/array-editor.component.html
  3. 18
      frontend/app/features/content/shared/forms/array-editor.component.ts
  4. 11
      frontend/app/features/content/shared/forms/array-item.component.ts
  5. 7
      frontend/app/shared/state/contents.forms.ts

6
frontend/app/features/content/pages/content/editor/content-section.component.ts

@ -56,14 +56,14 @@ export class ContentSectionComponent extends StatefulComponent<State> implements
this.changes.subscribe(state => { this.changes.subscribe(state => {
if (this.formSection?.separator && this.schema) { if (this.formSection?.separator && this.schema) {
this.localStore.setBoolean(this.configKey(), state.isCollapsed); this.localStore.setBoolean(this.expandedKey(), state.isCollapsed);
} }
}); });
} }
public ngOnChanges() { public ngOnChanges() {
if (this.formSection?.separator && this.schema) { if (this.formSection?.separator && this.schema) {
const isCollapsed = this.localStore.getBoolean(this.configKey()); const isCollapsed = this.localStore.getBoolean(this.expandedKey());
this.next({ isCollapsed }); this.next({ isCollapsed });
} }
@ -84,7 +84,7 @@ export class ContentSectionComponent extends StatefulComponent<State> implements
return formState.field.fieldId; return formState.field.fieldId;
} }
private configKey(): string { private expandedKey(): string {
return Settings.Local.FIELD_COLLAPSED(this.schema?.id, this.formSection?.separator?.fieldId); return Settings.Local.FIELD_COLLAPSED(this.schema?.id, this.formSection?.separator?.fieldId);
} }
} }

2
frontend/app/features/content/shared/forms/array-editor.component.html

@ -14,6 +14,7 @@
[formContext]="formContext" [formContext]="formContext"
[formModel]="itemForm" [formModel]="itemForm"
[index]="i" [index]="i"
[isCollapsedInitial]="isCollapsedInitial"
[isDisabled]="isDisabled | async" [isDisabled]="isDisabled | async"
[isFirst]="isFirst" [isFirst]="isFirst"
[isLast]="isLast" [isLast]="isLast"
@ -35,6 +36,7 @@
[formContext]="formContext" [formContext]="formContext"
[formModel]="itemForm" [formModel]="itemForm"
[index]="i" [index]="i"
[isCollapsedInitial]="isCollapsedInitial"
[isDisabled]="isDisabled | async" [isDisabled]="isDisabled | async"
[isFirst]="isFirst" [isFirst]="isFirst"
[isLast]="isLast" [isLast]="isLast"

18
frontend/app/features/content/shared/forms/array-editor.component.ts

@ -7,7 +7,7 @@
import { CdkDragDrop } from '@angular/cdk/drag-drop'; import { CdkDragDrop } from '@angular/cdk/drag-drop';
import { ChangeDetectionStrategy, Component, Input, OnChanges, QueryList, SimpleChanges, ViewChildren } from '@angular/core'; import { ChangeDetectionStrategy, Component, Input, OnChanges, QueryList, SimpleChanges, ViewChildren } from '@angular/core';
import { AppLanguageDto, ComponentsFieldPropertiesDto, disabled$, EditContentForm, fadeAnimation, FieldArrayForm, ModalModel, ObjectForm, SchemaDto, sorted, Types } from '@app/shared'; import { AppLanguageDto, ComponentsFieldPropertiesDto, disabled$, EditContentForm, fadeAnimation, FieldArrayForm, LocalStoreService, ModalModel, ObjectForm, SchemaDto, Settings, sorted, Types } from '@app/shared';
import { combineLatest, Observable } from 'rxjs'; import { combineLatest, Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { ArrayItemComponent } from './array-item.component'; import { ArrayItemComponent } from './array-item.component';
@ -49,6 +49,7 @@ export class ArrayEditorComponent implements OnChanges {
public schemasList: ReadonlyArray<SchemaDto>; public schemasList: ReadonlyArray<SchemaDto>;
public isDisabled: Observable<boolean>; public isDisabled: Observable<boolean>;
public isCollapsedInitial = false;
public isFull: Observable<boolean>; public isFull: Observable<boolean>;
@ -56,6 +57,11 @@ export class ArrayEditorComponent implements OnChanges {
return this.formModel.field['nested']?.length > 0; return this.formModel.field['nested']?.length > 0;
} }
constructor(
private readonly localStore: LocalStoreService,
) {
}
public ngOnChanges(changes: SimpleChanges) { public ngOnChanges(changes: SimpleChanges) {
if (changes['formModel']) { if (changes['formModel']) {
const maxItems = this.formModel.field.properties['maxItems'] || Number.MAX_VALUE; const maxItems = this.formModel.field.properties['maxItems'] || Number.MAX_VALUE;
@ -74,6 +80,8 @@ export class ArrayEditorComponent implements OnChanges {
]).pipe(map(([disabled, items]) => { ]).pipe(map(([disabled, items]) => {
return disabled || items.length >= maxItems; return disabled || items.length >= maxItems;
})); }));
this.isCollapsedInitial = this.localStore.getBoolean(this.expandedKey());
} }
} }
@ -113,12 +121,16 @@ export class ArrayEditorComponent implements OnChanges {
this.children.forEach(child => { this.children.forEach(child => {
child.collapse(); child.collapse();
}); });
this.localStore.setBoolean(this.expandedKey(), true);
} }
public expandAll() { public expandAll() {
this.children.forEach(child => { this.children.forEach(child => {
child.expand(); child.expand();
}); });
this.localStore.setBoolean(this.expandedKey(), false);
} }
private reset() { private reset() {
@ -126,4 +138,8 @@ export class ArrayEditorComponent implements OnChanges {
child.reset(); child.reset();
}); });
} }
private expandedKey(): string {
return Settings.Local.FIELD_COLLAPSED(this.form.schema?.id, this.formModel.field?.fieldId);
}
} }

11
frontend/app/features/content/shared/forms/array-item.component.ts

@ -5,7 +5,7 @@
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. * Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/ */
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, Output, QueryList, SimpleChanges, ViewChildren } from '@angular/core'; import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, OnInit, Output, QueryList, SimpleChanges, ViewChildren } from '@angular/core';
import { AppLanguageDto, ComponentForm, EditContentForm, FieldDto, FieldFormatter, FieldSection, invalid$, ObjectForm, RootFieldDto, StatefulComponent, Types, value$ } from '@app/shared'; import { AppLanguageDto, ComponentForm, EditContentForm, FieldDto, FieldFormatter, FieldSection, invalid$, ObjectForm, RootFieldDto, StatefulComponent, Types, value$ } from '@app/shared';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
@ -22,7 +22,7 @@ interface State {
templateUrl: './array-item.component.html', templateUrl: './array-item.component.html',
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
}) })
export class ArrayItemComponent extends StatefulComponent<State> implements OnChanges { export class ArrayItemComponent extends StatefulComponent<State> implements OnChanges, OnInit {
@Output() @Output()
public itemRemove = new EventEmitter(); public itemRemove = new EventEmitter();
@ -44,6 +44,9 @@ export class ArrayItemComponent extends StatefulComponent<State> implements OnCh
@Input() @Input()
public canUnset?: boolean | null; public canUnset?: boolean | null;
@Input()
public isCollapsedInitial = false;
@Input() @Input()
public isFirst?: boolean | null; public isFirst?: boolean | null;
@ -77,6 +80,10 @@ export class ArrayItemComponent extends StatefulComponent<State> implements OnCh
}); });
} }
public ngOnInit() {
this.next({ isCollapsed: this.isCollapsedInitial });
}
public ngOnChanges(changes: SimpleChanges) { public ngOnChanges(changes: SimpleChanges) {
if (changes['formModel']) { if (changes['formModel']) {
this.isInvalid = invalid$(this.formModel.form); this.isInvalid = invalid$(this.formModel.form);

7
frontend/app/shared/state/contents.forms.ts

@ -86,8 +86,11 @@ export class EditContentForm extends Form<FormGroup, any> {
return this.valueChange$.value; return this.valueChange$.value;
} }
constructor(languages: ReadonlyArray<AppLanguageDto>, schema: SchemaDto, schemas: { [id: string ]: SchemaDto }, constructor(
private context: any, debounce = 100, public readonly languages: ReadonlyArray<AppLanguageDto>,
public readonly schema: SchemaDto, schemas: { [id: string ]: SchemaDto },
public context: any,
debounce = 100,
) { ) {
super(new FormGroup({})); super(new FormGroup({}));

Loading…
Cancel
Save