@etsoo/appscript 1.2.72 → 1.2.75

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.
@@ -28,7 +28,7 @@ jobs:
28
28
  # Setup .npmrc file to publish to npm
29
29
  - uses: actions/setup-node@v1
30
30
  with:
31
- node-version: '14.18'
31
+ node-version: '18.x'
32
32
  registry-url: 'https://registry.npmjs.org'
33
33
 
34
34
  # Named after Continuous Integration, installs dependencies directly from package-lock.json
@@ -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
  });
@@ -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,7 +1,6 @@
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
@@ -14,31 +13,13 @@ export declare namespace BusinessUtils {
14
13
  * @returns Collection
15
14
  */
16
15
  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
16
  /**
36
17
  * Get 12-month items
37
18
  * @param monthLabels Month labels
38
19
  * @param startMonth Start month, 0 as Jan.
39
20
  * @returns 12 months
40
21
  */
41
- function getMonths(monthLabels: string[], startMonth?: number): DataTypes.IdLabelItem[];
22
+ function getMonths(monthLabels: string[], startMonth?: number): DataTypes.IdLabelItem<number>[];
42
23
  /**
43
24
  * Get product unit's label
44
25
  * Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BusinessUtils = void 0;
4
4
  const shared_1 = require("@etsoo/shared");
5
5
  const __1 = require("..");
6
- const EntityStatus_1 = require("./EntityStatus");
7
6
  const ProductUnit_1 = require("./ProductUnit");
8
7
  /**
9
8
  * Business utils
@@ -26,35 +25,6 @@ var BusinessUtils;
26
25
  });
27
26
  }
28
27
  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
28
  /**
59
29
  * Get 12-month items
60
30
  * @param monthLabels Month labels
@@ -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>[];
@@ -36,12 +36,14 @@
36
36
  "description": "Description",
37
37
  "done": "Done",
38
38
  "download": "Download",
39
+ "dragIndicator": "Drag indicator",
39
40
  "edit": "Edit",
40
41
  "email": "Email",
41
42
  "emailAddresses": "Email addresses",
42
43
  "enabled": "Enabled",
43
44
  "entityStatus": "Status",
44
45
  "environmentChanged": "The operating environment has changed, please log in again",
46
+ "error": "Error",
45
47
  "etsoo": "ETSOO",
46
48
  "expiry": "Expiry",
47
49
  "failed": "Operation failed",
@@ -36,12 +36,14 @@
36
36
  "description": "描述",
37
37
  "done": "完成",
38
38
  "download": "下载",
39
+ "dragIndicator": "拖动指示",
39
40
  "edit": "修改",
40
41
  "email": "电子邮箱",
41
42
  "emailAddresses": "电子邮箱",
42
43
  "enabled": "已启用",
43
44
  "entityStatus": "状态",
44
45
  "environmentChanged": "运行环境已改变,请重新登录",
46
+ "error": "错误",
45
47
  "etsoo": "亿速思维",
46
48
  "expiry": "到期时间",
47
49
  "failed": "操作失败",
@@ -36,12 +36,14 @@
36
36
  "description": "描述",
37
37
  "done": "完成",
38
38
  "download": "下載",
39
+ "dragIndicator": "拖動指示",
39
40
  "edit": "修改",
40
41
  "email": "電子郵箱",
41
42
  "emailAddresses": "電子郵箱",
42
43
  "enabled": "已啟用",
43
44
  "entityStatus": "狀態",
44
45
  "environmentChanged": "運行環境已改變,請重新登錄",
46
+ "error": "錯誤",
45
47
  "etsoo": "億速思維",
46
48
  "expiry": "到期時間",
47
49
  "failed": "操作失敗",
@@ -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
@@ -1,7 +1,6 @@
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
@@ -14,31 +13,13 @@ export declare namespace BusinessUtils {
14
13
  * @returns Collection
15
14
  */
16
15
  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
16
  /**
36
17
  * Get 12-month items
37
18
  * @param monthLabels Month labels
38
19
  * @param startMonth Start month, 0 as Jan.
39
20
  * @returns 12 months
40
21
  */
41
- function getMonths(monthLabels: string[], startMonth?: number): DataTypes.IdLabelItem[];
22
+ function getMonths(monthLabels: string[], startMonth?: number): DataTypes.IdLabelItem<number>[];
42
23
  /**
43
24
  * Get product unit's label
44
25
  * Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
@@ -1,6 +1,5 @@
1
1
  import { DataTypes } from '@etsoo/shared';
2
2
  import { RepeatOption } from '..';
3
- import { EntityStatus } from './EntityStatus';
4
3
  import { ProductUnit } from './ProductUnit';
5
4
  /**
6
5
  * Business utils
@@ -23,35 +22,6 @@ export var BusinessUtils;
23
22
  });
24
23
  }
25
24
  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
25
  /**
56
26
  * Get 12-month items
57
27
  * @param monthLabels Month labels
@@ -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>[];
@@ -36,12 +36,14 @@
36
36
  "description": "Description",
37
37
  "done": "Done",
38
38
  "download": "Download",
39
+ "dragIndicator": "Drag indicator",
39
40
  "edit": "Edit",
40
41
  "email": "Email",
41
42
  "emailAddresses": "Email addresses",
42
43
  "enabled": "Enabled",
43
44
  "entityStatus": "Status",
44
45
  "environmentChanged": "The operating environment has changed, please log in again",
46
+ "error": "Error",
45
47
  "etsoo": "ETSOO",
46
48
  "expiry": "Expiry",
47
49
  "failed": "Operation failed",
@@ -36,12 +36,14 @@
36
36
  "description": "描述",
37
37
  "done": "完成",
38
38
  "download": "下载",
39
+ "dragIndicator": "拖动指示",
39
40
  "edit": "修改",
40
41
  "email": "电子邮箱",
41
42
  "emailAddresses": "电子邮箱",
42
43
  "enabled": "已启用",
43
44
  "entityStatus": "状态",
44
45
  "environmentChanged": "运行环境已改变,请重新登录",
46
+ "error": "错误",
45
47
  "etsoo": "亿速思维",
46
48
  "expiry": "到期时间",
47
49
  "failed": "操作失败",
@@ -36,12 +36,14 @@
36
36
  "description": "描述",
37
37
  "done": "完成",
38
38
  "download": "下載",
39
+ "dragIndicator": "拖動指示",
39
40
  "edit": "修改",
40
41
  "email": "電子郵箱",
41
42
  "emailAddresses": "電子郵箱",
42
43
  "enabled": "已啟用",
43
44
  "entityStatus": "狀態",
44
45
  "environmentChanged": "運行環境已改變,請重新登錄",
46
+ "error": "錯誤",
45
47
  "etsoo": "億速思維",
46
48
  "expiry": "到期時間",
47
49
  "failed": "操作失敗",
@@ -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/mjs/index.js CHANGED
@@ -19,7 +19,6 @@ export * from './business/RepeatOption';
19
19
  // def
20
20
  export * from './def/ListItem';
21
21
  // dto
22
- export * from './dto/IdDto';
23
22
  export * from './dto/IdLabelDto';
24
23
  export * from './dto/IdLabelPrimaryDto';
25
24
  export * from './dto/InitCallDto';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.2.72",
3
+ "version": "1.2.75",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -54,7 +54,7 @@
54
54
  "dependencies": {
55
55
  "@etsoo/notificationbase": "^1.1.5",
56
56
  "@etsoo/restclient": "^1.0.70",
57
- "@etsoo/shared": "^1.1.41",
57
+ "@etsoo/shared": "^1.1.44",
58
58
  "@types/crypto-js": "^4.1.1",
59
59
  "crypto-js": "^4.1.1"
60
60
  },
@@ -65,9 +65,9 @@
65
65
  "@babel/preset-env": "^7.18.10",
66
66
  "@babel/runtime-corejs3": "^7.18.9",
67
67
  "@types/jest": "^28.1.6",
68
- "@typescript-eslint/eslint-plugin": "^5.32.0",
69
- "@typescript-eslint/parser": "^5.32.0",
70
- "eslint": "^8.21.0",
68
+ "@typescript-eslint/eslint-plugin": "^5.33.0",
69
+ "@typescript-eslint/parser": "^5.33.0",
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",
@@ -31,13 +31,14 @@ 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';
37
38
  import { ActionResultError } from '../result/ActionResultError';
38
39
  import { IActionResult } from '../result/IActionResult';
39
40
  import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
40
- import { IUser, IUserData } from '../state/User';
41
+ import { IUser } from '../state/User';
41
42
  import { IAppSettings } from './AppSettings';
42
43
  import { UserRole } from './UserRole';
43
44
 
@@ -374,18 +375,30 @@ export interface ICoreApp<
374
375
  */
375
376
  getCacheToken(): string | undefined;
376
377
 
377
- /**
378
- * Get entity status label
379
- * @param data Input data
380
- */
381
- getEntityStatusLabel<D extends { entityStatus?: number }>(data?: D): string;
382
-
383
378
  /**
384
379
  * Get all regions
385
380
  * @returns Regions
386
381
  */
387
382
  getRegions(): AddressRegion[];
388
383
 
384
+ /**
385
+ * Get roles
386
+ * @param role Combination role value
387
+ */
388
+ getRoles(role: number): IdLabelDto[];
389
+
390
+ /**
391
+ * Get status label
392
+ * @param status Status value
393
+ */
394
+ getStatusLabel(status: number | null | undefined): string;
395
+
396
+ /**
397
+ * Get status list
398
+ * @returns list
399
+ */
400
+ getStatusList(): IdLabelDto[];
401
+
389
402
  /**
390
403
  * Get refresh token from response headers
391
404
  * @param rawResponse Raw response from API call
@@ -1592,6 +1605,67 @@ export abstract class CoreApp<
1592
1605
  return this.storage.getData<string>(this.fields.headerToken);
1593
1606
  }
1594
1607
 
1608
+ /**
1609
+ * Get enum item number id list
1610
+ * @param em Enum
1611
+ * @param prefix Label prefix
1612
+ * @param filter Filter
1613
+ * @returns List
1614
+ */
1615
+ protected getEnumList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(
1616
+ em: E,
1617
+ prefix: string,
1618
+ filter?: (
1619
+ id: E[keyof E],
1620
+ key: keyof E & string
1621
+ ) => E[keyof E] | undefined
1622
+ ): IdLabelDto[] {
1623
+ const list: IdLabelDto<number>[] = [];
1624
+ const keys = DataTypes.getEnumKeys(em);
1625
+ for (const key of keys) {
1626
+ let id = em[key as keyof E];
1627
+ if (filter) {
1628
+ const fid = filter(id, key);
1629
+ if (fid == null) continue;
1630
+ id = fid;
1631
+ }
1632
+ if (typeof id !== 'number') continue;
1633
+ var label = this.get<string>(prefix + key) ?? key;
1634
+ list.push({ id, label });
1635
+ }
1636
+ return list;
1637
+ }
1638
+
1639
+ /**
1640
+ * Get enum item string id list
1641
+ * @param em Enum
1642
+ * @param prefix Label prefix
1643
+ * @param filter Filter
1644
+ * @returns List
1645
+ */
1646
+ protected getEnumStrList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(
1647
+ em: E,
1648
+ prefix: string,
1649
+ filter?: (
1650
+ id: E[keyof E],
1651
+ key: keyof E & string
1652
+ ) => E[keyof E] | undefined
1653
+ ): IdLabelDto<string>[] {
1654
+ const list: IdLabelDto<string>[] = [];
1655
+ const keys = DataTypes.getEnumKeys(em);
1656
+ for (const key of keys) {
1657
+ let id = em[key as keyof E];
1658
+ if (filter) {
1659
+ const fid = filter(id, key);
1660
+ if (fid == null) continue;
1661
+ id = fid;
1662
+ }
1663
+ var label = this.get<string>(prefix + key) ?? key;
1664
+ list.push({ id: id.toString(), label });
1665
+ }
1666
+ return list;
1667
+ }
1668
+
1595
1669
  /**
1596
1670
  * Get all regions
1597
1671
  * @returns Regions
@@ -1603,15 +1677,31 @@ export abstract class CoreApp<
1603
1677
  }
1604
1678
 
1605
1679
  /**
1606
- * Get entity status label
1607
- * @param data Input data
1680
+ * Get roles
1681
+ * @param role Combination role value
1608
1682
  */
1609
- getEntityStatusLabel<D extends { entityStatus?: number }>(data?: D) {
1610
- if (data == null || data.entityStatus == null) return '';
1611
- return BusinessUtils.getEntityStatusLabel(
1612
- data.entityStatus,
1613
- this.labelDelegate
1614
- );
1683
+ getRoles(role: number) {
1684
+ return this.getEnumList(UserRole, 'role', (id, _key) => {
1685
+ if ((id & role) > 0) return id;
1686
+ });
1687
+ }
1688
+
1689
+ /**
1690
+ * Get status list
1691
+ * @returns list
1692
+ */
1693
+ getStatusList() {
1694
+ return this.getEnumList(EntityStatus, 'status');
1695
+ }
1696
+
1697
+ /**
1698
+ * Get status label
1699
+ * @param status Status value
1700
+ */
1701
+ getStatusLabel(status: number | null | undefined) {
1702
+ if (status == null) return '';
1703
+ const key = EntityStatus[status];
1704
+ return this.get<string>('status' + key) ?? key;
1615
1705
  }
1616
1706
 
1617
1707
  /**
@@ -2,7 +2,6 @@ import { DataTypes } from '@etsoo/shared';
2
2
  import { RepeatOption } from '..';
3
3
  import { IdLabelDto } from '../dto/IdLabelDto';
4
4
  import { ICultureGet } from '../state/Culture';
5
- import { EntityStatus } from './EntityStatus';
6
5
  import { ProductUnit } from './ProductUnit';
7
6
 
8
7
  /**
@@ -25,37 +24,6 @@ export namespace BusinessUtils {
25
24
  }));
26
25
  }
27
26
 
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
27
  /**
60
28
  * Get 12-month items
61
29
  * @param monthLabels Month labels
@@ -1,19 +1,19 @@
1
1
  import { DataTypes } from '@etsoo/shared';
2
- import { IdDto } from './IdDto';
3
2
 
4
3
  /**
5
4
  * Dto with id and label field
6
5
  */
7
- export type IdLabelDto<T extends DataTypes.IdType = number> = IdDto<T> & {
8
- /**
9
- * Label
10
- */
11
- label: string;
12
- };
6
+ export type IdLabelDto<T extends DataTypes.IdType = number> =
7
+ DataTypes.IdItem<T> & {
8
+ /**
9
+ * Label
10
+ */
11
+ label: string;
12
+ };
13
13
 
14
14
  /**
15
15
  * Conditional IdLabel type
16
16
  */
17
17
  export type IdLabelConditional<T extends boolean> = T extends true
18
- ? IdLabelDto[]
18
+ ? IdLabelDto<number>[]
19
19
  : IdLabelDto<string>[];
@@ -36,12 +36,14 @@
36
36
  "description": "Description",
37
37
  "done": "Done",
38
38
  "download": "Download",
39
+ "dragIndicator": "Drag indicator",
39
40
  "edit": "Edit",
40
41
  "email": "Email",
41
42
  "emailAddresses": "Email addresses",
42
43
  "enabled": "Enabled",
43
44
  "entityStatus": "Status",
44
45
  "environmentChanged": "The operating environment has changed, please log in again",
46
+ "error": "Error",
45
47
  "etsoo": "ETSOO",
46
48
  "expiry": "Expiry",
47
49
  "failed": "Operation failed",
@@ -36,12 +36,14 @@
36
36
  "description": "描述",
37
37
  "done": "完成",
38
38
  "download": "下载",
39
+ "dragIndicator": "拖动指示",
39
40
  "edit": "修改",
40
41
  "email": "电子邮箱",
41
42
  "emailAddresses": "电子邮箱",
42
43
  "enabled": "已启用",
43
44
  "entityStatus": "状态",
44
45
  "environmentChanged": "运行环境已改变,请重新登录",
46
+ "error": "错误",
45
47
  "etsoo": "亿速思维",
46
48
  "expiry": "到期时间",
47
49
  "failed": "操作失败",
@@ -36,12 +36,14 @@
36
36
  "description": "描述",
37
37
  "done": "完成",
38
38
  "download": "下載",
39
+ "dragIndicator": "拖動指示",
39
40
  "edit": "修改",
40
41
  "email": "電子郵箱",
41
42
  "emailAddresses": "電子郵箱",
42
43
  "enabled": "已啟用",
43
44
  "entityStatus": "狀態",
44
45
  "environmentChanged": "運行環境已改變,請重新登錄",
46
+ "error": "錯誤",
45
47
  "etsoo": "億速思維",
46
48
  "expiry": "到期時間",
47
49
  "failed": "操作失敗",
package/src/index.ts CHANGED
@@ -24,7 +24,6 @@ export * from './business/RepeatOption';
24
24
  export * from './def/ListItem';
25
25
 
26
26
  // dto
27
- export * from './dto/IdDto';
28
27
  export * from './dto/IdLabelDto';
29
28
  export * from './dto/IdLabelPrimaryDto';
30
29
  export * from './dto/InitCallDto';
@@ -1,10 +0,0 @@
1
- import { DataTypes } from '@etsoo/shared';
2
- /**
3
- * Dto with id field
4
- */
5
- export declare type IdDto<T extends DataTypes.IdType = number> = {
6
- /**
7
- * Id
8
- */
9
- readonly id: T;
10
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,10 +0,0 @@
1
- import { DataTypes } from '@etsoo/shared';
2
- /**
3
- * Dto with id field
4
- */
5
- export declare type IdDto<T extends DataTypes.IdType = number> = {
6
- /**
7
- * Id
8
- */
9
- readonly id: T;
10
- };
@@ -1 +0,0 @@
1
- export {};
package/src/dto/IdDto.ts DELETED
@@ -1,11 +0,0 @@
1
- import { DataTypes } from '@etsoo/shared';
2
-
3
- /**
4
- * Dto with id field
5
- */
6
- export type IdDto<T extends DataTypes.IdType = number> = {
7
- /**
8
- * Id
9
- */
10
- readonly id: T;
11
- };