@etsoo/appscript 1.2.74 → 1.2.77
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/__tests__/business/BusinessUtils.ts +9 -0
- package/lib/cjs/app/CoreApp.d.ts +36 -9
- package/lib/cjs/app/CoreApp.js +69 -18
- package/lib/cjs/business/BusinessUtils.d.ts +8 -19
- package/lib/cjs/business/BusinessUtils.js +34 -32
- package/lib/cjs/i18n/en-US.json +4 -0
- package/lib/cjs/i18n/zh-CN.json +4 -0
- package/lib/cjs/i18n/zh-HK.json +4 -0
- package/lib/mjs/app/CoreApp.d.ts +36 -9
- package/lib/mjs/app/CoreApp.js +69 -18
- package/lib/mjs/business/BusinessUtils.d.ts +8 -19
- package/lib/mjs/business/BusinessUtils.js +33 -31
- package/lib/mjs/i18n/en-US.json +4 -0
- package/lib/mjs/i18n/zh-CN.json +4 -0
- package/lib/mjs/i18n/zh-HK.json +4 -0
- package/package.json +8 -8
- package/src/app/CoreApp.ts +93 -25
- package/src/business/BusinessUtils.ts +40 -33
- package/src/i18n/en-US.json +4 -0
- package/src/i18n/zh-CN.json +4 -0
- package/src/i18n/zh-HK.json +4 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BusinessUtils } from '../../src/business/BusinessUtils';
|
|
2
|
+
|
|
3
|
+
test('Tests for BusinessUtils.formatAvatarTitle', () => {
|
|
4
|
+
// Assert
|
|
5
|
+
expect(BusinessUtils.formatAvatarTitle('Garry Xiao')).toBe('GX');
|
|
6
|
+
expect(BusinessUtils.formatAvatarTitle('Etsoo')).toBe('ME');
|
|
7
|
+
expect(BusinessUtils.formatAvatarTitle('Etsoo', 3, 'E')).toBe('E');
|
|
8
|
+
expect(BusinessUtils.formatAvatarTitle('Etsoo', 5)).toBe('ETSOO');
|
|
9
|
+
});
|
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -235,8 +235,9 @@ export interface ICoreApp<U extends IUser, S extends IAppSettings, N, C extends
|
|
|
235
235
|
* Format result text
|
|
236
236
|
* @param result Action result
|
|
237
237
|
* @param forceToLocal Force to local labels
|
|
238
|
+
* @returns Message
|
|
238
239
|
*/
|
|
239
|
-
formatResult(result: IActionResult, forceToLocal?: boolean):
|
|
240
|
+
formatResult(result: IActionResult, forceToLocal?: boolean): string;
|
|
240
241
|
/**
|
|
241
242
|
* Fresh countdown UI
|
|
242
243
|
* @param callback Callback
|
|
@@ -260,11 +261,6 @@ export interface ICoreApp<U extends IUser, S extends IAppSettings, N, C extends
|
|
|
260
261
|
* @returns Cached token
|
|
261
262
|
*/
|
|
262
263
|
getCacheToken(): string | undefined;
|
|
263
|
-
/**
|
|
264
|
-
* Get entity status label
|
|
265
|
-
* @param status Status value
|
|
266
|
-
*/
|
|
267
|
-
getEntityStatusLabel(status: number | null | undefined): string;
|
|
268
264
|
/**
|
|
269
265
|
* Get all regions
|
|
270
266
|
* @returns Regions
|
|
@@ -275,6 +271,16 @@ export interface ICoreApp<U extends IUser, S extends IAppSettings, N, C extends
|
|
|
275
271
|
* @param role Combination role value
|
|
276
272
|
*/
|
|
277
273
|
getRoles(role: number): IdLabelDto[];
|
|
274
|
+
/**
|
|
275
|
+
* Get status label
|
|
276
|
+
* @param status Status value
|
|
277
|
+
*/
|
|
278
|
+
getStatusLabel(status: number | null | undefined): string;
|
|
279
|
+
/**
|
|
280
|
+
* Get status list
|
|
281
|
+
* @returns list
|
|
282
|
+
*/
|
|
283
|
+
getStatusList(): IdLabelDto[];
|
|
278
284
|
/**
|
|
279
285
|
* Get refresh token from response headers
|
|
280
286
|
* @param rawResponse Raw response from API call
|
|
@@ -686,7 +692,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
686
692
|
* @param result Action result
|
|
687
693
|
* @param forceToLocal Force to local labels
|
|
688
694
|
*/
|
|
689
|
-
formatResult(result: IActionResult, forceToLocal?: boolean):
|
|
695
|
+
formatResult(result: IActionResult, forceToLocal?: boolean): string;
|
|
690
696
|
/**
|
|
691
697
|
* Get culture resource
|
|
692
698
|
* @param key key
|
|
@@ -705,6 +711,22 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
705
711
|
* @returns Cached token
|
|
706
712
|
*/
|
|
707
713
|
getCacheToken(): string | undefined;
|
|
714
|
+
/**
|
|
715
|
+
* Get enum item number id list
|
|
716
|
+
* @param em Enum
|
|
717
|
+
* @param prefix Label prefix
|
|
718
|
+
* @param filter Filter
|
|
719
|
+
* @returns List
|
|
720
|
+
*/
|
|
721
|
+
protected getEnumList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(em: E, prefix: string, filter?: (id: E[keyof E], key: keyof E & string) => E[keyof E] | undefined): IdLabelDto[];
|
|
722
|
+
/**
|
|
723
|
+
* Get enum item string id list
|
|
724
|
+
* @param em Enum
|
|
725
|
+
* @param prefix Label prefix
|
|
726
|
+
* @param filter Filter
|
|
727
|
+
* @returns List
|
|
728
|
+
*/
|
|
729
|
+
protected getEnumStrList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(em: E, prefix: string, filter?: (id: E[keyof E], key: keyof E & string) => E[keyof E] | undefined): IdLabelDto<string>[];
|
|
708
730
|
/**
|
|
709
731
|
* Get all regions
|
|
710
732
|
* @returns Regions
|
|
@@ -716,10 +738,15 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
716
738
|
*/
|
|
717
739
|
getRoles(role: number): IdLabelDto<number>[];
|
|
718
740
|
/**
|
|
719
|
-
* Get
|
|
741
|
+
* Get status list
|
|
742
|
+
* @returns list
|
|
743
|
+
*/
|
|
744
|
+
getStatusList(): IdLabelDto<number>[];
|
|
745
|
+
/**
|
|
746
|
+
* Get status label
|
|
720
747
|
* @param status Status value
|
|
721
748
|
*/
|
|
722
|
-
|
|
749
|
+
getStatusLabel(status: number | null | undefined): string;
|
|
723
750
|
/**
|
|
724
751
|
* Get refresh token from response headers
|
|
725
752
|
* @param rawResponse Raw response from API call
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -9,6 +9,7 @@ const AddressRegion_1 = require("../address/AddressRegion");
|
|
|
9
9
|
const AddressUtils_1 = require("../address/AddressUtils");
|
|
10
10
|
const BridgeUtils_1 = require("../bridges/BridgeUtils");
|
|
11
11
|
const BusinessUtils_1 = require("../business/BusinessUtils");
|
|
12
|
+
const EntityStatus_1 = require("../business/EntityStatus");
|
|
12
13
|
const ActionResultError_1 = require("../result/ActionResultError");
|
|
13
14
|
const UserRole_1 = require("./UserRole");
|
|
14
15
|
/**
|
|
@@ -420,8 +421,7 @@ class CoreApp {
|
|
|
420
421
|
* @param callback Callback
|
|
421
422
|
*/
|
|
422
423
|
alertResult(result, callback) {
|
|
423
|
-
this.formatResult(result);
|
|
424
|
-
this.notifier.alert(ActionResultError_1.ActionResultError.format(result), callback);
|
|
424
|
+
this.notifier.alert(this.formatResult(result), callback);
|
|
425
425
|
}
|
|
426
426
|
/**
|
|
427
427
|
* Authorize
|
|
@@ -796,6 +796,7 @@ class CoreApp {
|
|
|
796
796
|
if (fieldLabel)
|
|
797
797
|
result.title = result.title.format(fieldLabel);
|
|
798
798
|
}
|
|
799
|
+
return ActionResultError_1.ActionResultError.format(result);
|
|
799
800
|
}
|
|
800
801
|
/**
|
|
801
802
|
* Get culture resource
|
|
@@ -829,6 +830,56 @@ class CoreApp {
|
|
|
829
830
|
return this.cachedRefreshToken;
|
|
830
831
|
return this.storage.getData(this.fields.headerToken);
|
|
831
832
|
}
|
|
833
|
+
/**
|
|
834
|
+
* Get enum item number id list
|
|
835
|
+
* @param em Enum
|
|
836
|
+
* @param prefix Label prefix
|
|
837
|
+
* @param filter Filter
|
|
838
|
+
* @returns List
|
|
839
|
+
*/
|
|
840
|
+
getEnumList(em, prefix, filter) {
|
|
841
|
+
var _a;
|
|
842
|
+
const list = [];
|
|
843
|
+
const keys = shared_1.DataTypes.getEnumKeys(em);
|
|
844
|
+
for (const key of keys) {
|
|
845
|
+
let id = em[key];
|
|
846
|
+
if (filter) {
|
|
847
|
+
const fid = filter(id, key);
|
|
848
|
+
if (fid == null)
|
|
849
|
+
continue;
|
|
850
|
+
id = fid;
|
|
851
|
+
}
|
|
852
|
+
if (typeof id !== 'number')
|
|
853
|
+
continue;
|
|
854
|
+
var label = (_a = this.get(prefix + key)) !== null && _a !== void 0 ? _a : key;
|
|
855
|
+
list.push({ id, label });
|
|
856
|
+
}
|
|
857
|
+
return list;
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* Get enum item string id list
|
|
861
|
+
* @param em Enum
|
|
862
|
+
* @param prefix Label prefix
|
|
863
|
+
* @param filter Filter
|
|
864
|
+
* @returns List
|
|
865
|
+
*/
|
|
866
|
+
getEnumStrList(em, prefix, filter) {
|
|
867
|
+
var _a;
|
|
868
|
+
const list = [];
|
|
869
|
+
const keys = shared_1.DataTypes.getEnumKeys(em);
|
|
870
|
+
for (const key of keys) {
|
|
871
|
+
let id = em[key];
|
|
872
|
+
if (filter) {
|
|
873
|
+
const fid = filter(id, key);
|
|
874
|
+
if (fid == null)
|
|
875
|
+
continue;
|
|
876
|
+
id = fid;
|
|
877
|
+
}
|
|
878
|
+
var label = (_a = this.get(prefix + key)) !== null && _a !== void 0 ? _a : key;
|
|
879
|
+
list.push({ id: id.toString(), label });
|
|
880
|
+
}
|
|
881
|
+
return list;
|
|
882
|
+
}
|
|
832
883
|
/**
|
|
833
884
|
* Get all regions
|
|
834
885
|
* @returns Regions
|
|
@@ -843,28 +894,28 @@ class CoreApp {
|
|
|
843
894
|
* @param role Combination role value
|
|
844
895
|
*/
|
|
845
896
|
getRoles(role) {
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
var id = UserRole_1.UserRole[key];
|
|
851
|
-
if ((id & role) > 0) {
|
|
852
|
-
roles.push({
|
|
853
|
-
id,
|
|
854
|
-
label: (_a = this.get(`role${key}`)) !== null && _a !== void 0 ? _a : key
|
|
855
|
-
});
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
return roles;
|
|
897
|
+
return this.getEnumList(UserRole_1.UserRole, 'role', (id, _key) => {
|
|
898
|
+
if ((id & role) > 0)
|
|
899
|
+
return id;
|
|
900
|
+
});
|
|
859
901
|
}
|
|
860
902
|
/**
|
|
861
|
-
* Get
|
|
903
|
+
* Get status list
|
|
904
|
+
* @returns list
|
|
905
|
+
*/
|
|
906
|
+
getStatusList() {
|
|
907
|
+
return this.getEnumList(EntityStatus_1.EntityStatus, 'status');
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Get status label
|
|
862
911
|
* @param status Status value
|
|
863
912
|
*/
|
|
864
|
-
|
|
913
|
+
getStatusLabel(status) {
|
|
914
|
+
var _a;
|
|
865
915
|
if (status == null)
|
|
866
916
|
return '';
|
|
867
|
-
|
|
917
|
+
const key = EntityStatus_1.EntityStatus[status];
|
|
918
|
+
return (_a = this.get('status' + key)) !== null && _a !== void 0 ? _a : key;
|
|
868
919
|
}
|
|
869
920
|
/**
|
|
870
921
|
* Get refresh token from response headers
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { DataTypes } from '@etsoo/shared';
|
|
2
2
|
import { IdLabelDto } from '../dto/IdLabelDto';
|
|
3
3
|
import { ICultureGet } from '../state/Culture';
|
|
4
|
-
import { EntityStatus } from './EntityStatus';
|
|
5
4
|
import { ProductUnit } from './ProductUnit';
|
|
6
5
|
/**
|
|
7
6
|
* Business utils
|
|
8
7
|
*/
|
|
9
8
|
export declare namespace BusinessUtils {
|
|
9
|
+
/**
|
|
10
|
+
* Format avatar title
|
|
11
|
+
* @param title Title
|
|
12
|
+
* @param maxChars Max characters
|
|
13
|
+
* @param defaultTitle Default title
|
|
14
|
+
* @returns Result
|
|
15
|
+
*/
|
|
16
|
+
function formatAvatarTitle(title?: string, maxChars?: number, defaultTitle?: string): string;
|
|
10
17
|
/**
|
|
11
18
|
* Get currency collection
|
|
12
19
|
* @param currencyNames Names like CNY, USD
|
|
@@ -14,24 +21,6 @@ export declare namespace BusinessUtils {
|
|
|
14
21
|
* @returns Collection
|
|
15
22
|
*/
|
|
16
23
|
function getCurrencies(currencyNames: string[], func: ICultureGet): IdLabelDto<string>[];
|
|
17
|
-
/**
|
|
18
|
-
* Get entity status's label
|
|
19
|
-
* Please define the label with key 'statusNormal' for Normal status
|
|
20
|
-
* @param unit Unit
|
|
21
|
-
* @param func Label delegate
|
|
22
|
-
* @returns Label
|
|
23
|
-
*/
|
|
24
|
-
function getEntityStatusLabel(status: EntityStatus, func: ICultureGet): string;
|
|
25
|
-
/**
|
|
26
|
-
* Get entity status collection
|
|
27
|
-
* @param unit Unit
|
|
28
|
-
* @param func Label delegate
|
|
29
|
-
* @returns Label
|
|
30
|
-
*/
|
|
31
|
-
function getEntityStatus(func: ICultureGet): {
|
|
32
|
-
id: EntityStatus;
|
|
33
|
-
label: string;
|
|
34
|
-
}[];
|
|
35
24
|
/**
|
|
36
25
|
* Get 12-month items
|
|
37
26
|
* @param monthLabels Month labels
|
|
@@ -2,14 +2,45 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BusinessUtils = void 0;
|
|
4
4
|
const shared_1 = require("@etsoo/shared");
|
|
5
|
-
const __1 = require("..");
|
|
6
|
-
const EntityStatus_1 = require("./EntityStatus");
|
|
7
5
|
const ProductUnit_1 = require("./ProductUnit");
|
|
6
|
+
const RepeatOption_1 = require("./RepeatOption");
|
|
8
7
|
/**
|
|
9
8
|
* Business utils
|
|
10
9
|
*/
|
|
11
10
|
var BusinessUtils;
|
|
12
11
|
(function (BusinessUtils) {
|
|
12
|
+
/**
|
|
13
|
+
* Format avatar title
|
|
14
|
+
* @param title Title
|
|
15
|
+
* @param maxChars Max characters
|
|
16
|
+
* @param defaultTitle Default title
|
|
17
|
+
* @returns Result
|
|
18
|
+
*/
|
|
19
|
+
function formatAvatarTitle(title, maxChars = 3, defaultTitle = 'ME') {
|
|
20
|
+
// Just return for empty cases
|
|
21
|
+
if (title == null || title === '')
|
|
22
|
+
return defaultTitle;
|
|
23
|
+
// split with words
|
|
24
|
+
const items = title.trim().split(/\s+/g);
|
|
25
|
+
if (items.length === 1) {
|
|
26
|
+
// 2-3 Chinese names
|
|
27
|
+
const titleLen = title.length;
|
|
28
|
+
if (titleLen <= maxChars)
|
|
29
|
+
return title.toUpperCase();
|
|
30
|
+
// Return default for simplicity
|
|
31
|
+
return defaultTitle;
|
|
32
|
+
}
|
|
33
|
+
// First letter of each item
|
|
34
|
+
var firstLetters = items
|
|
35
|
+
.map((item) => item[0])
|
|
36
|
+
.join('')
|
|
37
|
+
.toUpperCase();
|
|
38
|
+
const flen = firstLetters.length;
|
|
39
|
+
if (flen <= maxChars)
|
|
40
|
+
return firstLetters;
|
|
41
|
+
return defaultTitle;
|
|
42
|
+
}
|
|
43
|
+
BusinessUtils.formatAvatarTitle = formatAvatarTitle;
|
|
13
44
|
/**
|
|
14
45
|
* Get currency collection
|
|
15
46
|
* @param currencyNames Names like CNY, USD
|
|
@@ -26,35 +57,6 @@ var BusinessUtils;
|
|
|
26
57
|
});
|
|
27
58
|
}
|
|
28
59
|
BusinessUtils.getCurrencies = getCurrencies;
|
|
29
|
-
/**
|
|
30
|
-
* Get entity status's label
|
|
31
|
-
* Please define the label with key 'statusNormal' for Normal status
|
|
32
|
-
* @param unit Unit
|
|
33
|
-
* @param func Label delegate
|
|
34
|
-
* @returns Label
|
|
35
|
-
*/
|
|
36
|
-
function getEntityStatusLabel(status, func) {
|
|
37
|
-
var _a;
|
|
38
|
-
const key = EntityStatus_1.EntityStatus[status];
|
|
39
|
-
return (_a = func('status' + key)) !== null && _a !== void 0 ? _a : key;
|
|
40
|
-
}
|
|
41
|
-
BusinessUtils.getEntityStatusLabel = getEntityStatusLabel;
|
|
42
|
-
/**
|
|
43
|
-
* Get entity status collection
|
|
44
|
-
* @param unit Unit
|
|
45
|
-
* @param func Label delegate
|
|
46
|
-
* @returns Label
|
|
47
|
-
*/
|
|
48
|
-
function getEntityStatus(func) {
|
|
49
|
-
return shared_1.DataTypes.getEnumKeys(EntityStatus_1.EntityStatus).map((key) => {
|
|
50
|
-
const id = shared_1.DataTypes.getEnumByKey(EntityStatus_1.EntityStatus, key);
|
|
51
|
-
return {
|
|
52
|
-
id,
|
|
53
|
-
label: getEntityStatusLabel(id, func)
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
BusinessUtils.getEntityStatus = getEntityStatus;
|
|
58
60
|
/**
|
|
59
61
|
* Get 12-month items
|
|
60
62
|
* @param monthLabels Month labels
|
|
@@ -120,7 +122,7 @@ var BusinessUtils;
|
|
|
120
122
|
* @returns Units
|
|
121
123
|
*/
|
|
122
124
|
function getRepeatOptions(func, options, isJoined = true) {
|
|
123
|
-
options !== null && options !== void 0 ? options : (options = shared_1.DataTypes.getEnumKeys(
|
|
125
|
+
options !== null && options !== void 0 ? options : (options = shared_1.DataTypes.getEnumKeys(RepeatOption_1.RepeatOption));
|
|
124
126
|
isJoined !== null && isJoined !== void 0 ? isJoined : (isJoined = true);
|
|
125
127
|
return getUnits(func, options, isJoined);
|
|
126
128
|
}
|
package/lib/cjs/i18n/en-US.json
CHANGED
|
@@ -43,15 +43,18 @@
|
|
|
43
43
|
"enabled": "Enabled",
|
|
44
44
|
"entityStatus": "Status",
|
|
45
45
|
"environmentChanged": "The operating environment has changed, please log in again",
|
|
46
|
+
"error": "Error",
|
|
46
47
|
"etsoo": "ETSOO",
|
|
47
48
|
"expiry": "Expiry",
|
|
48
49
|
"failed": "Operation failed",
|
|
49
50
|
"field": "Field",
|
|
51
|
+
"help": "Help",
|
|
50
52
|
"id": "Number#",
|
|
51
53
|
"info": "Info",
|
|
52
54
|
"itemExists": "'{0}' already exists",
|
|
53
55
|
"loading": "Loading...",
|
|
54
56
|
"login": "Login",
|
|
57
|
+
"me": "ME",
|
|
55
58
|
"menuHome": "Home",
|
|
56
59
|
"message": "Message",
|
|
57
60
|
"mobile": "Mobile number",
|
|
@@ -139,6 +142,7 @@
|
|
|
139
142
|
"taxUSEIN": "Employer identification number",
|
|
140
143
|
"timeDifferenceInvalid": "The time difference between the device and the server is {0}, which exceeds the limit of {1} seconds. Please adjust the device time. If it is abnormal, please inform the administrator",
|
|
141
144
|
"tokenExpiry": "Your session is about to expire. Click the Cancel button to continue",
|
|
145
|
+
"type": "Type",
|
|
142
146
|
"yes": "Yes",
|
|
143
147
|
"unknownError": "Unknown Error",
|
|
144
148
|
"unitJoin": "per {0}",
|
package/lib/cjs/i18n/zh-CN.json
CHANGED
|
@@ -43,15 +43,18 @@
|
|
|
43
43
|
"enabled": "已启用",
|
|
44
44
|
"entityStatus": "状态",
|
|
45
45
|
"environmentChanged": "运行环境已改变,请重新登录",
|
|
46
|
+
"error": "错误",
|
|
46
47
|
"etsoo": "亿速思维",
|
|
47
48
|
"expiry": "到期时间",
|
|
48
49
|
"failed": "操作失败",
|
|
49
50
|
"field": "字段",
|
|
51
|
+
"help": "帮助",
|
|
50
52
|
"id": "编号",
|
|
51
53
|
"info": "信息",
|
|
52
54
|
"itemExists": "'{0}'已经存在",
|
|
53
55
|
"loading": "正在加载...",
|
|
54
56
|
"login": "登录",
|
|
57
|
+
"me": "我",
|
|
55
58
|
"menuHome": "首页",
|
|
56
59
|
"message": "留言",
|
|
57
60
|
"mobile": "手机号码",
|
|
@@ -139,6 +142,7 @@
|
|
|
139
142
|
"taxUSEIN": "雇主识别号码(EIN)",
|
|
140
143
|
"timeDifferenceInvalid": "设备时间和服务器时间差为{0},超过{1}秒的限制,请调整设备时间,如果异常请告知管理员",
|
|
141
144
|
"tokenExpiry": "您的会话即将过期。点击 取消 按钮继续使用",
|
|
145
|
+
"type": "类型",
|
|
142
146
|
"yes": "是",
|
|
143
147
|
"unknownError": "未知错误",
|
|
144
148
|
"unitJoin": "每{0}",
|
package/lib/cjs/i18n/zh-HK.json
CHANGED
|
@@ -43,15 +43,18 @@
|
|
|
43
43
|
"enabled": "已啟用",
|
|
44
44
|
"entityStatus": "狀態",
|
|
45
45
|
"environmentChanged": "運行環境已改變,請重新登錄",
|
|
46
|
+
"error": "錯誤",
|
|
46
47
|
"etsoo": "億速思維",
|
|
47
48
|
"expiry": "到期時間",
|
|
48
49
|
"failed": "操作失敗",
|
|
49
50
|
"field": "字段",
|
|
51
|
+
"help": "幫助",
|
|
50
52
|
"id": "編號",
|
|
51
53
|
"info": "信息",
|
|
52
54
|
"itemExists": "'{0}'已经存在",
|
|
53
55
|
"loading": "正在加載...",
|
|
54
56
|
"login": "登錄",
|
|
57
|
+
"me": "我",
|
|
55
58
|
"menuHome": "首頁",
|
|
56
59
|
"message": "留言",
|
|
57
60
|
"mobilePhone": "手機號碼",
|
|
@@ -139,6 +142,7 @@
|
|
|
139
142
|
"taxUSEIN": "雇主識別號碼(EIN)",
|
|
140
143
|
"timeDifferenceInvalid": "設備時間和服務器時間差為{0},超過{1}秒的限制,請調整設備時間,如果異常請告知管理員",
|
|
141
144
|
"tokenExpiry": "您的會話即將過期。點擊 取消 按鈕繼續使用",
|
|
145
|
+
"type": "類型",
|
|
142
146
|
"yes": "是",
|
|
143
147
|
"unknownError": "未知錯誤",
|
|
144
148
|
"unitJoin": "每{0}",
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -235,8 +235,9 @@ export interface ICoreApp<U extends IUser, S extends IAppSettings, N, C extends
|
|
|
235
235
|
* Format result text
|
|
236
236
|
* @param result Action result
|
|
237
237
|
* @param forceToLocal Force to local labels
|
|
238
|
+
* @returns Message
|
|
238
239
|
*/
|
|
239
|
-
formatResult(result: IActionResult, forceToLocal?: boolean):
|
|
240
|
+
formatResult(result: IActionResult, forceToLocal?: boolean): string;
|
|
240
241
|
/**
|
|
241
242
|
* Fresh countdown UI
|
|
242
243
|
* @param callback Callback
|
|
@@ -260,11 +261,6 @@ export interface ICoreApp<U extends IUser, S extends IAppSettings, N, C extends
|
|
|
260
261
|
* @returns Cached token
|
|
261
262
|
*/
|
|
262
263
|
getCacheToken(): string | undefined;
|
|
263
|
-
/**
|
|
264
|
-
* Get entity status label
|
|
265
|
-
* @param status Status value
|
|
266
|
-
*/
|
|
267
|
-
getEntityStatusLabel(status: number | null | undefined): string;
|
|
268
264
|
/**
|
|
269
265
|
* Get all regions
|
|
270
266
|
* @returns Regions
|
|
@@ -275,6 +271,16 @@ export interface ICoreApp<U extends IUser, S extends IAppSettings, N, C extends
|
|
|
275
271
|
* @param role Combination role value
|
|
276
272
|
*/
|
|
277
273
|
getRoles(role: number): IdLabelDto[];
|
|
274
|
+
/**
|
|
275
|
+
* Get status label
|
|
276
|
+
* @param status Status value
|
|
277
|
+
*/
|
|
278
|
+
getStatusLabel(status: number | null | undefined): string;
|
|
279
|
+
/**
|
|
280
|
+
* Get status list
|
|
281
|
+
* @returns list
|
|
282
|
+
*/
|
|
283
|
+
getStatusList(): IdLabelDto[];
|
|
278
284
|
/**
|
|
279
285
|
* Get refresh token from response headers
|
|
280
286
|
* @param rawResponse Raw response from API call
|
|
@@ -686,7 +692,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
686
692
|
* @param result Action result
|
|
687
693
|
* @param forceToLocal Force to local labels
|
|
688
694
|
*/
|
|
689
|
-
formatResult(result: IActionResult, forceToLocal?: boolean):
|
|
695
|
+
formatResult(result: IActionResult, forceToLocal?: boolean): string;
|
|
690
696
|
/**
|
|
691
697
|
* Get culture resource
|
|
692
698
|
* @param key key
|
|
@@ -705,6 +711,22 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
705
711
|
* @returns Cached token
|
|
706
712
|
*/
|
|
707
713
|
getCacheToken(): string | undefined;
|
|
714
|
+
/**
|
|
715
|
+
* Get enum item number id list
|
|
716
|
+
* @param em Enum
|
|
717
|
+
* @param prefix Label prefix
|
|
718
|
+
* @param filter Filter
|
|
719
|
+
* @returns List
|
|
720
|
+
*/
|
|
721
|
+
protected getEnumList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(em: E, prefix: string, filter?: (id: E[keyof E], key: keyof E & string) => E[keyof E] | undefined): IdLabelDto[];
|
|
722
|
+
/**
|
|
723
|
+
* Get enum item string id list
|
|
724
|
+
* @param em Enum
|
|
725
|
+
* @param prefix Label prefix
|
|
726
|
+
* @param filter Filter
|
|
727
|
+
* @returns List
|
|
728
|
+
*/
|
|
729
|
+
protected getEnumStrList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(em: E, prefix: string, filter?: (id: E[keyof E], key: keyof E & string) => E[keyof E] | undefined): IdLabelDto<string>[];
|
|
708
730
|
/**
|
|
709
731
|
* Get all regions
|
|
710
732
|
* @returns Regions
|
|
@@ -716,10 +738,15 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
716
738
|
*/
|
|
717
739
|
getRoles(role: number): IdLabelDto<number>[];
|
|
718
740
|
/**
|
|
719
|
-
* Get
|
|
741
|
+
* Get status list
|
|
742
|
+
* @returns list
|
|
743
|
+
*/
|
|
744
|
+
getStatusList(): IdLabelDto<number>[];
|
|
745
|
+
/**
|
|
746
|
+
* Get status label
|
|
720
747
|
* @param status Status value
|
|
721
748
|
*/
|
|
722
|
-
|
|
749
|
+
getStatusLabel(status: number | null | undefined): string;
|
|
723
750
|
/**
|
|
724
751
|
* Get refresh token from response headers
|
|
725
752
|
* @param rawResponse Raw response from API call
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -6,6 +6,7 @@ import { AddressRegion } from '../address/AddressRegion';
|
|
|
6
6
|
import { AddressUtils } from '../address/AddressUtils';
|
|
7
7
|
import { BridgeUtils } from '../bridges/BridgeUtils';
|
|
8
8
|
import { BusinessUtils } from '../business/BusinessUtils';
|
|
9
|
+
import { EntityStatus } from '../business/EntityStatus';
|
|
9
10
|
import { ActionResultError } from '../result/ActionResultError';
|
|
10
11
|
import { UserRole } from './UserRole';
|
|
11
12
|
/**
|
|
@@ -417,8 +418,7 @@ export class CoreApp {
|
|
|
417
418
|
* @param callback Callback
|
|
418
419
|
*/
|
|
419
420
|
alertResult(result, callback) {
|
|
420
|
-
this.formatResult(result);
|
|
421
|
-
this.notifier.alert(ActionResultError.format(result), callback);
|
|
421
|
+
this.notifier.alert(this.formatResult(result), callback);
|
|
422
422
|
}
|
|
423
423
|
/**
|
|
424
424
|
* Authorize
|
|
@@ -793,6 +793,7 @@ export class CoreApp {
|
|
|
793
793
|
if (fieldLabel)
|
|
794
794
|
result.title = result.title.format(fieldLabel);
|
|
795
795
|
}
|
|
796
|
+
return ActionResultError.format(result);
|
|
796
797
|
}
|
|
797
798
|
/**
|
|
798
799
|
* Get culture resource
|
|
@@ -826,6 +827,56 @@ export class CoreApp {
|
|
|
826
827
|
return this.cachedRefreshToken;
|
|
827
828
|
return this.storage.getData(this.fields.headerToken);
|
|
828
829
|
}
|
|
830
|
+
/**
|
|
831
|
+
* Get enum item number id list
|
|
832
|
+
* @param em Enum
|
|
833
|
+
* @param prefix Label prefix
|
|
834
|
+
* @param filter Filter
|
|
835
|
+
* @returns List
|
|
836
|
+
*/
|
|
837
|
+
getEnumList(em, prefix, filter) {
|
|
838
|
+
var _a;
|
|
839
|
+
const list = [];
|
|
840
|
+
const keys = DataTypes.getEnumKeys(em);
|
|
841
|
+
for (const key of keys) {
|
|
842
|
+
let id = em[key];
|
|
843
|
+
if (filter) {
|
|
844
|
+
const fid = filter(id, key);
|
|
845
|
+
if (fid == null)
|
|
846
|
+
continue;
|
|
847
|
+
id = fid;
|
|
848
|
+
}
|
|
849
|
+
if (typeof id !== 'number')
|
|
850
|
+
continue;
|
|
851
|
+
var label = (_a = this.get(prefix + key)) !== null && _a !== void 0 ? _a : key;
|
|
852
|
+
list.push({ id, label });
|
|
853
|
+
}
|
|
854
|
+
return list;
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Get enum item string id list
|
|
858
|
+
* @param em Enum
|
|
859
|
+
* @param prefix Label prefix
|
|
860
|
+
* @param filter Filter
|
|
861
|
+
* @returns List
|
|
862
|
+
*/
|
|
863
|
+
getEnumStrList(em, prefix, filter) {
|
|
864
|
+
var _a;
|
|
865
|
+
const list = [];
|
|
866
|
+
const keys = DataTypes.getEnumKeys(em);
|
|
867
|
+
for (const key of keys) {
|
|
868
|
+
let id = em[key];
|
|
869
|
+
if (filter) {
|
|
870
|
+
const fid = filter(id, key);
|
|
871
|
+
if (fid == null)
|
|
872
|
+
continue;
|
|
873
|
+
id = fid;
|
|
874
|
+
}
|
|
875
|
+
var label = (_a = this.get(prefix + key)) !== null && _a !== void 0 ? _a : key;
|
|
876
|
+
list.push({ id: id.toString(), label });
|
|
877
|
+
}
|
|
878
|
+
return list;
|
|
879
|
+
}
|
|
829
880
|
/**
|
|
830
881
|
* Get all regions
|
|
831
882
|
* @returns Regions
|
|
@@ -840,28 +891,28 @@ export class CoreApp {
|
|
|
840
891
|
* @param role Combination role value
|
|
841
892
|
*/
|
|
842
893
|
getRoles(role) {
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
var id = UserRole[key];
|
|
848
|
-
if ((id & role) > 0) {
|
|
849
|
-
roles.push({
|
|
850
|
-
id,
|
|
851
|
-
label: (_a = this.get(`role${key}`)) !== null && _a !== void 0 ? _a : key
|
|
852
|
-
});
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
return roles;
|
|
894
|
+
return this.getEnumList(UserRole, 'role', (id, _key) => {
|
|
895
|
+
if ((id & role) > 0)
|
|
896
|
+
return id;
|
|
897
|
+
});
|
|
856
898
|
}
|
|
857
899
|
/**
|
|
858
|
-
* Get
|
|
900
|
+
* Get status list
|
|
901
|
+
* @returns list
|
|
902
|
+
*/
|
|
903
|
+
getStatusList() {
|
|
904
|
+
return this.getEnumList(EntityStatus, 'status');
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* Get status label
|
|
859
908
|
* @param status Status value
|
|
860
909
|
*/
|
|
861
|
-
|
|
910
|
+
getStatusLabel(status) {
|
|
911
|
+
var _a;
|
|
862
912
|
if (status == null)
|
|
863
913
|
return '';
|
|
864
|
-
|
|
914
|
+
const key = EntityStatus[status];
|
|
915
|
+
return (_a = this.get('status' + key)) !== null && _a !== void 0 ? _a : key;
|
|
865
916
|
}
|
|
866
917
|
/**
|
|
867
918
|
* Get refresh token from response headers
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { DataTypes } from '@etsoo/shared';
|
|
2
2
|
import { IdLabelDto } from '../dto/IdLabelDto';
|
|
3
3
|
import { ICultureGet } from '../state/Culture';
|
|
4
|
-
import { EntityStatus } from './EntityStatus';
|
|
5
4
|
import { ProductUnit } from './ProductUnit';
|
|
6
5
|
/**
|
|
7
6
|
* Business utils
|
|
8
7
|
*/
|
|
9
8
|
export declare namespace BusinessUtils {
|
|
9
|
+
/**
|
|
10
|
+
* Format avatar title
|
|
11
|
+
* @param title Title
|
|
12
|
+
* @param maxChars Max characters
|
|
13
|
+
* @param defaultTitle Default title
|
|
14
|
+
* @returns Result
|
|
15
|
+
*/
|
|
16
|
+
function formatAvatarTitle(title?: string, maxChars?: number, defaultTitle?: string): string;
|
|
10
17
|
/**
|
|
11
18
|
* Get currency collection
|
|
12
19
|
* @param currencyNames Names like CNY, USD
|
|
@@ -14,24 +21,6 @@ export declare namespace BusinessUtils {
|
|
|
14
21
|
* @returns Collection
|
|
15
22
|
*/
|
|
16
23
|
function getCurrencies(currencyNames: string[], func: ICultureGet): IdLabelDto<string>[];
|
|
17
|
-
/**
|
|
18
|
-
* Get entity status's label
|
|
19
|
-
* Please define the label with key 'statusNormal' for Normal status
|
|
20
|
-
* @param unit Unit
|
|
21
|
-
* @param func Label delegate
|
|
22
|
-
* @returns Label
|
|
23
|
-
*/
|
|
24
|
-
function getEntityStatusLabel(status: EntityStatus, func: ICultureGet): string;
|
|
25
|
-
/**
|
|
26
|
-
* Get entity status collection
|
|
27
|
-
* @param unit Unit
|
|
28
|
-
* @param func Label delegate
|
|
29
|
-
* @returns Label
|
|
30
|
-
*/
|
|
31
|
-
function getEntityStatus(func: ICultureGet): {
|
|
32
|
-
id: EntityStatus;
|
|
33
|
-
label: string;
|
|
34
|
-
}[];
|
|
35
24
|
/**
|
|
36
25
|
* Get 12-month items
|
|
37
26
|
* @param monthLabels Month labels
|
|
@@ -1,12 +1,43 @@
|
|
|
1
1
|
import { DataTypes } from '@etsoo/shared';
|
|
2
|
-
import { RepeatOption } from '..';
|
|
3
|
-
import { EntityStatus } from './EntityStatus';
|
|
4
2
|
import { ProductUnit } from './ProductUnit';
|
|
3
|
+
import { RepeatOption } from './RepeatOption';
|
|
5
4
|
/**
|
|
6
5
|
* Business utils
|
|
7
6
|
*/
|
|
8
7
|
export var BusinessUtils;
|
|
9
8
|
(function (BusinessUtils) {
|
|
9
|
+
/**
|
|
10
|
+
* Format avatar title
|
|
11
|
+
* @param title Title
|
|
12
|
+
* @param maxChars Max characters
|
|
13
|
+
* @param defaultTitle Default title
|
|
14
|
+
* @returns Result
|
|
15
|
+
*/
|
|
16
|
+
function formatAvatarTitle(title, maxChars = 3, defaultTitle = 'ME') {
|
|
17
|
+
// Just return for empty cases
|
|
18
|
+
if (title == null || title === '')
|
|
19
|
+
return defaultTitle;
|
|
20
|
+
// split with words
|
|
21
|
+
const items = title.trim().split(/\s+/g);
|
|
22
|
+
if (items.length === 1) {
|
|
23
|
+
// 2-3 Chinese names
|
|
24
|
+
const titleLen = title.length;
|
|
25
|
+
if (titleLen <= maxChars)
|
|
26
|
+
return title.toUpperCase();
|
|
27
|
+
// Return default for simplicity
|
|
28
|
+
return defaultTitle;
|
|
29
|
+
}
|
|
30
|
+
// First letter of each item
|
|
31
|
+
var firstLetters = items
|
|
32
|
+
.map((item) => item[0])
|
|
33
|
+
.join('')
|
|
34
|
+
.toUpperCase();
|
|
35
|
+
const flen = firstLetters.length;
|
|
36
|
+
if (flen <= maxChars)
|
|
37
|
+
return firstLetters;
|
|
38
|
+
return defaultTitle;
|
|
39
|
+
}
|
|
40
|
+
BusinessUtils.formatAvatarTitle = formatAvatarTitle;
|
|
10
41
|
/**
|
|
11
42
|
* Get currency collection
|
|
12
43
|
* @param currencyNames Names like CNY, USD
|
|
@@ -23,35 +54,6 @@ export var BusinessUtils;
|
|
|
23
54
|
});
|
|
24
55
|
}
|
|
25
56
|
BusinessUtils.getCurrencies = getCurrencies;
|
|
26
|
-
/**
|
|
27
|
-
* Get entity status's label
|
|
28
|
-
* Please define the label with key 'statusNormal' for Normal status
|
|
29
|
-
* @param unit Unit
|
|
30
|
-
* @param func Label delegate
|
|
31
|
-
* @returns Label
|
|
32
|
-
*/
|
|
33
|
-
function getEntityStatusLabel(status, func) {
|
|
34
|
-
var _a;
|
|
35
|
-
const key = EntityStatus[status];
|
|
36
|
-
return (_a = func('status' + key)) !== null && _a !== void 0 ? _a : key;
|
|
37
|
-
}
|
|
38
|
-
BusinessUtils.getEntityStatusLabel = getEntityStatusLabel;
|
|
39
|
-
/**
|
|
40
|
-
* Get entity status collection
|
|
41
|
-
* @param unit Unit
|
|
42
|
-
* @param func Label delegate
|
|
43
|
-
* @returns Label
|
|
44
|
-
*/
|
|
45
|
-
function getEntityStatus(func) {
|
|
46
|
-
return DataTypes.getEnumKeys(EntityStatus).map((key) => {
|
|
47
|
-
const id = DataTypes.getEnumByKey(EntityStatus, key);
|
|
48
|
-
return {
|
|
49
|
-
id,
|
|
50
|
-
label: getEntityStatusLabel(id, func)
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
BusinessUtils.getEntityStatus = getEntityStatus;
|
|
55
57
|
/**
|
|
56
58
|
* Get 12-month items
|
|
57
59
|
* @param monthLabels Month labels
|
package/lib/mjs/i18n/en-US.json
CHANGED
|
@@ -43,15 +43,18 @@
|
|
|
43
43
|
"enabled": "Enabled",
|
|
44
44
|
"entityStatus": "Status",
|
|
45
45
|
"environmentChanged": "The operating environment has changed, please log in again",
|
|
46
|
+
"error": "Error",
|
|
46
47
|
"etsoo": "ETSOO",
|
|
47
48
|
"expiry": "Expiry",
|
|
48
49
|
"failed": "Operation failed",
|
|
49
50
|
"field": "Field",
|
|
51
|
+
"help": "Help",
|
|
50
52
|
"id": "Number#",
|
|
51
53
|
"info": "Info",
|
|
52
54
|
"itemExists": "'{0}' already exists",
|
|
53
55
|
"loading": "Loading...",
|
|
54
56
|
"login": "Login",
|
|
57
|
+
"me": "ME",
|
|
55
58
|
"menuHome": "Home",
|
|
56
59
|
"message": "Message",
|
|
57
60
|
"mobile": "Mobile number",
|
|
@@ -139,6 +142,7 @@
|
|
|
139
142
|
"taxUSEIN": "Employer identification number",
|
|
140
143
|
"timeDifferenceInvalid": "The time difference between the device and the server is {0}, which exceeds the limit of {1} seconds. Please adjust the device time. If it is abnormal, please inform the administrator",
|
|
141
144
|
"tokenExpiry": "Your session is about to expire. Click the Cancel button to continue",
|
|
145
|
+
"type": "Type",
|
|
142
146
|
"yes": "Yes",
|
|
143
147
|
"unknownError": "Unknown Error",
|
|
144
148
|
"unitJoin": "per {0}",
|
package/lib/mjs/i18n/zh-CN.json
CHANGED
|
@@ -43,15 +43,18 @@
|
|
|
43
43
|
"enabled": "已启用",
|
|
44
44
|
"entityStatus": "状态",
|
|
45
45
|
"environmentChanged": "运行环境已改变,请重新登录",
|
|
46
|
+
"error": "错误",
|
|
46
47
|
"etsoo": "亿速思维",
|
|
47
48
|
"expiry": "到期时间",
|
|
48
49
|
"failed": "操作失败",
|
|
49
50
|
"field": "字段",
|
|
51
|
+
"help": "帮助",
|
|
50
52
|
"id": "编号",
|
|
51
53
|
"info": "信息",
|
|
52
54
|
"itemExists": "'{0}'已经存在",
|
|
53
55
|
"loading": "正在加载...",
|
|
54
56
|
"login": "登录",
|
|
57
|
+
"me": "我",
|
|
55
58
|
"menuHome": "首页",
|
|
56
59
|
"message": "留言",
|
|
57
60
|
"mobile": "手机号码",
|
|
@@ -139,6 +142,7 @@
|
|
|
139
142
|
"taxUSEIN": "雇主识别号码(EIN)",
|
|
140
143
|
"timeDifferenceInvalid": "设备时间和服务器时间差为{0},超过{1}秒的限制,请调整设备时间,如果异常请告知管理员",
|
|
141
144
|
"tokenExpiry": "您的会话即将过期。点击 取消 按钮继续使用",
|
|
145
|
+
"type": "类型",
|
|
142
146
|
"yes": "是",
|
|
143
147
|
"unknownError": "未知错误",
|
|
144
148
|
"unitJoin": "每{0}",
|
package/lib/mjs/i18n/zh-HK.json
CHANGED
|
@@ -43,15 +43,18 @@
|
|
|
43
43
|
"enabled": "已啟用",
|
|
44
44
|
"entityStatus": "狀態",
|
|
45
45
|
"environmentChanged": "運行環境已改變,請重新登錄",
|
|
46
|
+
"error": "錯誤",
|
|
46
47
|
"etsoo": "億速思維",
|
|
47
48
|
"expiry": "到期時間",
|
|
48
49
|
"failed": "操作失敗",
|
|
49
50
|
"field": "字段",
|
|
51
|
+
"help": "幫助",
|
|
50
52
|
"id": "編號",
|
|
51
53
|
"info": "信息",
|
|
52
54
|
"itemExists": "'{0}'已经存在",
|
|
53
55
|
"loading": "正在加載...",
|
|
54
56
|
"login": "登錄",
|
|
57
|
+
"me": "我",
|
|
55
58
|
"menuHome": "首頁",
|
|
56
59
|
"message": "留言",
|
|
57
60
|
"mobilePhone": "手機號碼",
|
|
@@ -139,6 +142,7 @@
|
|
|
139
142
|
"taxUSEIN": "雇主識別號碼(EIN)",
|
|
140
143
|
"timeDifferenceInvalid": "設備時間和服務器時間差為{0},超過{1}秒的限制,請調整設備時間,如果異常請告知管理員",
|
|
141
144
|
"tokenExpiry": "您的會話即將過期。點擊 取消 按鈕繼續使用",
|
|
145
|
+
"type": "類型",
|
|
142
146
|
"yes": "是",
|
|
143
147
|
"unknownError": "未知錯誤",
|
|
144
148
|
"unitJoin": "每{0}",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/appscript",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.77",
|
|
4
4
|
"description": "Applications shared TypeScript framework",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
},
|
|
53
53
|
"homepage": "https://github.com/ETSOO/AppScript#readme",
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@etsoo/notificationbase": "^1.1.
|
|
55
|
+
"@etsoo/notificationbase": "^1.1.6",
|
|
56
56
|
"@etsoo/restclient": "^1.0.70",
|
|
57
|
-
"@etsoo/shared": "^1.1.
|
|
57
|
+
"@etsoo/shared": "^1.1.45",
|
|
58
58
|
"@types/crypto-js": "^4.1.1",
|
|
59
59
|
"crypto-js": "^4.1.1"
|
|
60
60
|
},
|
|
@@ -64,15 +64,15 @@
|
|
|
64
64
|
"@babel/plugin-transform-runtime": "^7.18.10",
|
|
65
65
|
"@babel/preset-env": "^7.18.10",
|
|
66
66
|
"@babel/runtime-corejs3": "^7.18.9",
|
|
67
|
-
"@types/jest": "^28.1.
|
|
68
|
-
"@typescript-eslint/eslint-plugin": "^5.33.
|
|
69
|
-
"@typescript-eslint/parser": "^5.33.
|
|
70
|
-
"eslint": "^8.
|
|
67
|
+
"@types/jest": "^28.1.7",
|
|
68
|
+
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
|
69
|
+
"@typescript-eslint/parser": "^5.33.1",
|
|
70
|
+
"eslint": "^8.22.0",
|
|
71
71
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
72
72
|
"eslint-plugin-import": "^2.26.0",
|
|
73
73
|
"jest": "^28.1.3",
|
|
74
74
|
"jest-environment-jsdom": "^28.1.3",
|
|
75
|
-
"ts-jest": "^28.0.
|
|
75
|
+
"ts-jest": "^28.0.8",
|
|
76
76
|
"typescript": "^4.7.4"
|
|
77
77
|
}
|
|
78
78
|
}
|
package/src/app/CoreApp.ts
CHANGED
|
@@ -31,6 +31,7 @@ import { AddressRegion } from '../address/AddressRegion';
|
|
|
31
31
|
import { AddressUtils } from '../address/AddressUtils';
|
|
32
32
|
import { BridgeUtils } from '../bridges/BridgeUtils';
|
|
33
33
|
import { BusinessUtils } from '../business/BusinessUtils';
|
|
34
|
+
import { EntityStatus } from '../business/EntityStatus';
|
|
34
35
|
import { ProductUnit } from '../business/ProductUnit';
|
|
35
36
|
import { IdLabelDto } from '../dto/IdLabelDto';
|
|
36
37
|
import { InitCallDto } from '../dto/InitCallDto';
|
|
@@ -346,8 +347,9 @@ export interface ICoreApp<
|
|
|
346
347
|
* Format result text
|
|
347
348
|
* @param result Action result
|
|
348
349
|
* @param forceToLocal Force to local labels
|
|
350
|
+
* @returns Message
|
|
349
351
|
*/
|
|
350
|
-
formatResult(result: IActionResult, forceToLocal?: boolean):
|
|
352
|
+
formatResult(result: IActionResult, forceToLocal?: boolean): string;
|
|
351
353
|
|
|
352
354
|
/**
|
|
353
355
|
* Fresh countdown UI
|
|
@@ -374,12 +376,6 @@ export interface ICoreApp<
|
|
|
374
376
|
*/
|
|
375
377
|
getCacheToken(): string | undefined;
|
|
376
378
|
|
|
377
|
-
/**
|
|
378
|
-
* Get entity status label
|
|
379
|
-
* @param status Status value
|
|
380
|
-
*/
|
|
381
|
-
getEntityStatusLabel(status: number | null | undefined): string;
|
|
382
|
-
|
|
383
379
|
/**
|
|
384
380
|
* Get all regions
|
|
385
381
|
* @returns Regions
|
|
@@ -392,6 +388,18 @@ export interface ICoreApp<
|
|
|
392
388
|
*/
|
|
393
389
|
getRoles(role: number): IdLabelDto[];
|
|
394
390
|
|
|
391
|
+
/**
|
|
392
|
+
* Get status label
|
|
393
|
+
* @param status Status value
|
|
394
|
+
*/
|
|
395
|
+
getStatusLabel(status: number | null | undefined): string;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Get status list
|
|
399
|
+
* @returns list
|
|
400
|
+
*/
|
|
401
|
+
getStatusList(): IdLabelDto[];
|
|
402
|
+
|
|
395
403
|
/**
|
|
396
404
|
* Get refresh token from response headers
|
|
397
405
|
* @param rawResponse Raw response from API call
|
|
@@ -1102,8 +1110,7 @@ export abstract class CoreApp<
|
|
|
1102
1110
|
* @param callback Callback
|
|
1103
1111
|
*/
|
|
1104
1112
|
alertResult(result: IActionResult, callback?: NotificationReturn<void>) {
|
|
1105
|
-
this.formatResult(result);
|
|
1106
|
-
this.notifier.alert(ActionResultError.format(result), callback);
|
|
1113
|
+
this.notifier.alert(this.formatResult(result), callback);
|
|
1107
1114
|
}
|
|
1108
1115
|
|
|
1109
1116
|
/**
|
|
@@ -1559,6 +1566,8 @@ export abstract class CoreApp<
|
|
|
1559
1566
|
const fieldLabel = this.get(result.field.formatInitial(false));
|
|
1560
1567
|
if (fieldLabel) result.title = result.title.format(fieldLabel);
|
|
1561
1568
|
}
|
|
1569
|
+
|
|
1570
|
+
return ActionResultError.format(result);
|
|
1562
1571
|
}
|
|
1563
1572
|
|
|
1564
1573
|
/**
|
|
@@ -1598,6 +1607,67 @@ export abstract class CoreApp<
|
|
|
1598
1607
|
return this.storage.getData<string>(this.fields.headerToken);
|
|
1599
1608
|
}
|
|
1600
1609
|
|
|
1610
|
+
/**
|
|
1611
|
+
* Get enum item number id list
|
|
1612
|
+
* @param em Enum
|
|
1613
|
+
* @param prefix Label prefix
|
|
1614
|
+
* @param filter Filter
|
|
1615
|
+
* @returns List
|
|
1616
|
+
*/
|
|
1617
|
+
protected getEnumList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(
|
|
1618
|
+
em: E,
|
|
1619
|
+
prefix: string,
|
|
1620
|
+
filter?: (
|
|
1621
|
+
id: E[keyof E],
|
|
1622
|
+
key: keyof E & string
|
|
1623
|
+
) => E[keyof E] | undefined
|
|
1624
|
+
): IdLabelDto[] {
|
|
1625
|
+
const list: IdLabelDto<number>[] = [];
|
|
1626
|
+
const keys = DataTypes.getEnumKeys(em);
|
|
1627
|
+
for (const key of keys) {
|
|
1628
|
+
let id = em[key as keyof E];
|
|
1629
|
+
if (filter) {
|
|
1630
|
+
const fid = filter(id, key);
|
|
1631
|
+
if (fid == null) continue;
|
|
1632
|
+
id = fid;
|
|
1633
|
+
}
|
|
1634
|
+
if (typeof id !== 'number') continue;
|
|
1635
|
+
var label = this.get<string>(prefix + key) ?? key;
|
|
1636
|
+
list.push({ id, label });
|
|
1637
|
+
}
|
|
1638
|
+
return list;
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
/**
|
|
1642
|
+
* Get enum item string id list
|
|
1643
|
+
* @param em Enum
|
|
1644
|
+
* @param prefix Label prefix
|
|
1645
|
+
* @param filter Filter
|
|
1646
|
+
* @returns List
|
|
1647
|
+
*/
|
|
1648
|
+
protected getEnumStrList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(
|
|
1649
|
+
em: E,
|
|
1650
|
+
prefix: string,
|
|
1651
|
+
filter?: (
|
|
1652
|
+
id: E[keyof E],
|
|
1653
|
+
key: keyof E & string
|
|
1654
|
+
) => E[keyof E] | undefined
|
|
1655
|
+
): IdLabelDto<string>[] {
|
|
1656
|
+
const list: IdLabelDto<string>[] = [];
|
|
1657
|
+
const keys = DataTypes.getEnumKeys(em);
|
|
1658
|
+
for (const key of keys) {
|
|
1659
|
+
let id = em[key as keyof E];
|
|
1660
|
+
if (filter) {
|
|
1661
|
+
const fid = filter(id, key);
|
|
1662
|
+
if (fid == null) continue;
|
|
1663
|
+
id = fid;
|
|
1664
|
+
}
|
|
1665
|
+
var label = this.get<string>(prefix + key) ?? key;
|
|
1666
|
+
list.push({ id: id.toString(), label });
|
|
1667
|
+
}
|
|
1668
|
+
return list;
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1601
1671
|
/**
|
|
1602
1672
|
* Get all regions
|
|
1603
1673
|
* @returns Regions
|
|
@@ -1613,29 +1683,27 @@ export abstract class CoreApp<
|
|
|
1613
1683
|
* @param role Combination role value
|
|
1614
1684
|
*/
|
|
1615
1685
|
getRoles(role: number) {
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
var id = UserRole[key as keyof typeof UserRole];
|
|
1621
|
-
if ((id & role) > 0) {
|
|
1622
|
-
roles.push({
|
|
1623
|
-
id,
|
|
1624
|
-
label: this.get<string>(`role${key}`) ?? key
|
|
1625
|
-
});
|
|
1626
|
-
}
|
|
1627
|
-
}
|
|
1686
|
+
return this.getEnumList(UserRole, 'role', (id, _key) => {
|
|
1687
|
+
if ((id & role) > 0) return id;
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1628
1690
|
|
|
1629
|
-
|
|
1691
|
+
/**
|
|
1692
|
+
* Get status list
|
|
1693
|
+
* @returns list
|
|
1694
|
+
*/
|
|
1695
|
+
getStatusList() {
|
|
1696
|
+
return this.getEnumList(EntityStatus, 'status');
|
|
1630
1697
|
}
|
|
1631
1698
|
|
|
1632
1699
|
/**
|
|
1633
|
-
* Get
|
|
1700
|
+
* Get status label
|
|
1634
1701
|
* @param status Status value
|
|
1635
1702
|
*/
|
|
1636
|
-
|
|
1703
|
+
getStatusLabel(status: number | null | undefined) {
|
|
1637
1704
|
if (status == null) return '';
|
|
1638
|
-
|
|
1705
|
+
const key = EntityStatus[status];
|
|
1706
|
+
return this.get<string>('status' + key) ?? key;
|
|
1639
1707
|
}
|
|
1640
1708
|
|
|
1641
1709
|
/**
|
|
@@ -1,14 +1,52 @@
|
|
|
1
1
|
import { DataTypes } from '@etsoo/shared';
|
|
2
|
-
import { RepeatOption } from '..';
|
|
3
2
|
import { IdLabelDto } from '../dto/IdLabelDto';
|
|
4
3
|
import { ICultureGet } from '../state/Culture';
|
|
5
|
-
import { EntityStatus } from './EntityStatus';
|
|
6
4
|
import { ProductUnit } from './ProductUnit';
|
|
5
|
+
import { RepeatOption } from './RepeatOption';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Business utils
|
|
10
9
|
*/
|
|
11
10
|
export namespace BusinessUtils {
|
|
11
|
+
/**
|
|
12
|
+
* Format avatar title
|
|
13
|
+
* @param title Title
|
|
14
|
+
* @param maxChars Max characters
|
|
15
|
+
* @param defaultTitle Default title
|
|
16
|
+
* @returns Result
|
|
17
|
+
*/
|
|
18
|
+
export function formatAvatarTitle(
|
|
19
|
+
title?: string,
|
|
20
|
+
maxChars: number = 3,
|
|
21
|
+
defaultTitle: string = 'ME'
|
|
22
|
+
): string {
|
|
23
|
+
// Just return for empty cases
|
|
24
|
+
if (title == null || title === '') return defaultTitle;
|
|
25
|
+
|
|
26
|
+
// split with words
|
|
27
|
+
const items = title.trim().split(/\s+/g);
|
|
28
|
+
|
|
29
|
+
if (items.length === 1) {
|
|
30
|
+
// 2-3 Chinese names
|
|
31
|
+
const titleLen = title.length;
|
|
32
|
+
if (titleLen <= maxChars) return title.toUpperCase();
|
|
33
|
+
|
|
34
|
+
// Return default for simplicity
|
|
35
|
+
return defaultTitle;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// First letter of each item
|
|
39
|
+
var firstLetters = items
|
|
40
|
+
.map((item) => item[0])
|
|
41
|
+
.join('')
|
|
42
|
+
.toUpperCase();
|
|
43
|
+
|
|
44
|
+
const flen = firstLetters.length;
|
|
45
|
+
if (flen <= maxChars) return firstLetters;
|
|
46
|
+
|
|
47
|
+
return defaultTitle;
|
|
48
|
+
}
|
|
49
|
+
|
|
12
50
|
/**
|
|
13
51
|
* Get currency collection
|
|
14
52
|
* @param currencyNames Names like CNY, USD
|
|
@@ -25,37 +63,6 @@ export namespace BusinessUtils {
|
|
|
25
63
|
}));
|
|
26
64
|
}
|
|
27
65
|
|
|
28
|
-
/**
|
|
29
|
-
* Get entity status's label
|
|
30
|
-
* Please define the label with key 'statusNormal' for Normal status
|
|
31
|
-
* @param unit Unit
|
|
32
|
-
* @param func Label delegate
|
|
33
|
-
* @returns Label
|
|
34
|
-
*/
|
|
35
|
-
export function getEntityStatusLabel(
|
|
36
|
-
status: EntityStatus,
|
|
37
|
-
func: ICultureGet
|
|
38
|
-
) {
|
|
39
|
-
const key = EntityStatus[status];
|
|
40
|
-
return func('status' + key) ?? key;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Get entity status collection
|
|
45
|
-
* @param unit Unit
|
|
46
|
-
* @param func Label delegate
|
|
47
|
-
* @returns Label
|
|
48
|
-
*/
|
|
49
|
-
export function getEntityStatus(func: ICultureGet) {
|
|
50
|
-
return DataTypes.getEnumKeys(EntityStatus).map((key) => {
|
|
51
|
-
const id = DataTypes.getEnumByKey(EntityStatus, key)!;
|
|
52
|
-
return {
|
|
53
|
-
id,
|
|
54
|
-
label: getEntityStatusLabel(id, func)
|
|
55
|
-
};
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
66
|
/**
|
|
60
67
|
* Get 12-month items
|
|
61
68
|
* @param monthLabels Month labels
|
package/src/i18n/en-US.json
CHANGED
|
@@ -43,15 +43,18 @@
|
|
|
43
43
|
"enabled": "Enabled",
|
|
44
44
|
"entityStatus": "Status",
|
|
45
45
|
"environmentChanged": "The operating environment has changed, please log in again",
|
|
46
|
+
"error": "Error",
|
|
46
47
|
"etsoo": "ETSOO",
|
|
47
48
|
"expiry": "Expiry",
|
|
48
49
|
"failed": "Operation failed",
|
|
49
50
|
"field": "Field",
|
|
51
|
+
"help": "Help",
|
|
50
52
|
"id": "Number#",
|
|
51
53
|
"info": "Info",
|
|
52
54
|
"itemExists": "'{0}' already exists",
|
|
53
55
|
"loading": "Loading...",
|
|
54
56
|
"login": "Login",
|
|
57
|
+
"me": "ME",
|
|
55
58
|
"menuHome": "Home",
|
|
56
59
|
"message": "Message",
|
|
57
60
|
"mobile": "Mobile number",
|
|
@@ -139,6 +142,7 @@
|
|
|
139
142
|
"taxUSEIN": "Employer identification number",
|
|
140
143
|
"timeDifferenceInvalid": "The time difference between the device and the server is {0}, which exceeds the limit of {1} seconds. Please adjust the device time. If it is abnormal, please inform the administrator",
|
|
141
144
|
"tokenExpiry": "Your session is about to expire. Click the Cancel button to continue",
|
|
145
|
+
"type": "Type",
|
|
142
146
|
"yes": "Yes",
|
|
143
147
|
"unknownError": "Unknown Error",
|
|
144
148
|
"unitJoin": "per {0}",
|
package/src/i18n/zh-CN.json
CHANGED
|
@@ -43,15 +43,18 @@
|
|
|
43
43
|
"enabled": "已启用",
|
|
44
44
|
"entityStatus": "状态",
|
|
45
45
|
"environmentChanged": "运行环境已改变,请重新登录",
|
|
46
|
+
"error": "错误",
|
|
46
47
|
"etsoo": "亿速思维",
|
|
47
48
|
"expiry": "到期时间",
|
|
48
49
|
"failed": "操作失败",
|
|
49
50
|
"field": "字段",
|
|
51
|
+
"help": "帮助",
|
|
50
52
|
"id": "编号",
|
|
51
53
|
"info": "信息",
|
|
52
54
|
"itemExists": "'{0}'已经存在",
|
|
53
55
|
"loading": "正在加载...",
|
|
54
56
|
"login": "登录",
|
|
57
|
+
"me": "我",
|
|
55
58
|
"menuHome": "首页",
|
|
56
59
|
"message": "留言",
|
|
57
60
|
"mobile": "手机号码",
|
|
@@ -139,6 +142,7 @@
|
|
|
139
142
|
"taxUSEIN": "雇主识别号码(EIN)",
|
|
140
143
|
"timeDifferenceInvalid": "设备时间和服务器时间差为{0},超过{1}秒的限制,请调整设备时间,如果异常请告知管理员",
|
|
141
144
|
"tokenExpiry": "您的会话即将过期。点击 取消 按钮继续使用",
|
|
145
|
+
"type": "类型",
|
|
142
146
|
"yes": "是",
|
|
143
147
|
"unknownError": "未知错误",
|
|
144
148
|
"unitJoin": "每{0}",
|
package/src/i18n/zh-HK.json
CHANGED
|
@@ -43,15 +43,18 @@
|
|
|
43
43
|
"enabled": "已啟用",
|
|
44
44
|
"entityStatus": "狀態",
|
|
45
45
|
"environmentChanged": "運行環境已改變,請重新登錄",
|
|
46
|
+
"error": "錯誤",
|
|
46
47
|
"etsoo": "億速思維",
|
|
47
48
|
"expiry": "到期時間",
|
|
48
49
|
"failed": "操作失敗",
|
|
49
50
|
"field": "字段",
|
|
51
|
+
"help": "幫助",
|
|
50
52
|
"id": "編號",
|
|
51
53
|
"info": "信息",
|
|
52
54
|
"itemExists": "'{0}'已经存在",
|
|
53
55
|
"loading": "正在加載...",
|
|
54
56
|
"login": "登錄",
|
|
57
|
+
"me": "我",
|
|
55
58
|
"menuHome": "首頁",
|
|
56
59
|
"message": "留言",
|
|
57
60
|
"mobilePhone": "手機號碼",
|
|
@@ -139,6 +142,7 @@
|
|
|
139
142
|
"taxUSEIN": "雇主識別號碼(EIN)",
|
|
140
143
|
"timeDifferenceInvalid": "設備時間和服務器時間差為{0},超過{1}秒的限制,請調整設備時間,如果異常請告知管理員",
|
|
141
144
|
"tokenExpiry": "您的會話即將過期。點擊 取消 按鈕繼續使用",
|
|
145
|
+
"type": "類型",
|
|
142
146
|
"yes": "是",
|
|
143
147
|
"unknownError": "未知錯誤",
|
|
144
148
|
"unitJoin": "每{0}",
|