core-cde
Version:
116 lines • 4.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TableWidget = void 0;
const tslib_1 = require("tslib");
const BaseWidget_1 = require("../BaseWidget");
const Errors_1 = require("../Errors");
const DM = (0, tslib_1.__importStar)(require("../../../data/Data.module"));
/**
* Описательный класс таблицы
*/
class TableWidget extends BaseWidget_1.BaseWidget {
constructor(type, id) {
super(type, id);
}
/**
* Получить объект класса TableWidget из json
* @param json валидная json строка
* @returns объект класса TableWidget
*/
static fromJSON(json, ds) {
if (!json) {
throw new Errors_1.EmptyParametersError('Table.fromJSON()');
}
try {
const twJSON = JSON.parse(json);
if (twJSON.tableJson) {
const dt = DM.DataTable.fromJSON(twJSON.tableJson);
ds.addTable(dt);
}
const tw = Object.assign(new TableWidget(null, null), twJSON);
if (twJSON.viewTableJson) {
tw.viewTable = DM.DataView.fromJSON(twJSON.viewTableJson);
}
if (twJSON.idTable) {
const table = ds.getTableById(twJSON.idTable);
tw.viewTable.table = table;
}
return tw;
}
catch (error) {
throw new Errors_1.JsonParseError('TableWidget');
}
}
/**
* Получить объект для сериализации
* @returns Объект для сериализации
*/
toJSON() {
var _a, _b, _c;
return Object.assign({}, null, {
id: this.id,
type: this.type,
originalPerformance: this.originalPerformance,
idTable: (_b = (_a = this.viewTable) === null || _a === void 0 ? void 0 : _a.table) === null || _b === void 0 ? void 0 : _b.id,
viewTableJson: this.viewTable ? JSON.stringify(this.viewTable) : null,
tableJson: this.originalPerformance ? JSON.stringify((_c = this === null || this === void 0 ? void 0 : this.viewTable) === null || _c === void 0 ? void 0 : _c.table) : null,
});
}
/**
* Получить название шаблона по типу опирации и фильтра
* @param filterOperation фильтр
* @returns Название шаблона
*/
getTemplateByOperationFilter(filterOperation) {
if (!filterOperation) {
throw new Errors_1.EmptyParametersError('getTemplateByOperationFilter');
}
switch (filterOperation.columnType) {
case DM.DataType.Number:
switch (filterOperation.operation) {
case DM.FilterOperation.Between:
case DM.FilterOperation.NotBetween:
return 'rangeValue';
case DM.FilterOperation.Equal:
case DM.FilterOperation.NotEqual:
case DM.FilterOperation.Greate:
case DM.FilterOperation.Less:
return 'inputValue';
}
case DM.DataType.String: {
switch (filterOperation.operation) {
case DM.FilterOperation.Contains:
case DM.FilterOperation.NotContains:
case DM.FilterOperation.Equal:
case DM.FilterOperation.NotEqual:
case DM.FilterOperation.StartWith:
return 'inputValue';
}
break;
}
case DM.DataType.Date:
switch (filterOperation.operation) {
case DM.FilterOperation.Before:
case DM.FilterOperation.After:
case DM.FilterOperation.Equal:
case DM.FilterOperation.NotEqual:
return 'dateValue';
}
break;
case DM.DataType.Select: {
return 'selectValue';
}
case DM.DataType.Boolean:
switch (filterOperation.operation) {
case DM.FilterOperation.Equal:
case DM.FilterOperation.NotEqual:
return 'boolValue';
}
break;
default:
return null;
}
}
}
exports.TableWidget = TableWidget;
//# sourceMappingURL=Table.js.map