react-hook-core 0.1.25 → 0.2.1
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/com.js +1 -1
- package/lib/components.js +64 -91
- package/lib/core.js +0 -28
- package/lib/edit.js +0 -13
- package/lib/formutil.js +36 -22
- package/lib/index.js +8 -0
- package/lib/input.js +0 -14
- package/lib/useEdit.js +423 -431
- package/lib/useSearch.js +0 -16
- package/lib/useView.js +107 -107
- package/package.json +1 -1
- package/src/com.ts +1 -1
- package/src/components.ts +58 -73
- package/src/core.ts +3 -2
- package/src/edit.ts +4 -2
- package/src/formutil.ts +31 -20
- package/src/index.ts +7 -0
- package/src/input.ts +3 -1
- package/src/useEdit.ts +14 -16
- package/src/useSearch.ts +15 -13
- package/src/useView.ts +3 -3
package/lib/useSearch.js
CHANGED
|
@@ -70,18 +70,6 @@ function mergeParam(p) {
|
|
|
70
70
|
if (p.hideFilter === undefined) {
|
|
71
71
|
p.hideFilter = true;
|
|
72
72
|
}
|
|
73
|
-
if (p.addable === undefined) {
|
|
74
|
-
p.addable = true;
|
|
75
|
-
}
|
|
76
|
-
if (p.editable === undefined) {
|
|
77
|
-
p.editable = true;
|
|
78
|
-
}
|
|
79
|
-
if (p.approvable === undefined) {
|
|
80
|
-
p.approvable = true;
|
|
81
|
-
}
|
|
82
|
-
if (p.deletable === undefined) {
|
|
83
|
-
p.deletable = true;
|
|
84
|
-
}
|
|
85
73
|
return p;
|
|
86
74
|
}
|
|
87
75
|
else {
|
|
@@ -91,10 +79,6 @@ function mergeParam(p) {
|
|
|
91
79
|
pageSizes: core_1.pageSizes,
|
|
92
80
|
pageMaxSize: 7,
|
|
93
81
|
hideFilter: true,
|
|
94
|
-
addable: true,
|
|
95
|
-
editable: true,
|
|
96
|
-
approvable: true,
|
|
97
|
-
deletable: true
|
|
98
82
|
};
|
|
99
83
|
}
|
|
100
84
|
}
|
package/lib/useView.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
var react_1 = require("react");
|
|
@@ -17,110 +17,110 @@ var core_1 = require("./core");
|
|
|
17
17
|
var formutil_1 = require("./formutil");
|
|
18
18
|
var merge_1 = require("./merge");
|
|
19
19
|
exports.useViewOne = function (p) {
|
|
20
|
-
|
|
20
|
+
return exports.useCoreView(p.refForm, p.initialState, p.service, p, p);
|
|
21
21
|
};
|
|
22
22
|
exports.useView = function (refForm, initialState, service, p1, p) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
var baseProps = exports.useCoreView(refForm, initialState, service, p1, p);
|
|
24
|
+
var _a = merge_1.useMergeState(initialState), setState = _a[1];
|
|
25
|
+
var params = react_router_1.useParams();
|
|
26
|
+
react_1.useEffect(function () {
|
|
27
|
+
if (baseProps.refForm) {
|
|
28
|
+
core_1.initForm(baseProps.refForm.current);
|
|
29
|
+
}
|
|
30
|
+
var id = core_1.buildId(params, p ? p.keys : undefined);
|
|
31
|
+
if (id) {
|
|
32
|
+
if (p && p.initialize) {
|
|
33
|
+
p.initialize(id, baseProps.load, setState, p.callback);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
baseProps.load(id, p ? p.callback : undefined);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}, []);
|
|
40
|
+
return __assign({}, baseProps);
|
|
41
41
|
};
|
|
42
42
|
exports.useCoreView = function (refForm, initialState, service, p1, p) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
navigate(-1);
|
|
51
|
-
};
|
|
52
|
-
var getModelName = function (f) {
|
|
53
|
-
if (p && p.name) {
|
|
54
|
-
return p.name;
|
|
55
|
-
}
|
|
56
|
-
return core_1.getModelName(f, 'model');
|
|
57
|
-
};
|
|
58
|
-
var showModel = function (model) {
|
|
59
|
-
var n = getModelName(refForm.current);
|
|
60
|
-
var objSet = {};
|
|
61
|
-
objSet[n] = model;
|
|
62
|
-
setState(objSet);
|
|
63
|
-
};
|
|
64
|
-
var _handleNotFound = function (form) {
|
|
65
|
-
var msg = core_1.message(p1.resource.value, 'error_not_found', 'error');
|
|
66
|
-
if (form) {
|
|
67
|
-
formutil_1.readOnly(form);
|
|
68
|
-
}
|
|
69
|
-
p1.showError(msg.message, msg.title);
|
|
70
|
-
};
|
|
71
|
-
var handleNotFound = (p && p.handleNotFound ? p.handleNotFound : _handleNotFound);
|
|
72
|
-
var _load = function (_id, callback) {
|
|
73
|
-
var id = _id;
|
|
74
|
-
if (id != null && id !== '') {
|
|
75
|
-
setRunning(true);
|
|
76
|
-
core_1.showLoading(p1.loading);
|
|
77
|
-
var fn = (typeof service === 'function' ? service : service.load);
|
|
78
|
-
fn(id).then(function (obj) {
|
|
79
|
-
if (!obj) {
|
|
80
|
-
handleNotFound(refForm.current);
|
|
43
|
+
var _a = merge_1.useMergeState(initialState), state = _a[0], setState = _a[1];
|
|
44
|
+
var _b = react_1.useState(), running = _b[0], setRunning = _b[1];
|
|
45
|
+
var navigate = react_router_1.useNavigate();
|
|
46
|
+
var back = function (event) {
|
|
47
|
+
if (event) {
|
|
48
|
+
event.preventDefault();
|
|
81
49
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
showModel(obj);
|
|
88
|
-
}
|
|
50
|
+
navigate(-1);
|
|
51
|
+
};
|
|
52
|
+
var getModelName = function (f) {
|
|
53
|
+
if (p && p.name) {
|
|
54
|
+
return p.name;
|
|
89
55
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
var
|
|
94
|
-
var
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
56
|
+
return core_1.getModelName(f, 'model');
|
|
57
|
+
};
|
|
58
|
+
var showModel = function (model) {
|
|
59
|
+
var n = getModelName(refForm.current);
|
|
60
|
+
var objSet = {};
|
|
61
|
+
objSet[n] = model;
|
|
62
|
+
setState(objSet);
|
|
63
|
+
};
|
|
64
|
+
var _handleNotFound = function (form) {
|
|
65
|
+
var msg = core_1.message(p1.resource.value, 'error_not_found', 'error');
|
|
66
|
+
if (form) {
|
|
67
|
+
formutil_1.setReadOnly(form);
|
|
99
68
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
69
|
+
p1.showError(msg.message, msg.title);
|
|
70
|
+
};
|
|
71
|
+
var handleNotFound = (p && p.handleNotFound ? p.handleNotFound : _handleNotFound);
|
|
72
|
+
var _load = function (_id, callback) {
|
|
73
|
+
var id = _id;
|
|
74
|
+
if (id != null && id !== '') {
|
|
75
|
+
setRunning(true);
|
|
76
|
+
core_1.showLoading(p1.loading);
|
|
77
|
+
var fn = (typeof service === 'function' ? service : service.load);
|
|
78
|
+
fn(id).then(function (obj) {
|
|
79
|
+
if (!obj) {
|
|
80
|
+
handleNotFound(refForm.current);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
if (callback) {
|
|
84
|
+
callback(obj, showModel);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
showModel(obj);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
setRunning(false);
|
|
91
|
+
core_1.hideLoading(p1.loading);
|
|
92
|
+
}).catch(function (err) {
|
|
93
|
+
var data = (err && err.response) ? err.response : err;
|
|
94
|
+
var r = p1.resource;
|
|
95
|
+
var title = r.value('error');
|
|
96
|
+
var msg = r.value('error_internal');
|
|
97
|
+
if (data && data.status === 404) {
|
|
98
|
+
handleNotFound(refForm.current);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
if (data && data.status) {
|
|
102
|
+
msg = core_1.messageByHttpStatus(data.status, r.value);
|
|
103
|
+
}
|
|
104
|
+
formutil_1.setReadOnly(refForm.current);
|
|
105
|
+
p1.showError(msg, title);
|
|
106
|
+
}
|
|
107
|
+
setRunning(false);
|
|
108
|
+
core_1.hideLoading(p1.loading);
|
|
109
|
+
});
|
|
106
110
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
handleNotFound: handleNotFound,
|
|
123
|
-
load: load,
|
|
124
|
-
back: back
|
|
125
|
-
};
|
|
111
|
+
};
|
|
112
|
+
var load = (p && p.load ? p.load : _load);
|
|
113
|
+
return {
|
|
114
|
+
state: state,
|
|
115
|
+
setState: setState,
|
|
116
|
+
refForm: refForm,
|
|
117
|
+
resource: p1.resource.resource(),
|
|
118
|
+
running: running,
|
|
119
|
+
setRunning: setRunning,
|
|
120
|
+
showModel: showModel,
|
|
121
|
+
getModelName: getModelName,
|
|
122
|
+
handleNotFound: handleNotFound,
|
|
123
|
+
load: load,
|
|
124
|
+
back: back
|
|
125
|
+
};
|
|
126
126
|
};
|
package/package.json
CHANGED
package/src/com.ts
CHANGED
|
@@ -12,7 +12,7 @@ export function PageSizeSelect(p: PageSizeProps) {
|
|
|
12
12
|
const g = p.sizes;
|
|
13
13
|
const s = (!g || g.length === 0 ? pageSizes : g);
|
|
14
14
|
const opts = s.map(pgSize => React.createElement('option', { key: pgSize, value: pgSize }, pgSize));
|
|
15
|
-
return React.createElement('select', { id: p.id, name: p.name,
|
|
15
|
+
return React.createElement('select', { id: p.id, name: p.name, defaultValue: p.size, onChange: p.onChange }, opts);
|
|
16
16
|
}
|
|
17
17
|
export interface Props {
|
|
18
18
|
id?: string;
|
package/src/components.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {BaseDiffState,
|
|
3
|
-
import {Attributes,
|
|
2
|
+
import {BaseDiffState, DiffApprService, DiffParameter, DiffState, handleToggle, hideLoading, showLoading} from './core';
|
|
3
|
+
import {Attributes, error, ErrorMessage, Filter, getCurrencyCode, getModelName as getModelName2, initForm, LoadingService, Locale, message, messageByHttpStatus, PageChange, pageSizes, removePhoneFormat, ResourceService, SearchParameter, SearchResult, SearchService, SearchState, StringMap, UIService, ViewParameter, ViewService} from './core';
|
|
4
4
|
import {formatDiffModel, getDataFields} from './diff';
|
|
5
|
-
import {build, createModel as createModel2, EditParameter, GenericService,
|
|
6
|
-
import {focusFirstError,
|
|
7
|
-
import {getAutoSearch, getConfirmFunc,
|
|
5
|
+
import {build, createModel as createModel2, EditParameter, GenericService, handleVersion, initPropertyNullInModel} from './edit';
|
|
6
|
+
import {focusFirstError, setReadOnly} from './formutil';
|
|
7
|
+
import {getAutoSearch, getConfirmFunc, getErrorFunc, getLoadingFunc, getLocaleFunc, getMsgFunc, getResource, getUIService} from './input';
|
|
8
8
|
import {clone, diff, makeDiff} from './reflect';
|
|
9
9
|
import {buildFromUrl} from './route';
|
|
10
10
|
import {addParametersIntoUrl, append, buildMessage, changePage, changePageSize, formatResults, getFieldsFromForm, getModel, handleAppend, handleSortEvent, initFilter, mergeFilter as mergeFilter2, more, Pagination, reset, showPaging, Sortable, validate} from './search';
|
|
@@ -105,7 +105,7 @@ export class ViewComponent<T, ID, P, S> extends React.Component<P, S> {
|
|
|
105
105
|
handleNotFound(form?: HTMLFormElement): void {
|
|
106
106
|
const msg = message(this.resourceService.value, 'error_not_found', 'error');
|
|
107
107
|
if (form) {
|
|
108
|
-
|
|
108
|
+
setReadOnly(form);
|
|
109
109
|
}
|
|
110
110
|
this.showError(msg.message, msg.title);
|
|
111
111
|
}
|
|
@@ -366,11 +366,11 @@ export class BaseSearchComponent<T, F extends Filter, P, I extends SearchState<T
|
|
|
366
366
|
// locationSearch: string;
|
|
367
367
|
// _currentSortField: string;
|
|
368
368
|
|
|
369
|
-
viewable?: boolean = true;
|
|
370
|
-
addable?: boolean = true;
|
|
371
|
-
editable?: boolean = true;
|
|
372
|
-
approvable?: boolean;
|
|
373
|
-
deletable?: boolean;
|
|
369
|
+
// viewable?: boolean = true;
|
|
370
|
+
// addable?: boolean = true;
|
|
371
|
+
// editable?: boolean = true;
|
|
372
|
+
// approvable?: boolean;
|
|
373
|
+
// deletable?: boolean;
|
|
374
374
|
|
|
375
375
|
getModelName(): string {
|
|
376
376
|
return 'filter';
|
|
@@ -702,11 +702,11 @@ export abstract class BaseEditComponent<T, P, S> extends BaseComponent<P, S> {
|
|
|
702
702
|
getLocale?: () => Locale,
|
|
703
703
|
protected ui?: UIService,
|
|
704
704
|
protected loading?: LoadingService,
|
|
705
|
-
status?: EditStatusConfig,
|
|
705
|
+
// status?: EditStatusConfig,
|
|
706
706
|
patchable?: boolean, backOnSaveSuccess?: boolean) {
|
|
707
707
|
super(props, getLocale, (ui ? ui.removeError : undefined));
|
|
708
708
|
this.resource = resourceService.resource();
|
|
709
|
-
this.status = createEditStatus(status);
|
|
709
|
+
// this.status = createEditStatus(status);
|
|
710
710
|
if (patchable === false) {
|
|
711
711
|
this.patchable = patchable;
|
|
712
712
|
}
|
|
@@ -739,7 +739,7 @@ export abstract class BaseEditComponent<T, P, S> extends BaseComponent<P, S> {
|
|
|
739
739
|
this.postSave = this.postSave.bind(this);
|
|
740
740
|
this.handleDuplicateKey = this.handleDuplicateKey.bind(this);
|
|
741
741
|
}
|
|
742
|
-
status: EditStatusConfig;
|
|
742
|
+
// status: EditStatusConfig;
|
|
743
743
|
protected name?: string;
|
|
744
744
|
protected backOnSuccess = true;
|
|
745
745
|
protected resource: StringMap;
|
|
@@ -751,9 +751,9 @@ export abstract class BaseEditComponent<T, P, S> extends BaseComponent<P, S> {
|
|
|
751
751
|
protected patchable = true;
|
|
752
752
|
protected orginalModel?: T;
|
|
753
753
|
|
|
754
|
-
addable?: boolean = true;
|
|
754
|
+
// addable?: boolean = true;
|
|
755
755
|
readOnly?: boolean;
|
|
756
|
-
deletable?: boolean;
|
|
756
|
+
// deletable?: boolean;
|
|
757
757
|
|
|
758
758
|
insertSuccessMsg: string;
|
|
759
759
|
updateSuccessMsg: string;
|
|
@@ -770,7 +770,7 @@ export abstract class BaseEditComponent<T, P, S> extends BaseComponent<P, S> {
|
|
|
770
770
|
handleNotFound(form?: HTMLFormElement|null): void {
|
|
771
771
|
const msg = message(this.resourceService.value, 'error_not_found', 'error');
|
|
772
772
|
if (form) {
|
|
773
|
-
|
|
773
|
+
setReadOnly(form);
|
|
774
774
|
}
|
|
775
775
|
this.showError(msg.message, msg.title);
|
|
776
776
|
}
|
|
@@ -791,7 +791,7 @@ export abstract class BaseEditComponent<T, P, S> extends BaseComponent<P, S> {
|
|
|
791
791
|
objSet[modelName] = model;
|
|
792
792
|
this.setState(objSet, () => {
|
|
793
793
|
if (this.readOnly) {
|
|
794
|
-
|
|
794
|
+
setReadOnly(f);
|
|
795
795
|
}
|
|
796
796
|
});
|
|
797
797
|
}
|
|
@@ -834,40 +834,30 @@ export abstract class BaseEditComponent<T, P, S> extends BaseComponent<P, S> {
|
|
|
834
834
|
}
|
|
835
835
|
onSave(isBack?: boolean) {
|
|
836
836
|
const r = this.resourceService;
|
|
837
|
-
if (this.
|
|
838
|
-
const m = message(r.value, 'error_permission_add', 'error_permission');
|
|
839
|
-
this.showError(m.message, m.title);
|
|
840
|
-
return;
|
|
841
|
-
} else if (!this.newMode && this.readOnly) {
|
|
842
|
-
const msg = message(r.value, 'error_permission_edit', 'error_permission');
|
|
843
|
-
this.showError(msg.message, msg.title);
|
|
837
|
+
if (this.running) {
|
|
844
838
|
return;
|
|
839
|
+
}
|
|
840
|
+
const com = this;
|
|
841
|
+
const obj = com.getModel();
|
|
842
|
+
if (this.newMode) {
|
|
843
|
+
com.validate(obj, () => {
|
|
844
|
+
const msg = message(r.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
|
|
845
|
+
this.confirm(msg.message, msg.title, () => {
|
|
846
|
+
com.doSave(obj, obj, isBack);
|
|
847
|
+
}, msg.no, msg.yes);
|
|
848
|
+
});
|
|
845
849
|
} else {
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
if (this.newMode) {
|
|
850
|
+
const diffObj = makeDiff(initPropertyNullInModel(this.orginalModel, this.metadata), obj, this.keys, this.version);
|
|
851
|
+
const keys = Object.keys(diffObj as any);
|
|
852
|
+
if (keys.length === 0) {
|
|
853
|
+
this.showMessage(r.value('msg_no_change'));
|
|
854
|
+
} else {
|
|
852
855
|
com.validate(obj, () => {
|
|
853
856
|
const msg = message(r.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
|
|
854
857
|
this.confirm(msg.message, msg.title, () => {
|
|
855
|
-
com.doSave(obj,
|
|
858
|
+
com.doSave(obj, diffObj, isBack);
|
|
856
859
|
}, msg.no, msg.yes);
|
|
857
860
|
});
|
|
858
|
-
} else {
|
|
859
|
-
const diffObj = makeDiff(initPropertyNullInModel(this.orginalModel, this.metadata), obj, this.keys, this.version);
|
|
860
|
-
const keys = Object.keys(diffObj as any);
|
|
861
|
-
if (keys.length === 0) {
|
|
862
|
-
this.showMessage(r.value('msg_no_change'));
|
|
863
|
-
} else {
|
|
864
|
-
com.validate(obj, () => {
|
|
865
|
-
const msg = message(r.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
|
|
866
|
-
this.confirm(msg.message, msg.title, () => {
|
|
867
|
-
com.doSave(obj, diffObj, isBack);
|
|
868
|
-
}, msg.no, msg.yes);
|
|
869
|
-
});
|
|
870
|
-
}
|
|
871
861
|
}
|
|
872
862
|
}
|
|
873
863
|
}
|
|
@@ -930,7 +920,7 @@ export abstract class BaseEditComponent<T, P, S> extends BaseComponent<P, S> {
|
|
|
930
920
|
postSave(res: number|string|T|ErrorMessage[], origin: T, isPatch: boolean, backOnSave?: boolean) {
|
|
931
921
|
this.running = false;
|
|
932
922
|
hideLoading(this.loading);
|
|
933
|
-
const st = this.status;
|
|
923
|
+
// const st = this.status;
|
|
934
924
|
const newMod = this.newMode;
|
|
935
925
|
const successMsg = (newMod ? this.insertSuccessMsg : this.updateSuccessMsg);
|
|
936
926
|
const x: any = res;
|
|
@@ -938,15 +928,15 @@ export abstract class BaseEditComponent<T, P, S> extends BaseComponent<P, S> {
|
|
|
938
928
|
if (Array.isArray(x)) {
|
|
939
929
|
this.fail(x);
|
|
940
930
|
} else if (!isNaN(x)) {
|
|
941
|
-
if (x
|
|
931
|
+
if (x > 0) {
|
|
942
932
|
this.succeed(successMsg, origin, backOnSave);
|
|
943
933
|
} else {
|
|
944
|
-
if (newMod && x
|
|
934
|
+
if (newMod && x <= 0) {
|
|
945
935
|
this.handleDuplicateKey();
|
|
946
|
-
} else if (!newMod && x ===
|
|
936
|
+
} else if (!newMod && x === 0) {
|
|
947
937
|
this.handleNotFound();
|
|
948
938
|
} else {
|
|
949
|
-
|
|
939
|
+
this.showError(r.value('error_version'), r.value('error'));
|
|
950
940
|
}
|
|
951
941
|
}
|
|
952
942
|
} else {
|
|
@@ -977,8 +967,8 @@ export class EditComponent<T, ID, P, S> extends BaseEditComponent<T, P, S> {
|
|
|
977
967
|
confirm?: (m2: string, header: string, yesCallback?: () => void, btnLeftText?: string, btnRightText?: string, noCallback?: () => void) => void,
|
|
978
968
|
getLocale?: (profile?: string) => Locale,
|
|
979
969
|
uis?: UIService,
|
|
980
|
-
loading?: LoadingService,
|
|
981
|
-
super(props, getResource(param), getMsgFunc(param, showMessage), getErrorFunc(param, showError), getConfirmFunc(param, confirm), getLocaleFunc(param, getLocale), getUIService(param, uis), getLoadingFunc(param, loading),
|
|
970
|
+
loading?: LoadingService, patchable?: boolean, backOnSaveSuccess?: boolean) {
|
|
971
|
+
super(props, getResource(param), getMsgFunc(param, showMessage), getErrorFunc(param, showError), getConfirmFunc(param, confirm), getLocaleFunc(param, getLocale), getUIService(param, uis), getLoadingFunc(param, loading), patchable, backOnSaveSuccess);
|
|
982
972
|
if (service.metadata) {
|
|
983
973
|
const metadata = service.metadata();
|
|
984
974
|
if (metadata) {
|
|
@@ -1037,7 +1027,7 @@ export class EditComponent<T, ID, P, S> extends BaseEditComponent<T, P, S> {
|
|
|
1037
1027
|
msg = messageByHttpStatus(data.status, gv);
|
|
1038
1028
|
}
|
|
1039
1029
|
if (data && (data.status === 401 || data.status === 403)) {
|
|
1040
|
-
|
|
1030
|
+
setReadOnly(com.form);
|
|
1041
1031
|
}
|
|
1042
1032
|
com.showError(msg, title);
|
|
1043
1033
|
}
|
|
@@ -1086,7 +1076,7 @@ export class BaseDiffApprComponent<T, ID, P, S extends BaseDiffState> extends Re
|
|
|
1086
1076
|
protected showMessage: (msg: string, option?: string) => void,
|
|
1087
1077
|
protected showError: (m: string, title?: string, detail?: string, callback?: () => void) => void,
|
|
1088
1078
|
protected loading?: LoadingService,
|
|
1089
|
-
status?: DiffStatusConfig,
|
|
1079
|
+
// status?: DiffStatusConfig,
|
|
1090
1080
|
) {
|
|
1091
1081
|
super(props);
|
|
1092
1082
|
// this._id = props['props'].match.params.id || props['props'].match.params.cId || props.match.params.cId;
|
|
@@ -1099,12 +1089,12 @@ export class BaseDiffApprComponent<T, ID, P, S extends BaseDiffState> extends Re
|
|
|
1099
1089
|
this.postReject = this.postReject.bind(this);
|
|
1100
1090
|
this.format = this.format.bind(this);
|
|
1101
1091
|
this.handleNotFound = this.handleNotFound.bind(this);
|
|
1102
|
-
this.status = createDiffStatus(status);
|
|
1092
|
+
// this.status = createDiffStatus(status);
|
|
1103
1093
|
this.state = {
|
|
1104
1094
|
disabled: false
|
|
1105
1095
|
};
|
|
1106
1096
|
}
|
|
1107
|
-
status: DiffStatusConfig;
|
|
1097
|
+
// status: DiffStatusConfig;
|
|
1108
1098
|
id?: ID;
|
|
1109
1099
|
form?: HTMLFormElement;
|
|
1110
1100
|
running?: boolean;
|
|
@@ -1118,32 +1108,28 @@ export class BaseDiffApprComponent<T, ID, P, S extends BaseDiffState> extends Re
|
|
|
1118
1108
|
postApprove(s: number|string, err?: any) {
|
|
1119
1109
|
this.setState({ disabled: true });
|
|
1120
1110
|
const r = this.resourceService;
|
|
1121
|
-
const st = this.status;
|
|
1122
|
-
if (s
|
|
1111
|
+
// const st = this.status;
|
|
1112
|
+
if (s > 0) {
|
|
1123
1113
|
this.showMessage(r.value('msg_approve_success'));
|
|
1124
|
-
} else if (s ===
|
|
1125
|
-
const msg = message(r.value, 'msg_approve_version_error', 'error');
|
|
1126
|
-
this.showError(msg.message, msg.title);
|
|
1127
|
-
} else if (s === st.not_found) {
|
|
1114
|
+
} else if (s === 0) {
|
|
1128
1115
|
this.handleNotFound();
|
|
1129
1116
|
} else {
|
|
1130
|
-
|
|
1117
|
+
const msg = message(r.value, 'msg_approve_version_error', 'error');
|
|
1118
|
+
this.showError(msg.message, msg.title);
|
|
1131
1119
|
}
|
|
1132
1120
|
}
|
|
1133
1121
|
|
|
1134
1122
|
postReject(status: number|string, err?: any) {
|
|
1135
1123
|
this.setState({ disabled: true });
|
|
1136
1124
|
const r = this.resourceService;
|
|
1137
|
-
const st = this.status;
|
|
1138
|
-
if (status
|
|
1125
|
+
// const st = this.status;
|
|
1126
|
+
if (status > 0) {
|
|
1139
1127
|
this.showMessage(r.value('msg_reject_success'));
|
|
1140
|
-
} else if (status ===
|
|
1141
|
-
const msg = message(r.value, 'msg_approve_version_error', 'error');
|
|
1142
|
-
this.showError(msg.message, msg.title);
|
|
1143
|
-
} else if (status === st.not_found) {
|
|
1128
|
+
} else if (status === 0) {
|
|
1144
1129
|
this.handleNotFound();
|
|
1145
1130
|
} else {
|
|
1146
|
-
|
|
1131
|
+
const msg = message(r.value, 'msg_approve_version_error', 'error');
|
|
1132
|
+
this.showError(msg.message, msg.title);
|
|
1147
1133
|
}
|
|
1148
1134
|
}
|
|
1149
1135
|
|
|
@@ -1197,9 +1183,8 @@ export class DiffApprComponent<T, ID, P, S extends DiffState<T>> extends BaseDif
|
|
|
1197
1183
|
param: ResourceService|DiffParameter,
|
|
1198
1184
|
showMessage?: (msg: string, option?: string) => void,
|
|
1199
1185
|
showError?: (m: string, title?: string, detail?: string, callback?: () => void) => void,
|
|
1200
|
-
loading?: LoadingService
|
|
1201
|
-
|
|
1202
|
-
super(props, service.keys(), getResource(param), getMsgFunc(param, showMessage), getErrorFunc(param, showError), getLoadingFunc(param, loading), getDiffStatusFunc(param, status));
|
|
1186
|
+
loading?: LoadingService) {
|
|
1187
|
+
super(props, service.keys(), getResource(param), getMsgFunc(param, showMessage), getErrorFunc(param, showError), getLoadingFunc(param, loading));
|
|
1203
1188
|
this.approve = this.approve.bind(this);
|
|
1204
1189
|
this.reject = this.reject.bind(this);
|
|
1205
1190
|
this.formatFields = this.formatFields.bind(this);
|
package/src/core.ts
CHANGED
|
@@ -35,6 +35,7 @@ export interface SearchParameter {
|
|
|
35
35
|
loading?: LoadingService;
|
|
36
36
|
auto?: boolean;
|
|
37
37
|
}
|
|
38
|
+
/*
|
|
38
39
|
export interface EditStatusConfig {
|
|
39
40
|
duplicate_key: number | string;
|
|
40
41
|
not_found: number | string;
|
|
@@ -75,7 +76,7 @@ export function createDiffStatus(status?: DiffStatusConfig): DiffStatusConfig {
|
|
|
75
76
|
};
|
|
76
77
|
return s;
|
|
77
78
|
}
|
|
78
|
-
|
|
79
|
+
*/
|
|
79
80
|
export interface Filter {
|
|
80
81
|
q?: string;
|
|
81
82
|
page?: number;
|
|
@@ -116,7 +117,7 @@ export interface DiffParameter {
|
|
|
116
117
|
showMessage: (msg: string, option?: string) => void;
|
|
117
118
|
showError: (m: string, header?: string, detail?: string, callback?: () => void) => void;
|
|
118
119
|
loading?: LoadingService;
|
|
119
|
-
status?: DiffStatusConfig;
|
|
120
|
+
// status?: DiffStatusConfig;
|
|
120
121
|
}
|
|
121
122
|
export interface BaseDiffState {
|
|
122
123
|
disabled: boolean;
|
package/src/edit.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {Attribute, Attributes,
|
|
1
|
+
import {Attribute, Attributes, ErrorMessage, LoadingService, Locale, resource, ResourceService, UIService, ViewService} from './core';
|
|
2
2
|
|
|
3
3
|
export interface ResultInfo<T> {
|
|
4
4
|
status: number|string;
|
|
@@ -14,7 +14,7 @@ export interface EditParameter {
|
|
|
14
14
|
ui?: UIService;
|
|
15
15
|
getLocale?: (profile?: string) => Locale;
|
|
16
16
|
loading?: LoadingService;
|
|
17
|
-
status?: EditStatusConfig;
|
|
17
|
+
// status?: EditStatusConfig;
|
|
18
18
|
}
|
|
19
19
|
export interface GenericService<T, ID, R> extends ViewService<T, ID> {
|
|
20
20
|
patch?(obj: Partial<T>, ctx?: any): Promise<R>;
|
|
@@ -130,6 +130,7 @@ export function initPropertyNullInModel<T>(obj: T, m?: Attributes): T {
|
|
|
130
130
|
}
|
|
131
131
|
return obj;
|
|
132
132
|
}
|
|
133
|
+
/*
|
|
133
134
|
export function handleStatus(x: number|string, st: EditStatusConfig, gv: (k: string, p?: any) => string, se: (m: string, title?: string, detail?: string, callback?: () => void) => void): void {
|
|
134
135
|
const title = gv('error');
|
|
135
136
|
if (x === st.version_error) {
|
|
@@ -140,6 +141,7 @@ export function handleStatus(x: number|string, st: EditStatusConfig, gv: (k: str
|
|
|
140
141
|
se(gv('error_internal'), title);
|
|
141
142
|
}
|
|
142
143
|
}
|
|
144
|
+
*/
|
|
143
145
|
export function handleVersion<T>(obj: T, version?: string): void {
|
|
144
146
|
if (obj && version && version.length > 0) {
|
|
145
147
|
const v = (obj as any)[version];
|