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.
 
 
 
 
 

45 lines
1.1 KiB

/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { Pipe, PipeTransform } from '@angular/core';
import { FieldDto } from '@app/shared';
export interface FieldSection<T> {
separator?: T;
fields: ReadonlyArray<T>;
}
@Pipe({
name: 'sqxGroupFields',
pure: true
})
export class GroupFieldsPipe<T extends FieldDto> implements PipeTransform {
public transform(fields: ReadonlyArray<T>) {
const sections: FieldSection<T>[] = [];
let currentSeparator: T | undefined = undefined;
let currentFields: T[] = [];
for (const field of fields) {
if (field.properties.isContentField) {
currentFields.push(field);
} else {
sections.push({ separator: currentSeparator, fields: currentFields });
currentFields = [];
currentSeparator = field;
}
}
if (currentFields.length > 0) {
sections.push({ separator: currentSeparator, fields: currentFields });
}
return sections;
}
}