react-hook-core 0.0.1 → 0.1.0
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 +370 -486
- package/lib/core.js +89 -27
- package/lib/diff.js +3 -0
- package/lib/edit.js +35 -33
- package/lib/formutil.js +5 -2
- package/lib/index.js +7 -0
- package/lib/merge.js +1 -1
- package/lib/state.js +17 -10
- package/lib/update.js +36 -55
- package/lib/useEdit.js +181 -327
- package/lib/useMessage.js +25 -0
- package/lib/useSearch.js +118 -238
- package/lib/useView.js +70 -161
- package/lib/util.js +6 -2
- package/package.json +7 -9
- package/src/components.ts +345 -301
- package/src/core.ts +110 -49
- package/src/diff.ts +4 -1
- package/src/edit.ts +44 -42
- package/src/formutil.ts +7 -4
- package/src/index.ts +8 -0
- package/src/merge.ts +3 -3
- package/src/state.ts +25 -19
- package/src/update.ts +35 -58
- package/src/useEdit.ts +165 -244
- package/src/useMessage.ts +37 -0
- package/src/useSearch.ts +145 -225
- 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
|
-
if (this.loading) {
|
|
137
|
-
this.loading.showLoading();
|
|
138
|
-
}
|
|
139
|
-
_a.label = 1;
|
|
140
|
-
case 1:
|
|
141
|
-
_a.trys.push([1, 6, 7, 8]);
|
|
142
|
-
ctx = {};
|
|
143
|
-
obj = void 0;
|
|
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);
|
|
183
107
|
}
|
|
108
|
+
else {
|
|
109
|
+
if (callback) {
|
|
110
|
+
callback(obj, com_1.showModel);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
com_1.showModel(obj);
|
|
114
|
+
}
|
|
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,10 +244,62 @@ 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;
|
|
@@ -326,16 +322,12 @@ var BaseSearchComponent = (function (_super) {
|
|
|
326
322
|
var url = _this.props['props'].match.url + '/add';
|
|
327
323
|
_this.props.history.push(url);
|
|
328
324
|
};
|
|
329
|
-
_this.pagingOnClick = function (size, e) {
|
|
330
|
-
_this.setState(function (prevState) { return ({ isPageSizeOpenDropDown: !prevState.isPageSizeOpenDropDown }); });
|
|
331
|
-
_this.pageSizeChanged(size);
|
|
332
|
-
};
|
|
333
325
|
_this.pageSizeOnClick = function () {
|
|
334
326
|
_this.setState(function (prevState) { return ({ isPageSizeOpenDropDown: !prevState.isPageSizeOpenDropDown }); });
|
|
335
327
|
};
|
|
336
328
|
_this.pageSizeChanged = function (event) {
|
|
337
|
-
var size = parseInt(event.currentTarget.value,
|
|
338
|
-
|
|
329
|
+
var size = parseInt(event.currentTarget.value, 10);
|
|
330
|
+
search_core_1.changePageSize(_this, size);
|
|
339
331
|
_this.tmpPageIndex = 1;
|
|
340
332
|
_this.doSearch();
|
|
341
333
|
};
|
|
@@ -347,11 +339,11 @@ var BaseSearchComponent = (function (_super) {
|
|
|
347
339
|
_this.add = _this.add.bind(_this);
|
|
348
340
|
_this.getSearchForm = _this.getSearchForm.bind(_this);
|
|
349
341
|
_this.setSearchForm = _this.setSearchForm.bind(_this);
|
|
350
|
-
_this.
|
|
351
|
-
_this.
|
|
352
|
-
_this.
|
|
342
|
+
_this.setFilter = _this.setFilter.bind(_this);
|
|
343
|
+
_this.getFilter = _this.getFilter.bind(_this);
|
|
344
|
+
_this.getFields = _this.getFields.bind(_this);
|
|
353
345
|
_this.pageSizeChanged = _this.pageSizeChanged.bind(_this);
|
|
354
|
-
_this.
|
|
346
|
+
_this.clearQ = _this.clearQ.bind(_this);
|
|
355
347
|
_this.searchOnClick = _this.searchOnClick.bind(_this);
|
|
356
348
|
_this.resetAndSearch = _this.resetAndSearch.bind(_this);
|
|
357
349
|
_this.doSearch = _this.doSearch.bind(_this);
|
|
@@ -367,14 +359,14 @@ var BaseSearchComponent = (function (_super) {
|
|
|
367
359
|
return _this;
|
|
368
360
|
}
|
|
369
361
|
BaseSearchComponent.prototype.getModelName = function () {
|
|
370
|
-
return '
|
|
362
|
+
return 'filter';
|
|
371
363
|
};
|
|
372
364
|
BaseSearchComponent.prototype.toggleFilter = function (event) {
|
|
373
365
|
this.hideFilter = !this.hideFilter;
|
|
374
366
|
};
|
|
375
367
|
BaseSearchComponent.prototype.load = function (s, autoSearch) {
|
|
376
|
-
var obj2 =
|
|
377
|
-
this.
|
|
368
|
+
var obj2 = search_core_1.initFilter(s, this);
|
|
369
|
+
this.setFilter(obj2);
|
|
378
370
|
var com = this;
|
|
379
371
|
if (autoSearch) {
|
|
380
372
|
setTimeout(function () {
|
|
@@ -391,29 +383,35 @@ var BaseSearchComponent = (function (_super) {
|
|
|
391
383
|
}
|
|
392
384
|
return this.form;
|
|
393
385
|
};
|
|
394
|
-
BaseSearchComponent.prototype.
|
|
395
|
-
this.setState(
|
|
386
|
+
BaseSearchComponent.prototype.setFilter = function (filter) {
|
|
387
|
+
this.setState(filter);
|
|
396
388
|
};
|
|
397
389
|
BaseSearchComponent.prototype.getCurrencyCode = function () {
|
|
398
390
|
return core_2.getCurrencyCode(this.form);
|
|
399
391
|
};
|
|
400
|
-
BaseSearchComponent.prototype.
|
|
392
|
+
BaseSearchComponent.prototype.getFilter = function () {
|
|
401
393
|
var name = this.getModelName();
|
|
402
|
-
var lc
|
|
394
|
+
var lc;
|
|
395
|
+
if (this.getLocale) {
|
|
396
|
+
lc = this.getLocale();
|
|
397
|
+
}
|
|
398
|
+
if (!lc) {
|
|
399
|
+
lc = state_1.enLocale;
|
|
400
|
+
}
|
|
403
401
|
var cc = this.getCurrencyCode();
|
|
404
|
-
var fields = this.
|
|
402
|
+
var fields = this.getFields();
|
|
405
403
|
var l = this.getList();
|
|
406
404
|
var f = this.getSearchForm();
|
|
407
|
-
var dc = (this.ui ? this.ui.decodeFromForm :
|
|
408
|
-
var obj3 =
|
|
405
|
+
var dc = (this.ui ? this.ui.decodeFromForm : undefined);
|
|
406
|
+
var obj3 = search_core_1.getModel(this.state, name, this, fields, this.excluding, this.keys, l, f, dc, lc, cc);
|
|
409
407
|
return obj3;
|
|
410
408
|
};
|
|
411
|
-
BaseSearchComponent.prototype.
|
|
412
|
-
var fs =
|
|
413
|
-
this.
|
|
409
|
+
BaseSearchComponent.prototype.getFields = function () {
|
|
410
|
+
var fs = search_core_1.getFieldsFromForm(this.fields, this.initFields, this.form);
|
|
411
|
+
this.initFields = true;
|
|
414
412
|
return fs;
|
|
415
413
|
};
|
|
416
|
-
BaseSearchComponent.prototype.
|
|
414
|
+
BaseSearchComponent.prototype.clearQ = function () {
|
|
417
415
|
var m = this.state.model;
|
|
418
416
|
if (m) {
|
|
419
417
|
m.q = '';
|
|
@@ -443,7 +441,7 @@ var BaseSearchComponent = (function (_super) {
|
|
|
443
441
|
this.triggerSearch = true;
|
|
444
442
|
return;
|
|
445
443
|
}
|
|
446
|
-
|
|
444
|
+
search_core_1.reset(this);
|
|
447
445
|
this.tmpPageIndex = 1;
|
|
448
446
|
this.doSearch();
|
|
449
447
|
};
|
|
@@ -453,18 +451,16 @@ var BaseSearchComponent = (function (_super) {
|
|
|
453
451
|
if (listForm && this.ui) {
|
|
454
452
|
this.ui.removeFormError(listForm);
|
|
455
453
|
}
|
|
456
|
-
var s = this.
|
|
454
|
+
var s = this.getFilter();
|
|
457
455
|
var com = this;
|
|
458
456
|
this.validateSearch(s, function () {
|
|
459
457
|
if (com.running === true) {
|
|
460
458
|
return;
|
|
461
459
|
}
|
|
462
460
|
com.running = true;
|
|
463
|
-
|
|
464
|
-
_this.loading.showLoading();
|
|
465
|
-
}
|
|
461
|
+
core_1.showLoading(_this.loading);
|
|
466
462
|
if (!_this.ignoreUrlParam) {
|
|
467
|
-
|
|
463
|
+
search_core_1.addParametersIntoUrl(s, isFirstLoad);
|
|
468
464
|
}
|
|
469
465
|
com.call(s);
|
|
470
466
|
});
|
|
@@ -473,15 +469,15 @@ var BaseSearchComponent = (function (_super) {
|
|
|
473
469
|
};
|
|
474
470
|
BaseSearchComponent.prototype.validateSearch = function (se, callback) {
|
|
475
471
|
var u = this.ui;
|
|
476
|
-
var vl = (u ? u.validateForm :
|
|
477
|
-
|
|
472
|
+
var vl = (u ? u.validateForm : undefined);
|
|
473
|
+
search_core_1.validate(se, callback, this.getSearchForm(), state_1.localeOf(undefined, this.getLocale), vl);
|
|
478
474
|
};
|
|
479
475
|
BaseSearchComponent.prototype.showResults = function (s, sr) {
|
|
480
476
|
var com = this;
|
|
481
477
|
var results = sr.list;
|
|
482
478
|
if (results && results.length > 0) {
|
|
483
|
-
var lc = this.getLocale
|
|
484
|
-
|
|
479
|
+
var lc = state_1.localeOf(undefined, this.getLocale);
|
|
480
|
+
search_core_1.formatResultsByComponent(results, com, lc);
|
|
485
481
|
}
|
|
486
482
|
var am = com.appendMode;
|
|
487
483
|
com.pageIndex = (s.page && s.page >= 1 ? s.page : 1);
|
|
@@ -490,12 +486,12 @@ var BaseSearchComponent = (function (_super) {
|
|
|
490
486
|
}
|
|
491
487
|
if (am) {
|
|
492
488
|
var limit = s.limit;
|
|
493
|
-
if (s.page <= 1 && s.firstLimit && s.firstLimit > 0) {
|
|
489
|
+
if ((!s.page || s.page <= 1) && s.firstLimit && s.firstLimit > 0) {
|
|
494
490
|
limit = s.firstLimit;
|
|
495
491
|
}
|
|
496
492
|
com.nextPageToken = sr.nextPageToken;
|
|
497
|
-
|
|
498
|
-
if (com.append && s.page > 1) {
|
|
493
|
+
search_core_1.handleAppend(com, sr.list, limit, sr.nextPageToken);
|
|
494
|
+
if (com.append && (s.page && s.page > 1)) {
|
|
499
495
|
com.appendList(results);
|
|
500
496
|
}
|
|
501
497
|
else {
|
|
@@ -503,25 +499,24 @@ var BaseSearchComponent = (function (_super) {
|
|
|
503
499
|
}
|
|
504
500
|
}
|
|
505
501
|
else {
|
|
506
|
-
|
|
502
|
+
search_core_1.showPaging(com, sr.list, s.limit, sr.total);
|
|
507
503
|
com.setList(results);
|
|
508
504
|
com.tmpPageIndex = s.page;
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
com.running = false;
|
|
513
|
-
if (this.loading) {
|
|
514
|
-
this.loading.hideLoading();
|
|
505
|
+
if (s.limit) {
|
|
506
|
+
this.showMessage(search_core_1.buildMessage(this.resourceService, s.page, s.limit, sr.list, sr.total));
|
|
507
|
+
}
|
|
515
508
|
}
|
|
509
|
+
com.running = undefined;
|
|
510
|
+
core_1.hideLoading(com.loading);
|
|
516
511
|
if (com.triggerSearch) {
|
|
517
|
-
com.triggerSearch =
|
|
512
|
+
com.triggerSearch = undefined;
|
|
518
513
|
com.resetAndSearch();
|
|
519
514
|
}
|
|
520
515
|
};
|
|
521
516
|
BaseSearchComponent.prototype.appendList = function (results) {
|
|
522
517
|
var _a;
|
|
523
518
|
var list = this.state.list;
|
|
524
|
-
var arr =
|
|
519
|
+
var arr = search_core_1.append(list, results);
|
|
525
520
|
var listForm = this.getSearchForm();
|
|
526
521
|
var props = this.props;
|
|
527
522
|
var setGlobalState = props.props.setGlobalState;
|
|
@@ -550,7 +545,7 @@ var BaseSearchComponent = (function (_super) {
|
|
|
550
545
|
};
|
|
551
546
|
BaseSearchComponent.prototype.sort = function (event) {
|
|
552
547
|
event.preventDefault();
|
|
553
|
-
|
|
548
|
+
search_core_1.handleSortEvent(event, this);
|
|
554
549
|
if (!this.appendMode) {
|
|
555
550
|
this.doSearch();
|
|
556
551
|
}
|
|
@@ -561,12 +556,12 @@ var BaseSearchComponent = (function (_super) {
|
|
|
561
556
|
BaseSearchComponent.prototype.showMore = function (event) {
|
|
562
557
|
event.preventDefault();
|
|
563
558
|
this.tmpPageIndex = this.pageIndex;
|
|
564
|
-
|
|
559
|
+
search_core_1.more(this);
|
|
565
560
|
this.doSearch();
|
|
566
561
|
};
|
|
567
562
|
BaseSearchComponent.prototype.pageChanged = function (data) {
|
|
568
563
|
var currentPage = data.currentPage, itemsPerPage = data.itemsPerPage;
|
|
569
|
-
|
|
564
|
+
search_core_1.changePage(this, currentPage, itemsPerPage);
|
|
570
565
|
this.doSearch();
|
|
571
566
|
};
|
|
572
567
|
return BaseSearchComponent;
|
|
@@ -583,90 +578,70 @@ var SearchComponent = (function (_super) {
|
|
|
583
578
|
_this.search = x;
|
|
584
579
|
}
|
|
585
580
|
else {
|
|
586
|
-
_this.
|
|
587
|
-
if (
|
|
588
|
-
_this.keys =
|
|
581
|
+
_this.search = sv.search;
|
|
582
|
+
if (sv.keys) {
|
|
583
|
+
_this.keys = sv.keys();
|
|
589
584
|
}
|
|
590
585
|
}
|
|
591
586
|
}
|
|
592
587
|
_this.call = _this.call.bind(_this);
|
|
593
588
|
_this.showError = input_1.getErrorFunc(param, showError);
|
|
594
589
|
_this.componentDidMount = _this.componentDidMount.bind(_this);
|
|
595
|
-
_this.
|
|
596
|
-
_this.
|
|
590
|
+
_this.mergeFilter = _this.mergeFilter.bind(_this);
|
|
591
|
+
_this.createFilter = _this.createFilter.bind(_this);
|
|
597
592
|
_this.ref = React.createRef();
|
|
598
593
|
return _this;
|
|
599
594
|
}
|
|
600
595
|
SearchComponent.prototype.componentDidMount = function () {
|
|
601
|
-
var k = (this.ui ? this.ui.registerEvents :
|
|
596
|
+
var k = (this.ui ? this.ui.registerEvents : undefined);
|
|
602
597
|
this.form = core_2.initForm(this.ref.current, k);
|
|
603
|
-
var s = this.
|
|
598
|
+
var s = this.mergeFilter(route_1.buildFromUrl(), this.createFilter());
|
|
604
599
|
this.load(s, this.autoSearch);
|
|
605
600
|
};
|
|
606
|
-
SearchComponent.prototype.
|
|
607
|
-
return
|
|
601
|
+
SearchComponent.prototype.mergeFilter = function (obj, b, arrs) {
|
|
602
|
+
return search_core_1.mergeFilter(obj, b, this.pageSizes, arrs);
|
|
608
603
|
};
|
|
609
|
-
SearchComponent.prototype.
|
|
604
|
+
SearchComponent.prototype.createFilter = function () {
|
|
610
605
|
var s = {};
|
|
611
606
|
return s;
|
|
612
607
|
};
|
|
613
608
|
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
|
-
}
|
|
609
|
+
this.running = true;
|
|
610
|
+
var s = reflectx_1.clone(se);
|
|
611
|
+
var page = this.pageIndex;
|
|
612
|
+
if (!page || page < 1) {
|
|
613
|
+
page = 1;
|
|
614
|
+
}
|
|
615
|
+
var offset;
|
|
616
|
+
if (se.limit) {
|
|
617
|
+
if (se.firstLimit && se.firstLimit > 0) {
|
|
618
|
+
offset = se.limit * (page - 2) + se.firstLimit;
|
|
619
|
+
}
|
|
620
|
+
else {
|
|
621
|
+
offset = se.limit * (page - 1);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
var limit = (page <= 1 && se.firstLimit && se.firstLimit > 0 ? se.firstLimit : se.limit);
|
|
625
|
+
var next = (this.nextPageToken && this.nextPageToken.length > 0 ? this.nextPageToken : offset);
|
|
626
|
+
var fields = se.fields;
|
|
627
|
+
delete se['page'];
|
|
628
|
+
delete se['fields'];
|
|
629
|
+
delete se['limit'];
|
|
630
|
+
delete se['firstLimit'];
|
|
631
|
+
core_1.showLoading(this.loading);
|
|
632
|
+
var com = this;
|
|
633
|
+
if (this.search) {
|
|
634
|
+
this.search(s, limit, next, fields).then(function (sr) {
|
|
635
|
+
com.showResults(s, sr);
|
|
636
|
+
com.running = undefined;
|
|
637
|
+
core_1.hideLoading(com.loading);
|
|
638
|
+
}).catch(function (err) {
|
|
639
|
+
com.pageIndex = com.tmpPageIndex;
|
|
640
|
+
core_2.error(err, com.resourceService.value, com.showError);
|
|
641
|
+
com.running = undefined;
|
|
642
|
+
core_1.hideLoading(com.loading);
|
|
668
643
|
});
|
|
669
|
-
}
|
|
644
|
+
}
|
|
670
645
|
};
|
|
671
646
|
return SearchComponent;
|
|
672
647
|
}(BaseSearchComponent));
|
|
@@ -674,14 +649,13 @@ exports.SearchComponent = SearchComponent;
|
|
|
674
649
|
var BaseEditComponent = (function (_super) {
|
|
675
650
|
__extends(BaseEditComponent, _super);
|
|
676
651
|
function BaseEditComponent(props, resourceService, showMessage, showError, confirm, getLocale, ui, loading, status, patchable, backOnSaveSuccess) {
|
|
677
|
-
var _this = _super.call(this, props, getLocale, (ui ? ui.removeError :
|
|
652
|
+
var _this = _super.call(this, props, getLocale, (ui ? ui.removeError : undefined)) || this;
|
|
678
653
|
_this.resourceService = resourceService;
|
|
679
654
|
_this.showMessage = showMessage;
|
|
680
655
|
_this.showError = showError;
|
|
681
656
|
_this.confirm = confirm;
|
|
682
657
|
_this.ui = ui;
|
|
683
658
|
_this.loading = loading;
|
|
684
|
-
_this.status = status;
|
|
685
659
|
_this.backOnSuccess = true;
|
|
686
660
|
_this.patchable = true;
|
|
687
661
|
_this.addable = true;
|
|
@@ -693,12 +667,12 @@ var BaseEditComponent = (function (_super) {
|
|
|
693
667
|
_this.form = event.target.form;
|
|
694
668
|
}
|
|
695
669
|
var obj = _this.createModel();
|
|
696
|
-
_this.resetState(true, obj,
|
|
670
|
+
_this.resetState(true, obj, undefined);
|
|
697
671
|
var u = _this.ui;
|
|
698
|
-
|
|
699
|
-
|
|
672
|
+
var f = _this.form;
|
|
673
|
+
if (u && f) {
|
|
700
674
|
setTimeout(function () {
|
|
701
|
-
u.removeFormError(
|
|
675
|
+
u.removeFormError(f);
|
|
702
676
|
}, 100);
|
|
703
677
|
}
|
|
704
678
|
};
|
|
@@ -711,6 +685,7 @@ var BaseEditComponent = (function (_super) {
|
|
|
711
685
|
_this.onSave(_this.backOnSuccess);
|
|
712
686
|
};
|
|
713
687
|
_this.resource = resourceService.resource();
|
|
688
|
+
_this.status = core_1.createEditStatus(status);
|
|
714
689
|
if (patchable === false) {
|
|
715
690
|
_this.patchable = patchable;
|
|
716
691
|
}
|
|
@@ -807,13 +782,13 @@ var BaseEditComponent = (function (_super) {
|
|
|
807
782
|
if (this.running) {
|
|
808
783
|
return;
|
|
809
784
|
}
|
|
810
|
-
var
|
|
811
|
-
var obj_1 =
|
|
785
|
+
var com_2 = this;
|
|
786
|
+
var obj_1 = com_2.getModel();
|
|
812
787
|
if (this.newMode) {
|
|
813
|
-
|
|
788
|
+
com_2.validate(obj_1, function () {
|
|
814
789
|
var msg = core_2.message(r.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
|
|
815
790
|
_this.confirm(msg.message, msg.title, function () {
|
|
816
|
-
|
|
791
|
+
com_2.save(obj_1, obj_1, isBack);
|
|
817
792
|
}, msg.no, msg.yes);
|
|
818
793
|
});
|
|
819
794
|
}
|
|
@@ -824,10 +799,10 @@ var BaseEditComponent = (function (_super) {
|
|
|
824
799
|
this.showMessage(r.value('msg_no_change'));
|
|
825
800
|
}
|
|
826
801
|
else {
|
|
827
|
-
|
|
802
|
+
com_2.validate(obj_1, function () {
|
|
828
803
|
var msg = core_2.message(r.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
|
|
829
804
|
_this.confirm(msg.message, msg.title, function () {
|
|
830
|
-
|
|
805
|
+
com_2.save(obj_1, diffObj_1, isBack);
|
|
831
806
|
}, msg.no, msg.yes);
|
|
832
807
|
});
|
|
833
808
|
}
|
|
@@ -835,8 +810,8 @@ var BaseEditComponent = (function (_super) {
|
|
|
835
810
|
}
|
|
836
811
|
};
|
|
837
812
|
BaseEditComponent.prototype.validate = function (obj, callback) {
|
|
838
|
-
if (this.ui) {
|
|
839
|
-
var valid = this.ui.validateForm(this.form, this.getLocale
|
|
813
|
+
if (this.ui && this.form) {
|
|
814
|
+
var valid = this.ui.validateForm(this.form, state_1.localeOf(undefined, this.getLocale));
|
|
840
815
|
if (valid) {
|
|
841
816
|
callback(obj);
|
|
842
817
|
}
|
|
@@ -871,7 +846,7 @@ var BaseEditComponent = (function (_super) {
|
|
|
871
846
|
var errors = result.errors;
|
|
872
847
|
var f = this.form;
|
|
873
848
|
var u = this.ui;
|
|
874
|
-
if (u) {
|
|
849
|
+
if (u && f) {
|
|
875
850
|
var unmappedErrors = u.showFormError(f, errors);
|
|
876
851
|
if (!result.message) {
|
|
877
852
|
if (errors && errors.length === 1) {
|
|
@@ -886,14 +861,14 @@ var BaseEditComponent = (function (_super) {
|
|
|
886
861
|
else if (errors && errors.length === 1) {
|
|
887
862
|
result.message = errors[0].message;
|
|
888
863
|
}
|
|
889
|
-
|
|
890
|
-
|
|
864
|
+
if (result.message) {
|
|
865
|
+
var t = this.resourceService.value('error');
|
|
866
|
+
this.showError(result.message, t);
|
|
867
|
+
}
|
|
891
868
|
};
|
|
892
869
|
BaseEditComponent.prototype.postSave = function (res, backOnSave) {
|
|
893
870
|
this.running = false;
|
|
894
|
-
|
|
895
|
-
this.loading.hideLoading();
|
|
896
|
-
}
|
|
871
|
+
core_1.hideLoading(this.loading);
|
|
897
872
|
var st = this.status;
|
|
898
873
|
var newMod = this.newMode;
|
|
899
874
|
var successMsg = (newMod ? this.insertSuccessMsg : this.updateSuccessMsg);
|
|
@@ -951,8 +926,10 @@ var EditComponent = (function (_super) {
|
|
|
951
926
|
var metadata = service.metadata();
|
|
952
927
|
if (metadata) {
|
|
953
928
|
var meta = edit_1.build(metadata);
|
|
954
|
-
|
|
955
|
-
|
|
929
|
+
if (meta) {
|
|
930
|
+
_this.keys = meta.keys;
|
|
931
|
+
_this.version = meta.version;
|
|
932
|
+
}
|
|
956
933
|
_this.metadata = metadata;
|
|
957
934
|
}
|
|
958
935
|
}
|
|
@@ -972,135 +949,91 @@ var EditComponent = (function (_super) {
|
|
|
972
949
|
return _this;
|
|
973
950
|
}
|
|
974
951
|
EditComponent.prototype.componentDidMount = function () {
|
|
975
|
-
var k = (this.ui ? this.ui.registerEvents :
|
|
952
|
+
var k = (this.ui ? this.ui.registerEvents : undefined);
|
|
976
953
|
this.form = core_2.initForm(this.ref.current, k);
|
|
977
954
|
var id = core_2.buildId(this.props, this.keys);
|
|
978
|
-
|
|
955
|
+
if (id) {
|
|
956
|
+
this.load(id);
|
|
957
|
+
}
|
|
979
958
|
};
|
|
980
959
|
EditComponent.prototype.load = function (_id, callback) {
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
obj
|
|
999
|
-
|
|
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];
|
|
960
|
+
var _this = this;
|
|
961
|
+
var id = _id;
|
|
962
|
+
if (id != null && id !== '') {
|
|
963
|
+
var com_3 = this;
|
|
964
|
+
this.running = true;
|
|
965
|
+
core_1.showLoading(com_3.loading);
|
|
966
|
+
this.service.load(id).then(function (obj) {
|
|
967
|
+
if (!obj) {
|
|
968
|
+
com_3.handleNotFound(_this.form);
|
|
969
|
+
}
|
|
970
|
+
else {
|
|
971
|
+
com_3.newMode = false;
|
|
972
|
+
com_3.orginalModel = reflectx_1.clone(obj);
|
|
973
|
+
if (!callback) {
|
|
974
|
+
com_3.showModel(obj);
|
|
975
|
+
}
|
|
976
|
+
else {
|
|
977
|
+
callback(obj, com_3.showModel);
|
|
978
|
+
}
|
|
1052
979
|
}
|
|
980
|
+
com_3.running = false;
|
|
981
|
+
core_1.hideLoading(com_3.loading);
|
|
982
|
+
}).catch(function (err) {
|
|
983
|
+
var data = (err && err.response) ? err.response : err;
|
|
984
|
+
var r = com_3.resourceService;
|
|
985
|
+
var gv = r.value;
|
|
986
|
+
var title = gv('error');
|
|
987
|
+
var msg = gv('error_internal');
|
|
988
|
+
if (data && data.status === 404) {
|
|
989
|
+
com_3.handleNotFound(com_3.form);
|
|
990
|
+
}
|
|
991
|
+
else {
|
|
992
|
+
if (data.status && !isNaN(data.status)) {
|
|
993
|
+
msg = core_2.messageByHttpStatus(data.status, gv);
|
|
994
|
+
}
|
|
995
|
+
if (data && (data.status === 401 || data.status === 403)) {
|
|
996
|
+
formutil_1.readOnly(com_3.form);
|
|
997
|
+
}
|
|
998
|
+
com_3.showError(msg, title);
|
|
999
|
+
}
|
|
1000
|
+
com_3.running = false;
|
|
1001
|
+
core_1.hideLoading(com_3.loading);
|
|
1053
1002
|
});
|
|
1054
|
-
}
|
|
1003
|
+
}
|
|
1004
|
+
else {
|
|
1005
|
+
this.newMode = true;
|
|
1006
|
+
this.orginalModel = undefined;
|
|
1007
|
+
var obj = this.createModel();
|
|
1008
|
+
if (callback) {
|
|
1009
|
+
callback(obj, this.showModel);
|
|
1010
|
+
}
|
|
1011
|
+
else {
|
|
1012
|
+
this.showModel(obj);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1055
1015
|
};
|
|
1056
1016
|
EditComponent.prototype.save = function (obj, body, isBack) {
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
com.postSave(result, isBackO);
|
|
1078
|
-
return [3, 5];
|
|
1079
|
-
case 3: return [4, this.service.update(obj, ctx)];
|
|
1080
|
-
case 4:
|
|
1081
|
-
result = _a.sent();
|
|
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];
|
|
1102
|
-
}
|
|
1103
|
-
});
|
|
1017
|
+
this.running = true;
|
|
1018
|
+
core_1.showLoading(this.loading);
|
|
1019
|
+
var isBackO = (isBack == null || isBack === undefined ? this.backOnSuccess : isBack);
|
|
1020
|
+
var com = this;
|
|
1021
|
+
var m = obj;
|
|
1022
|
+
var fn = this.newMode ? this.service.insert : this.service.update;
|
|
1023
|
+
if (!this.newMode) {
|
|
1024
|
+
if (this.patchable === true && this.service.patch && body && Object.keys(body).length > 0) {
|
|
1025
|
+
m = body;
|
|
1026
|
+
fn = this.service.patch;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
fn(m).then(function (result) {
|
|
1030
|
+
com.postSave(result, isBackO);
|
|
1031
|
+
com.running = false;
|
|
1032
|
+
core_1.hideLoading(com.loading);
|
|
1033
|
+
}).then(function (err) {
|
|
1034
|
+
core_2.error(err, com.resourceService.value, com.showError);
|
|
1035
|
+
com.running = false;
|
|
1036
|
+
core_1.hideLoading(com.loading);
|
|
1104
1037
|
});
|
|
1105
1038
|
};
|
|
1106
1039
|
return EditComponent;
|
|
@@ -1115,7 +1048,6 @@ var BaseDiffApprComponent = (function (_super) {
|
|
|
1115
1048
|
_this.showMessage = showMessage;
|
|
1116
1049
|
_this.showError = showError;
|
|
1117
1050
|
_this.loading = loading;
|
|
1118
|
-
_this.status = status;
|
|
1119
1051
|
_this.resource = resourceService.resource();
|
|
1120
1052
|
_this.showMessage = _this.showMessage.bind(_this);
|
|
1121
1053
|
_this.showError = _this.showError.bind(_this);
|
|
@@ -1125,9 +1057,7 @@ var BaseDiffApprComponent = (function (_super) {
|
|
|
1125
1057
|
_this.postReject = _this.postReject.bind(_this);
|
|
1126
1058
|
_this.format = _this.format.bind(_this);
|
|
1127
1059
|
_this.handleNotFound = _this.handleNotFound.bind(_this);
|
|
1128
|
-
|
|
1129
|
-
_this.status = core_1.createDiffStatus();
|
|
1130
|
-
}
|
|
1060
|
+
_this.status = core_1.createDiffStatus(status);
|
|
1131
1061
|
_this.state = {
|
|
1132
1062
|
disabled: false
|
|
1133
1063
|
};
|
|
@@ -1186,13 +1116,16 @@ var BaseDiffApprComponent = (function (_super) {
|
|
|
1186
1116
|
var differentKeys_1 = reflectx_1.diff(diffModel.origin, diffModel.value);
|
|
1187
1117
|
var dataFields = diff_1.getDataFields(this.form);
|
|
1188
1118
|
dataFields.forEach(function (e) {
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
e.childNodes
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1119
|
+
var x = e.getAttribute('data-field');
|
|
1120
|
+
if (x) {
|
|
1121
|
+
if (differentKeys_1.indexOf(x) >= 0) {
|
|
1122
|
+
if (e.childNodes.length === 3) {
|
|
1123
|
+
e.childNodes[1].classList.add('highlight');
|
|
1124
|
+
e.childNodes[2].classList.add('highlight');
|
|
1125
|
+
}
|
|
1126
|
+
else {
|
|
1127
|
+
e.classList.add('highlight');
|
|
1128
|
+
}
|
|
1196
1129
|
}
|
|
1197
1130
|
}
|
|
1198
1131
|
});
|
|
@@ -1202,13 +1135,16 @@ var BaseDiffApprComponent = (function (_super) {
|
|
|
1202
1135
|
var differentKeys_2 = reflectx_1.diff(origin_1, value);
|
|
1203
1136
|
var dataFields = diff_1.getDataFields(this.form);
|
|
1204
1137
|
dataFields.forEach(function (e) {
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
e.childNodes
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1138
|
+
var x = e.getAttribute('data-field');
|
|
1139
|
+
if (x) {
|
|
1140
|
+
if (differentKeys_2.indexOf(x) >= 0) {
|
|
1141
|
+
if (e.childNodes.length === 3) {
|
|
1142
|
+
e.childNodes[1].classList.add('highlight');
|
|
1143
|
+
e.childNodes[2].classList.add('highlight');
|
|
1144
|
+
}
|
|
1145
|
+
else {
|
|
1146
|
+
e.classList.add('highlight');
|
|
1147
|
+
}
|
|
1212
1148
|
}
|
|
1213
1149
|
}
|
|
1214
1150
|
});
|
|
@@ -1241,131 +1177,79 @@ var DiffApprComponent = (function (_super) {
|
|
|
1241
1177
|
DiffApprComponent.prototype.componentDidMount = function () {
|
|
1242
1178
|
this.form = this.ref.current;
|
|
1243
1179
|
var id = core_2.buildId(this.props, this.keys);
|
|
1244
|
-
|
|
1180
|
+
if (id) {
|
|
1181
|
+
this.load(id);
|
|
1182
|
+
}
|
|
1245
1183
|
};
|
|
1246
1184
|
DiffApprComponent.prototype.formatFields = function (value) {
|
|
1247
1185
|
return value;
|
|
1248
1186
|
};
|
|
1249
1187
|
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
|
-
this.setState({
|
|
1274
|
-
origin: formatdDiff.origin,
|
|
1275
|
-
value: formatdDiff.value
|
|
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];
|
|
1188
|
+
var id = _id;
|
|
1189
|
+
if (id != null && id !== '') {
|
|
1190
|
+
this.id = _id;
|
|
1191
|
+
var com_4 = this;
|
|
1192
|
+
this.running = true;
|
|
1193
|
+
core_1.showLoading(this.loading);
|
|
1194
|
+
this.service.diff(id).then(function (dobj) {
|
|
1195
|
+
if (!dobj) {
|
|
1196
|
+
com_4.handleNotFound();
|
|
1197
|
+
}
|
|
1198
|
+
else {
|
|
1199
|
+
var formatdDiff = diff_1.formatDiffModel(dobj, com_4.formatFields);
|
|
1200
|
+
com_4.setState({
|
|
1201
|
+
origin: formatdDiff.origin,
|
|
1202
|
+
value: formatdDiff.value
|
|
1203
|
+
}, com_4.format);
|
|
1204
|
+
}
|
|
1205
|
+
com_4.running = false;
|
|
1206
|
+
core_1.hideLoading(com_4.loading);
|
|
1207
|
+
}).catch(function (err) {
|
|
1208
|
+
var data = (err && err.response) ? err.response : err;
|
|
1209
|
+
if (data && data.status === 404) {
|
|
1210
|
+
com_4.handleNotFound();
|
|
1296
1211
|
}
|
|
1212
|
+
else {
|
|
1213
|
+
core_2.error(err, com_4.resourceService.value, com_4.showError);
|
|
1214
|
+
}
|
|
1215
|
+
com_4.running = false;
|
|
1216
|
+
core_1.hideLoading(com_4.loading);
|
|
1297
1217
|
});
|
|
1298
|
-
}
|
|
1218
|
+
}
|
|
1299
1219
|
};
|
|
1300
1220
|
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
|
-
}
|
|
1221
|
+
event.preventDefault();
|
|
1222
|
+
var com = this;
|
|
1223
|
+
this.running = true;
|
|
1224
|
+
core_1.showLoading(this.loading);
|
|
1225
|
+
if (this.id) {
|
|
1226
|
+
this.service.approve(this.id).then(function (status) {
|
|
1227
|
+
com.postApprove(status, null);
|
|
1228
|
+
com.running = false;
|
|
1229
|
+
core_1.hideLoading(com.loading);
|
|
1230
|
+
}).catch(function (err) {
|
|
1231
|
+
com.postApprove(4, err);
|
|
1232
|
+
com.running = false;
|
|
1233
|
+
core_1.hideLoading(com.loading);
|
|
1332
1234
|
});
|
|
1333
|
-
}
|
|
1235
|
+
}
|
|
1334
1236
|
};
|
|
1335
1237
|
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
|
-
}
|
|
1238
|
+
event.preventDefault();
|
|
1239
|
+
var com = this;
|
|
1240
|
+
this.running = true;
|
|
1241
|
+
core_1.showLoading(this.loading);
|
|
1242
|
+
if (this.id) {
|
|
1243
|
+
this.service.reject(this.id).then(function (status) {
|
|
1244
|
+
com.postReject(status, null);
|
|
1245
|
+
com.running = false;
|
|
1246
|
+
core_1.hideLoading(com.loading);
|
|
1247
|
+
}).catch(function (err) {
|
|
1248
|
+
com.postReject(4, err);
|
|
1249
|
+
com.running = false;
|
|
1250
|
+
core_1.hideLoading(com.loading);
|
|
1367
1251
|
});
|
|
1368
|
-
}
|
|
1252
|
+
}
|
|
1369
1253
|
};
|
|
1370
1254
|
return DiffApprComponent;
|
|
1371
1255
|
}(BaseDiffApprComponent));
|