import { Record, SelectionMode } from "./interfaces/dataUnit.js"; import { Filter, Sort } from "./metadata/UnitMetadata.js"; export class SelectionInfo { public mode: SelectionMode; public filters?: Array; public sort?: Array; public getAllRecords?: () => Array; private _records: Array; private _total?: number; constructor(records: Array, mode: SelectionMode = SelectionMode.SOME_RECORDS, total?: number, filters?: Array, sort?: Array) { this._records = records; this._total = total; this.mode = mode; this.filters = filters; this.sort = sort; } public get records(): Array { if (this.isAllRecords()) { if (this.getAllRecords != undefined) { return this.getAllRecords(); } throw new Error("Erro interno: Impossível retornar os registros selecionados numa seleção virtual."); } return this._records; } public get recordIds(): Array | undefined { const records = this.records; if (records == undefined) { return undefined; } return records.map(record => record.__record__id__); } public get length(): number { if (this.isAllRecords()) { return this._total || 0; } return this.records == undefined ? 0 : (this.records as Array).length; } public isAllRecords(): boolean { return this.mode === SelectionMode.ALL_RECORDS; } public isEmpty(): boolean { return this.length === 0; } }