@wcardinal/wcardinal-geditor
Version:
WebGL-based graphic editor, tester and viewer for supervisory systems
353 lines • 11.7 kB
JavaScript
import { __extends } from "tslib";
import { DDialogLayered, DInputTextAndLabel, DLayoutSpace, DTable, EShapeDataMapperImpl, EShapeDataValueImpl, EShapeDataValueScope } from "@wcardinal/wcardinal-ui";
var EDialogDataMappingValue = /** @class */ (function (_super) {
__extends(EDialogDataMappingValue, _super);
function EDialogDataMappingValue() {
return _super !== null && _super.apply(this, arguments) || this;
}
EDialogDataMappingValue.prototype.newContentChildren = function (theme, options) {
var result = _super.prototype.newContentChildren.call(this, theme, options);
result.push(this.inputSource, this.inputDestination, this.inputInitial, new DLayoutSpace({
height: 6
}), this.table);
return result;
};
Object.defineProperty(EDialogDataMappingValue.prototype, "inputSource", {
get: function () {
var result = this._inputSource;
if (result == null) {
result = this.newInputSource();
this._inputSource = result;
}
return result;
},
enumerable: false,
configurable: true
});
EDialogDataMappingValue.prototype.newInputSource = function () {
var _this = this;
return new DInputTextAndLabel({
width: "padding",
height: "auto",
input: {
weight: 1,
on: {
input: function (value) {
_this.onInputSourceChanged(value);
},
enter: function () {
_this.ok();
}
}
},
label: {
width: 60,
text: {
value: this.theme.getInputSourceLabel()
}
},
space: {
width: 60
}
});
};
EDialogDataMappingValue.prototype.onInputSourceChanged = function (value) {
this._newSource = value;
this.updateRows();
};
Object.defineProperty(EDialogDataMappingValue.prototype, "inputDestination", {
get: function () {
var result = this._inputDestination;
if (result == null) {
result = this.newInputDestination();
this._inputDestination = result;
}
return result;
},
enumerable: false,
configurable: true
});
EDialogDataMappingValue.prototype.newInputDestination = function () {
var _this = this;
return new DInputTextAndLabel({
width: "padding",
height: "auto",
input: {
weight: 1,
text: {
value: ""
},
on: {
input: function (value) {
_this.onInputDestinationChanged(value);
},
enter: function () {
_this.ok();
}
}
},
label: {
width: 60,
text: {
value: this.theme.getInputDestinationLabel()
}
},
space: {
width: 60
}
});
};
EDialogDataMappingValue.prototype.onInputDestinationChanged = function (value) {
this._newDestination = value;
this.updateRows();
};
Object.defineProperty(EDialogDataMappingValue.prototype, "inputInitial", {
get: function () {
var result = this._inputInitial;
if (result == null) {
result = this.newInputInitial();
this._inputInitial = result;
}
return result;
},
enumerable: false,
configurable: true
});
EDialogDataMappingValue.prototype.newInputInitial = function () {
var _this = this;
return new DInputTextAndLabel({
width: "padding",
height: "auto",
input: {
weight: 1,
text: {
value: ""
},
on: {
enter: function () {
_this.ok();
}
}
},
label: {
width: 60,
text: {
value: this.theme.getInputInitialLabel()
}
},
space: {
width: 60
}
});
};
Object.defineProperty(EDialogDataMappingValue.prototype, "table", {
get: function () {
var result = this._table;
if (result == null) {
result = this.newTable();
this._table = result;
}
return result;
},
enumerable: false,
configurable: true
});
EDialogDataMappingValue.prototype.newTable = function () {
return new DTable({
width: "padding",
height: 300,
columns: this.newColumnOptions()
});
};
EDialogDataMappingValue.prototype.newColumnOptions = function () {
var theme = this.theme;
return [
{
type: "TEXT",
label: theme.getTableColumnDataIdLabel(),
editable: false,
sortable: true,
getter: function (row) {
return row.id;
}
},
{
type: "TEXT",
label: theme.getTableColumnMappedToLabel(),
editable: false,
sortable: true,
getter: function (row) {
return row.mappedId;
}
}
];
};
EDialogDataMappingValue.prototype.set = function (value, shape) {
var isChanged = false;
if (value !== undefined) {
if (value != null) {
this.inputSource.input.value = value[0];
this.inputDestination.input.value = value[1];
this.inputInitial.input.value = value[2];
this._newSource = value[0];
this._newDestination = value[1];
}
else {
this.inputSource.input.value = "";
this.inputDestination.input.value = "";
this.inputInitial.input.value = "";
this._newSource = "";
this._newDestination = "";
}
isChanged = true;
}
if (shape !== undefined) {
this._ids = this.toIds(shape);
isChanged = true;
}
if (isChanged) {
this.updateRows();
}
return this;
};
Object.defineProperty(EDialogDataMappingValue.prototype, "value", {
get: function () {
return [
this.inputSource.input.value.trim(),
this.inputDestination.input.value.trim(),
this.inputInitial.input.value.trim()
];
},
set: function (value) {
this.set(value);
},
enumerable: false,
configurable: true
});
EDialogDataMappingValue.prototype.getResolvedValue = function () {
return this.value;
};
EDialogDataMappingValue.prototype.toIds = function (shape) {
var result = [];
if (shape != null) {
var ids = new Set();
this.newIds(shape.children, ids);
ids.forEach(function (id) {
result.push(id);
});
result.sort();
}
return result;
};
EDialogDataMappingValue.prototype.newIds = function (shapes, result) {
for (var i = 0, imax = shapes.length; i < imax; ++i) {
var shape = shapes[i];
var data = shape.data;
for (var j = 0, jmax = data.size(); j < jmax; ++j) {
var value = data.get(j);
if (value && value.scope !== EShapeDataValueScope.PRIVATE) {
result.add(value.id);
}
}
var children = shape.children;
if (0 < children.length) {
this.newIds(children, result);
}
}
};
Object.defineProperty(EDialogDataMappingValue.prototype, "onUpdateRowsBound", {
get: function () {
var result = this._onUpdateRowsBound;
if (result == null) {
result = this.newOnUpdateRowsBound();
this._onUpdateRowsBound = result;
}
return result;
},
enumerable: false,
configurable: true
});
EDialogDataMappingValue.prototype.newOnUpdateRowsBound = function () {
var _this = this;
return function () {
_this.onUpdateRows();
};
};
EDialogDataMappingValue.prototype.onUpdateRows = function () {
this._onUpdateRowsTimeout = undefined;
if (this._isRowsDirty) {
this._isRowsDirty = false;
this.table.data.clearAndAddAll(this.newRows());
this._onUpdateRowsTimeout = window.setTimeout(this.onUpdateRowsBound, 100);
}
};
EDialogDataMappingValue.prototype.newRows = function () {
var ids = this._ids;
if (ids == null || ids.length <= 0) {
return [];
}
// Source
var mapper = this._mapper;
var newSource = this._newSource;
if (mapper === undefined || this._lastSource !== newSource) {
this._lastSource = newSource;
if (newSource != null) {
var newSourceTrimmed = newSource.trim();
if (0 < newSourceTrimmed.length) {
mapper = new EShapeDataMapperImpl(newSource);
}
else {
mapper = null;
}
}
else {
mapper = null;
}
}
// Destination
var destinations = this._destinations;
var newDestination = this._newDestination;
if (destinations === undefined || this._lastDestination !== newDestination) {
this._lastDestination = newDestination;
destinations = EShapeDataMapperImpl.split(newDestination);
}
// Rows
var result = [];
if (mapper != null) {
var value = new EShapeDataValueImpl();
value.initial = "";
for (var i = 0, imax = ids.length; i < imax; ++i) {
var id = ids[i];
value.id = id;
if (mapper.map(value, destinations, "")) {
result.push({
id: id,
mappedId: value.id
});
}
}
}
else {
for (var i = 0, imax = ids.length; i < imax; ++i) {
var id = ids[i];
result.push({
id: id,
mappedId: id
});
}
}
return result;
};
EDialogDataMappingValue.prototype.updateRows = function () {
this._isRowsDirty = true;
if (this._onUpdateRowsTimeout == null) {
this.onUpdateRows();
}
};
EDialogDataMappingValue.prototype.getType = function () {
return "EDialogDataMappingValue";
};
return EDialogDataMappingValue;
}(DDialogLayered));
export { EDialogDataMappingValue };
//# sourceMappingURL=e-dialog-data-mapping-value.js.map