UNPKG

core-cde

Version:

137 lines 4.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DataRowStateChangedArg = exports.DataRow = void 0; const StringBuilder_1 = require("typescript-dotnet-commonjs/System/Text/StringBuilder"); const Events_module_1 = require("../../events/Events.module"); const Data_module_1 = require("../Data.module"); const StateChanger_module_1 = require("../../stateChanger/StateChanger.module"); /** * Класс строки данных */ class DataRow { constructor() { this._state = Data_module_1.DataRowState.Unchanged; this._onDataRowStateChanged = new Events_module_1.EventDispatcher(); this.id = StateChanger_module_1.UUID.get(); this._items = new Array(); } /** * Индекс строки */ get index() { return this._index; } set index(value) { this._index = value; } static createNew(table, items) { const res = new DataRow(); res._table = table; if (items === undefined) { res._items = new Array(table.columnsCount); res._sheetItems = new Array(table.columnsCount); } else { res.setItems(items); } return res; } static fromJSON(json) { if (typeof json === 'string') { return DataRow.fromJSON(JSON.parse(json)); } else { const dataRow = Object.create(DataRow.prototype); return Object.assign(dataRow, json, {}); } } toJSON() { const items = new Array(); this.items.forEach((value, index) => { var _a; items.push({ guidColumn: this._table.getColumnByIndex(index).id, value, guidRow: ((_a = this._table.rowCollection.get(index)) === null || _a === void 0 ? void 0 : _a.id) || null }); }); return Object.assign({}, null, { items, index: this.index, id: this.id }); } setItems(values) { if (values.length !== this._table.columnsCount) { throw new Error('The length of the value array is not equal to the length of the column array'); } this._items = values; this._sheetItems = new Array(this._table.columnsCount); } /** Не предназначен для использования внешним кодом */ silentSetItems(values) { this._items = values; this._sheetItems = new Array(values.length); } /** * Событие изменения состояния строки */ get onDataRowStateChanged() { return this._onDataRowStateChanged; } /** * Возврвщает массив оригинальных элементов строки */ get items() { return this._items; } /** * Возврвщает массив рассчитанных элементов строки */ get sheetItems() { return this._sheetItems; } /** * Задает массив рассчитанных элементов строки */ set sheetItems(value) { this._sheetItems = value; } /** * Возвращает признак состояния строки */ get state() { return this._state; } /** * Задает признак состояния записи */ set state(value) { if (this._state !== value) { if ((this._state === Data_module_1.DataRowState.Added) && (value === Data_module_1.DataRowState.Modified)) { return; } this._state = value; this._onDataRowStateChanged.dispatch(new DataRowStateChangedArg(this._state)); } } toString() { const sb = new StringBuilder_1.StringBuilder(); // tslint:disable-next-line: prefer-for-of for (let i = 0; i < this._items.length; i++) { if (!sb.isEmpty) { sb.append(', '); } sb.append(`[${this._items[i]}]`); } return sb.toString(); } } exports.DataRow = DataRow; class DataRowStateChangedArg { constructor(newState) { this.newState = newState; } } exports.DataRowStateChangedArg = DataRowStateChangedArg; //# sourceMappingURL=DataRow.js.map