ywana-core8 0.0.470 → 0.0.473
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/index.cjs +1125 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +1124 -32
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +1125 -32
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/domain/ContentType.js +1 -0
- package/src/domain/TabbedTablePage.js +20 -11
- package/src/domain/index.js +1 -0
- package/src/site/site.test.js +2 -2
package/dist/index.modern.js
CHANGED
@@ -8,7 +8,7 @@ import { ReactNotifications, Store } from 'react-notifications-component';
|
|
8
8
|
import 'react-notifications-component/dist/theme.css';
|
9
9
|
import equal from 'deep-equal';
|
10
10
|
|
11
|
-
function _catch$
|
11
|
+
function _catch$3(body, recover) {
|
12
12
|
try {
|
13
13
|
var result = body();
|
14
14
|
} catch (e) {
|
@@ -40,7 +40,7 @@ var fetchAsync = function fetchAsync(method, URL, body, token, headers) {
|
|
40
40
|
body: body
|
41
41
|
};
|
42
42
|
if (headers) request.headers = request.headers;
|
43
|
-
return Promise.resolve(_catch$
|
43
|
+
return Promise.resolve(_catch$3(function () {
|
44
44
|
return Promise.resolve(fetch(URL, request)).then(function (response) {
|
45
45
|
var _exit;
|
46
46
|
|
@@ -4646,7 +4646,7 @@ var EditContentDialog = function EditContentDialog(_ref) {
|
|
4646
4646
|
* Collection Page
|
4647
4647
|
*/
|
4648
4648
|
|
4649
|
-
function _catch$
|
4649
|
+
function _catch$2(body, recover) {
|
4650
4650
|
try {
|
4651
4651
|
var result = body();
|
4652
4652
|
} catch (e) {
|
@@ -5033,7 +5033,7 @@ var CollectionContext = function CollectionContext(url, field, host, page) {
|
|
5033
5033
|
try {
|
5034
5034
|
var _this2 = this;
|
5035
5035
|
|
5036
|
-
var _temp2 = _catch$
|
5036
|
+
var _temp2 = _catch$2(function () {
|
5037
5037
|
return Promise.resolve(API.all(null, page)).then(function (data) {
|
5038
5038
|
_this2.all = field ? data[field] : data;
|
5039
5039
|
});
|
@@ -5059,7 +5059,7 @@ var CollectionContext = function CollectionContext(url, field, host, page) {
|
|
5059
5059
|
try {
|
5060
5060
|
var _this4 = this;
|
5061
5061
|
|
5062
|
-
var _temp4 = _catch$
|
5062
|
+
var _temp4 = _catch$2(function () {
|
5063
5063
|
return Promise.resolve(API.create(form)).then(function () {
|
5064
5064
|
return Promise.resolve(_this4.load()).then(function () {});
|
5065
5065
|
});
|
@@ -5076,7 +5076,7 @@ var CollectionContext = function CollectionContext(url, field, host, page) {
|
|
5076
5076
|
try {
|
5077
5077
|
var _this6 = this;
|
5078
5078
|
|
5079
|
-
var _temp6 = _catch$
|
5079
|
+
var _temp6 = _catch$2(function () {
|
5080
5080
|
return Promise.resolve(API.update(form)).then(function () {
|
5081
5081
|
return Promise.resolve(_this6.load()).then(function () {});
|
5082
5082
|
});
|
@@ -5093,7 +5093,7 @@ var CollectionContext = function CollectionContext(url, field, host, page) {
|
|
5093
5093
|
try {
|
5094
5094
|
var _this8 = this;
|
5095
5095
|
|
5096
|
-
var _temp8 = _catch$
|
5096
|
+
var _temp8 = _catch$2(function () {
|
5097
5097
|
return Promise.resolve(API.patch(id, form)).then(function () {
|
5098
5098
|
return Promise.resolve(_this8.load()).then(function () {});
|
5099
5099
|
});
|
@@ -5110,7 +5110,7 @@ var CollectionContext = function CollectionContext(url, field, host, page) {
|
|
5110
5110
|
try {
|
5111
5111
|
var _this10 = this;
|
5112
5112
|
|
5113
|
-
var _temp10 = _catch$
|
5113
|
+
var _temp10 = _catch$2(function () {
|
5114
5114
|
return Promise.resolve(API.updateProperty(id, propertyName, form)).then(function () {
|
5115
5115
|
return Promise.resolve(_this10.load()).then(function () {});
|
5116
5116
|
});
|
@@ -5127,7 +5127,7 @@ var CollectionContext = function CollectionContext(url, field, host, page) {
|
|
5127
5127
|
try {
|
5128
5128
|
var _this12 = this;
|
5129
5129
|
|
5130
|
-
var _temp12 = _catch$
|
5130
|
+
var _temp12 = _catch$2(function () {
|
5131
5131
|
return Promise.resolve(API.remove(id)).then(function () {
|
5132
5132
|
return Promise.resolve(_this12.load()).then(function () {});
|
5133
5133
|
});
|
@@ -5339,7 +5339,7 @@ var QUERY = {
|
|
5339
5339
|
* Table Page
|
5340
5340
|
*/
|
5341
5341
|
|
5342
|
-
function _catch(body, recover) {
|
5342
|
+
function _catch$1(body, recover) {
|
5343
5343
|
try {
|
5344
5344
|
var result = body();
|
5345
5345
|
} catch (e) {
|
@@ -5464,7 +5464,7 @@ var TablePage = function TablePage(props) {
|
|
5464
5464
|
pageContext = _useContext[0],
|
5465
5465
|
setPageContext = _useContext[1];
|
5466
5466
|
|
5467
|
-
var context = TableContext(url, field, host, urlQuery);
|
5467
|
+
var context = TableContext$1(url, field, host, urlQuery);
|
5468
5468
|
var selected = pageContext.selected;
|
5469
5469
|
var timer = useRef(null);
|
5470
5470
|
|
@@ -5564,13 +5564,13 @@ var TablePage = function TablePage(props) {
|
|
5564
5564
|
if (rowSelected || rowChecked) {
|
5565
5565
|
return /*#__PURE__*/React.createElement("aside", {
|
5566
5566
|
className: "table-page"
|
5567
|
-
}, rowSelected ? /*#__PURE__*/React.createElement(TableRowEditor, {
|
5567
|
+
}, rowSelected ? /*#__PURE__*/React.createElement(TableRowEditor$1, {
|
5568
5568
|
content: new Content(schema, form),
|
5569
5569
|
filter: editorFilter,
|
5570
5570
|
onChange: change,
|
5571
5571
|
onClose: closeAside,
|
5572
5572
|
editable: canEdit
|
5573
|
-
}) : null, rowChecked ? /*#__PURE__*/React.createElement(TableSelector, {
|
5573
|
+
}) : null, rowChecked ? /*#__PURE__*/React.createElement(TableSelector$1, {
|
5574
5574
|
schema: schema,
|
5575
5575
|
actions: selectionActions
|
5576
5576
|
}) : null);
|
@@ -5611,17 +5611,17 @@ var TablePage = function TablePage(props) {
|
|
5611
5611
|
onSelect: playScenario
|
5612
5612
|
})) : null, renderActions()), canQuery || canFilter ? /*#__PURE__*/React.createElement("menu", {
|
5613
5613
|
className: "table-page"
|
5614
|
-
}, canQuery ? /*#__PURE__*/React.createElement(TableQueries, {
|
5614
|
+
}, canQuery ? /*#__PURE__*/React.createElement(TableQueries$1, {
|
5615
5615
|
schema: schema,
|
5616
5616
|
url: url,
|
5617
5617
|
user: user
|
5618
|
-
}) : null, canFilter ? /*#__PURE__*/React.createElement(TableFilters, {
|
5618
|
+
}) : null, canFilter ? /*#__PURE__*/React.createElement(TableFilters$1, {
|
5619
5619
|
schema: schema,
|
5620
5620
|
onSave: canQuery ? saveQuery : null
|
5621
5621
|
}) : null) : null, /*#__PURE__*/React.createElement("main", {
|
5622
5622
|
key: id,
|
5623
5623
|
className: "table-page"
|
5624
|
-
}, /*#__PURE__*/React.createElement(TableEditor, {
|
5624
|
+
}, /*#__PURE__*/React.createElement(TableEditor$1, {
|
5625
5625
|
icon: icon,
|
5626
5626
|
title: name,
|
5627
5627
|
schema: schema,
|
@@ -5634,7 +5634,7 @@ var TablePage = function TablePage(props) {
|
|
5634
5634
|
}), children ? /*#__PURE__*/React.createElement("article", null, children) : null), renderAside());
|
5635
5635
|
};
|
5636
5636
|
|
5637
|
-
var TableRowEditor = function TableRowEditor(props) {
|
5637
|
+
var TableRowEditor$1 = function TableRowEditor(props) {
|
5638
5638
|
var name = props.name,
|
5639
5639
|
content = props.content,
|
5640
5640
|
filter = props.filter,
|
@@ -5663,7 +5663,7 @@ var TableRowEditor = function TableRowEditor(props) {
|
|
5663
5663
|
*/
|
5664
5664
|
|
5665
5665
|
|
5666
|
-
var TableSelector = function TableSelector(props) {
|
5666
|
+
var TableSelector$1 = function TableSelector(props) {
|
5667
5667
|
var schema = props.schema,
|
5668
5668
|
_props$actions2 = props.actions,
|
5669
5669
|
actions = _props$actions2 === void 0 ? [] : _props$actions2;
|
@@ -5726,7 +5726,7 @@ var TableSelector = function TableSelector(props) {
|
|
5726
5726
|
*/
|
5727
5727
|
|
5728
5728
|
|
5729
|
-
var TableQueries = function TableQueries(props) {
|
5729
|
+
var TableQueries$1 = function TableQueries(props) {
|
5730
5730
|
var remove = function remove(id) {
|
5731
5731
|
try {
|
5732
5732
|
return Promise.resolve(pageContext.removeQuery(id, user)).then(function () {
|
@@ -5788,7 +5788,7 @@ var TableQueries = function TableQueries(props) {
|
|
5788
5788
|
*/
|
5789
5789
|
|
5790
5790
|
|
5791
|
-
var TableFilters = function TableFilters(props) {
|
5791
|
+
var TableFilters$1 = function TableFilters(props) {
|
5792
5792
|
var reload = function reload() {
|
5793
5793
|
try {
|
5794
5794
|
return Promise.resolve(pageContext.load(form)).then(function () {
|
@@ -5884,7 +5884,7 @@ var TableFilters = function TableFilters(props) {
|
|
5884
5884
|
*/
|
5885
5885
|
|
5886
5886
|
|
5887
|
-
var TableEditor = function TableEditor(props) {
|
5887
|
+
var TableEditor$1 = function TableEditor(props) {
|
5888
5888
|
var checkOne = function checkOne(id, field, value) {
|
5889
5889
|
check([id], value);
|
5890
5890
|
return Promise.resolve();
|
@@ -6109,8 +6109,8 @@ var TableEditor = function TableEditor(props) {
|
|
6109
6109
|
* Table Context
|
6110
6110
|
*/
|
6111
6111
|
|
6112
|
-
var TableContext = function TableContext(url, field, host, urlQuery) {
|
6113
|
-
var API = TableAPI(url, host);
|
6112
|
+
var TableContext$1 = function TableContext(url, field, host, urlQuery) {
|
6113
|
+
var API = TableAPI$1(url, host);
|
6114
6114
|
return {
|
6115
6115
|
all: [],
|
6116
6116
|
checked: new Set([]),
|
@@ -6121,7 +6121,7 @@ var TableContext = function TableContext(url, field, host, urlQuery) {
|
|
6121
6121
|
try {
|
6122
6122
|
var _this2 = this;
|
6123
6123
|
|
6124
|
-
var _temp5 = _catch(function () {
|
6124
|
+
var _temp5 = _catch$1(function () {
|
6125
6125
|
var filters = filter ? Object.keys(filter).reduce(function (filters, key) {
|
6126
6126
|
var field = filter[key];
|
6127
6127
|
|
@@ -6180,7 +6180,7 @@ var TableContext = function TableContext(url, field, host, urlQuery) {
|
|
6180
6180
|
try {
|
6181
6181
|
var _this5 = this;
|
6182
6182
|
|
6183
|
-
var _temp7 = _catch(function () {
|
6183
|
+
var _temp7 = _catch$1(function () {
|
6184
6184
|
return Promise.resolve(API.create(form)).then(function () {
|
6185
6185
|
return Promise.resolve(_this5.load()).then(function () {});
|
6186
6186
|
});
|
@@ -6197,7 +6197,7 @@ var TableContext = function TableContext(url, field, host, urlQuery) {
|
|
6197
6197
|
try {
|
6198
6198
|
var _this7 = this;
|
6199
6199
|
|
6200
|
-
var _temp9 = _catch(function () {
|
6200
|
+
var _temp9 = _catch$1(function () {
|
6201
6201
|
return Promise.resolve(API.update(form)).then(function () {
|
6202
6202
|
return Promise.resolve(_this7.load()).then(function () {});
|
6203
6203
|
});
|
@@ -6214,7 +6214,7 @@ var TableContext = function TableContext(url, field, host, urlQuery) {
|
|
6214
6214
|
try {
|
6215
6215
|
var _this9 = this;
|
6216
6216
|
|
6217
|
-
var _temp11 = _catch(function () {
|
6217
|
+
var _temp11 = _catch$1(function () {
|
6218
6218
|
return Promise.resolve(API.remove(id)).then(function () {
|
6219
6219
|
return Promise.resolve(_this9.load()).then(function () {});
|
6220
6220
|
});
|
@@ -6234,7 +6234,7 @@ var TableContext = function TableContext(url, field, host, urlQuery) {
|
|
6234
6234
|
try {
|
6235
6235
|
var _this11 = this;
|
6236
6236
|
|
6237
|
-
var _temp13 = _catch(function () {
|
6237
|
+
var _temp13 = _catch$1(function () {
|
6238
6238
|
return Promise.resolve(API.queries(user, urlQuery)).then(function (_API$queries) {
|
6239
6239
|
_this11.queries = _API$queries;
|
6240
6240
|
});
|
@@ -6251,7 +6251,7 @@ var TableContext = function TableContext(url, field, host, urlQuery) {
|
|
6251
6251
|
try {
|
6252
6252
|
var _this13 = this;
|
6253
6253
|
|
6254
|
-
var _temp15 = _catch(function () {
|
6254
|
+
var _temp15 = _catch$1(function () {
|
6255
6255
|
return Promise.resolve(API.createQuery(query, urlQuery)).then(function () {
|
6256
6256
|
return Promise.resolve(_this13.loadQueries(user)).then(function () {});
|
6257
6257
|
});
|
@@ -6268,7 +6268,7 @@ var TableContext = function TableContext(url, field, host, urlQuery) {
|
|
6268
6268
|
try {
|
6269
6269
|
var _this15 = this;
|
6270
6270
|
|
6271
|
-
var _temp17 = _catch(function () {
|
6271
|
+
var _temp17 = _catch$1(function () {
|
6272
6272
|
return Promise.resolve(API.removeQuery(id, urlQuery)).then(function () {
|
6273
6273
|
return Promise.resolve(_this15.loadQueries(user)).then(function () {});
|
6274
6274
|
});
|
@@ -6288,7 +6288,7 @@ var TableContext = function TableContext(url, field, host, urlQuery) {
|
|
6288
6288
|
*/
|
6289
6289
|
|
6290
6290
|
|
6291
|
-
var TableAPI = function TableAPI(url, host) {
|
6291
|
+
var TableAPI$1 = function TableAPI(url, host) {
|
6292
6292
|
var http = HTTPClient(host || window.API || process.env.REACT_APP_API, Session);
|
6293
6293
|
return {
|
6294
6294
|
all: function all(filters) {
|
@@ -6347,9 +6347,1101 @@ var TableAPI = function TableAPI(url, host) {
|
|
6347
6347
|
};
|
6348
6348
|
};
|
6349
6349
|
|
6350
|
+
/**
|
6351
|
+
* Tabbed Table Page
|
6352
|
+
*/
|
6353
|
+
|
6354
|
+
function _catch(body, recover) {
|
6355
|
+
try {
|
6356
|
+
var result = body();
|
6357
|
+
} catch (e) {
|
6358
|
+
return recover(e);
|
6359
|
+
}
|
6360
|
+
|
6361
|
+
if (result && result.then) {
|
6362
|
+
return result.then(void 0, recover);
|
6363
|
+
}
|
6364
|
+
|
6365
|
+
return result;
|
6366
|
+
}
|
6367
|
+
/**
|
6368
|
+
* TableRowEditor
|
6369
|
+
*/
|
6370
|
+
|
6371
|
+
|
6372
|
+
var TabbedTablePage = function TabbedTablePage(props) {
|
6373
|
+
var playScenario = function playScenario() {
|
6374
|
+
try {
|
6375
|
+
var promises1 = pageContext.all.map(function (item) {
|
6376
|
+
try {
|
6377
|
+
return Promise.resolve(pageContext.remove(item.id));
|
6378
|
+
} catch (e) {
|
6379
|
+
return Promise.reject(e);
|
6380
|
+
}
|
6381
|
+
});
|
6382
|
+
Promise.all(promises1).then(function () {
|
6383
|
+
try {
|
6384
|
+
var promises2 = scenario.map(function (item) {
|
6385
|
+
try {
|
6386
|
+
return Promise.resolve(pageContext.create(item));
|
6387
|
+
} catch (e) {
|
6388
|
+
return Promise.reject(e);
|
6389
|
+
}
|
6390
|
+
});
|
6391
|
+
Promise.all(promises2).then(function () {
|
6392
|
+
try {
|
6393
|
+
return Promise.resolve(pageContext.load()).then(function () {
|
6394
|
+
setPageContext(Object.assign({}, pageContext));
|
6395
|
+
});
|
6396
|
+
} catch (e) {
|
6397
|
+
return Promise.reject(e);
|
6398
|
+
}
|
6399
|
+
});
|
6400
|
+
return Promise.resolve();
|
6401
|
+
} catch (e) {
|
6402
|
+
return Promise.reject(e);
|
6403
|
+
}
|
6404
|
+
});
|
6405
|
+
return Promise.resolve();
|
6406
|
+
} catch (e) {
|
6407
|
+
return Promise.reject(e);
|
6408
|
+
}
|
6409
|
+
};
|
6410
|
+
|
6411
|
+
var save = function save() {
|
6412
|
+
try {
|
6413
|
+
console.log('saving.....');
|
6414
|
+
return Promise.resolve(pageContext.update(form)).then(function () {
|
6415
|
+
setPageContext(Object.assign({}, pageContext));
|
6416
|
+
});
|
6417
|
+
} catch (e) {
|
6418
|
+
return Promise.reject(e);
|
6419
|
+
}
|
6420
|
+
};
|
6421
|
+
|
6422
|
+
var reload = function reload() {
|
6423
|
+
try {
|
6424
|
+
var _filter2;
|
6425
|
+
|
6426
|
+
var filter = (_filter2 = {}, _filter2[tab.field] = tab.value, _filter2);
|
6427
|
+
return Promise.resolve(pageContext.load(filter, false)).then(function () {
|
6428
|
+
setPageContext(Object.assign({}, pageContext));
|
6429
|
+
});
|
6430
|
+
} catch (e) {
|
6431
|
+
return Promise.reject(e);
|
6432
|
+
}
|
6433
|
+
};
|
6434
|
+
|
6435
|
+
var site = useContext(SiteContext);
|
6436
|
+
var _props$id = props.id,
|
6437
|
+
id = _props$id === void 0 ? "table" : _props$id,
|
6438
|
+
icon = props.icon,
|
6439
|
+
title = props.title,
|
6440
|
+
name = props.name,
|
6441
|
+
schema = props.schema,
|
6442
|
+
url = props.url,
|
6443
|
+
field = props.field,
|
6444
|
+
host = props.host,
|
6445
|
+
_props$autosave = props.autosave,
|
6446
|
+
autosave = _props$autosave === void 0 ? true : _props$autosave,
|
6447
|
+
_props$delay = props.delay,
|
6448
|
+
delay = _props$delay === void 0 ? 1000 : _props$delay,
|
6449
|
+
editable = props.editable,
|
6450
|
+
_props$actions = props.actions,
|
6451
|
+
actions = _props$actions === void 0 ? [] : _props$actions,
|
6452
|
+
_props$dev = props.dev,
|
6453
|
+
dev = _props$dev === void 0 ? false : _props$dev,
|
6454
|
+
tableActions = props.tableActions,
|
6455
|
+
_props$selectionActio = props.selectionActions,
|
6456
|
+
selectionActions = _props$selectionActio === void 0 ? [] : _props$selectionActio,
|
6457
|
+
_props$canFilter = props.canFilter,
|
6458
|
+
canFilter = _props$canFilter === void 0 ? false : _props$canFilter,
|
6459
|
+
_props$canAdd = props.canAdd,
|
6460
|
+
canAdd = _props$canAdd === void 0 ? true : _props$canAdd,
|
6461
|
+
_props$canDelete = props.canDelete,
|
6462
|
+
canDelete = _props$canDelete === void 0 ? true : _props$canDelete,
|
6463
|
+
_props$canEdit = props.canEdit,
|
6464
|
+
canEdit = _props$canEdit === void 0 ? true : _props$canEdit,
|
6465
|
+
_props$canQuery = props.canQuery,
|
6466
|
+
canQuery = _props$canQuery === void 0 ? false : _props$canQuery,
|
6467
|
+
urlQuery = props.urlQuery,
|
6468
|
+
user = props.user,
|
6469
|
+
groupBy = props.groupBy,
|
6470
|
+
validator = props.validator,
|
6471
|
+
scenario = props.scenario,
|
6472
|
+
formFilter = props.formFilter,
|
6473
|
+
tableFilter = props.tableFilter,
|
6474
|
+
_props$editorFilter = props.editorFilter,
|
6475
|
+
editorFilter = _props$editorFilter === void 0 ? false : _props$editorFilter,
|
6476
|
+
children = props.children;
|
6477
|
+
|
6478
|
+
var _useContext = useContext(PageContext),
|
6479
|
+
pageContext = _useContext[0],
|
6480
|
+
setPageContext = _useContext[1];
|
6481
|
+
|
6482
|
+
var context = TableContext(url, field, host, urlQuery);
|
6483
|
+
var selected = pageContext.selected,
|
6484
|
+
tab = pageContext.tab;
|
6485
|
+
var timer = useRef(null);
|
6486
|
+
|
6487
|
+
var _useState = useState(selected),
|
6488
|
+
form = _useState[0],
|
6489
|
+
setForm = _useState[1];
|
6490
|
+
|
6491
|
+
var _useState2 = useState([]),
|
6492
|
+
tabs = _useState2[0],
|
6493
|
+
setTabs = _useState2[1];
|
6494
|
+
|
6495
|
+
useEffect(function () {
|
6496
|
+
try {
|
6497
|
+
var _field = Object.values(schema).find(function (field) {
|
6498
|
+
return field.tab && field.tab === true;
|
6499
|
+
});
|
6500
|
+
|
6501
|
+
var _tabs = _field.options.map(function (option) {
|
6502
|
+
return Object.assign({}, option, {
|
6503
|
+
field: _field.id
|
6504
|
+
});
|
6505
|
+
});
|
6506
|
+
|
6507
|
+
setTabs(_tabs);
|
6508
|
+
context.changeTab(_tabs[0]);
|
6509
|
+
setPageContext(context);
|
6510
|
+
return Promise.resolve();
|
6511
|
+
} catch (e) {
|
6512
|
+
return Promise.reject(e);
|
6513
|
+
}
|
6514
|
+
}, []);
|
6515
|
+
useEffect(function () {
|
6516
|
+
try {
|
6517
|
+
console.log("TAB", tab);
|
6518
|
+
|
6519
|
+
var _temp2 = function () {
|
6520
|
+
if (tab) {
|
6521
|
+
var _filter;
|
6522
|
+
|
6523
|
+
var filter = (_filter = {}, _filter[tab.field] = tab.value, _filter);
|
6524
|
+
return Promise.resolve(pageContext.load(filter, [])).then(function () {
|
6525
|
+
setPageContext(Object.assign({}, pageContext));
|
6526
|
+
});
|
6527
|
+
}
|
6528
|
+
}();
|
6529
|
+
|
6530
|
+
return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
|
6531
|
+
} catch (e) {
|
6532
|
+
return Promise.reject(e);
|
6533
|
+
}
|
6534
|
+
}, [tab]);
|
6535
|
+
useEffect(function () {
|
6536
|
+
setForm(selected);
|
6537
|
+
}, [selected]);
|
6538
|
+
useEffect(function () {
|
6539
|
+
if (autosave) {
|
6540
|
+
clearTimeout(timer.current);
|
6541
|
+
timer.current = setTimeout(function () {
|
6542
|
+
if (canSave()) save();
|
6543
|
+
}, delay);
|
6544
|
+
}
|
6545
|
+
}, [form]);
|
6546
|
+
|
6547
|
+
function add() {
|
6548
|
+
var onOK = function onOK(form) {
|
6549
|
+
try {
|
6550
|
+
return Promise.resolve(pageContext.create(form)).then(function () {
|
6551
|
+
setPageContext(Object.assign({}, pageContext));
|
6552
|
+
});
|
6553
|
+
} catch (e) {
|
6554
|
+
return Promise.reject(e);
|
6555
|
+
}
|
6556
|
+
};
|
6557
|
+
|
6558
|
+
site.openDialog( /*#__PURE__*/React.createElement(CreateContentDialog, {
|
6559
|
+
label: "Crear " + name,
|
6560
|
+
type: schema,
|
6561
|
+
onOK: onOK,
|
6562
|
+
validator: validator,
|
6563
|
+
filter: formFilter
|
6564
|
+
}));
|
6565
|
+
}
|
6566
|
+
|
6567
|
+
function saveQuery(filters) {
|
6568
|
+
var onOK = function onOK(form) {
|
6569
|
+
try {
|
6570
|
+
form.filters = filters;
|
6571
|
+
form.layout = {};
|
6572
|
+
form.user = user;
|
6573
|
+
form.url = url;
|
6574
|
+
return Promise.resolve(pageContext.createQuery(form, user)).then(function () {
|
6575
|
+
setPageContext(Object.assign({}, pageContext));
|
6576
|
+
});
|
6577
|
+
} catch (e) {
|
6578
|
+
return Promise.reject(e);
|
6579
|
+
}
|
6580
|
+
};
|
6581
|
+
|
6582
|
+
site.openDialog( /*#__PURE__*/React.createElement(CreateContentDialog, {
|
6583
|
+
label: "Nueva query",
|
6584
|
+
type: QUERY,
|
6585
|
+
onOK: onOK
|
6586
|
+
}));
|
6587
|
+
}
|
6588
|
+
|
6589
|
+
function change(next) {
|
6590
|
+
setForm(next);
|
6591
|
+
}
|
6592
|
+
|
6593
|
+
function canSave() {
|
6594
|
+
var can = !equal(form, selected);
|
6595
|
+
return can;
|
6596
|
+
}
|
6597
|
+
|
6598
|
+
function closeAside() {
|
6599
|
+
pageContext.select(null);
|
6600
|
+
setPageContext(Object.assign({}, pageContext));
|
6601
|
+
}
|
6602
|
+
|
6603
|
+
function renderAside() {
|
6604
|
+
var rowSelected = selected && form;
|
6605
|
+
var rowChecked = pageContext.checked && pageContext.checked.size > 0;
|
6606
|
+
|
6607
|
+
if (rowSelected || rowChecked) {
|
6608
|
+
return /*#__PURE__*/React.createElement("aside", {
|
6609
|
+
className: "table-page"
|
6610
|
+
}, rowSelected ? /*#__PURE__*/React.createElement(TableRowEditor, {
|
6611
|
+
content: new Content(schema, form),
|
6612
|
+
filter: editorFilter,
|
6613
|
+
onChange: change,
|
6614
|
+
onClose: closeAside,
|
6615
|
+
editable: canEdit
|
6616
|
+
}) : null, rowChecked ? /*#__PURE__*/React.createElement(TableSelector, {
|
6617
|
+
schema: schema,
|
6618
|
+
actions: selectionActions
|
6619
|
+
}) : null);
|
6620
|
+
}
|
6621
|
+
|
6622
|
+
return null;
|
6623
|
+
}
|
6624
|
+
|
6625
|
+
function renderActions() {
|
6626
|
+
return actions.map(function (element) {
|
6627
|
+
var action = function action() {
|
6628
|
+
return element.props.action(pageContext);
|
6629
|
+
};
|
6630
|
+
|
6631
|
+
var clone = React.cloneElement(element, {
|
6632
|
+
action: action
|
6633
|
+
});
|
6634
|
+
return clone;
|
6635
|
+
});
|
6636
|
+
}
|
6637
|
+
|
6638
|
+
function changeTab(id) {
|
6639
|
+
var tab = tabs.find(function (tab) {
|
6640
|
+
return tab.value === id;
|
6641
|
+
});
|
6642
|
+
pageContext.changeTab(tab);
|
6643
|
+
setPageContext(Object.assign({}, pageContext));
|
6644
|
+
}
|
6645
|
+
|
6646
|
+
function renderTabs() {
|
6647
|
+
var selected = tab ? tab.value : null;
|
6648
|
+
console.log(selected);
|
6649
|
+
return /*#__PURE__*/React.createElement(Tabs, {
|
6650
|
+
selected: selected,
|
6651
|
+
onChange: changeTab
|
6652
|
+
}, tabs.map(function (tab) {
|
6653
|
+
return /*#__PURE__*/React.createElement(Tab, {
|
6654
|
+
id: tab.value,
|
6655
|
+
label: tab.label
|
6656
|
+
});
|
6657
|
+
}));
|
6658
|
+
}
|
6659
|
+
|
6660
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Header, {
|
6661
|
+
className: "table-page",
|
6662
|
+
title: /*#__PURE__*/React.createElement(Text, null, title)
|
6663
|
+
}, canAdd ? /*#__PURE__*/React.createElement(Button, {
|
6664
|
+
icon: "add",
|
6665
|
+
label: "A\xF1adir",
|
6666
|
+
action: add,
|
6667
|
+
raised: true
|
6668
|
+
}) : null, "\xA0", /*#__PURE__*/React.createElement(Button, {
|
6669
|
+
icon: "refresh",
|
6670
|
+
label: "Reload",
|
6671
|
+
action: reload
|
6672
|
+
}), dev ? /*#__PURE__*/React.createElement(MenuIcon, {
|
6673
|
+
align: "alignRight"
|
6674
|
+
}, /*#__PURE__*/React.createElement(MenuItem, {
|
6675
|
+
label: "Cargar Escenario 1",
|
6676
|
+
onSelect: playScenario
|
6677
|
+
})) : null, renderActions()), canQuery || canFilter ? /*#__PURE__*/React.createElement("menu", {
|
6678
|
+
className: "table-page"
|
6679
|
+
}, canQuery ? /*#__PURE__*/React.createElement(TableQueries, {
|
6680
|
+
schema: schema,
|
6681
|
+
url: url,
|
6682
|
+
user: user
|
6683
|
+
}) : null, canFilter ? /*#__PURE__*/React.createElement(TableFilters, {
|
6684
|
+
schema: schema,
|
6685
|
+
onSave: canQuery ? saveQuery : null
|
6686
|
+
}) : null) : null, /*#__PURE__*/React.createElement("main", {
|
6687
|
+
key: id,
|
6688
|
+
className: "table-page"
|
6689
|
+
}, /*#__PURE__*/React.createElement(TableEditor, {
|
6690
|
+
icon: icon,
|
6691
|
+
title: name,
|
6692
|
+
tabs: renderTabs(),
|
6693
|
+
schema: schema,
|
6694
|
+
delay: delay,
|
6695
|
+
editable: editable,
|
6696
|
+
groupBy: groupBy,
|
6697
|
+
filter: tableFilter,
|
6698
|
+
actions: tableActions,
|
6699
|
+
canDelete: canDelete
|
6700
|
+
}), children ? /*#__PURE__*/React.createElement("article", null, children) : null), renderAside());
|
6701
|
+
};
|
6702
|
+
|
6703
|
+
var TableRowEditor = function TableRowEditor(props) {
|
6704
|
+
var name = props.name,
|
6705
|
+
content = props.content,
|
6706
|
+
filter = props.filter,
|
6707
|
+
editable = props.editable,
|
6708
|
+
onChange = props.onChange,
|
6709
|
+
onClose = props.onClose;
|
6710
|
+
return /*#__PURE__*/React.createElement("div", {
|
6711
|
+
className: "table-row-editor"
|
6712
|
+
}, /*#__PURE__*/React.createElement(Header, {
|
6713
|
+
icon: "local_offer",
|
6714
|
+
title: name || "Propiedades"
|
6715
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
6716
|
+
icon: "close",
|
6717
|
+
clickable: true,
|
6718
|
+
action: onClose
|
6719
|
+
})), /*#__PURE__*/React.createElement("main", null, editable ? /*#__PURE__*/React.createElement(ContentEditor, {
|
6720
|
+
content: content,
|
6721
|
+
onChange: onChange,
|
6722
|
+
filter: filter
|
6723
|
+
}) : /*#__PURE__*/React.createElement(ContentViewer, {
|
6724
|
+
content: content
|
6725
|
+
})));
|
6726
|
+
};
|
6727
|
+
/**
|
6728
|
+
* Table Selector
|
6729
|
+
*/
|
6730
|
+
|
6731
|
+
|
6732
|
+
var TableSelector = function TableSelector(props) {
|
6733
|
+
var schema = props.schema,
|
6734
|
+
_props$actions2 = props.actions,
|
6735
|
+
actions = _props$actions2 === void 0 ? [] : _props$actions2;
|
6736
|
+
|
6737
|
+
var _useContext2 = useContext(PageContext),
|
6738
|
+
pageContext = _useContext2[0],
|
6739
|
+
setPageContext = _useContext2[1];
|
6740
|
+
|
6741
|
+
var all = pageContext.all,
|
6742
|
+
checked = pageContext.checked;
|
6743
|
+
var count = checked.size + "/" + all.length;
|
6744
|
+
var columns = Object.keys(schema).filter(function (key) {
|
6745
|
+
return schema[key].selectorColumn === true;
|
6746
|
+
}).map(function (key) {
|
6747
|
+
var field = schema[key];
|
6748
|
+
return {
|
6749
|
+
id: field.id,
|
6750
|
+
label: field.label
|
6751
|
+
};
|
6752
|
+
});
|
6753
|
+
var rows = all.filter(function (item) {
|
6754
|
+
return checked.has(item.id);
|
6755
|
+
});
|
6756
|
+
var table = {
|
6757
|
+
columns: columns,
|
6758
|
+
rows: rows || []
|
6759
|
+
};
|
6760
|
+
var buttons = actions.map(function (_ref) {
|
6761
|
+
var label = _ref.label,
|
6762
|
+
_action = _ref.action,
|
6763
|
+
validate = _ref.validate;
|
6764
|
+
return /*#__PURE__*/React.createElement(Button, {
|
6765
|
+
label: label,
|
6766
|
+
raised: true,
|
6767
|
+
action: function action() {
|
6768
|
+
return _action(checked, pageContext, function () {
|
6769
|
+
try {
|
6770
|
+
return Promise.resolve(pageContext.load()).then(function () {
|
6771
|
+
setPageContext(Object.assign({}, pageContext));
|
6772
|
+
});
|
6773
|
+
} catch (e) {
|
6774
|
+
return Promise.reject(e);
|
6775
|
+
}
|
6776
|
+
}, rows);
|
6777
|
+
},
|
6778
|
+
disabled: !validate(checked, rows)
|
6779
|
+
});
|
6780
|
+
});
|
6781
|
+
return /*#__PURE__*/React.createElement("div", {
|
6782
|
+
className: "table-selector"
|
6783
|
+
}, /*#__PURE__*/React.createElement(Header, {
|
6784
|
+
icon: "checklist_rtl",
|
6785
|
+
title: "Selecci\xF3n"
|
6786
|
+
}, /*#__PURE__*/React.createElement("span", {
|
6787
|
+
className: "size"
|
6788
|
+
}, count)), /*#__PURE__*/React.createElement("main", null, /*#__PURE__*/React.createElement(DataTable, table)), /*#__PURE__*/React.createElement("footer", null, buttons));
|
6789
|
+
};
|
6790
|
+
/**
|
6791
|
+
* Table Queries
|
6792
|
+
*/
|
6793
|
+
|
6794
|
+
|
6795
|
+
var TableQueries = function TableQueries(props) {
|
6796
|
+
var remove = function remove(id) {
|
6797
|
+
try {
|
6798
|
+
return Promise.resolve(pageContext.removeQuery(id, user)).then(function () {
|
6799
|
+
setPageContext(Object.assign({}, pageContext));
|
6800
|
+
});
|
6801
|
+
} catch (e) {
|
6802
|
+
return Promise.reject(e);
|
6803
|
+
}
|
6804
|
+
};
|
6805
|
+
|
6806
|
+
var _useContext3 = useContext(PageContext),
|
6807
|
+
pageContext = _useContext3[0],
|
6808
|
+
setPageContext = _useContext3[1];
|
6809
|
+
|
6810
|
+
var url = props.url,
|
6811
|
+
user = props.user;
|
6812
|
+
var _pageContext$queries = pageContext.queries,
|
6813
|
+
queries = _pageContext$queries === void 0 ? [] : _pageContext$queries;
|
6814
|
+
|
6815
|
+
var _useState3 = useState(),
|
6816
|
+
selected = _useState3[0],
|
6817
|
+
setSelected = _useState3[1];
|
6818
|
+
|
6819
|
+
function select(query) {
|
6820
|
+
setSelected(query.id);
|
6821
|
+
pageContext.changeFilters(query.filters);
|
6822
|
+
setPageContext(Object.assign({}, pageContext));
|
6823
|
+
}
|
6824
|
+
|
6825
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Header, {
|
6826
|
+
className: "table-queries",
|
6827
|
+
title: /*#__PURE__*/React.createElement(Text, null, "Queries")
|
6828
|
+
}), /*#__PURE__*/React.createElement("main", {
|
6829
|
+
className: "table-queries"
|
6830
|
+
}, queries ? queries.filter(function (query) {
|
6831
|
+
return query.url === url;
|
6832
|
+
}).map(function (query) {
|
6833
|
+
var style = selected === query.id ? "selected" : "";
|
6834
|
+
return /*#__PURE__*/React.createElement("div", {
|
6835
|
+
className: "table-queries-item " + style,
|
6836
|
+
onClick: function onClick() {
|
6837
|
+
return select(query);
|
6838
|
+
}
|
6839
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
6840
|
+
icon: "star",
|
6841
|
+
size: "small"
|
6842
|
+
}), /*#__PURE__*/React.createElement("label", null, query.name), /*#__PURE__*/React.createElement(Icon, {
|
6843
|
+
icon: "close",
|
6844
|
+
clickable: true,
|
6845
|
+
size: "small",
|
6846
|
+
action: function action() {
|
6847
|
+
return remove(query.id);
|
6848
|
+
}
|
6849
|
+
}));
|
6850
|
+
}) : /*#__PURE__*/React.createElement("div", null, "...empty...")));
|
6851
|
+
};
|
6852
|
+
/**
|
6853
|
+
* Table Filters
|
6854
|
+
*/
|
6855
|
+
|
6856
|
+
|
6857
|
+
var TableFilters = function TableFilters(props) {
|
6858
|
+
var reload = function reload() {
|
6859
|
+
try {
|
6860
|
+
return Promise.resolve(pageContext.load(form, likes)).then(function () {
|
6861
|
+
setPageContext(Object.assign({}, pageContext));
|
6862
|
+
});
|
6863
|
+
} catch (e) {
|
6864
|
+
return Promise.reject(e);
|
6865
|
+
}
|
6866
|
+
};
|
6867
|
+
|
6868
|
+
var change = function change(next) {
|
6869
|
+
try {
|
6870
|
+
setForm(next);
|
6871
|
+
return Promise.resolve();
|
6872
|
+
} catch (e) {
|
6873
|
+
return Promise.reject(e);
|
6874
|
+
}
|
6875
|
+
};
|
6876
|
+
|
6877
|
+
var _useContext4 = useContext(PageContext),
|
6878
|
+
pageContext = _useContext4[0],
|
6879
|
+
setPageContext = _useContext4[1];
|
6880
|
+
|
6881
|
+
var filters = pageContext.filters;
|
6882
|
+
var schema = props.schema,
|
6883
|
+
onSave = props.onSave;
|
6884
|
+
|
6885
|
+
var _useState4 = useState({}),
|
6886
|
+
form = _useState4[0],
|
6887
|
+
setForm = _useState4[1];
|
6888
|
+
|
6889
|
+
var filterSchema = useMemo(function () {
|
6890
|
+
var filterSchema = Object.assign({}, schema);
|
6891
|
+
|
6892
|
+
for (var key in filterSchema) {
|
6893
|
+
if (filterSchema[key].filter === false) {
|
6894
|
+
delete filterSchema[key];
|
6895
|
+
} else {
|
6896
|
+
if (filterSchema[key].type === TYPES.ENTITY) {
|
6897
|
+
var fs = filterSchema[key].item;
|
6898
|
+
|
6899
|
+
for (var key in fs) {
|
6900
|
+
if (fs[key].filter === false) delete fs[key];
|
6901
|
+
}
|
6902
|
+
}
|
6903
|
+
}
|
6904
|
+
} //Object.values(filterSchema).forEach(field => field.section = null)
|
6905
|
+
|
6906
|
+
|
6907
|
+
delete filterSchema.flows;
|
6908
|
+
return filterSchema;
|
6909
|
+
}, [schema]);
|
6910
|
+
var likes = useMemo(function () {
|
6911
|
+
var fields = Object.values(schema);
|
6912
|
+
return fields.reduce(function (likes, field) {
|
6913
|
+
if (field.like === true) likes.push(field.id);
|
6914
|
+
return likes;
|
6915
|
+
}, []);
|
6916
|
+
}, [schema]);
|
6917
|
+
useEffect(function () {
|
6918
|
+
if (filters) setForm(filters);
|
6919
|
+
}, [filters]);
|
6920
|
+
useEffect(function () {
|
6921
|
+
reload();
|
6922
|
+
}, [form]);
|
6923
|
+
|
6924
|
+
function clear() {
|
6925
|
+
change({});
|
6926
|
+
}
|
6927
|
+
|
6928
|
+
function save() {
|
6929
|
+
if (onSave) {
|
6930
|
+
onSave(form);
|
6931
|
+
}
|
6932
|
+
}
|
6933
|
+
|
6934
|
+
var content = new Content(filterSchema, form);
|
6935
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Header, {
|
6936
|
+
className: "table-filters",
|
6937
|
+
title: /*#__PURE__*/React.createElement(Text, null, "Filters")
|
6938
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
6939
|
+
icon: "filter_list_off",
|
6940
|
+
size: "small",
|
6941
|
+
clickable: true,
|
6942
|
+
action: clear
|
6943
|
+
}), onSave ? /*#__PURE__*/React.createElement(Icon, {
|
6944
|
+
icon: "save",
|
6945
|
+
size: "small",
|
6946
|
+
clickable: true,
|
6947
|
+
action: save
|
6948
|
+
}) : null), /*#__PURE__*/React.createElement("main", {
|
6949
|
+
className: "table-filters"
|
6950
|
+
}, /*#__PURE__*/React.createElement(ContentEditor, {
|
6951
|
+
content: content,
|
6952
|
+
onChange: change
|
6953
|
+
})));
|
6954
|
+
};
|
6955
|
+
/**
|
6956
|
+
* Table Editor
|
6957
|
+
*/
|
6958
|
+
|
6959
|
+
|
6960
|
+
var TableEditor = function TableEditor(props) {
|
6961
|
+
var checkOne = function checkOne(id, field, value) {
|
6962
|
+
check([id], value);
|
6963
|
+
return Promise.resolve();
|
6964
|
+
};
|
6965
|
+
|
6966
|
+
var check = function check(ids, value) {
|
6967
|
+
try {
|
6968
|
+
pageContext.check(ids, value);
|
6969
|
+
setPageContext(Object.assign({}, pageContext));
|
6970
|
+
return Promise.resolve();
|
6971
|
+
} catch (e) {
|
6972
|
+
return Promise.reject(e);
|
6973
|
+
}
|
6974
|
+
};
|
6975
|
+
|
6976
|
+
var select = function select(row, event) {
|
6977
|
+
try {
|
6978
|
+
clear();
|
6979
|
+
return Promise.resolve(pageContext.select(row.id)).then(function () {
|
6980
|
+
setPageContext(Object.assign({}, pageContext));
|
6981
|
+
});
|
6982
|
+
} catch (e) {
|
6983
|
+
return Promise.reject(e);
|
6984
|
+
}
|
6985
|
+
};
|
6986
|
+
|
6987
|
+
var remove = function remove(id) {
|
6988
|
+
try {
|
6989
|
+
return Promise.resolve(site.confirm("Are you sure ?")).then(function (confirm) {
|
6990
|
+
var _temp3 = function () {
|
6991
|
+
if (confirm) {
|
6992
|
+
return Promise.resolve(pageContext.remove(id)).then(function () {
|
6993
|
+
pageContext.clear();
|
6994
|
+
setPageContext(Object.assign({}, pageContext));
|
6995
|
+
});
|
6996
|
+
}
|
6997
|
+
}();
|
6998
|
+
|
6999
|
+
if (_temp3 && _temp3.then) return _temp3.then(function () {});
|
7000
|
+
});
|
7001
|
+
} catch (e) {
|
7002
|
+
return Promise.reject(e);
|
7003
|
+
}
|
7004
|
+
};
|
7005
|
+
|
7006
|
+
var site = useContext(SiteContext);
|
7007
|
+
|
7008
|
+
var _useContext5 = useContext(PageContext),
|
7009
|
+
pageContext = _useContext5[0],
|
7010
|
+
setPageContext = _useContext5[1];
|
7011
|
+
|
7012
|
+
var _pageContext$all = pageContext.all,
|
7013
|
+
all = _pageContext$all === void 0 ? [] : _pageContext$all;
|
7014
|
+
var icon = props.icon,
|
7015
|
+
title = props.title,
|
7016
|
+
schema = props.schema,
|
7017
|
+
editable = props.editable,
|
7018
|
+
canDelete = props.canDelete,
|
7019
|
+
filter = props.filter,
|
7020
|
+
actions = props.actions,
|
7021
|
+
tabs = props.tabs;
|
7022
|
+
|
7023
|
+
var _useState5 = useState(props.groupBy),
|
7024
|
+
groupBy = _useState5[0],
|
7025
|
+
setGroupBy = _useState5[1];
|
7026
|
+
|
7027
|
+
function changeGroup(id, value) {
|
7028
|
+
setGroupBy(value);
|
7029
|
+
}
|
7030
|
+
|
7031
|
+
function change(rowID, cellID, value) {
|
7032
|
+
var _Object$assign;
|
7033
|
+
|
7034
|
+
var row = all.find(function (r) {
|
7035
|
+
return r.id === rowID;
|
7036
|
+
});
|
7037
|
+
var next = Object.assign({}, row, (_Object$assign = {}, _Object$assign[cellID] = value, _Object$assign));
|
7038
|
+
delete next.actions;
|
7039
|
+
pageContext.update(next);
|
7040
|
+
setPageContext(Object.assign({}, pageContext));
|
7041
|
+
}
|
7042
|
+
|
7043
|
+
function clear() {
|
7044
|
+
pageContext.clear();
|
7045
|
+
setPageContext(Object.assign({}, pageContext));
|
7046
|
+
}
|
7047
|
+
|
7048
|
+
function run(action, item) {
|
7049
|
+
action.action(item.id, pageContext, function () {
|
7050
|
+
try {
|
7051
|
+
return Promise.resolve(pageContext.load()).then(function () {
|
7052
|
+
setPageContext(Object.assign({}, pageContext));
|
7053
|
+
});
|
7054
|
+
} catch (e) {
|
7055
|
+
return Promise.reject(e);
|
7056
|
+
}
|
7057
|
+
});
|
7058
|
+
}
|
7059
|
+
|
7060
|
+
function renderGroupLabel(groupName) {
|
7061
|
+
var grouper = schema[groupBy];
|
7062
|
+
if (!groupName || !grouper) return "";
|
7063
|
+
|
7064
|
+
if (grouper.options) {
|
7065
|
+
var options = CHECK['isFunction'](grouper.options) ? grouper.options() : grouper.options;
|
7066
|
+
var option = options.find(function (option) {
|
7067
|
+
return option.value === groupName;
|
7068
|
+
});
|
7069
|
+
return option ? option.label : groupName;
|
7070
|
+
} else {
|
7071
|
+
return groupName;
|
7072
|
+
}
|
7073
|
+
}
|
7074
|
+
|
7075
|
+
function renderGroups() {
|
7076
|
+
var items = filter ? filter(all) : all;
|
7077
|
+
var groups = items.reduce(function (groups, item) {
|
7078
|
+
var groupName = item[groupBy];
|
7079
|
+
var group = groups[groupName];
|
7080
|
+
if (!group) groups[groupName] = [];
|
7081
|
+
groups[groupName].push(item);
|
7082
|
+
return groups;
|
7083
|
+
}, {});
|
7084
|
+
return Object.keys(groups).map(function (groupName) {
|
7085
|
+
var table = {
|
7086
|
+
columns: Object.values(schema).filter(function (field) {
|
7087
|
+
return field.column === true;
|
7088
|
+
}).map(function (field) {
|
7089
|
+
var options = field.options;
|
7090
|
+
|
7091
|
+
if (options && typeof options == 'function') {
|
7092
|
+
options = options();
|
7093
|
+
}
|
7094
|
+
|
7095
|
+
return {
|
7096
|
+
id: field.id,
|
7097
|
+
label: field.label,
|
7098
|
+
type: field.type,
|
7099
|
+
format: field.format,
|
7100
|
+
item: field.item ? field.item : [],
|
7101
|
+
onChange: field.id === "checked" ? checkOne : field.editable ? change : null,
|
7102
|
+
|
7103
|
+
/* checked has it´s own handler */
|
7104
|
+
options: options
|
7105
|
+
};
|
7106
|
+
}),
|
7107
|
+
rows: groups[groupName].map(function (item) {
|
7108
|
+
item.checked = pageContext.checked ? pageContext.checked.has(item.id) : false;
|
7109
|
+
item.actions = actions ? actions.map(function (_action2) {
|
7110
|
+
return _action2.filter ? _action2.filter(item) ? /*#__PURE__*/React.createElement(Icon, {
|
7111
|
+
icon: _action2.icon,
|
7112
|
+
clickable: true,
|
7113
|
+
size: "small",
|
7114
|
+
action: function action() {
|
7115
|
+
return run(_action2, item);
|
7116
|
+
}
|
7117
|
+
}) : null : /*#__PURE__*/React.createElement(Icon, {
|
7118
|
+
icon: _action2.icon,
|
7119
|
+
clickable: true,
|
7120
|
+
size: "small",
|
7121
|
+
action: function action() {
|
7122
|
+
return run(_action2, item);
|
7123
|
+
}
|
7124
|
+
});
|
7125
|
+
}) : [];
|
7126
|
+
if (canDelete) item.actions.push( /*#__PURE__*/React.createElement(Icon, {
|
7127
|
+
icon: "delete",
|
7128
|
+
size: "small",
|
7129
|
+
clickable: true,
|
7130
|
+
action: function action() {
|
7131
|
+
return remove(item.id);
|
7132
|
+
}
|
7133
|
+
}));
|
7134
|
+
return item;
|
7135
|
+
})
|
7136
|
+
};
|
7137
|
+
table.columns.push({
|
7138
|
+
id: "actions"
|
7139
|
+
});
|
7140
|
+
var groupSize = groups[groupName].length;
|
7141
|
+
var title = /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("span", {
|
7142
|
+
className: "size"
|
7143
|
+
}, groupSize), renderGroupLabel(groupName));
|
7144
|
+
return /*#__PURE__*/React.createElement(Fragment, {
|
7145
|
+
key: groupName
|
7146
|
+
}, /*#__PURE__*/React.createElement(Header, {
|
7147
|
+
title: title
|
7148
|
+
}, /*#__PURE__*/React.createElement("span", {
|
7149
|
+
className: "size"
|
7150
|
+
}, groupSize)), /*#__PURE__*/React.createElement(DataTable, _extends({}, table, {
|
7151
|
+
onRowSelection: select,
|
7152
|
+
editable: editable,
|
7153
|
+
onCheckAll: check
|
7154
|
+
})));
|
7155
|
+
});
|
7156
|
+
}
|
7157
|
+
|
7158
|
+
function buildGroupOptions(schema) {
|
7159
|
+
return Object.values(schema).filter(function (field) {
|
7160
|
+
return field.grouper === true;
|
7161
|
+
}).map(function (field) {
|
7162
|
+
return {
|
7163
|
+
label: field.label,
|
7164
|
+
value: field.id
|
7165
|
+
};
|
7166
|
+
});
|
7167
|
+
}
|
7168
|
+
|
7169
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Header, {
|
7170
|
+
icon: icon,
|
7171
|
+
title: /*#__PURE__*/React.createElement(Text, null, title)
|
7172
|
+
}, /*#__PURE__*/React.createElement(DropDown, {
|
7173
|
+
id: "groupBy",
|
7174
|
+
label: "Agrupar Por",
|
7175
|
+
value: groupBy,
|
7176
|
+
options: buildGroupOptions(schema),
|
7177
|
+
onChange: changeGroup
|
7178
|
+
}), tabs), /*#__PURE__*/React.createElement("main", {
|
7179
|
+
className: "table-editor"
|
7180
|
+
}, renderGroups()));
|
7181
|
+
};
|
7182
|
+
/**
|
7183
|
+
* Table Context
|
7184
|
+
*/
|
7185
|
+
|
7186
|
+
var TableContext = function TableContext(url, field, host, urlQuery) {
|
7187
|
+
var API = TableAPI(url, host);
|
7188
|
+
return {
|
7189
|
+
all: [],
|
7190
|
+
checked: new Set([]),
|
7191
|
+
selected: null,
|
7192
|
+
filters: {},
|
7193
|
+
queries: [],
|
7194
|
+
tab: null,
|
7195
|
+
load: function load(filter, like) {
|
7196
|
+
if (like === void 0) {
|
7197
|
+
like = [];
|
7198
|
+
}
|
7199
|
+
|
7200
|
+
try {
|
7201
|
+
var _this2 = this;
|
7202
|
+
|
7203
|
+
var _temp5 = _catch(function () {
|
7204
|
+
var filters = filter ? Object.keys(filter).reduce(function (filters, key) {
|
7205
|
+
var field = filter[key];
|
7206
|
+
|
7207
|
+
if (field) {
|
7208
|
+
if (CHECK['isObject'](field)) {
|
7209
|
+
Object.keys(field).forEach(function (key2) {
|
7210
|
+
var subfield = field[key2];
|
7211
|
+
if (subfield) filters[key + "." + key2] = subfield;
|
7212
|
+
});
|
7213
|
+
} else {
|
7214
|
+
filters[key] = field;
|
7215
|
+
}
|
7216
|
+
}
|
7217
|
+
|
7218
|
+
return filters;
|
7219
|
+
}, {}) : [];
|
7220
|
+
|
7221
|
+
if (_this2.tab) {
|
7222
|
+
filters[_this2.tab.field] = _this2.tab.value;
|
7223
|
+
}
|
7224
|
+
|
7225
|
+
return Promise.resolve(API.all(filters, like)).then(function (data) {
|
7226
|
+
_this2.all = field ? data[field] : data;
|
7227
|
+
});
|
7228
|
+
}, function (error) {
|
7229
|
+
console.log(error);
|
7230
|
+
});
|
7231
|
+
|
7232
|
+
return Promise.resolve(_temp5 && _temp5.then ? _temp5.then(function () {}) : void 0);
|
7233
|
+
} catch (e) {
|
7234
|
+
return Promise.reject(e);
|
7235
|
+
}
|
7236
|
+
},
|
7237
|
+
check: function check(ids, isChecked) {
|
7238
|
+
var _this3 = this;
|
7239
|
+
|
7240
|
+
if (isChecked === void 0) {
|
7241
|
+
isChecked = true;
|
7242
|
+
}
|
7243
|
+
|
7244
|
+
if (isChecked) {
|
7245
|
+
ids.forEach(function (id) {
|
7246
|
+
return _this3.checked.add(id);
|
7247
|
+
});
|
7248
|
+
} else {
|
7249
|
+
ids.forEach(function (id) {
|
7250
|
+
return _this3.checked["delete"](id);
|
7251
|
+
});
|
7252
|
+
}
|
7253
|
+
},
|
7254
|
+
changeTab: function changeTab(tab) {
|
7255
|
+
this.tab = tab;
|
7256
|
+
},
|
7257
|
+
select: function select(id) {
|
7258
|
+
var result = this.all.find(function (item) {
|
7259
|
+
return item.id === id;
|
7260
|
+
});
|
7261
|
+
this.selected = result;
|
7262
|
+
},
|
7263
|
+
clear: function clear() {
|
7264
|
+
this.selected = null;
|
7265
|
+
},
|
7266
|
+
create: function create(form) {
|
7267
|
+
try {
|
7268
|
+
var _this5 = this;
|
7269
|
+
|
7270
|
+
var _temp7 = _catch(function () {
|
7271
|
+
return Promise.resolve(API.create(form)).then(function () {
|
7272
|
+
return Promise.resolve(_this5.load({}, [])).then(function () {});
|
7273
|
+
});
|
7274
|
+
}, function (error) {
|
7275
|
+
console.log(error);
|
7276
|
+
});
|
7277
|
+
|
7278
|
+
return Promise.resolve(_temp7 && _temp7.then ? _temp7.then(function () {}) : void 0);
|
7279
|
+
} catch (e) {
|
7280
|
+
return Promise.reject(e);
|
7281
|
+
}
|
7282
|
+
},
|
7283
|
+
update: function update(form) {
|
7284
|
+
try {
|
7285
|
+
var _this7 = this;
|
7286
|
+
|
7287
|
+
var _temp9 = _catch(function () {
|
7288
|
+
return Promise.resolve(API.update(form)).then(function () {
|
7289
|
+
return Promise.resolve(_this7.load()).then(function () {});
|
7290
|
+
});
|
7291
|
+
}, function (error) {
|
7292
|
+
console.log(error);
|
7293
|
+
});
|
7294
|
+
|
7295
|
+
return Promise.resolve(_temp9 && _temp9.then ? _temp9.then(function () {}) : void 0);
|
7296
|
+
} catch (e) {
|
7297
|
+
return Promise.reject(e);
|
7298
|
+
}
|
7299
|
+
},
|
7300
|
+
remove: function remove(id) {
|
7301
|
+
try {
|
7302
|
+
var _this9 = this;
|
7303
|
+
|
7304
|
+
var _temp11 = _catch(function () {
|
7305
|
+
return Promise.resolve(API.remove(id)).then(function () {
|
7306
|
+
return Promise.resolve(_this9.load()).then(function () {});
|
7307
|
+
});
|
7308
|
+
}, function (error) {
|
7309
|
+
console.log(error);
|
7310
|
+
});
|
7311
|
+
|
7312
|
+
return Promise.resolve(_temp11 && _temp11.then ? _temp11.then(function () {}) : void 0);
|
7313
|
+
} catch (e) {
|
7314
|
+
return Promise.reject(e);
|
7315
|
+
}
|
7316
|
+
},
|
7317
|
+
changeFilters: function changeFilters(filters) {
|
7318
|
+
this.filters = filters;
|
7319
|
+
},
|
7320
|
+
loadQueries: function loadQueries(user) {
|
7321
|
+
try {
|
7322
|
+
var _this11 = this;
|
7323
|
+
|
7324
|
+
var _temp13 = _catch(function () {
|
7325
|
+
return Promise.resolve(API.queries(user, urlQuery)).then(function (_API$queries) {
|
7326
|
+
_this11.queries = _API$queries;
|
7327
|
+
});
|
7328
|
+
}, function (error) {
|
7329
|
+
console.log(error);
|
7330
|
+
});
|
7331
|
+
|
7332
|
+
return Promise.resolve(_temp13 && _temp13.then ? _temp13.then(function () {}) : void 0);
|
7333
|
+
} catch (e) {
|
7334
|
+
return Promise.reject(e);
|
7335
|
+
}
|
7336
|
+
},
|
7337
|
+
createQuery: function createQuery(query, user) {
|
7338
|
+
try {
|
7339
|
+
var _this13 = this;
|
7340
|
+
|
7341
|
+
var _temp15 = _catch(function () {
|
7342
|
+
return Promise.resolve(API.createQuery(query, urlQuery)).then(function () {
|
7343
|
+
return Promise.resolve(_this13.loadQueries(user)).then(function () {});
|
7344
|
+
});
|
7345
|
+
}, function (error) {
|
7346
|
+
console.log(error);
|
7347
|
+
});
|
7348
|
+
|
7349
|
+
return Promise.resolve(_temp15 && _temp15.then ? _temp15.then(function () {}) : void 0);
|
7350
|
+
} catch (e) {
|
7351
|
+
return Promise.reject(e);
|
7352
|
+
}
|
7353
|
+
},
|
7354
|
+
removeQuery: function removeQuery(id, user) {
|
7355
|
+
try {
|
7356
|
+
var _this15 = this;
|
7357
|
+
|
7358
|
+
var _temp17 = _catch(function () {
|
7359
|
+
return Promise.resolve(API.removeQuery(id, urlQuery)).then(function () {
|
7360
|
+
return Promise.resolve(_this15.loadQueries(user)).then(function () {});
|
7361
|
+
});
|
7362
|
+
}, function (error) {
|
7363
|
+
console.log(error);
|
7364
|
+
});
|
7365
|
+
|
7366
|
+
return Promise.resolve(_temp17 && _temp17.then ? _temp17.then(function () {}) : void 0);
|
7367
|
+
} catch (e) {
|
7368
|
+
return Promise.reject(e);
|
7369
|
+
}
|
7370
|
+
}
|
7371
|
+
};
|
7372
|
+
};
|
7373
|
+
/**
|
7374
|
+
* table API
|
7375
|
+
*/
|
7376
|
+
|
7377
|
+
|
7378
|
+
var TableAPI = function TableAPI(url, host) {
|
7379
|
+
var http = HTTPClient(host || window.API || process.env.REACT_APP_API, Session);
|
7380
|
+
return {
|
7381
|
+
all: function all(filters, like) {
|
7382
|
+
if (like === void 0) {
|
7383
|
+
like = [];
|
7384
|
+
}
|
7385
|
+
|
7386
|
+
console.log(like);
|
7387
|
+
var queryParams = "?";
|
7388
|
+
|
7389
|
+
if (filters) {
|
7390
|
+
var filterQuery = Object.keys(filters).reduce(function (query, key) {
|
7391
|
+
var value = filters[key];
|
7392
|
+
|
7393
|
+
if (typeof value === 'boolean') {
|
7394
|
+
return query.concat(key + "=" + value + "&");
|
7395
|
+
} else if (Array.isArray(value)) {
|
7396
|
+
var param = value.length === 0 ? '' : value.reduce(function (param, item) {
|
7397
|
+
param = param.concat(key + "=" + item + "&");
|
7398
|
+
return param;
|
7399
|
+
}, "");
|
7400
|
+
return query.concat(param);
|
7401
|
+
} else {
|
7402
|
+
return like.includes(key) ? query.concat(key + "=%" + filters[key] + "%&") : query.concat(key + "=" + filters[key] + "&");
|
7403
|
+
}
|
7404
|
+
}, "");
|
7405
|
+
queryParams = queryParams.concat(filterQuery);
|
7406
|
+
}
|
7407
|
+
|
7408
|
+
return http.GET(url + queryParams);
|
7409
|
+
},
|
7410
|
+
find: function find(id) {
|
7411
|
+
return http.GET(url + "/" + id);
|
7412
|
+
},
|
7413
|
+
create: function create(form) {
|
7414
|
+
var body = JSON.stringify(form);
|
7415
|
+
return http.POST(url, body);
|
7416
|
+
},
|
7417
|
+
update: function update(form) {
|
7418
|
+
var body = JSON.stringify(form);
|
7419
|
+
return http.PUT(url + "/" + form.id, body);
|
7420
|
+
},
|
7421
|
+
remove: function remove(id) {
|
7422
|
+
return http.DELETE(url + "/" + id);
|
7423
|
+
},
|
7424
|
+
queries: function queries(user, url2) {
|
7425
|
+
var url3 = url2 ? url2 : url;
|
7426
|
+
url3 = url3 + "queries";
|
7427
|
+
if (user) url3 = url3 + ("?user=" + user);
|
7428
|
+
return http.GET(url3);
|
7429
|
+
},
|
7430
|
+
createQuery: function createQuery(form, url2) {
|
7431
|
+
var url3 = url2 ? url2 : url;
|
7432
|
+
var body = JSON.stringify(form);
|
7433
|
+
return http.POST(url3 + "queries", body);
|
7434
|
+
},
|
7435
|
+
removeQuery: function removeQuery(id, url2) {
|
7436
|
+
var url3 = url2 ? url2 : url;
|
7437
|
+
return http.DELETE(url3 + "queries/" + id);
|
7438
|
+
}
|
7439
|
+
};
|
7440
|
+
};
|
7441
|
+
|
6350
7442
|
var isFunction = function isFunction(value) {
|
6351
7443
|
return value && (Object.prototype.toString.call(value) === "[object Function]" || "function" === typeof value || value instanceof Function);
|
6352
7444
|
};
|
6353
7445
|
|
6354
|
-
export { Avatar, Button, CheckBox, Chip, Chips, CircularProgress, CollectionContext, CollectionEditor$1 as CollectionEditor, CollectionPage, CollectionTree, Content, ContentEditor, ContentForm, CreateContentDialog, DataTable, Dialog, DropDown, EditContentDialog, FORMATS, FieldEditor, FileExplorer, FileIconsView, Form, HTTPClient, Header, Icon, Kanban, KanbanCard, KanbanColumn, LinearProgress, List, ListEditor, LoginBox, Menu, MenuIcon, MenuItem, MenuSeparator, Page, PageContext, PageProvider, Planner, Property, RadioButton, ResetPasswordBox, Section, Session, Site, SiteContext, SiteProvider, Stack, Switch, TEXTFORMATS, TYPES, Tab, TabbedContentEditor, TableEditor, TablePage, Tabs, Text, TextArea, TextField, Thumbnail, TokenField, Tooltip, Tree, TreeItem, TreeNode, TreededContentEditor, UploadArea, UploadDialog, UploadFile, UploadIcon, Uploader, View, Viewer, WaitScreen, isFunction };
|
7446
|
+
export { Avatar, Button, CheckBox, Chip, Chips, CircularProgress, CollectionContext, CollectionEditor$1 as CollectionEditor, CollectionPage, CollectionTree, Content, ContentEditor, ContentForm, CreateContentDialog, DataTable, Dialog, DropDown, EditContentDialog, FORMATS, FieldEditor, FileExplorer, FileIconsView, Form, HTTPClient, Header, Icon, Kanban, KanbanCard, KanbanColumn, LinearProgress, List, ListEditor, LoginBox, Menu, MenuIcon, MenuItem, MenuSeparator, Page, PageContext, PageProvider, Planner, Property, RadioButton, ResetPasswordBox, Section, Session, Site, SiteContext, SiteProvider, Stack, Switch, TEXTFORMATS, TYPES, Tab, TabbedContentEditor, TabbedTablePage, TableEditor$1 as TableEditor, TablePage, Tabs, Text, TextArea, TextField, Thumbnail, TokenField, Tooltip, Tree, TreeItem, TreeNode, TreededContentEditor, UploadArea, UploadDialog, UploadFile, UploadIcon, Uploader, View, Viewer, WaitScreen, isFunction };
|
6355
7447
|
//# sourceMappingURL=index.modern.js.map
|