@etsoo/appscript 1.2.73 → 1.2.76

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.
@@ -8,7 +8,7 @@ import {
8
8
  } from '@etsoo/notificationbase';
9
9
  import { ApiAuthorizationScheme, createClient } from '@etsoo/restclient';
10
10
  import { DataTypes, DomUtils, Utils, WindowStorage } from '@etsoo/shared';
11
- import { BusinessUtils, IUser } from '../../src';
11
+ import { BusinessUtils, IUser, UserRole } from '../../src';
12
12
  import { AddressUtils } from '../../src/address/AddressUtils';
13
13
  import { IAppSettings } from '../../src/app/AppSettings';
14
14
  import { CoreApp } from '../../src/app/CoreApp';
@@ -161,6 +161,12 @@ test('Tests for initCallUpdateLocal', () => {
161
161
  expect(passphrase).not.toBeNull();
162
162
  });
163
163
 
164
+ test('Tests for getRoles', () => {
165
+ var roles = app.getRoles(UserRole.User | UserRole.Manager | UserRole.Admin);
166
+ expect(roles.length).toBe(3);
167
+ expect(roles.map((r) => r.id)).toEqual([8, 128, 8192]);
168
+ });
169
+
164
170
  test('Tests for getUnitLabel', () => {
165
171
  expect(app.getUnitLabel(12, true)).toBe('每年');
166
172
  });
@@ -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
+ });
@@ -260,18 +260,26 @@ export interface ICoreApp<U extends IUser, S extends IAppSettings, N, C extends
260
260
  * @returns Cached token
261
261
  */
262
262
  getCacheToken(): string | undefined;
263
- /**
264
- * Get entity status label
265
- * @param data Input data
266
- */
267
- getEntityStatusLabel<D extends {
268
- entityStatus?: number;
269
- }>(data?: D): string;
270
263
  /**
271
264
  * Get all regions
272
265
  * @returns Regions
273
266
  */
274
267
  getRegions(): AddressRegion[];
268
+ /**
269
+ * Get roles
270
+ * @param role Combination role value
271
+ */
272
+ getRoles(role: number): IdLabelDto[];
273
+ /**
274
+ * Get status label
275
+ * @param status Status value
276
+ */
277
+ getStatusLabel(status: number | null | undefined): string;
278
+ /**
279
+ * Get status list
280
+ * @returns list
281
+ */
282
+ getStatusList(): IdLabelDto[];
275
283
  /**
276
284
  * Get refresh token from response headers
277
285
  * @param rawResponse Raw response from API call
@@ -702,18 +710,42 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
702
710
  * @returns Cached token
703
711
  */
704
712
  getCacheToken(): string | undefined;
713
+ /**
714
+ * Get enum item number id list
715
+ * @param em Enum
716
+ * @param prefix Label prefix
717
+ * @param filter Filter
718
+ * @returns List
719
+ */
720
+ 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[];
721
+ /**
722
+ * Get enum item string id list
723
+ * @param em Enum
724
+ * @param prefix Label prefix
725
+ * @param filter Filter
726
+ * @returns List
727
+ */
728
+ 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>[];
705
729
  /**
706
730
  * Get all regions
707
731
  * @returns Regions
708
732
  */
709
733
  getRegions(): AddressRegion[];
710
734
  /**
711
- * Get entity status label
712
- * @param data Input data
735
+ * Get roles
736
+ * @param role Combination role value
737
+ */
738
+ getRoles(role: number): IdLabelDto<number>[];
739
+ /**
740
+ * Get status list
741
+ * @returns list
742
+ */
743
+ getStatusList(): IdLabelDto<number>[];
744
+ /**
745
+ * Get status label
746
+ * @param status Status value
713
747
  */
714
- getEntityStatusLabel<D extends {
715
- entityStatus?: number;
716
- }>(data?: D): string;
748
+ getStatusLabel(status: number | null | undefined): string;
717
749
  /**
718
750
  * Get refresh token from response headers
719
751
  * @param rawResponse Raw response from API call
@@ -9,7 +9,9 @@ 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");
14
+ const UserRole_1 = require("./UserRole");
13
15
  /**
14
16
  * App fields
15
17
  */
@@ -828,6 +830,56 @@ class CoreApp {
828
830
  return this.cachedRefreshToken;
829
831
  return this.storage.getData(this.fields.headerToken);
830
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
+ }
831
883
  /**
832
884
  * Get all regions
833
885
  * @returns Regions
@@ -838,13 +890,32 @@ class CoreApp {
838
890
  });
839
891
  }
840
892
  /**
841
- * Get entity status label
842
- * @param data Input data
893
+ * Get roles
894
+ * @param role Combination role value
843
895
  */
844
- getEntityStatusLabel(data) {
845
- if (data == null || data.entityStatus == null)
896
+ getRoles(role) {
897
+ return this.getEnumList(UserRole_1.UserRole, 'role', (id, _key) => {
898
+ if ((id & role) > 0)
899
+ return id;
900
+ });
901
+ }
902
+ /**
903
+ * Get status list
904
+ * @returns list
905
+ */
906
+ getStatusList() {
907
+ return this.getEnumList(EntityStatus_1.EntityStatus, 'status');
908
+ }
909
+ /**
910
+ * Get status label
911
+ * @param status Status value
912
+ */
913
+ getStatusLabel(status) {
914
+ var _a;
915
+ if (status == null)
846
916
  return '';
847
- return BusinessUtils_1.BusinessUtils.getEntityStatusLabel(data.entityStatus, this.labelDelegate);
917
+ const key = EntityStatus_1.EntityStatus[status];
918
+ return (_a = this.get('status' + key)) !== null && _a !== void 0 ? _a : key;
848
919
  }
849
920
  /**
850
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,31 +21,13 @@ 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
38
27
  * @param startMonth Start month, 0 as Jan.
39
28
  * @returns 12 months
40
29
  */
41
- function getMonths(monthLabels: string[], startMonth?: number): DataTypes.IdLabelItem[];
30
+ function getMonths(monthLabels: string[], startMonth?: number): DataTypes.IdLabelItem<number>[];
42
31
  /**
43
32
  * Get product unit's label
44
33
  * Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
@@ -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(__1.RepeatOption));
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
  }
@@ -1,9 +1,8 @@
1
1
  import { DataTypes } from '@etsoo/shared';
2
- import { IdDto } from './IdDto';
3
2
  /**
4
3
  * Dto with id and label field
5
4
  */
6
- export declare type IdLabelDto<T extends DataTypes.IdType = number> = IdDto<T> & {
5
+ export declare type IdLabelDto<T extends DataTypes.IdType = number> = DataTypes.IdItem<T> & {
7
6
  /**
8
7
  * Label
9
8
  */
@@ -12,4 +11,4 @@ export declare type IdLabelDto<T extends DataTypes.IdType = number> = IdDto<T> &
12
11
  /**
13
12
  * Conditional IdLabel type
14
13
  */
15
- export declare type IdLabelConditional<T extends boolean> = T extends true ? IdLabelDto[] : IdLabelDto<string>[];
14
+ export declare type IdLabelConditional<T extends boolean> = T extends true ? IdLabelDto<number>[] : IdLabelDto<string>[];
@@ -43,6 +43,7 @@
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",
@@ -52,6 +53,7 @@
52
53
  "itemExists": "'{0}' already exists",
53
54
  "loading": "Loading...",
54
55
  "login": "Login",
56
+ "me": "ME",
55
57
  "menuHome": "Home",
56
58
  "message": "Message",
57
59
  "mobile": "Mobile number",
@@ -139,6 +141,7 @@
139
141
  "taxUSEIN": "Employer identification number",
140
142
  "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
143
  "tokenExpiry": "Your session is about to expire. Click the Cancel button to continue",
144
+ "type": "Type",
142
145
  "yes": "Yes",
143
146
  "unknownError": "Unknown Error",
144
147
  "unitJoin": "per {0}",
@@ -43,6 +43,7 @@
43
43
  "enabled": "已启用",
44
44
  "entityStatus": "状态",
45
45
  "environmentChanged": "运行环境已改变,请重新登录",
46
+ "error": "错误",
46
47
  "etsoo": "亿速思维",
47
48
  "expiry": "到期时间",
48
49
  "failed": "操作失败",
@@ -52,6 +53,7 @@
52
53
  "itemExists": "'{0}'已经存在",
53
54
  "loading": "正在加载...",
54
55
  "login": "登录",
56
+ "me": "我",
55
57
  "menuHome": "首页",
56
58
  "message": "留言",
57
59
  "mobile": "手机号码",
@@ -139,6 +141,7 @@
139
141
  "taxUSEIN": "雇主识别号码(EIN)",
140
142
  "timeDifferenceInvalid": "设备时间和服务器时间差为{0},超过{1}秒的限制,请调整设备时间,如果异常请告知管理员",
141
143
  "tokenExpiry": "您的会话即将过期。点击 取消 按钮继续使用",
144
+ "type": "类型",
142
145
  "yes": "是",
143
146
  "unknownError": "未知错误",
144
147
  "unitJoin": "每{0}",
@@ -43,6 +43,7 @@
43
43
  "enabled": "已啟用",
44
44
  "entityStatus": "狀態",
45
45
  "environmentChanged": "運行環境已改變,請重新登錄",
46
+ "error": "錯誤",
46
47
  "etsoo": "億速思維",
47
48
  "expiry": "到期時間",
48
49
  "failed": "操作失敗",
@@ -52,6 +53,7 @@
52
53
  "itemExists": "'{0}'已经存在",
53
54
  "loading": "正在加載...",
54
55
  "login": "登錄",
56
+ "me": "我",
55
57
  "menuHome": "首頁",
56
58
  "message": "留言",
57
59
  "mobilePhone": "手機號碼",
@@ -139,6 +141,7 @@
139
141
  "taxUSEIN": "雇主識別號碼(EIN)",
140
142
  "timeDifferenceInvalid": "設備時間和服務器時間差為{0},超過{1}秒的限制,請調整設備時間,如果異常請告知管理員",
141
143
  "tokenExpiry": "您的會話即將過期。點擊 取消 按鈕繼續使用",
144
+ "type": "類型",
142
145
  "yes": "是",
143
146
  "unknownError": "未知錯誤",
144
147
  "unitJoin": "每{0}",
@@ -13,7 +13,6 @@ export * from './business/EntityStatus';
13
13
  export * from './business/ProductUnit';
14
14
  export * from './business/RepeatOption';
15
15
  export * from './def/ListItem';
16
- export * from './dto/IdDto';
17
16
  export * from './dto/IdLabelDto';
18
17
  export * from './dto/IdLabelPrimaryDto';
19
18
  export * from './dto/InitCallDto';
package/lib/cjs/index.js CHANGED
@@ -36,7 +36,6 @@ __exportStar(require("./business/RepeatOption"), exports);
36
36
  // def
37
37
  __exportStar(require("./def/ListItem"), exports);
38
38
  // dto
39
- __exportStar(require("./dto/IdDto"), exports);
40
39
  __exportStar(require("./dto/IdLabelDto"), exports);
41
40
  __exportStar(require("./dto/IdLabelPrimaryDto"), exports);
42
41
  __exportStar(require("./dto/InitCallDto"), exports);
@@ -260,18 +260,26 @@ export interface ICoreApp<U extends IUser, S extends IAppSettings, N, C extends
260
260
  * @returns Cached token
261
261
  */
262
262
  getCacheToken(): string | undefined;
263
- /**
264
- * Get entity status label
265
- * @param data Input data
266
- */
267
- getEntityStatusLabel<D extends {
268
- entityStatus?: number;
269
- }>(data?: D): string;
270
263
  /**
271
264
  * Get all regions
272
265
  * @returns Regions
273
266
  */
274
267
  getRegions(): AddressRegion[];
268
+ /**
269
+ * Get roles
270
+ * @param role Combination role value
271
+ */
272
+ getRoles(role: number): IdLabelDto[];
273
+ /**
274
+ * Get status label
275
+ * @param status Status value
276
+ */
277
+ getStatusLabel(status: number | null | undefined): string;
278
+ /**
279
+ * Get status list
280
+ * @returns list
281
+ */
282
+ getStatusList(): IdLabelDto[];
275
283
  /**
276
284
  * Get refresh token from response headers
277
285
  * @param rawResponse Raw response from API call
@@ -702,18 +710,42 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
702
710
  * @returns Cached token
703
711
  */
704
712
  getCacheToken(): string | undefined;
713
+ /**
714
+ * Get enum item number id list
715
+ * @param em Enum
716
+ * @param prefix Label prefix
717
+ * @param filter Filter
718
+ * @returns List
719
+ */
720
+ 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[];
721
+ /**
722
+ * Get enum item string id list
723
+ * @param em Enum
724
+ * @param prefix Label prefix
725
+ * @param filter Filter
726
+ * @returns List
727
+ */
728
+ 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>[];
705
729
  /**
706
730
  * Get all regions
707
731
  * @returns Regions
708
732
  */
709
733
  getRegions(): AddressRegion[];
710
734
  /**
711
- * Get entity status label
712
- * @param data Input data
735
+ * Get roles
736
+ * @param role Combination role value
737
+ */
738
+ getRoles(role: number): IdLabelDto<number>[];
739
+ /**
740
+ * Get status list
741
+ * @returns list
742
+ */
743
+ getStatusList(): IdLabelDto<number>[];
744
+ /**
745
+ * Get status label
746
+ * @param status Status value
713
747
  */
714
- getEntityStatusLabel<D extends {
715
- entityStatus?: number;
716
- }>(data?: D): string;
748
+ getStatusLabel(status: number | null | undefined): string;
717
749
  /**
718
750
  * Get refresh token from response headers
719
751
  * @param rawResponse Raw response from API call
@@ -1,12 +1,14 @@
1
1
  import { NotificationAlign, NotificationMessageType } from '@etsoo/notificationbase';
2
2
  import { ApiDataError } from '@etsoo/restclient';
3
- import { DateUtils, DomUtils, NumberUtils, Utils } from '@etsoo/shared';
3
+ import { DataTypes, DateUtils, DomUtils, NumberUtils, Utils } from '@etsoo/shared';
4
4
  import { AES, algo, enc, HmacSHA512, lib, mode, pad, PBKDF2, SHA3 } from 'crypto-js';
5
5
  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';
11
+ import { UserRole } from './UserRole';
10
12
  /**
11
13
  * App fields
12
14
  */
@@ -825,6 +827,56 @@ export class CoreApp {
825
827
  return this.cachedRefreshToken;
826
828
  return this.storage.getData(this.fields.headerToken);
827
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
+ }
828
880
  /**
829
881
  * Get all regions
830
882
  * @returns Regions
@@ -835,13 +887,32 @@ export class CoreApp {
835
887
  });
836
888
  }
837
889
  /**
838
- * Get entity status label
839
- * @param data Input data
890
+ * Get roles
891
+ * @param role Combination role value
840
892
  */
841
- getEntityStatusLabel(data) {
842
- if (data == null || data.entityStatus == null)
893
+ getRoles(role) {
894
+ return this.getEnumList(UserRole, 'role', (id, _key) => {
895
+ if ((id & role) > 0)
896
+ return id;
897
+ });
898
+ }
899
+ /**
900
+ * Get status list
901
+ * @returns list
902
+ */
903
+ getStatusList() {
904
+ return this.getEnumList(EntityStatus, 'status');
905
+ }
906
+ /**
907
+ * Get status label
908
+ * @param status Status value
909
+ */
910
+ getStatusLabel(status) {
911
+ var _a;
912
+ if (status == null)
843
913
  return '';
844
- return BusinessUtils.getEntityStatusLabel(data.entityStatus, this.labelDelegate);
914
+ const key = EntityStatus[status];
915
+ return (_a = this.get('status' + key)) !== null && _a !== void 0 ? _a : key;
845
916
  }
846
917
  /**
847
918
  * Get refresh token from response headers