mirror of https://github.com/Squidex/squidex.git
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.
111 lines
3.1 KiB
111 lines
3.1 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { CdkDragDrop, CdkDragStart } from '@angular/cdk/drag-drop';
|
|
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Output } from '@angular/core';
|
|
import { fadeAnimation, LocalStoreService, SchemaCategory, SchemaDto, SchemasState } from '@app/shared/internal';
|
|
|
|
const ITEM_HEIGHT = 2.5;
|
|
|
|
@Component({
|
|
selector: 'sqx-schema-category[schemaCategory]',
|
|
styleUrls: ['./schema-category.component.scss'],
|
|
templateUrl: './schema-category.component.html',
|
|
animations: [
|
|
fadeAnimation,
|
|
],
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
})
|
|
export class SchemaCategoryComponent implements OnChanges {
|
|
@Output()
|
|
public remove = new EventEmitter<string>();
|
|
|
|
@Input()
|
|
public schemaCategory: SchemaCategory;
|
|
|
|
@Input()
|
|
public forContent?: boolean | null;
|
|
|
|
public isCollapsed = false;
|
|
|
|
public visibleCount = 0;
|
|
|
|
public get schemas() {
|
|
return this.schemaCategory.schemas;
|
|
}
|
|
|
|
constructor(
|
|
private readonly localStore: LocalStoreService,
|
|
private readonly schemasState: SchemasState,
|
|
) {
|
|
}
|
|
|
|
public toggle() {
|
|
this.isCollapsed = !this.isCollapsed;
|
|
|
|
this.localStore.setBoolean(this.configKey(), this.isCollapsed);
|
|
}
|
|
|
|
public ngOnChanges() {
|
|
this.visibleCount = this.getCount(this.schemaCategory);
|
|
if (this.schemaCategory.schemas.length < this.schemaCategory.schemaTotalCount) {
|
|
this.isCollapsed = false;
|
|
} else {
|
|
this.isCollapsed = this.localStore.getBoolean(this.configKey());
|
|
}
|
|
}
|
|
|
|
private getCount(category: SchemaCategory): number {
|
|
const childCount = category.categories.reduce((total, child) => total + this.getCount(child), 0);
|
|
return childCount + category.schemas.length;
|
|
}
|
|
|
|
public schemaRoute(schema: SchemaDto) {
|
|
if (schema.type === 'Singleton' && this.forContent) {
|
|
return [schema.name, schema.id, 'history'];
|
|
} else {
|
|
return [schema.name];
|
|
}
|
|
}
|
|
|
|
public changeCategory(drag: CdkDragDrop<any>) {
|
|
if (drag.previousContainer !== drag.container) {
|
|
this.schemasState.changeCategory(drag.item.data, this.schemaCategory.name);
|
|
}
|
|
}
|
|
|
|
public dragStarted(event: CdkDragStart) {
|
|
setTimeout(() => {
|
|
const dropContainer = event.source._dragRef['_dropContainer'];
|
|
|
|
if (dropContainer) {
|
|
dropContainer['_cacheOwnPosition']();
|
|
dropContainer['_cacheItemPositions']();
|
|
}
|
|
});
|
|
}
|
|
|
|
public getItemHeight() {
|
|
return `${ITEM_HEIGHT}rem`;
|
|
}
|
|
|
|
public getContainerHeight() {
|
|
return `${ITEM_HEIGHT * this.schemas.length}rem`;
|
|
}
|
|
|
|
public trackBySchema(_index: number, schema: SchemaDto) {
|
|
return schema.id;
|
|
}
|
|
|
|
public trackByCategory(_index: number, category: SchemaCategory) {
|
|
return category.name;
|
|
}
|
|
|
|
private configKey(): string {
|
|
return `squidex.schema.category.${this.schemaCategory.name}.collapsed`;
|
|
}
|
|
}
|
|
|