@netgrif/components-core
Version:
Netgrif Application engine frontend core Angular library
146 lines (145 loc) • 7.12 kB
TypeScript
import { DatafieldGridLayoutElement } from './datafield-grid-layout-element';
import { IncrementingCounter } from '../../utility/incrementing-counter';
import { DataField } from '../../data-fields/models/abstract-data-field';
import { FieldTypeResource } from './field-type-resource';
import { DataGroup } from '../../resources/interface/data-groups';
import { BehaviorSubject } from 'rxjs';
import { AsyncRenderingConfiguration } from './async-rendering-configuration';
/**
* A configuration for one subgrid - a basic layouting unit
*/
export declare class Subgrid {
subgridId: string;
cols: number;
protected _asyncRenderingConfig: AsyncRenderingConfiguration;
/**
* the css `gridAreas` configuration, that determines the layout of the grids content
*/
gridAreas: string;
/**
* The elements that are contained in the subgrid
*/
protected _content: Array<DatafieldGridLayoutElement>;
/**
* The elements that are contained in the subgrid and have already been rendered to the user
*/
protected _renderedContent$: BehaviorSubject<Array<DatafieldGridLayoutElement>>;
/**
* A 2D representation of the grid element IDs
*/
protected _grid: Array<Array<string>>;
/**
* Counter to assure element ID uniqueness
*/
protected _runningTitleCount: IncrementingCounter;
/**
* Grid area identifiers that are already in use
*/
protected _existingIdentifiers: Set<string>;
protected _asyncRenderingTimeout: number;
protected _keptElements: Array<DatafieldGridLayoutElement>;
protected _newElements: Array<DatafieldGridLayoutElement>;
/**
* @param subgridId a unique identifier of the subgrid in the task layout
* @param cols Number of columns of the subgrid
* @param _asyncRenderingConfig configuration object for async rendering of data fields
*/
constructor(subgridId: string, cols: number, _asyncRenderingConfig: AsyncRenderingConfiguration);
get content(): Array<DatafieldGridLayoutElement>;
/**
* Completes the underlying stream and clears any running timeouts
*/
destroy(): void;
/**
* @returns the columns configuration for the grid layout
*/
getGridColumns(): string;
getRunningTitleCount(): IncrementingCounter;
/**
* Converts a {@link DataField} into a {@link DatafieldGridLayoutElement} and adds it to the content of this subgrid.
*
* Beware that this method DOES NOT add the element into the resulting grid. This must be done independently by calling the
* [addRow]{@link Subgrid#addRow} method.
* @param field the field that should be added to the subgrid
* @param type the type of the field
* @returns the created grid element
*/
addField(field: DataField<unknown>, type: FieldTypeResource): DatafieldGridLayoutElement;
/**
* Converts a {@link DataGroup} into a {@link DatafieldGridLayoutElement} and adds it to the content of this subgrid.
*
* Beware that this method DOES NOT add the element into the resulting grid. This must be done independently by calling the
* [addRow]{@link Subgrid#addRow} method.
* @param dataGroup the data group whose title should be added to the grid
* @returns the created grid element
*/
addTitle(dataGroup: DataGroup): DatafieldGridLayoutElement;
protected addElement(element: DatafieldGridLayoutElement): void;
/**
* Adds a row of CSS `gridAreaId`s into the grid that is held in this subgrid.
* @param row the field Ids. The width of the row should match the number of columns of the grid. If not an error is thrown.
*/
addRow(row: Array<string>): void;
/**
* Converts the provided configuration into data that can be fed into CSS grid layout
*/
finalize(): void;
/**
* Fills empty tiles in the grid with blank elements
*/
protected fillEmptySpace(): void;
/**
* @param field the field whose representation should be created
* @param type the type of the data field
* @returns an object that represents the provided data field in the layout
*/
protected fieldElement(field: DataField<unknown>, type: FieldTypeResource): DatafieldGridLayoutElement;
/**
* @param fillerCounter the counter that is used to track the number of already created filler elements
* @returns a filler element object with a unique ID. The provided counter is incremented by one.
*/
protected fillerElement(fillerCounter: IncrementingCounter): DatafieldGridLayoutElement;
/**
* @param dataGroup the data group whose title element should be created
* @returns an object that represents a title element of the provided data group. The provided counter is incremented by one.
*/
protected groupTitleElement(dataGroup: DataGroup): DatafieldGridLayoutElement;
/**
* Assures that the provided identifier will be unique.
* @param identifier the base for the identifier
* @returns the base identifier, if it already is unique. A unique variation on the base identifier if it is already in use.
*/
protected assureUniqueness(identifier: string): string;
/**
* Joins the grid of element into a string accepted by `[gdAreas]` input property of Angular flex layout
*/
protected createGridAreasString(): void;
/**
* Marks all contained elements as kept and displays them.
*/
displayAllFields(): void;
/**
* Determines which elements from the provided subgrid are contained in this subgrid.
* Marks these elements as kept and displays them. Marks the remaining elements as new.
*
* New elements can be displayed asynchronously over time by calling the
* [renderContentOverTime]{@link Subgrid#renderContentOverTime} method.
* @param subgrid the "previous" subgrid that is used to compute the element "difference"
*/
determineKeptFields(subgrid: Subgrid): void;
/**
* If elements are not sorted into new and kept, marks all elements as new.
* The [determineKeptFields]{@link Subgrid#determineKeptFields} method can be used to mark elements as kept.
*
* Then pushes the new elements with the kept elements into the output array over time as specified by the
* {@link AsyncRenderingConfiguration} provided in the subgrids constructor.
*
* @param callback the function that is called once all new elements were pushed into the output array
* @param first whether this is the first subgrid that si rendered. If this is the first subgrid then on the initial rendering of
* elements a batch of new fields alongside the loader elements is displayed so that some content is immediately available.
* Otherwise The initial batch contains only loader elements. Being first effectively shortens the rendering by one batch, since the
* first loader-only batch is skipped.
*/
renderContentOverTime(callback: () => void, first?: boolean): void;
protected spreadFieldRenderingOverTime(callback: () => void, iteration?: number): void;
}