react-hook-core 0.0.1 → 0.1.3
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/lib/components.js +404 -511
- package/lib/core.js +90 -27
- package/lib/diff.js +3 -0
- package/lib/edit.js +35 -33
- package/lib/formutil.js +5 -2
- package/lib/index.js +22 -0
- package/lib/merge.js +1 -1
- package/lib/state.js +17 -10
- package/lib/update.js +36 -55
- package/lib/useEdit.js +186 -333
- package/lib/useMessage.js +25 -0
- package/lib/useSearch.js +140 -253
- package/lib/useView.js +70 -161
- package/lib/util.js +6 -2
- package/package.json +7 -9
- package/src/components.ts +430 -376
- package/src/core.ts +115 -59
- package/src/diff.ts +4 -1
- package/src/edit.ts +44 -42
- package/src/formutil.ts +7 -4
- package/src/index.ts +33 -0
- package/src/merge.ts +3 -3
- package/src/state.ts +25 -19
- package/src/update.ts +36 -59
- package/src/useEdit.ts +171 -250
- package/src/useMessage.ts +37 -0
- package/src/useSearch.ts +173 -244
- package/src/useView.ts +64 -101
- package/src/util.ts +8 -4
- package/tsconfig.json +1 -0
package/lib/components.js
CHANGED
|
@@ -23,46 +23,10 @@ var __assign = (this && this.__assign) || function () {
|
|
|
23
23
|
};
|
|
24
24
|
return __assign.apply(this, arguments);
|
|
25
25
|
};
|
|
26
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
27
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
28
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
29
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
30
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
31
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
32
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
36
|
-
var _ = { label: 0, sent: function () { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
37
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
|
38
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
39
|
-
function step(op) {
|
|
40
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
41
|
-
while (_) try {
|
|
42
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
43
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
44
|
-
switch (op[0]) {
|
|
45
|
-
case 0: case 1: t = op; break;
|
|
46
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
47
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
48
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
49
|
-
default:
|
|
50
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
51
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
52
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
53
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
54
|
-
if (t[2]) _.ops.pop();
|
|
55
|
-
_.trys.pop(); continue;
|
|
56
|
-
}
|
|
57
|
-
op = body.call(thisArg, _);
|
|
58
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
59
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
63
27
|
var React = require("react");
|
|
64
28
|
var reflectx_1 = require("reflectx");
|
|
65
|
-
var
|
|
29
|
+
var search_core_1 = require("search-core");
|
|
66
30
|
var core_1 = require("./core");
|
|
67
31
|
var core_2 = require("./core");
|
|
68
32
|
var diff_1 = require("./diff");
|
|
@@ -85,13 +49,15 @@ var ViewComponent = (function (_super) {
|
|
|
85
49
|
_this.loadData = sv;
|
|
86
50
|
}
|
|
87
51
|
else {
|
|
88
|
-
_this.
|
|
89
|
-
if (
|
|
90
|
-
var m =
|
|
52
|
+
_this.loadData = sv.load;
|
|
53
|
+
if (sv.metadata) {
|
|
54
|
+
var m = sv.metadata();
|
|
91
55
|
if (m) {
|
|
92
56
|
_this.metadata = m;
|
|
93
57
|
var meta = edit_1.build(m);
|
|
94
|
-
|
|
58
|
+
if (meta) {
|
|
59
|
+
_this.keys = meta.keys;
|
|
60
|
+
}
|
|
95
61
|
}
|
|
96
62
|
}
|
|
97
63
|
}
|
|
@@ -118,71 +84,49 @@ var ViewComponent = (function (_super) {
|
|
|
118
84
|
if (!n || n.length === 0) {
|
|
119
85
|
return 'model';
|
|
120
86
|
}
|
|
87
|
+
else {
|
|
88
|
+
return n;
|
|
89
|
+
}
|
|
121
90
|
};
|
|
122
91
|
ViewComponent.prototype.componentDidMount = function () {
|
|
123
92
|
this.form = this.ref.current;
|
|
124
93
|
var id = core_2.buildId(this.props, this.keys);
|
|
125
|
-
|
|
94
|
+
if (id) {
|
|
95
|
+
this.load(id);
|
|
96
|
+
}
|
|
126
97
|
};
|
|
127
98
|
ViewComponent.prototype.load = function (_id, callback) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (!this.loadData) return [3, 3];
|
|
145
|
-
return [4, this.loadData(id, ctx)];
|
|
146
|
-
case 2:
|
|
147
|
-
obj = _a.sent();
|
|
148
|
-
return [3, 5];
|
|
149
|
-
case 3: return [4, this.service.load(id, ctx)];
|
|
150
|
-
case 4:
|
|
151
|
-
obj = _a.sent();
|
|
152
|
-
_a.label = 5;
|
|
153
|
-
case 5:
|
|
154
|
-
if (!obj) {
|
|
155
|
-
this.handleNotFound(this.form);
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
if (callback) {
|
|
159
|
-
callback(obj, this.showModel);
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
this.showModel(obj);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return [3, 8];
|
|
166
|
-
case 6:
|
|
167
|
-
err_1 = _a.sent();
|
|
168
|
-
data = (err_1 && err_1.response) ? err_1.response : err_1;
|
|
169
|
-
if (data && data.status === 404) {
|
|
170
|
-
this.handleNotFound(this.form);
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
core_2.error(err_1, this.resourceService.value, this.showError);
|
|
174
|
-
}
|
|
175
|
-
return [3, 8];
|
|
176
|
-
case 7:
|
|
177
|
-
this.running = false;
|
|
178
|
-
if (this.loading) {
|
|
179
|
-
this.loading.hideLoading();
|
|
180
|
-
}
|
|
181
|
-
return [7];
|
|
182
|
-
case 8: return [2];
|
|
99
|
+
var id = _id;
|
|
100
|
+
if (id != null && id !== '' && this.loadData) {
|
|
101
|
+
this.running = true;
|
|
102
|
+
core_1.showLoading(this.loading);
|
|
103
|
+
var com_1 = this;
|
|
104
|
+
this.loadData(id).then(function (obj) {
|
|
105
|
+
if (!obj) {
|
|
106
|
+
com_1.handleNotFound(com_1.form);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
if (callback) {
|
|
110
|
+
callback(obj, com_1.showModel);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
com_1.showModel(obj);
|
|
114
|
+
}
|
|
183
115
|
}
|
|
116
|
+
com_1.running = false;
|
|
117
|
+
core_1.hideLoading(com_1.loading);
|
|
118
|
+
}).catch(function (err) {
|
|
119
|
+
var data = (err && err.response) ? err.response : err;
|
|
120
|
+
if (data && data.status === 404) {
|
|
121
|
+
com_1.handleNotFound(com_1.form);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
core_2.error(err, com_1.resourceService.value, com_1.showError);
|
|
125
|
+
}
|
|
126
|
+
com_1.running = false;
|
|
127
|
+
core_1.hideLoading(com_1.loading);
|
|
184
128
|
});
|
|
185
|
-
}
|
|
129
|
+
}
|
|
186
130
|
};
|
|
187
131
|
ViewComponent.prototype.handleNotFound = function (form) {
|
|
188
132
|
var msg = core_2.message(this.resourceService.value, 'error_not_found', 'error');
|
|
@@ -300,42 +244,85 @@ var BaseComponent = (function (_super) {
|
|
|
300
244
|
return BaseComponent;
|
|
301
245
|
}(React.Component));
|
|
302
246
|
exports.BaseComponent = BaseComponent;
|
|
247
|
+
var MessageComponent = (function (_super) {
|
|
248
|
+
__extends(MessageComponent, _super);
|
|
249
|
+
function MessageComponent(props, getLocale, removeErr) {
|
|
250
|
+
var _this = _super.call(this, props, getLocale, removeErr) || this;
|
|
251
|
+
_this.alertClass = '';
|
|
252
|
+
_this.showMessage = function (msg) {
|
|
253
|
+
_this.alertClass = 'alert alert-info';
|
|
254
|
+
_this.setState({ message: msg });
|
|
255
|
+
};
|
|
256
|
+
_this.showError = function (msg) {
|
|
257
|
+
_this.alertClass = 'alert alert-error';
|
|
258
|
+
if (typeof msg === 'string') {
|
|
259
|
+
_this.setState({ message: msg });
|
|
260
|
+
}
|
|
261
|
+
else if (Array.isArray(msg) && msg.length > 0) {
|
|
262
|
+
_this.setState({ message: msg[0].message });
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
var x = JSON.stringify(msg);
|
|
266
|
+
_this.setState({ message: x });
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
_this.hideMessage = function () {
|
|
270
|
+
_this.alertClass = '';
|
|
271
|
+
_this.setState({ message: '' });
|
|
272
|
+
};
|
|
273
|
+
_this.getModelName = _this.getModelName.bind(_this);
|
|
274
|
+
_this.showMessage = _this.showMessage.bind(_this);
|
|
275
|
+
_this.showError = _this.showError.bind(_this);
|
|
276
|
+
_this.hideMessage = _this.hideMessage.bind(_this);
|
|
277
|
+
_this.ref = React.createRef();
|
|
278
|
+
return _this;
|
|
279
|
+
}
|
|
280
|
+
MessageComponent.prototype.getModelName = function (f) {
|
|
281
|
+
if (this.name && this.name.length > 0) {
|
|
282
|
+
return this.name;
|
|
283
|
+
}
|
|
284
|
+
var f2 = f;
|
|
285
|
+
if (!f2) {
|
|
286
|
+
f2 = this.form;
|
|
287
|
+
}
|
|
288
|
+
if (f2) {
|
|
289
|
+
var a = core_2.getModelName(f2);
|
|
290
|
+
if (a && a.length > 0) {
|
|
291
|
+
return a;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return 'model';
|
|
295
|
+
};
|
|
296
|
+
return MessageComponent;
|
|
297
|
+
}(BaseComponent));
|
|
298
|
+
exports.MessageComponent = MessageComponent;
|
|
303
299
|
var BaseSearchComponent = (function (_super) {
|
|
304
300
|
__extends(BaseSearchComponent, _super);
|
|
305
301
|
function BaseSearchComponent(props, resourceService, showMessage, getLocale, ui, loading, listFormId) {
|
|
306
|
-
var _this = _super.call(this, props, getLocale, (ui ? ui.removeError :
|
|
302
|
+
var _this = _super.call(this, props, getLocale, (ui ? ui.removeError : undefined)) || this;
|
|
307
303
|
_this.resourceService = resourceService;
|
|
308
304
|
_this.showMessage = showMessage;
|
|
309
305
|
_this.ui = ui;
|
|
310
306
|
_this.loading = loading;
|
|
311
307
|
_this.listFormId = listFormId;
|
|
312
|
-
_this.initPageSize =
|
|
313
|
-
_this.pageSize =
|
|
308
|
+
_this.initPageSize = 24;
|
|
309
|
+
_this.pageSize = 24;
|
|
314
310
|
_this.pageIndex = 1;
|
|
315
|
-
_this.
|
|
316
|
-
_this.
|
|
311
|
+
_this.total = 0;
|
|
312
|
+
_this.pages = 0;
|
|
317
313
|
_this.sequenceNo = 'sequenceNo';
|
|
318
314
|
_this.tmpPageIndex = 1;
|
|
319
315
|
_this.pageMaxSize = 7;
|
|
320
|
-
_this.pageSizes =
|
|
316
|
+
_this.pageSizes = core_2.pageSizes;
|
|
321
317
|
_this.viewable = true;
|
|
322
318
|
_this.addable = true;
|
|
323
319
|
_this.editable = true;
|
|
324
|
-
_this.add = function (event) {
|
|
325
|
-
event.preventDefault();
|
|
326
|
-
var url = _this.props['props'].match.url + '/add';
|
|
327
|
-
_this.props.history.push(url);
|
|
328
|
-
};
|
|
329
|
-
_this.pagingOnClick = function (size, e) {
|
|
330
|
-
_this.setState(function (prevState) { return ({ isPageSizeOpenDropDown: !prevState.isPageSizeOpenDropDown }); });
|
|
331
|
-
_this.pageSizeChanged(size);
|
|
332
|
-
};
|
|
333
320
|
_this.pageSizeOnClick = function () {
|
|
334
321
|
_this.setState(function (prevState) { return ({ isPageSizeOpenDropDown: !prevState.isPageSizeOpenDropDown }); });
|
|
335
322
|
};
|
|
336
323
|
_this.pageSizeChanged = function (event) {
|
|
337
|
-
var size = parseInt(event.currentTarget.value,
|
|
338
|
-
|
|
324
|
+
var size = parseInt(event.currentTarget.value, 10);
|
|
325
|
+
search_core_1.changePageSize(_this, size);
|
|
339
326
|
_this.tmpPageIndex = 1;
|
|
340
327
|
_this.doSearch();
|
|
341
328
|
};
|
|
@@ -344,15 +331,14 @@ var BaseSearchComponent = (function (_super) {
|
|
|
344
331
|
_this.showMessage = _this.showMessage.bind(_this);
|
|
345
332
|
_this.toggleFilter = _this.toggleFilter.bind(_this);
|
|
346
333
|
_this.load = _this.load.bind(_this);
|
|
347
|
-
_this.add = _this.add.bind(_this);
|
|
348
334
|
_this.getSearchForm = _this.getSearchForm.bind(_this);
|
|
349
335
|
_this.setSearchForm = _this.setSearchForm.bind(_this);
|
|
350
|
-
_this.
|
|
351
|
-
_this.
|
|
352
|
-
_this.
|
|
336
|
+
_this.setFilter = _this.setFilter.bind(_this);
|
|
337
|
+
_this.getFilter = _this.getFilter.bind(_this);
|
|
338
|
+
_this.getFields = _this.getFields.bind(_this);
|
|
353
339
|
_this.pageSizeChanged = _this.pageSizeChanged.bind(_this);
|
|
354
|
-
_this.
|
|
355
|
-
_this.
|
|
340
|
+
_this.clearQ = _this.clearQ.bind(_this);
|
|
341
|
+
_this.search = _this.search.bind(_this);
|
|
356
342
|
_this.resetAndSearch = _this.resetAndSearch.bind(_this);
|
|
357
343
|
_this.doSearch = _this.doSearch.bind(_this);
|
|
358
344
|
_this.call = _this.call.bind(_this);
|
|
@@ -363,18 +349,19 @@ var BaseSearchComponent = (function (_super) {
|
|
|
363
349
|
_this.sort = _this.sort.bind(_this);
|
|
364
350
|
_this.showMore = _this.showMore.bind(_this);
|
|
365
351
|
_this.pageChanged = _this.pageChanged.bind(_this);
|
|
366
|
-
|
|
352
|
+
var currentUrl = window.location.host + window.location.pathname;
|
|
353
|
+
_this.url = removeUrlParams(currentUrl);
|
|
367
354
|
return _this;
|
|
368
355
|
}
|
|
369
356
|
BaseSearchComponent.prototype.getModelName = function () {
|
|
370
|
-
return '
|
|
357
|
+
return 'filter';
|
|
371
358
|
};
|
|
372
359
|
BaseSearchComponent.prototype.toggleFilter = function (event) {
|
|
373
360
|
this.hideFilter = !this.hideFilter;
|
|
374
361
|
};
|
|
375
362
|
BaseSearchComponent.prototype.load = function (s, autoSearch) {
|
|
376
|
-
var obj2 =
|
|
377
|
-
this.
|
|
363
|
+
var obj2 = search_core_1.initFilter(s, this);
|
|
364
|
+
this.setFilter(obj2);
|
|
378
365
|
var com = this;
|
|
379
366
|
if (autoSearch) {
|
|
380
367
|
setTimeout(function () {
|
|
@@ -391,29 +378,38 @@ var BaseSearchComponent = (function (_super) {
|
|
|
391
378
|
}
|
|
392
379
|
return this.form;
|
|
393
380
|
};
|
|
394
|
-
BaseSearchComponent.prototype.
|
|
395
|
-
this.
|
|
381
|
+
BaseSearchComponent.prototype.setFilter = function (filter) {
|
|
382
|
+
var modelName = this.getModelName();
|
|
383
|
+
var objSet = {};
|
|
384
|
+
objSet[modelName] = filter;
|
|
385
|
+
this.setState(objSet);
|
|
396
386
|
};
|
|
397
387
|
BaseSearchComponent.prototype.getCurrencyCode = function () {
|
|
398
388
|
return core_2.getCurrencyCode(this.form);
|
|
399
389
|
};
|
|
400
|
-
BaseSearchComponent.prototype.
|
|
390
|
+
BaseSearchComponent.prototype.getFilter = function () {
|
|
401
391
|
var name = this.getModelName();
|
|
402
|
-
var lc
|
|
392
|
+
var lc;
|
|
393
|
+
if (this.getLocale) {
|
|
394
|
+
lc = this.getLocale();
|
|
395
|
+
}
|
|
396
|
+
if (!lc) {
|
|
397
|
+
lc = state_1.enLocale;
|
|
398
|
+
}
|
|
403
399
|
var cc = this.getCurrencyCode();
|
|
404
|
-
var fields = this.
|
|
400
|
+
var fields = this.getFields();
|
|
405
401
|
var l = this.getList();
|
|
406
402
|
var f = this.getSearchForm();
|
|
407
|
-
var dc = (this.ui ? this.ui.decodeFromForm :
|
|
408
|
-
var obj3 =
|
|
403
|
+
var dc = (this.ui ? this.ui.decodeFromForm : undefined);
|
|
404
|
+
var obj3 = search_core_1.getModel(this.state, name, this, fields, this.excluding, this.keys, l, f, dc, lc, cc);
|
|
409
405
|
return obj3;
|
|
410
406
|
};
|
|
411
|
-
BaseSearchComponent.prototype.
|
|
412
|
-
var fs =
|
|
413
|
-
this.
|
|
407
|
+
BaseSearchComponent.prototype.getFields = function () {
|
|
408
|
+
var fs = search_core_1.getFieldsFromForm(this.fields, this.initFields, this.form);
|
|
409
|
+
this.initFields = true;
|
|
414
410
|
return fs;
|
|
415
411
|
};
|
|
416
|
-
BaseSearchComponent.prototype.
|
|
412
|
+
BaseSearchComponent.prototype.clearQ = function () {
|
|
417
413
|
var m = this.state.model;
|
|
418
414
|
if (m) {
|
|
419
415
|
m.q = '';
|
|
@@ -425,7 +421,7 @@ var BaseSearchComponent = (function (_super) {
|
|
|
425
421
|
});
|
|
426
422
|
}
|
|
427
423
|
};
|
|
428
|
-
BaseSearchComponent.prototype.
|
|
424
|
+
BaseSearchComponent.prototype.search = function (event) {
|
|
429
425
|
if (event) {
|
|
430
426
|
event.preventDefault();
|
|
431
427
|
if (!this.getSearchForm()) {
|
|
@@ -443,7 +439,7 @@ var BaseSearchComponent = (function (_super) {
|
|
|
443
439
|
this.triggerSearch = true;
|
|
444
440
|
return;
|
|
445
441
|
}
|
|
446
|
-
|
|
442
|
+
search_core_1.reset(this);
|
|
447
443
|
this.tmpPageIndex = 1;
|
|
448
444
|
this.doSearch();
|
|
449
445
|
};
|
|
@@ -453,18 +449,16 @@ var BaseSearchComponent = (function (_super) {
|
|
|
453
449
|
if (listForm && this.ui) {
|
|
454
450
|
this.ui.removeFormError(listForm);
|
|
455
451
|
}
|
|
456
|
-
var s = this.
|
|
452
|
+
var s = this.getFilter();
|
|
457
453
|
var com = this;
|
|
458
454
|
this.validateSearch(s, function () {
|
|
459
455
|
if (com.running === true) {
|
|
460
456
|
return;
|
|
461
457
|
}
|
|
462
458
|
com.running = true;
|
|
463
|
-
|
|
464
|
-
_this.loading.showLoading();
|
|
465
|
-
}
|
|
459
|
+
core_1.showLoading(_this.loading);
|
|
466
460
|
if (!_this.ignoreUrlParam) {
|
|
467
|
-
|
|
461
|
+
search_core_1.addParametersIntoUrl(s, isFirstLoad);
|
|
468
462
|
}
|
|
469
463
|
com.call(s);
|
|
470
464
|
});
|
|
@@ -473,29 +467,29 @@ var BaseSearchComponent = (function (_super) {
|
|
|
473
467
|
};
|
|
474
468
|
BaseSearchComponent.prototype.validateSearch = function (se, callback) {
|
|
475
469
|
var u = this.ui;
|
|
476
|
-
var vl = (u ? u.validateForm :
|
|
477
|
-
|
|
470
|
+
var vl = (u ? u.validateForm : undefined);
|
|
471
|
+
search_core_1.validate(se, callback, this.getSearchForm(), state_1.localeOf(undefined, this.getLocale), vl);
|
|
478
472
|
};
|
|
479
473
|
BaseSearchComponent.prototype.showResults = function (s, sr) {
|
|
480
474
|
var com = this;
|
|
481
475
|
var results = sr.list;
|
|
482
476
|
if (results && results.length > 0) {
|
|
483
|
-
var lc = this.getLocale
|
|
484
|
-
|
|
477
|
+
var lc = state_1.localeOf(undefined, this.getLocale);
|
|
478
|
+
search_core_1.formatResults(results, com.pageIndex, com.pageSize, com.pageSize, com.sequenceNo, com.format, lc);
|
|
485
479
|
}
|
|
486
480
|
var am = com.appendMode;
|
|
487
481
|
com.pageIndex = (s.page && s.page >= 1 ? s.page : 1);
|
|
488
482
|
if (sr.total) {
|
|
489
|
-
com.
|
|
483
|
+
com.total = sr.total;
|
|
490
484
|
}
|
|
491
485
|
if (am) {
|
|
492
486
|
var limit = s.limit;
|
|
493
|
-
if (s.page <= 1 && s.firstLimit && s.firstLimit > 0) {
|
|
487
|
+
if ((!s.page || s.page <= 1) && s.firstLimit && s.firstLimit > 0) {
|
|
494
488
|
limit = s.firstLimit;
|
|
495
489
|
}
|
|
496
490
|
com.nextPageToken = sr.nextPageToken;
|
|
497
|
-
|
|
498
|
-
if (com.append && s.page > 1) {
|
|
491
|
+
search_core_1.handleAppend(com, sr.list, limit, sr.nextPageToken);
|
|
492
|
+
if (com.append && (s.page && s.page > 1)) {
|
|
499
493
|
com.appendList(results);
|
|
500
494
|
}
|
|
501
495
|
else {
|
|
@@ -503,25 +497,24 @@ var BaseSearchComponent = (function (_super) {
|
|
|
503
497
|
}
|
|
504
498
|
}
|
|
505
499
|
else {
|
|
506
|
-
|
|
500
|
+
search_core_1.showPaging(com, sr.list, s.limit, sr.total);
|
|
507
501
|
com.setList(results);
|
|
508
502
|
com.tmpPageIndex = s.page;
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
com.running = false;
|
|
513
|
-
if (this.loading) {
|
|
514
|
-
this.loading.hideLoading();
|
|
503
|
+
if (s.limit) {
|
|
504
|
+
this.showMessage(search_core_1.buildMessage(this.resourceService, s.page, s.limit, sr.list, sr.total));
|
|
505
|
+
}
|
|
515
506
|
}
|
|
507
|
+
com.running = undefined;
|
|
508
|
+
core_1.hideLoading(com.loading);
|
|
516
509
|
if (com.triggerSearch) {
|
|
517
|
-
com.triggerSearch =
|
|
510
|
+
com.triggerSearch = undefined;
|
|
518
511
|
com.resetAndSearch();
|
|
519
512
|
}
|
|
520
513
|
};
|
|
521
514
|
BaseSearchComponent.prototype.appendList = function (results) {
|
|
522
515
|
var _a;
|
|
523
516
|
var list = this.state.list;
|
|
524
|
-
var arr =
|
|
517
|
+
var arr = search_core_1.append(list, results);
|
|
525
518
|
var listForm = this.getSearchForm();
|
|
526
519
|
var props = this.props;
|
|
527
520
|
var setGlobalState = props.props.setGlobalState;
|
|
@@ -550,7 +543,7 @@ var BaseSearchComponent = (function (_super) {
|
|
|
550
543
|
};
|
|
551
544
|
BaseSearchComponent.prototype.sort = function (event) {
|
|
552
545
|
event.preventDefault();
|
|
553
|
-
|
|
546
|
+
search_core_1.handleSortEvent(event, this);
|
|
554
547
|
if (!this.appendMode) {
|
|
555
548
|
this.doSearch();
|
|
556
549
|
}
|
|
@@ -561,12 +554,12 @@ var BaseSearchComponent = (function (_super) {
|
|
|
561
554
|
BaseSearchComponent.prototype.showMore = function (event) {
|
|
562
555
|
event.preventDefault();
|
|
563
556
|
this.tmpPageIndex = this.pageIndex;
|
|
564
|
-
|
|
557
|
+
search_core_1.more(this);
|
|
565
558
|
this.doSearch();
|
|
566
559
|
};
|
|
567
560
|
BaseSearchComponent.prototype.pageChanged = function (data) {
|
|
568
|
-
var
|
|
569
|
-
|
|
561
|
+
var page = data.page, size = data.size;
|
|
562
|
+
search_core_1.changePage(this, page, size);
|
|
570
563
|
this.doSearch();
|
|
571
564
|
};
|
|
572
565
|
return BaseSearchComponent;
|
|
@@ -576,97 +569,83 @@ var SearchComponent = (function (_super) {
|
|
|
576
569
|
__extends(SearchComponent, _super);
|
|
577
570
|
function SearchComponent(props, sv, param, showMessage, showError, getLocale, uis, loading, listFormId) {
|
|
578
571
|
var _this = _super.call(this, props, input_1.getResource(param), input_1.getMsgFunc(param, showMessage), input_1.getLocaleFunc(param, getLocale), input_1.getUIService(param, uis), input_1.getLoadingFunc(param, loading), listFormId) || this;
|
|
572
|
+
_this.add = function (event) {
|
|
573
|
+
event.preventDefault();
|
|
574
|
+
var url = _this.url + '/add';
|
|
575
|
+
_this.props.history.push(url);
|
|
576
|
+
};
|
|
579
577
|
_this.autoSearch = input_1.getAutoSearch(param);
|
|
580
578
|
if (sv) {
|
|
581
579
|
if (typeof sv === 'function') {
|
|
582
580
|
var x = sv;
|
|
583
|
-
_this.
|
|
581
|
+
_this.service = x;
|
|
584
582
|
}
|
|
585
583
|
else {
|
|
586
|
-
_this.service = sv;
|
|
587
|
-
if (
|
|
588
|
-
_this.keys =
|
|
584
|
+
_this.service = sv.search;
|
|
585
|
+
if (sv.keys) {
|
|
586
|
+
_this.keys = sv.keys();
|
|
589
587
|
}
|
|
590
588
|
}
|
|
591
589
|
}
|
|
590
|
+
_this.add = _this.add.bind(_this);
|
|
592
591
|
_this.call = _this.call.bind(_this);
|
|
593
592
|
_this.showError = input_1.getErrorFunc(param, showError);
|
|
594
593
|
_this.componentDidMount = _this.componentDidMount.bind(_this);
|
|
595
|
-
_this.
|
|
596
|
-
_this.
|
|
594
|
+
_this.mergeFilter = _this.mergeFilter.bind(_this);
|
|
595
|
+
_this.createFilter = _this.createFilter.bind(_this);
|
|
597
596
|
_this.ref = React.createRef();
|
|
598
597
|
return _this;
|
|
599
598
|
}
|
|
600
599
|
SearchComponent.prototype.componentDidMount = function () {
|
|
601
|
-
var k = (this.ui ? this.ui.registerEvents :
|
|
600
|
+
var k = (this.ui ? this.ui.registerEvents : undefined);
|
|
602
601
|
this.form = core_2.initForm(this.ref.current, k);
|
|
603
|
-
var s = this.
|
|
602
|
+
var s = this.mergeFilter(route_1.buildFromUrl(), this.createFilter());
|
|
604
603
|
this.load(s, this.autoSearch);
|
|
605
604
|
};
|
|
606
|
-
SearchComponent.prototype.
|
|
607
|
-
return
|
|
605
|
+
SearchComponent.prototype.mergeFilter = function (obj, b, arrs) {
|
|
606
|
+
return search_core_1.mergeFilter(obj, b, this.pageSizes, arrs);
|
|
608
607
|
};
|
|
609
|
-
SearchComponent.prototype.
|
|
608
|
+
SearchComponent.prototype.createFilter = function () {
|
|
610
609
|
var s = {};
|
|
611
610
|
return s;
|
|
612
611
|
};
|
|
613
612
|
SearchComponent.prototype.call = function (se) {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
return [3, 4];
|
|
649
|
-
case 2: return [4, this.service.search(s, limit, next, fields)];
|
|
650
|
-
case 3:
|
|
651
|
-
sr = _a.sent();
|
|
652
|
-
this.showResults(s, sr);
|
|
653
|
-
_a.label = 4;
|
|
654
|
-
case 4: return [3, 7];
|
|
655
|
-
case 5:
|
|
656
|
-
err_2 = _a.sent();
|
|
657
|
-
this.pageIndex = this.tmpPageIndex;
|
|
658
|
-
core_2.error(err_2, this.resourceService.value, this.showError);
|
|
659
|
-
return [3, 7];
|
|
660
|
-
case 6:
|
|
661
|
-
this.running = false;
|
|
662
|
-
if (this.loading) {
|
|
663
|
-
this.loading.hideLoading();
|
|
664
|
-
}
|
|
665
|
-
return [7];
|
|
666
|
-
case 7: return [2];
|
|
667
|
-
}
|
|
613
|
+
this.running = true;
|
|
614
|
+
var s = reflectx_1.clone(se);
|
|
615
|
+
var page = this.pageIndex;
|
|
616
|
+
if (!page || page < 1) {
|
|
617
|
+
page = 1;
|
|
618
|
+
}
|
|
619
|
+
var offset;
|
|
620
|
+
if (se.limit) {
|
|
621
|
+
if (se.firstLimit && se.firstLimit > 0) {
|
|
622
|
+
offset = se.limit * (page - 2) + se.firstLimit;
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
offset = se.limit * (page - 1);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
var limit = (page <= 1 && se.firstLimit && se.firstLimit > 0 ? se.firstLimit : se.limit);
|
|
629
|
+
var next = (this.nextPageToken && this.nextPageToken.length > 0 ? this.nextPageToken : offset);
|
|
630
|
+
var fields = se.fields;
|
|
631
|
+
delete se['page'];
|
|
632
|
+
delete se['fields'];
|
|
633
|
+
delete se['limit'];
|
|
634
|
+
delete se['firstLimit'];
|
|
635
|
+
core_1.showLoading(this.loading);
|
|
636
|
+
var com = this;
|
|
637
|
+
if (this.service) {
|
|
638
|
+
this.service(s, limit, next, fields).then(function (sr) {
|
|
639
|
+
com.showResults(s, sr);
|
|
640
|
+
com.running = undefined;
|
|
641
|
+
core_1.hideLoading(com.loading);
|
|
642
|
+
}).catch(function (err) {
|
|
643
|
+
com.pageIndex = com.tmpPageIndex;
|
|
644
|
+
core_2.error(err, com.resourceService.value, com.showError);
|
|
645
|
+
com.running = undefined;
|
|
646
|
+
core_1.hideLoading(com.loading);
|
|
668
647
|
});
|
|
669
|
-
}
|
|
648
|
+
}
|
|
670
649
|
};
|
|
671
650
|
return SearchComponent;
|
|
672
651
|
}(BaseSearchComponent));
|
|
@@ -674,18 +653,17 @@ exports.SearchComponent = SearchComponent;
|
|
|
674
653
|
var BaseEditComponent = (function (_super) {
|
|
675
654
|
__extends(BaseEditComponent, _super);
|
|
676
655
|
function BaseEditComponent(props, resourceService, showMessage, showError, confirm, getLocale, ui, loading, status, patchable, backOnSaveSuccess) {
|
|
677
|
-
var _this = _super.call(this, props, getLocale, (ui ? ui.removeError :
|
|
656
|
+
var _this = _super.call(this, props, getLocale, (ui ? ui.removeError : undefined)) || this;
|
|
678
657
|
_this.resourceService = resourceService;
|
|
679
658
|
_this.showMessage = showMessage;
|
|
680
659
|
_this.showError = showError;
|
|
681
660
|
_this.confirm = confirm;
|
|
682
661
|
_this.ui = ui;
|
|
683
662
|
_this.loading = loading;
|
|
684
|
-
_this.status = status;
|
|
685
663
|
_this.backOnSuccess = true;
|
|
686
664
|
_this.patchable = true;
|
|
687
665
|
_this.addable = true;
|
|
688
|
-
_this.
|
|
666
|
+
_this.create = function (event) {
|
|
689
667
|
if (event) {
|
|
690
668
|
event.preventDefault();
|
|
691
669
|
}
|
|
@@ -693,16 +671,16 @@ var BaseEditComponent = (function (_super) {
|
|
|
693
671
|
_this.form = event.target.form;
|
|
694
672
|
}
|
|
695
673
|
var obj = _this.createModel();
|
|
696
|
-
_this.resetState(true, obj,
|
|
674
|
+
_this.resetState(true, obj, undefined);
|
|
697
675
|
var u = _this.ui;
|
|
698
|
-
|
|
699
|
-
|
|
676
|
+
var f = _this.form;
|
|
677
|
+
if (u && f) {
|
|
700
678
|
setTimeout(function () {
|
|
701
|
-
u.removeFormError(
|
|
679
|
+
u.removeFormError(f);
|
|
702
680
|
}, 100);
|
|
703
681
|
}
|
|
704
682
|
};
|
|
705
|
-
_this.
|
|
683
|
+
_this.save = function (event) {
|
|
706
684
|
event.preventDefault();
|
|
707
685
|
event.persist();
|
|
708
686
|
if (!_this.form && event && event.target) {
|
|
@@ -711,6 +689,7 @@ var BaseEditComponent = (function (_super) {
|
|
|
711
689
|
_this.onSave(_this.backOnSuccess);
|
|
712
690
|
};
|
|
713
691
|
_this.resource = resourceService.resource();
|
|
692
|
+
_this.status = core_1.createEditStatus(status);
|
|
714
693
|
if (patchable === false) {
|
|
715
694
|
_this.patchable = patchable;
|
|
716
695
|
}
|
|
@@ -729,11 +708,11 @@ var BaseEditComponent = (function (_super) {
|
|
|
729
708
|
_this.showModel = _this.showModel.bind(_this);
|
|
730
709
|
_this.getModel = _this.getModel.bind(_this);
|
|
731
710
|
_this.createModel = _this.createModel.bind(_this);
|
|
732
|
-
_this.
|
|
733
|
-
_this.
|
|
711
|
+
_this.create = _this.create.bind(_this);
|
|
712
|
+
_this.save = _this.save.bind(_this);
|
|
734
713
|
_this.onSave = _this.onSave.bind(_this);
|
|
735
714
|
_this.validate = _this.validate.bind(_this);
|
|
736
|
-
_this.
|
|
715
|
+
_this.doSave = _this.doSave.bind(_this);
|
|
737
716
|
_this.succeed = _this.succeed.bind(_this);
|
|
738
717
|
_this.fail = _this.fail.bind(_this);
|
|
739
718
|
_this.postSave = _this.postSave.bind(_this);
|
|
@@ -807,13 +786,13 @@ var BaseEditComponent = (function (_super) {
|
|
|
807
786
|
if (this.running) {
|
|
808
787
|
return;
|
|
809
788
|
}
|
|
810
|
-
var
|
|
811
|
-
var obj_1 =
|
|
789
|
+
var com_2 = this;
|
|
790
|
+
var obj_1 = com_2.getModel();
|
|
812
791
|
if (this.newMode) {
|
|
813
|
-
|
|
792
|
+
com_2.validate(obj_1, function () {
|
|
814
793
|
var msg = core_2.message(r.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
|
|
815
794
|
_this.confirm(msg.message, msg.title, function () {
|
|
816
|
-
|
|
795
|
+
com_2.doSave(obj_1, obj_1, isBack);
|
|
817
796
|
}, msg.no, msg.yes);
|
|
818
797
|
});
|
|
819
798
|
}
|
|
@@ -824,10 +803,10 @@ var BaseEditComponent = (function (_super) {
|
|
|
824
803
|
this.showMessage(r.value('msg_no_change'));
|
|
825
804
|
}
|
|
826
805
|
else {
|
|
827
|
-
|
|
806
|
+
com_2.validate(obj_1, function () {
|
|
828
807
|
var msg = core_2.message(r.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
|
|
829
808
|
_this.confirm(msg.message, msg.title, function () {
|
|
830
|
-
|
|
809
|
+
com_2.doSave(obj_1, diffObj_1, isBack);
|
|
831
810
|
}, msg.no, msg.yes);
|
|
832
811
|
});
|
|
833
812
|
}
|
|
@@ -835,8 +814,8 @@ var BaseEditComponent = (function (_super) {
|
|
|
835
814
|
}
|
|
836
815
|
};
|
|
837
816
|
BaseEditComponent.prototype.validate = function (obj, callback) {
|
|
838
|
-
if (this.ui) {
|
|
839
|
-
var valid = this.ui.validateForm(this.form, this.getLocale
|
|
817
|
+
if (this.ui && this.form) {
|
|
818
|
+
var valid = this.ui.validateForm(this.form, state_1.localeOf(undefined, this.getLocale));
|
|
840
819
|
if (valid) {
|
|
841
820
|
callback(obj);
|
|
842
821
|
}
|
|
@@ -845,7 +824,7 @@ var BaseEditComponent = (function (_super) {
|
|
|
845
824
|
callback(obj);
|
|
846
825
|
}
|
|
847
826
|
};
|
|
848
|
-
BaseEditComponent.prototype.
|
|
827
|
+
BaseEditComponent.prototype.doSave = function (obj, dif, isBack) {
|
|
849
828
|
};
|
|
850
829
|
BaseEditComponent.prototype.succeed = function (msg, isBack, result) {
|
|
851
830
|
if (result) {
|
|
@@ -871,7 +850,7 @@ var BaseEditComponent = (function (_super) {
|
|
|
871
850
|
var errors = result.errors;
|
|
872
851
|
var f = this.form;
|
|
873
852
|
var u = this.ui;
|
|
874
|
-
if (u) {
|
|
853
|
+
if (u && f) {
|
|
875
854
|
var unmappedErrors = u.showFormError(f, errors);
|
|
876
855
|
if (!result.message) {
|
|
877
856
|
if (errors && errors.length === 1) {
|
|
@@ -886,14 +865,14 @@ var BaseEditComponent = (function (_super) {
|
|
|
886
865
|
else if (errors && errors.length === 1) {
|
|
887
866
|
result.message = errors[0].message;
|
|
888
867
|
}
|
|
889
|
-
|
|
890
|
-
|
|
868
|
+
if (result.message) {
|
|
869
|
+
var t = this.resourceService.value('error');
|
|
870
|
+
this.showError(result.message, t);
|
|
871
|
+
}
|
|
891
872
|
};
|
|
892
873
|
BaseEditComponent.prototype.postSave = function (res, backOnSave) {
|
|
893
874
|
this.running = false;
|
|
894
|
-
|
|
895
|
-
this.loading.hideLoading();
|
|
896
|
-
}
|
|
875
|
+
core_1.hideLoading(this.loading);
|
|
897
876
|
var st = this.status;
|
|
898
877
|
var newMod = this.newMode;
|
|
899
878
|
var successMsg = (newMod ? this.insertSuccessMsg : this.updateSuccessMsg);
|
|
@@ -951,8 +930,10 @@ var EditComponent = (function (_super) {
|
|
|
951
930
|
var metadata = service.metadata();
|
|
952
931
|
if (metadata) {
|
|
953
932
|
var meta = edit_1.build(metadata);
|
|
954
|
-
|
|
955
|
-
|
|
933
|
+
if (meta) {
|
|
934
|
+
_this.keys = meta.keys;
|
|
935
|
+
_this.version = meta.version;
|
|
936
|
+
}
|
|
956
937
|
_this.metadata = metadata;
|
|
957
938
|
}
|
|
958
939
|
}
|
|
@@ -966,141 +947,97 @@ var EditComponent = (function (_super) {
|
|
|
966
947
|
_this.keys = [];
|
|
967
948
|
}
|
|
968
949
|
_this.load = _this.load.bind(_this);
|
|
969
|
-
_this.
|
|
950
|
+
_this.doSave = _this.doSave.bind(_this);
|
|
970
951
|
_this.componentDidMount = _this.componentDidMount.bind(_this);
|
|
971
952
|
_this.ref = React.createRef();
|
|
972
953
|
return _this;
|
|
973
954
|
}
|
|
974
955
|
EditComponent.prototype.componentDidMount = function () {
|
|
975
|
-
var k = (this.ui ? this.ui.registerEvents :
|
|
956
|
+
var k = (this.ui ? this.ui.registerEvents : undefined);
|
|
976
957
|
this.form = core_2.initForm(this.ref.current, k);
|
|
977
958
|
var id = core_2.buildId(this.props, this.keys);
|
|
978
|
-
|
|
959
|
+
if (id) {
|
|
960
|
+
this.load(id);
|
|
961
|
+
}
|
|
979
962
|
};
|
|
980
963
|
EditComponent.prototype.load = function (_id, callback) {
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
_a.trys.push([1, 3, 4, 5]);
|
|
991
|
-
this.running = true;
|
|
992
|
-
if (this.loading) {
|
|
993
|
-
this.loading.showLoading();
|
|
994
|
-
}
|
|
995
|
-
ctx = {};
|
|
996
|
-
return [4, this.service.load(id, ctx)];
|
|
997
|
-
case 2:
|
|
998
|
-
obj = _a.sent();
|
|
999
|
-
if (!obj) {
|
|
1000
|
-
this.handleNotFound(this.form);
|
|
1001
|
-
}
|
|
1002
|
-
else {
|
|
1003
|
-
this.newMode = false;
|
|
1004
|
-
this.orginalModel = reflectx_1.clone(obj);
|
|
1005
|
-
if (!callback) {
|
|
1006
|
-
this.showModel(obj);
|
|
1007
|
-
}
|
|
1008
|
-
else {
|
|
1009
|
-
callback(obj, this.showModel);
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
return [3, 5];
|
|
1013
|
-
case 3:
|
|
1014
|
-
err_3 = _a.sent();
|
|
1015
|
-
data = (err_3 && err_3.response) ? err_3.response : err_3;
|
|
1016
|
-
r = this.resourceService;
|
|
1017
|
-
gv = r.value;
|
|
1018
|
-
title = gv('error');
|
|
1019
|
-
msg = gv('error_internal');
|
|
1020
|
-
if (data && data.status === 404) {
|
|
1021
|
-
this.handleNotFound(this.form);
|
|
1022
|
-
}
|
|
1023
|
-
else {
|
|
1024
|
-
if (data.status && !isNaN(data.status)) {
|
|
1025
|
-
msg = core_2.messageByHttpStatus(data.status, gv);
|
|
1026
|
-
}
|
|
1027
|
-
if (data && (data.status === 401 || data.status === 403)) {
|
|
1028
|
-
formutil_1.readOnly(this.form);
|
|
1029
|
-
}
|
|
1030
|
-
this.showError(msg, title);
|
|
1031
|
-
}
|
|
1032
|
-
return [3, 5];
|
|
1033
|
-
case 4:
|
|
1034
|
-
this.running = false;
|
|
1035
|
-
if (this.loading) {
|
|
1036
|
-
this.loading.hideLoading();
|
|
1037
|
-
}
|
|
1038
|
-
return [7];
|
|
1039
|
-
case 5: return [3, 7];
|
|
1040
|
-
case 6:
|
|
1041
|
-
this.newMode = true;
|
|
1042
|
-
this.orginalModel = null;
|
|
1043
|
-
obj = this.createModel();
|
|
1044
|
-
if (callback) {
|
|
1045
|
-
callback(obj, this.showModel);
|
|
1046
|
-
}
|
|
1047
|
-
else {
|
|
1048
|
-
this.showModel(obj);
|
|
1049
|
-
}
|
|
1050
|
-
_a.label = 7;
|
|
1051
|
-
case 7: return [2];
|
|
964
|
+
var _this = this;
|
|
965
|
+
var id = _id;
|
|
966
|
+
if (id != null && id !== '') {
|
|
967
|
+
var com_3 = this;
|
|
968
|
+
this.running = true;
|
|
969
|
+
core_1.showLoading(com_3.loading);
|
|
970
|
+
this.service.load(id).then(function (obj) {
|
|
971
|
+
if (!obj) {
|
|
972
|
+
com_3.handleNotFound(_this.form);
|
|
1052
973
|
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
com.postSave(result, isBackO);
|
|
1083
|
-
_a.label = 5;
|
|
1084
|
-
case 5: return [3, 8];
|
|
1085
|
-
case 6: return [4, this.service.insert(obj, ctx)];
|
|
1086
|
-
case 7:
|
|
1087
|
-
result = _a.sent();
|
|
1088
|
-
com.postSave(result, isBackO);
|
|
1089
|
-
_a.label = 8;
|
|
1090
|
-
case 8: return [3, 11];
|
|
1091
|
-
case 9:
|
|
1092
|
-
err_4 = _a.sent();
|
|
1093
|
-
core_2.error(err_4, this.resourceService.value, this.showError);
|
|
1094
|
-
return [3, 11];
|
|
1095
|
-
case 10:
|
|
1096
|
-
this.running = false;
|
|
1097
|
-
if (this.loading) {
|
|
1098
|
-
this.loading.hideLoading();
|
|
1099
|
-
}
|
|
1100
|
-
return [7];
|
|
1101
|
-
case 11: return [2];
|
|
974
|
+
else {
|
|
975
|
+
com_3.newMode = false;
|
|
976
|
+
com_3.orginalModel = reflectx_1.clone(obj);
|
|
977
|
+
if (!callback) {
|
|
978
|
+
com_3.showModel(obj);
|
|
979
|
+
}
|
|
980
|
+
else {
|
|
981
|
+
callback(obj, com_3.showModel);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
com_3.running = false;
|
|
985
|
+
core_1.hideLoading(com_3.loading);
|
|
986
|
+
}).catch(function (err) {
|
|
987
|
+
var data = (err && err.response) ? err.response : err;
|
|
988
|
+
var r = com_3.resourceService;
|
|
989
|
+
var gv = r.value;
|
|
990
|
+
var title = gv('error');
|
|
991
|
+
var msg = gv('error_internal');
|
|
992
|
+
if (data && data.status === 404) {
|
|
993
|
+
com_3.handleNotFound(com_3.form);
|
|
994
|
+
}
|
|
995
|
+
else {
|
|
996
|
+
if (data.status && !isNaN(data.status)) {
|
|
997
|
+
msg = core_2.messageByHttpStatus(data.status, gv);
|
|
998
|
+
}
|
|
999
|
+
if (data && (data.status === 401 || data.status === 403)) {
|
|
1000
|
+
formutil_1.readOnly(com_3.form);
|
|
1001
|
+
}
|
|
1002
|
+
com_3.showError(msg, title);
|
|
1102
1003
|
}
|
|
1004
|
+
com_3.running = false;
|
|
1005
|
+
core_1.hideLoading(com_3.loading);
|
|
1103
1006
|
});
|
|
1007
|
+
}
|
|
1008
|
+
else {
|
|
1009
|
+
this.newMode = true;
|
|
1010
|
+
this.orginalModel = undefined;
|
|
1011
|
+
var obj = this.createModel();
|
|
1012
|
+
if (callback) {
|
|
1013
|
+
callback(obj, this.showModel);
|
|
1014
|
+
}
|
|
1015
|
+
else {
|
|
1016
|
+
this.showModel(obj);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
EditComponent.prototype.doSave = function (obj, body, isBack) {
|
|
1021
|
+
this.running = true;
|
|
1022
|
+
core_1.showLoading(this.loading);
|
|
1023
|
+
var isBackO = (isBack == null || isBack === undefined ? this.backOnSuccess : isBack);
|
|
1024
|
+
var com = this;
|
|
1025
|
+
var m = obj;
|
|
1026
|
+
var fn = this.newMode ? this.service.insert : this.service.update;
|
|
1027
|
+
if (!this.newMode) {
|
|
1028
|
+
if (this.patchable === true && this.service.patch && body && Object.keys(body).length > 0) {
|
|
1029
|
+
m = body;
|
|
1030
|
+
fn = this.service.patch;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
fn(m).then(function (result) {
|
|
1034
|
+
com.postSave(result, isBackO);
|
|
1035
|
+
com.running = false;
|
|
1036
|
+
core_1.hideLoading(com.loading);
|
|
1037
|
+
}).then(function (err) {
|
|
1038
|
+
core_2.error(err, com.resourceService.value, com.showError);
|
|
1039
|
+
com.running = false;
|
|
1040
|
+
core_1.hideLoading(com.loading);
|
|
1104
1041
|
});
|
|
1105
1042
|
};
|
|
1106
1043
|
return EditComponent;
|
|
@@ -1115,7 +1052,6 @@ var BaseDiffApprComponent = (function (_super) {
|
|
|
1115
1052
|
_this.showMessage = showMessage;
|
|
1116
1053
|
_this.showError = showError;
|
|
1117
1054
|
_this.loading = loading;
|
|
1118
|
-
_this.status = status;
|
|
1119
1055
|
_this.resource = resourceService.resource();
|
|
1120
1056
|
_this.showMessage = _this.showMessage.bind(_this);
|
|
1121
1057
|
_this.showError = _this.showError.bind(_this);
|
|
@@ -1125,9 +1061,7 @@ var BaseDiffApprComponent = (function (_super) {
|
|
|
1125
1061
|
_this.postReject = _this.postReject.bind(_this);
|
|
1126
1062
|
_this.format = _this.format.bind(_this);
|
|
1127
1063
|
_this.handleNotFound = _this.handleNotFound.bind(_this);
|
|
1128
|
-
|
|
1129
|
-
_this.status = core_1.createDiffStatus();
|
|
1130
|
-
}
|
|
1064
|
+
_this.status = core_1.createDiffStatus(status);
|
|
1131
1065
|
_this.state = {
|
|
1132
1066
|
disabled: false
|
|
1133
1067
|
};
|
|
@@ -1186,13 +1120,16 @@ var BaseDiffApprComponent = (function (_super) {
|
|
|
1186
1120
|
var differentKeys_1 = reflectx_1.diff(diffModel.origin, diffModel.value);
|
|
1187
1121
|
var dataFields = diff_1.getDataFields(this.form);
|
|
1188
1122
|
dataFields.forEach(function (e) {
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
e.childNodes
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1123
|
+
var x = e.getAttribute('data-field');
|
|
1124
|
+
if (x) {
|
|
1125
|
+
if (differentKeys_1.indexOf(x) >= 0) {
|
|
1126
|
+
if (e.childNodes.length === 3) {
|
|
1127
|
+
e.childNodes[1].classList.add('highlight');
|
|
1128
|
+
e.childNodes[2].classList.add('highlight');
|
|
1129
|
+
}
|
|
1130
|
+
else {
|
|
1131
|
+
e.classList.add('highlight');
|
|
1132
|
+
}
|
|
1196
1133
|
}
|
|
1197
1134
|
}
|
|
1198
1135
|
});
|
|
@@ -1202,13 +1139,16 @@ var BaseDiffApprComponent = (function (_super) {
|
|
|
1202
1139
|
var differentKeys_2 = reflectx_1.diff(origin_1, value);
|
|
1203
1140
|
var dataFields = diff_1.getDataFields(this.form);
|
|
1204
1141
|
dataFields.forEach(function (e) {
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
e.childNodes
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1142
|
+
var x = e.getAttribute('data-field');
|
|
1143
|
+
if (x) {
|
|
1144
|
+
if (differentKeys_2.indexOf(x) >= 0) {
|
|
1145
|
+
if (e.childNodes.length === 3) {
|
|
1146
|
+
e.childNodes[1].classList.add('highlight');
|
|
1147
|
+
e.childNodes[2].classList.add('highlight');
|
|
1148
|
+
}
|
|
1149
|
+
else {
|
|
1150
|
+
e.classList.add('highlight');
|
|
1151
|
+
}
|
|
1212
1152
|
}
|
|
1213
1153
|
}
|
|
1214
1154
|
});
|
|
@@ -1241,132 +1181,85 @@ var DiffApprComponent = (function (_super) {
|
|
|
1241
1181
|
DiffApprComponent.prototype.componentDidMount = function () {
|
|
1242
1182
|
this.form = this.ref.current;
|
|
1243
1183
|
var id = core_2.buildId(this.props, this.keys);
|
|
1244
|
-
|
|
1184
|
+
if (id) {
|
|
1185
|
+
this.load(id);
|
|
1186
|
+
}
|
|
1245
1187
|
};
|
|
1246
1188
|
DiffApprComponent.prototype.formatFields = function (value) {
|
|
1247
1189
|
return value;
|
|
1248
1190
|
};
|
|
1249
1191
|
DiffApprComponent.prototype.load = function (_id) {
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
}, this.format);
|
|
1277
|
-
}
|
|
1278
|
-
return [3, 5];
|
|
1279
|
-
case 3:
|
|
1280
|
-
err_5 = _a.sent();
|
|
1281
|
-
data = (err_5 && err_5.response) ? err_5.response : err_5;
|
|
1282
|
-
if (data && data.status === 404) {
|
|
1283
|
-
this.handleNotFound();
|
|
1284
|
-
}
|
|
1285
|
-
else {
|
|
1286
|
-
core_2.error(err_5, this.resourceService.value, this.showError);
|
|
1287
|
-
}
|
|
1288
|
-
return [3, 5];
|
|
1289
|
-
case 4:
|
|
1290
|
-
this.running = false;
|
|
1291
|
-
if (this.loading) {
|
|
1292
|
-
this.loading.hideLoading();
|
|
1293
|
-
}
|
|
1294
|
-
return [7];
|
|
1295
|
-
case 5: return [2];
|
|
1192
|
+
var id = _id;
|
|
1193
|
+
if (id != null && id !== '') {
|
|
1194
|
+
this.id = _id;
|
|
1195
|
+
var com_4 = this;
|
|
1196
|
+
this.running = true;
|
|
1197
|
+
core_1.showLoading(this.loading);
|
|
1198
|
+
this.service.diff(id).then(function (dobj) {
|
|
1199
|
+
if (!dobj) {
|
|
1200
|
+
com_4.handleNotFound();
|
|
1201
|
+
}
|
|
1202
|
+
else {
|
|
1203
|
+
var formatdDiff = diff_1.formatDiffModel(dobj, com_4.formatFields);
|
|
1204
|
+
com_4.setState({
|
|
1205
|
+
origin: formatdDiff.origin,
|
|
1206
|
+
value: formatdDiff.value
|
|
1207
|
+
}, com_4.format);
|
|
1208
|
+
}
|
|
1209
|
+
com_4.running = false;
|
|
1210
|
+
core_1.hideLoading(com_4.loading);
|
|
1211
|
+
}).catch(function (err) {
|
|
1212
|
+
var data = (err && err.response) ? err.response : err;
|
|
1213
|
+
if (data && data.status === 404) {
|
|
1214
|
+
com_4.handleNotFound();
|
|
1215
|
+
}
|
|
1216
|
+
else {
|
|
1217
|
+
core_2.error(err, com_4.resourceService.value, com_4.showError);
|
|
1296
1218
|
}
|
|
1219
|
+
com_4.running = false;
|
|
1220
|
+
core_1.hideLoading(com_4.loading);
|
|
1297
1221
|
});
|
|
1298
|
-
}
|
|
1222
|
+
}
|
|
1299
1223
|
};
|
|
1300
1224
|
DiffApprComponent.prototype.approve = function (event) {
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
id = this.id;
|
|
1315
|
-
return [4, this.service.approve(id)];
|
|
1316
|
-
case 2:
|
|
1317
|
-
status_1 = _a.sent();
|
|
1318
|
-
this.postApprove(status_1, null);
|
|
1319
|
-
return [3, 5];
|
|
1320
|
-
case 3:
|
|
1321
|
-
err_6 = _a.sent();
|
|
1322
|
-
this.postApprove(4, err_6);
|
|
1323
|
-
return [3, 5];
|
|
1324
|
-
case 4:
|
|
1325
|
-
this.running = false;
|
|
1326
|
-
if (this.loading) {
|
|
1327
|
-
this.loading.hideLoading();
|
|
1328
|
-
}
|
|
1329
|
-
return [7];
|
|
1330
|
-
case 5: return [2];
|
|
1331
|
-
}
|
|
1225
|
+
event.preventDefault();
|
|
1226
|
+
var com = this;
|
|
1227
|
+
this.running = true;
|
|
1228
|
+
core_1.showLoading(this.loading);
|
|
1229
|
+
if (this.id) {
|
|
1230
|
+
this.service.approve(this.id).then(function (status) {
|
|
1231
|
+
com.postApprove(status, null);
|
|
1232
|
+
com.running = false;
|
|
1233
|
+
core_1.hideLoading(com.loading);
|
|
1234
|
+
}).catch(function (err) {
|
|
1235
|
+
com.postApprove(4, err);
|
|
1236
|
+
com.running = false;
|
|
1237
|
+
core_1.hideLoading(com.loading);
|
|
1332
1238
|
});
|
|
1333
|
-
}
|
|
1239
|
+
}
|
|
1334
1240
|
};
|
|
1335
1241
|
DiffApprComponent.prototype.reject = function (event) {
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
id = this.id;
|
|
1350
|
-
return [4, this.service.reject(id)];
|
|
1351
|
-
case 2:
|
|
1352
|
-
status_2 = _a.sent();
|
|
1353
|
-
this.postReject(status_2, null);
|
|
1354
|
-
return [3, 5];
|
|
1355
|
-
case 3:
|
|
1356
|
-
err_7 = _a.sent();
|
|
1357
|
-
this.postReject(4, err_7);
|
|
1358
|
-
return [3, 5];
|
|
1359
|
-
case 4:
|
|
1360
|
-
this.running = false;
|
|
1361
|
-
if (this.loading) {
|
|
1362
|
-
this.loading.hideLoading();
|
|
1363
|
-
}
|
|
1364
|
-
return [7];
|
|
1365
|
-
case 5: return [2];
|
|
1366
|
-
}
|
|
1242
|
+
event.preventDefault();
|
|
1243
|
+
var com = this;
|
|
1244
|
+
this.running = true;
|
|
1245
|
+
core_1.showLoading(this.loading);
|
|
1246
|
+
if (this.id) {
|
|
1247
|
+
this.service.reject(this.id).then(function (status) {
|
|
1248
|
+
com.postReject(status, null);
|
|
1249
|
+
com.running = false;
|
|
1250
|
+
core_1.hideLoading(com.loading);
|
|
1251
|
+
}).catch(function (err) {
|
|
1252
|
+
com.postReject(4, err);
|
|
1253
|
+
com.running = false;
|
|
1254
|
+
core_1.hideLoading(com.loading);
|
|
1367
1255
|
});
|
|
1368
|
-
}
|
|
1256
|
+
}
|
|
1369
1257
|
};
|
|
1370
1258
|
return DiffApprComponent;
|
|
1371
1259
|
}(BaseDiffApprComponent));
|
|
1372
1260
|
exports.DiffApprComponent = DiffApprComponent;
|
|
1261
|
+
function removeUrlParams(url) {
|
|
1262
|
+
var startParams = url.indexOf('?');
|
|
1263
|
+
return startParams !== -1 ? url.substring(0, startParams) : url;
|
|
1264
|
+
}
|
|
1265
|
+
exports.removeUrlParams = removeUrlParams;
|