core-cde
Version:
124 lines • 3.72 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataColumn = void 0;
// import { IWithId, UUID } from '../../stateChanger/StateChanger.module';
const Data_module_1 = require("../Data.module");
const short_uuid_1 = require("short-uuid");
/**
* Класс колонки данных
*/
class DataColumn {
/** Конструктор
* Не предназначен для использования внешним кодом.
* Следует использовать DataColumn.createNew()
*/
constructor() {
this._MIN_WIDTH_COLUMN = 200;
this.id = (0, short_uuid_1.generate)();
this._width = this._MIN_WIDTH_COLUMN;
}
static createNew(name, dataType) {
if (typeof dataType === 'undefined') {
dataType = Data_module_1.DataType.String;
}
const res = new DataColumn();
res._dataType = dataType;
res._name = name;
return res;
}
static fromJSON(json) {
if (typeof json === 'string') {
return DataColumn.fromJSON(JSON.parse(json));
}
else {
const dataColumn = new DataColumn();
return Object.assign(dataColumn, null, {
_name: json.name,
_index: json.index,
_dataType: json.dataType,
_width: json.width,
id: json.id
});
}
}
toJSON() {
return Object.assign({}, null, {
dataType: this._dataType,
name: this._name,
// index: this._index,
with: this._width,
id: this.id
});
}
/**
* Ширина колонки
*/
get width() {
return this._width;
}
set width(value) {
if (!value) {
value = this._MIN_WIDTH_COLUMN;
}
this._width = value;
}
/**
* Индекс колонки в коллекции
*/
get index() {
return this._index;
}
set index(value) {
this._index = value;
this._symbol = Data_module_1.SYSMBOLS[this._index];
}
/**
* Символический индекс колонки в коллекции (A, B, и т.д.)
*/
get symbol() {
return this._symbol;
}
/**
* Задает коллекцию, в которой находится колонка
* @param columnCollection Коллекция
*/
setCollection(columnCollection) {
this._columnCollection = columnCollection;
}
/**
* Возвращает тип данных колонки
*/
get dataType() {
return this._dataType;
}
/**
* Задает тип данных колонки
*/
set dataType(value) {
if (this._dataType !== value) {
this._dataType = value;
}
}
/**
* Возвращает имя колонки
*/
get name() {
return this._name;
}
/**
* Задает имя колонки
*/
set name(value) {
var _a;
if (this._name !== value) {
if (this._columnCollection !== null) {
if (typeof ((_a = this._columnCollection) === null || _a === void 0 ? void 0 : _a.getByName(value)) !== 'undefined') {
throw new Error(`Колонка с именем ${value} уже существует`);
}
}
this._name = value;
}
}
}
exports.DataColumn = DataColumn;
//# sourceMappingURL=DataColumn.js.map