chem-generic-ui 0.1.15 → 0.1.18-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.js +10 -0
- package/dist/components/details/GenDSDetails.js +4 -3
- package/dist/components/details/GenSgDetails.js +571 -0
- package/dist/components/dnd/PanelDnD.js +0 -1
- package/dist/components/fields/GenProperties.js +0 -4
- package/dist/components/fields/GenPropertiesFields.js +8 -2
- package/dist/components/layers/GenPropertiesLayer.js +1 -5
- package/dist/components/layers/LayerModal.js +81 -0
- package/dist/components/models/Attachment.js +73 -0
- package/dist/components/tools/collate.js +103 -0
- package/dist/components/tools/orten.js +294 -0
- package/dist/components/tools/utils.js +63 -15
- package/dist/data/SystemUnits.js +588 -0
- package/dist/index.js +4 -2
- package/dist/{Simulate.js → simulations/SimuDS.js} +11 -11
- package/dist/simulations/SimuSG.js +118 -0
- package/package.json +15 -14
|
@@ -333,6 +333,9 @@ var GenPropertiesSelect = function GenPropertiesSelect(opt) {
|
|
|
333
333
|
label: opt.label,
|
|
334
334
|
desc: opt.description
|
|
335
335
|
});
|
|
336
|
+
var val = options.find(function (o) {
|
|
337
|
+
return o.value === opt.value;
|
|
338
|
+
}) || null;
|
|
336
339
|
return /*#__PURE__*/_react.default.createElement(_reactBootstrap.FormGroup, null, fieldHeader, /*#__PURE__*/_react.default.createElement(_reactSelect.default, {
|
|
337
340
|
isClearable: true,
|
|
338
341
|
menuContainerStyle: {
|
|
@@ -341,7 +344,7 @@ var GenPropertiesSelect = function GenPropertiesSelect(opt) {
|
|
|
341
344
|
name: opt.field,
|
|
342
345
|
multi: false,
|
|
343
346
|
options: options,
|
|
344
|
-
value:
|
|
347
|
+
value: val,
|
|
345
348
|
onChange: opt.onChange,
|
|
346
349
|
className: className,
|
|
347
350
|
disabled: opt.readOnly
|
|
@@ -593,6 +596,9 @@ var GenWFNext = function GenWFNext(opt) {
|
|
|
593
596
|
label: opt.label,
|
|
594
597
|
desc: opt.description
|
|
595
598
|
});
|
|
599
|
+
var val = options.find(function (o) {
|
|
600
|
+
return o.value === opt.value;
|
|
601
|
+
}) || null;
|
|
596
602
|
return /*#__PURE__*/_react.default.createElement(_reactBootstrap.FormGroup, null, fieldHeader, /*#__PURE__*/_react.default.createElement(_reactSelect.default, {
|
|
597
603
|
menuContainerStyle: {
|
|
598
604
|
position: 'absolute'
|
|
@@ -600,7 +606,7 @@ var GenWFNext = function GenWFNext(opt) {
|
|
|
600
606
|
name: opt.field,
|
|
601
607
|
multi: false,
|
|
602
608
|
options: options,
|
|
603
|
-
value:
|
|
609
|
+
value: val,
|
|
604
610
|
onChange: opt.onChange,
|
|
605
611
|
className: className,
|
|
606
612
|
disabled: opt.readOnly
|
|
@@ -216,11 +216,7 @@ var GenPropertiesLayer = /*#__PURE__*/function (_Component) {
|
|
|
216
216
|
style = layer.style,
|
|
217
217
|
label = layer.label;
|
|
218
218
|
var bs = color || 'default';
|
|
219
|
-
var cl = (style || 'panel_generic_heading').replace('panel_generic_heading', 'panel_generic_heading_slim');
|
|
220
|
-
console.log('render');
|
|
221
|
-
console.log(layer);
|
|
222
|
-
console.log(label);
|
|
223
|
-
console.log(cl); // panel header color is based on input bs value
|
|
219
|
+
var cl = (style || 'panel_generic_heading').replace('panel_generic_heading', 'panel_generic_heading_slim'); // panel header color is based on input bs value
|
|
224
220
|
|
|
225
221
|
var panelDnD = /*#__PURE__*/_react.default.createElement(_PanelDnD.default, {
|
|
226
222
|
type: "gen_panel",
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _reactBootstrap = require("react-bootstrap");
|
|
13
|
+
|
|
14
|
+
var _lodash = require("lodash");
|
|
15
|
+
|
|
16
|
+
var _reactFontawesome = require("@fortawesome/react-fontawesome");
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
/* eslint-disable react/forbid-prop-types */
|
|
21
|
+
var block = function block(layer, fnAdd) {
|
|
22
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
23
|
+
className: "generic_layer_column"
|
|
24
|
+
}, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("b", null, layer.label), /*#__PURE__*/_react.default.createElement("br", null), "(", layer.key, ")"), /*#__PURE__*/_react.default.createElement(_reactBootstrap.OverlayTrigger, {
|
|
25
|
+
delayShow: 1000,
|
|
26
|
+
placement: "top",
|
|
27
|
+
overlay: /*#__PURE__*/_react.default.createElement(_reactBootstrap.Tooltip, {
|
|
28
|
+
id: "_tooltip_layers"
|
|
29
|
+
}, "click to add layer")
|
|
30
|
+
}, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Button, {
|
|
31
|
+
bsStyle: "primary",
|
|
32
|
+
onClick: function onClick(event) {
|
|
33
|
+
return fnAdd(event, layer);
|
|
34
|
+
}
|
|
35
|
+
}, /*#__PURE__*/_react.default.createElement(_reactFontawesome.FontAwesomeIcon, {
|
|
36
|
+
icon: "fas fa-plus"
|
|
37
|
+
})))));
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
var drawLayout = function drawLayout(layers, fnAdd) {
|
|
41
|
+
var layout = [];
|
|
42
|
+
layers.forEach(function (layer) {
|
|
43
|
+
layout.push( /*#__PURE__*/_react.default.createElement("div", {
|
|
44
|
+
key: layer.key
|
|
45
|
+
}, block(layer, fnAdd)));
|
|
46
|
+
});
|
|
47
|
+
return layout;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
var LayerModal = function LayerModal(props) {
|
|
51
|
+
var show = props.show,
|
|
52
|
+
layers = props.layers,
|
|
53
|
+
fnClose = props.fnClose,
|
|
54
|
+
fnAdd = props.fnAdd;
|
|
55
|
+
if (!show) return null;
|
|
56
|
+
var sortedLayers = (0, _lodash.sortBy)(layers, ['position', 'wf_position']) || [];
|
|
57
|
+
if (sortedLayers.length < 1) return null;
|
|
58
|
+
var layout = drawLayout(sortedLayers, fnAdd);
|
|
59
|
+
return /*#__PURE__*/_react.default.createElement(_reactBootstrap.Modal, {
|
|
60
|
+
show: show,
|
|
61
|
+
onHide: fnClose
|
|
62
|
+
}, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Modal.Header, {
|
|
63
|
+
closeButton: true
|
|
64
|
+
}, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Modal.Title, null, "Choose Layer")), /*#__PURE__*/_react.default.createElement(_reactBootstrap.Modal.Body, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
65
|
+
style: {
|
|
66
|
+
maxHeight: '80vh',
|
|
67
|
+
overflow: 'auto'
|
|
68
|
+
}
|
|
69
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
70
|
+
className: "generic_grid"
|
|
71
|
+
}, layout))));
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
LayerModal.propTypes = {
|
|
75
|
+
show: _propTypes.default.bool.isRequired,
|
|
76
|
+
layers: _propTypes.default.object.isRequired,
|
|
77
|
+
fnClose: _propTypes.default.func.isRequired,
|
|
78
|
+
fnAdd: _propTypes.default.func.isRequired
|
|
79
|
+
};
|
|
80
|
+
var _default = LayerModal;
|
|
81
|
+
exports.default = _default;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _uuid = require("uuid");
|
|
9
|
+
|
|
10
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
+
|
|
12
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
13
|
+
|
|
14
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
15
|
+
|
|
16
|
+
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
17
|
+
|
|
18
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
19
|
+
|
|
20
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
21
|
+
|
|
22
|
+
var Attachment = /*#__PURE__*/function () {
|
|
23
|
+
function Attachment(args) {
|
|
24
|
+
_classCallCheck(this, Attachment);
|
|
25
|
+
|
|
26
|
+
Object.assign(this, args);
|
|
27
|
+
|
|
28
|
+
if (!this.id) {
|
|
29
|
+
this.id = Attachment.buildID();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
_createClass(Attachment, [{
|
|
34
|
+
key: "isNew",
|
|
35
|
+
get: function get() {
|
|
36
|
+
return this.is_new === true;
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
key: "serialize",
|
|
40
|
+
value: function serialize() {
|
|
41
|
+
return _get(_getPrototypeOf(Attachment.prototype), "serialize", this).call(this, {
|
|
42
|
+
filename: this.filename,
|
|
43
|
+
identifier: this.identifier,
|
|
44
|
+
file: this.file,
|
|
45
|
+
thumb: this.thumb,
|
|
46
|
+
content_type: this.content_type,
|
|
47
|
+
is_deleted: this.is_deleted,
|
|
48
|
+
id: this.id,
|
|
49
|
+
is_new: this.isNew || false
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}], [{
|
|
53
|
+
key: "buildID",
|
|
54
|
+
value: function buildID() {
|
|
55
|
+
return (0, _uuid.v4)();
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
key: "fromFile",
|
|
59
|
+
value: function fromFile(file) {
|
|
60
|
+
return new Attachment({
|
|
61
|
+
file: file,
|
|
62
|
+
name: file.name,
|
|
63
|
+
filename: file.name,
|
|
64
|
+
identifier: file.id,
|
|
65
|
+
is_deleted: false
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}]);
|
|
69
|
+
|
|
70
|
+
return Attachment;
|
|
71
|
+
}();
|
|
72
|
+
|
|
73
|
+
exports.default = Attachment;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _lodash = require("lodash");
|
|
9
|
+
|
|
10
|
+
var _utils = require("./utils");
|
|
11
|
+
|
|
12
|
+
var _GenericSubField = _interopRequireDefault(require("../models/GenericSubField"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
+
|
|
18
|
+
var collateValues = function collateValues(currentFields, previousFields, previousValues) {
|
|
19
|
+
var result = [];
|
|
20
|
+
var newSub = new _GenericSubField.default();
|
|
21
|
+
currentFields.map(function (e) {
|
|
22
|
+
return Object.assign(newSub, _defineProperty({}, e.id, ''));
|
|
23
|
+
});
|
|
24
|
+
var currentValuKeys = Object.keys(newSub);
|
|
25
|
+
var previousValueKeys = Object.keys(previousValues[0]);
|
|
26
|
+
var notInCurrent = previousValueKeys.filter(function (e) {
|
|
27
|
+
return !currentValuKeys.includes(e);
|
|
28
|
+
});
|
|
29
|
+
var currObj = {};
|
|
30
|
+
currentFields.map(function (c) {
|
|
31
|
+
if (c.type === 'text') return Object.assign(currObj, _defineProperty({}, c.id, ''));
|
|
32
|
+
return Object.assign(currObj, _defineProperty({}, c.id, {
|
|
33
|
+
value: '',
|
|
34
|
+
value_system: c.value_system
|
|
35
|
+
}));
|
|
36
|
+
});
|
|
37
|
+
previousValues.forEach(function (e) {
|
|
38
|
+
newSub = new _GenericSubField.default();
|
|
39
|
+
Object.assign(newSub, currObj, e);
|
|
40
|
+
notInCurrent.forEach(function (c) {
|
|
41
|
+
return delete newSub[c];
|
|
42
|
+
});
|
|
43
|
+
previousValueKeys.forEach(function (preKey) {
|
|
44
|
+
if (newSub[preKey] === undefined || preKey === 'id') return;
|
|
45
|
+
var curr = currentFields.find(function (f) {
|
|
46
|
+
return f.id === preKey;
|
|
47
|
+
});
|
|
48
|
+
var prev = previousFields.find(function (f) {
|
|
49
|
+
return f.id === preKey;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
if (curr.type === 'drag_molecule') {
|
|
53
|
+
if (['text', 'system-defined', 'drag_sample'].includes(prev.type)) {
|
|
54
|
+
newSub[preKey] = {
|
|
55
|
+
value: undefined
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (curr.type === 'text') {
|
|
61
|
+
if (prev.type === 'system-defined') {
|
|
62
|
+
newSub[preKey] = newSub[preKey].value;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (['drag_molecule', 'drag_sample'].includes(prev.type)) {
|
|
66
|
+
newSub[preKey] = '';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (curr.type === 'system-defined') {
|
|
71
|
+
if (prev.type === 'system-defined' && curr.option_layers !== prev.option_layers) {
|
|
72
|
+
newSub[preKey].value_system = curr.value_system;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (['text', 'drag_molecule', 'drag_sample'].includes(prev.type)) {
|
|
76
|
+
newSub[preKey] = {
|
|
77
|
+
value: '',
|
|
78
|
+
value_system: curr.value_system
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
newSub[preKey].value = (0, _utils.unitConversion)(curr.option_layer, newSub[preKey].value_system, newSub[preKey].value);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
result.push(newSub);
|
|
86
|
+
});
|
|
87
|
+
return result;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
var organizeSubValues = function organizeSubValues(cur, pre) {
|
|
91
|
+
var currentFields = (0, _lodash.cloneDeep)(cur.sub_fields || []);
|
|
92
|
+
var previousFields = (0, _lodash.cloneDeep)(pre.sub_fields || []);
|
|
93
|
+
var previousValues = (0, _lodash.cloneDeep)(pre.sub_values || []);
|
|
94
|
+
|
|
95
|
+
if (currentFields.length < 1 || previousFields.length < 1 || previousValues.length < 1) {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return collateValues(currentFields, previousFields, previousValues);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
var _default = organizeSubValues;
|
|
103
|
+
exports.default = _default;
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.removeFromObject = exports.reformCondFields = exports.orgLayerObject = exports.getWFNode = exports.getFlowLayer = exports.buildInitWF = exports.addToObject = void 0;
|
|
7
|
+
|
|
8
|
+
var _lodash = require("lodash");
|
|
9
|
+
|
|
10
|
+
var _uuid = require("uuid");
|
|
11
|
+
|
|
12
|
+
/* eslint-disable no-param-reassign */
|
|
13
|
+
|
|
14
|
+
/* eslint-disable import/prefer-default-export */
|
|
15
|
+
var getWFNode = function getWFNode(_flow, nodeId) {
|
|
16
|
+
return _flow.elements.filter(function (e) {
|
|
17
|
+
return e.id === nodeId;
|
|
18
|
+
})[0];
|
|
19
|
+
}; // full-flow, node id
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
exports.getWFNode = getWFNode;
|
|
23
|
+
|
|
24
|
+
var getFlowLayer = function getFlowLayer(templateFlow, nodeId, sourceLayer, sIdx) {
|
|
25
|
+
var flow = (0, _lodash.cloneDeep)(templateFlow);
|
|
26
|
+
var nd = flow.elements.filter(function (e) {
|
|
27
|
+
return e.id === nodeId;
|
|
28
|
+
}); // fetch node
|
|
29
|
+
|
|
30
|
+
if (nd.length < 1) return null;
|
|
31
|
+
var layer = nd[0].data.layer;
|
|
32
|
+
var ls = flow.elements.filter(function (e) {
|
|
33
|
+
return e.animated;
|
|
34
|
+
}); // lines
|
|
35
|
+
|
|
36
|
+
var ns = flow.elements.filter(function (e) {
|
|
37
|
+
return e.type === 'default' && e.data;
|
|
38
|
+
}); // nodes - Start - End
|
|
39
|
+
|
|
40
|
+
var ndNs = ls.filter(function (e) {
|
|
41
|
+
return e.source === nodeId;
|
|
42
|
+
}).map(function (e) {
|
|
43
|
+
return e.target;
|
|
44
|
+
}); // next nodes' id
|
|
45
|
+
|
|
46
|
+
var wfOpts = ns.filter(function (n) {
|
|
47
|
+
return ndNs.includes(n.id);
|
|
48
|
+
}).map(function (e) {
|
|
49
|
+
return {
|
|
50
|
+
key: e.id,
|
|
51
|
+
label: "".concat(e.data.layer.label, "(").concat(e.data.layer.key, ")")
|
|
52
|
+
};
|
|
53
|
+
}); // next nodes
|
|
54
|
+
|
|
55
|
+
if (wfOpts.length > 0) {
|
|
56
|
+
var position = (layer.fields || []).length + 1;
|
|
57
|
+
layer.fields.push({
|
|
58
|
+
type: 'wf-next',
|
|
59
|
+
default: '',
|
|
60
|
+
field: '_wf_next',
|
|
61
|
+
label: 'Next',
|
|
62
|
+
required: false,
|
|
63
|
+
sub_fields: [],
|
|
64
|
+
text_sub_fields: [],
|
|
65
|
+
position: position,
|
|
66
|
+
wf_options: wfOpts
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
layer.wf_info = {
|
|
71
|
+
node_id: nodeId,
|
|
72
|
+
source_layer: sourceLayer
|
|
73
|
+
};
|
|
74
|
+
layer.wf_position = sIdx + 1;
|
|
75
|
+
return layer;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
exports.getFlowLayer = getFlowLayer;
|
|
79
|
+
|
|
80
|
+
var orgLayerObject = function orgLayerObject() {
|
|
81
|
+
var _layers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
82
|
+
|
|
83
|
+
var layers = _layers;
|
|
84
|
+
return layers.reduce(function (alles, name) {
|
|
85
|
+
var all = alles;
|
|
86
|
+
var ok = Object.keys(all);
|
|
87
|
+
|
|
88
|
+
if (ok.includes(name.key)) {
|
|
89
|
+
var cnt = ok.filter(function (e) {
|
|
90
|
+
return e === name.key || e.startsWith("".concat(name.key, "."));
|
|
91
|
+
}).length;
|
|
92
|
+
var nName = "".concat(name.key, ".").concat(cnt);
|
|
93
|
+
name.key = nName;
|
|
94
|
+
all[nName] = name;
|
|
95
|
+
} else {
|
|
96
|
+
all[name.key] = name;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return all;
|
|
100
|
+
}, {});
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
exports.orgLayerObject = orgLayerObject;
|
|
104
|
+
|
|
105
|
+
var reformCondFields = function reformCondFields(_layer, _oKey) {
|
|
106
|
+
var layer = _layer;
|
|
107
|
+
layer.fields.map(function (_f) {
|
|
108
|
+
var f = _f;
|
|
109
|
+
var conds = f.cond_fields; // no cond_fields
|
|
110
|
+
|
|
111
|
+
if (!conds || conds.length < 1 || conds.filter(function (o) {
|
|
112
|
+
return !o.field || o.field === '';
|
|
113
|
+
}).length === conds.length) return f;
|
|
114
|
+
conds = conds.filter(function (o) {
|
|
115
|
+
return o.layer === _oKey;
|
|
116
|
+
}); // no same layer, remove cond_fields
|
|
117
|
+
|
|
118
|
+
if (conds.length < 1) {
|
|
119
|
+
delete f.cond_fields;
|
|
120
|
+
return f;
|
|
121
|
+
} // rename layer
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
conds = conds.map(function (o) {
|
|
125
|
+
var n = o;
|
|
126
|
+
n.layer = layer.key;
|
|
127
|
+
return n;
|
|
128
|
+
});
|
|
129
|
+
f.cond_fields = conds;
|
|
130
|
+
return f;
|
|
131
|
+
});
|
|
132
|
+
return layer.fields;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
exports.reformCondFields = reformCondFields;
|
|
136
|
+
|
|
137
|
+
var addToObject = function addToObject(obj, key, addAfter) {
|
|
138
|
+
var temp = {};
|
|
139
|
+
var ok = Object.keys(obj);
|
|
140
|
+
Object.keys(obj).forEach(function (e) {
|
|
141
|
+
if (Object.prototype.hasOwnProperty.call(obj, e)) {
|
|
142
|
+
temp[e] = obj[e];
|
|
143
|
+
|
|
144
|
+
if (e === key) {
|
|
145
|
+
var srcPosition = temp[e].position;
|
|
146
|
+
var cnt = ok.filter(function (o) {
|
|
147
|
+
return o === addAfter.key || o.startsWith("".concat(addAfter.key, "."));
|
|
148
|
+
}).length;
|
|
149
|
+
|
|
150
|
+
if (cnt === 0) {
|
|
151
|
+
temp[addAfter.key] = addAfter;
|
|
152
|
+
temp[addAfter.key].position = srcPosition;
|
|
153
|
+
} else {
|
|
154
|
+
var oKey = addAfter.key;
|
|
155
|
+
temp["".concat(addAfter.key, ".").concat(cnt)] = addAfter;
|
|
156
|
+
temp["".concat(addAfter.key, ".").concat(cnt)].position = srcPosition;
|
|
157
|
+
temp["".concat(addAfter.key, ".").concat(cnt)].key = "".concat(addAfter.key, ".").concat(cnt);
|
|
158
|
+
temp[addAfter.key].fields = reformCondFields(addAfter, oKey);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
if (Object.keys(obj).length === 0) temp[addAfter.key] = addAfter;
|
|
164
|
+
return temp;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
exports.addToObject = addToObject;
|
|
168
|
+
|
|
169
|
+
var traverseToRemove = function traverseToRemove(layers, rmKey) {
|
|
170
|
+
var rms = [];
|
|
171
|
+
Object.keys(layers).forEach(function (e) {
|
|
172
|
+
if (Object.prototype.hasOwnProperty.call(layers, e)) {
|
|
173
|
+
if (layers[e].key === rmKey) rms = rms.concat(rmKey);else if (layers[e].wf_info && layers[e].wf_info.source_layer === rmKey) {
|
|
174
|
+
rms = rms.concat(traverseToRemove(layers, layers[e].key));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
return rms;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
var removeFromObject = function removeFromObject() {
|
|
182
|
+
var _propertiesLayers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
183
|
+
|
|
184
|
+
var srcLayer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
185
|
+
var rmNode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
186
|
+
var layers = _propertiesLayers;
|
|
187
|
+
var rmLayer = rmNode.data && rmNode.data.layer ? rmNode.data.layer.key : null;
|
|
188
|
+
if (!rmLayer) return [];
|
|
189
|
+
var rms = [];
|
|
190
|
+
Object.keys(layers).forEach(function (e) {
|
|
191
|
+
if (Object.prototype.hasOwnProperty.call(layers, e)) {
|
|
192
|
+
var wf = layers[e].wf_info;
|
|
193
|
+
|
|
194
|
+
if (wf && wf.source_layer === srcLayer && wf.node_id === rmNode.id) {
|
|
195
|
+
rms = rms.concat(traverseToRemove(layers, layers[e].key));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
rms.forEach(function (e) {
|
|
200
|
+
return delete layers[e];
|
|
201
|
+
});
|
|
202
|
+
return layers;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
exports.removeFromObject = removeFromObject;
|
|
206
|
+
|
|
207
|
+
var buildInitWF = function buildInitWF(template) {
|
|
208
|
+
var orig = (0, _lodash.cloneDeep)(template);
|
|
209
|
+
var layers = orig.layers,
|
|
210
|
+
flow = orig.flow;
|
|
211
|
+
var sortedLayers = (0, _lodash.sortBy)(layers, function (l) {
|
|
212
|
+
return l.position;
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
if (flow && flow.elements.filter(function (e) {
|
|
216
|
+
return !['input', 'output'].includes(e.type).length > 0;
|
|
217
|
+
})) {
|
|
218
|
+
// id = 1 Start, id = 2 End
|
|
219
|
+
var nls = flow.elements; // nodes + lines
|
|
220
|
+
|
|
221
|
+
var ls = nls.filter(function (e) {
|
|
222
|
+
return e.animated;
|
|
223
|
+
}); // lines
|
|
224
|
+
|
|
225
|
+
var ns = nls.filter(function (e) {
|
|
226
|
+
return e.type === 'default' && e.data;
|
|
227
|
+
}); // nodes - Start - End
|
|
228
|
+
|
|
229
|
+
var nNs = ls.filter(function (e) {
|
|
230
|
+
return e.source === '1';
|
|
231
|
+
}).map(function (e) {
|
|
232
|
+
return e.target;
|
|
233
|
+
}); // get target ids from Start
|
|
234
|
+
|
|
235
|
+
var nextNodes = ns.filter(function (n) {
|
|
236
|
+
return nNs.includes(n.id);
|
|
237
|
+
}); // target nodes
|
|
238
|
+
|
|
239
|
+
var result = [];
|
|
240
|
+
sortedLayers.forEach(function (sortedLayer) {
|
|
241
|
+
var fLayer = sortedLayer;
|
|
242
|
+
|
|
243
|
+
if (fLayer.wf) {
|
|
244
|
+
var position = (fLayer.fields || []).length + 1;
|
|
245
|
+
var passen = nextNodes.filter(function (n) {
|
|
246
|
+
return n.data.layer.key === fLayer.key;
|
|
247
|
+
});
|
|
248
|
+
passen.forEach(function (pas) {
|
|
249
|
+
var nextOptions = ls.filter(function (e) {
|
|
250
|
+
return e.source === pas.id && e.source !== e.target;
|
|
251
|
+
}).map(function (e) {
|
|
252
|
+
return e.target;
|
|
253
|
+
});
|
|
254
|
+
var wfOpts = ns.filter(function (n) {
|
|
255
|
+
return nextOptions.includes(n.id);
|
|
256
|
+
}).map(function (e) {
|
|
257
|
+
return {
|
|
258
|
+
key: e.id,
|
|
259
|
+
label: "".concat(e.data.layer.label, "(").concat(e.data.layer.key, ")")
|
|
260
|
+
};
|
|
261
|
+
}); // next nodes
|
|
262
|
+
|
|
263
|
+
fLayer.fields.push({
|
|
264
|
+
type: 'wf-next',
|
|
265
|
+
default: '',
|
|
266
|
+
field: '_wf_next',
|
|
267
|
+
label: 'Next',
|
|
268
|
+
required: false,
|
|
269
|
+
sub_fields: [],
|
|
270
|
+
text_sub_fields: [],
|
|
271
|
+
position: position,
|
|
272
|
+
wf_options: wfOpts
|
|
273
|
+
});
|
|
274
|
+
fLayer.wf_info = {
|
|
275
|
+
node_id: pas.id
|
|
276
|
+
};
|
|
277
|
+
fLayer.wf_position = 1;
|
|
278
|
+
fLayer.wf_uuid = (0, _uuid.v4)();
|
|
279
|
+
result.push(fLayer);
|
|
280
|
+
});
|
|
281
|
+
} else {
|
|
282
|
+
result.push(fLayer);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
var ll = orgLayerObject(result);
|
|
286
|
+
orig.layers = ll;
|
|
287
|
+
} else {
|
|
288
|
+
orig.layers = layers;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return orig;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
exports.buildInitWF = buildInitWF;
|