@etsoo/appscript 1.3.5 → 1.3.7

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.
@@ -143,6 +143,10 @@ const appClass = EnhanceApp(CoreAppTest);
143
143
  const app = new appClass();
144
144
  app.changeCulture(app.settings.cultures[0]);
145
145
 
146
+ test('Test for properties', () => {
147
+ expect(app.settings.currentRegion.label).toBe('中国大陆');
148
+ });
149
+
146
150
  test('Tests for addRootUrl', () => {
147
151
  expect(app.addRootUrl('/home')).toBe('/cms/home');
148
152
  expect(app.addRootUrl('./home')).toBe('/cms/./home');
@@ -201,10 +205,7 @@ test('Tests for addressApi', async () => {
201
205
  const continents = await app.addressApi.continents();
202
206
  expect(continents.length).toBe(7);
203
207
 
204
- const labels = await app.addressApi.getLabels('en-NZ');
205
- expect(labels['regionHK']).toBe('Hong Kong, China');
206
-
207
- const regions = await app.addressApi.regions('zh-CN');
208
+ const regions = await app.addressApi.regions();
208
209
  const cn = regions.find((r) => r.id === 'CN');
209
210
  expect(cn?.label).toBe('中国大陆');
210
211
  });
@@ -217,16 +218,4 @@ test('Tests for publicApi', async () => {
217
218
 
218
219
  const currencies = await app.publicApi.currencies(['NZD', 'AUD', 'USD']);
219
220
  expect(currencies[1].id).toBe('AUD');
220
-
221
- //const currenciesRemote = await app.publicApi.currencies();
222
- //console.log(currenciesRemote);
223
-
224
- //const history = await app.publicApi.exchangeRateHistory(['NZD', 'AUD'], 24);
225
- //console.log(history);
226
-
227
- //const qrcode = await app.publicApi.mobileQRCode('xz@etsoo.com');
228
- //console.log(qrcode);
229
-
230
- //const exchangeRate = await app.publicApi.exchangeRate('USD');
231
- //console.log(exchangeRate);
232
221
  });
@@ -216,6 +216,10 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
216
216
  * @param culture New culture definition
217
217
  */
218
218
  changeCulture(culture: DataTypes.CultureDefinition): void;
219
+ /**
220
+ * Update current region label
221
+ */
222
+ protected updateRegionLabel(): void;
219
223
  /**
220
224
  * Check language is supported or not, return a valid language when supported
221
225
  * @param language Language
@@ -360,6 +364,12 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
360
364
  * @returns List
361
365
  */
362
366
  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): ListType1[];
367
+ /**
368
+ * Get region label
369
+ * @param id Region id
370
+ * @returns Label
371
+ */
372
+ getRegionLabel(id: string): string;
363
373
  /**
364
374
  * Get all regions
365
375
  * @returns Regions
@@ -487,6 +487,7 @@ class CoreApp {
487
487
  this._region = regionId;
488
488
  // Hold the current country or region
489
489
  this.settings.currentRegion = regionItem;
490
+ this.updateRegionLabel();
490
491
  }
491
492
  /**
492
493
  * Change culture
@@ -507,6 +508,14 @@ class CoreApp {
507
508
  this._culture = name;
508
509
  // Hold the current resources
509
510
  this.settings.currentCulture = culture;
511
+ this.updateRegionLabel();
512
+ }
513
+ /**
514
+ * Update current region label
515
+ */
516
+ updateRegionLabel() {
517
+ const region = this.settings.currentRegion;
518
+ region.label = this.getRegionLabel(region.id);
510
519
  }
511
520
  /**
512
521
  * Check language is supported or not, return a valid language when supported
@@ -894,6 +903,15 @@ class CoreApp {
894
903
  }
895
904
  return list;
896
905
  }
906
+ /**
907
+ * Get region label
908
+ * @param id Region id
909
+ * @returns Label
910
+ */
911
+ getRegionLabel(id) {
912
+ var _a;
913
+ return (_a = this.get('region' + id)) !== null && _a !== void 0 ? _a : id;
914
+ }
897
915
  /**
898
916
  * Get all regions
899
917
  * @returns Regions
@@ -284,6 +284,12 @@ export interface IApp {
284
284
  * @returns Cached token
285
285
  */
286
286
  getCacheToken(): string | undefined;
287
+ /**
288
+ * Get region label
289
+ * @param id Region id
290
+ * @returns Label
291
+ */
292
+ getRegionLabel(id: string): string;
287
293
  /**
288
294
  * Get all regions
289
295
  * @returns Regions
@@ -1,4 +1,4 @@
1
- import { DataTypes } from '@etsoo/shared';
1
+ import { AddressContinent } from '../address/AddressContinent';
2
2
  import { AddressRegion, AddressRegionDb } from '../address/AddressRegion';
3
3
  import { AddressState } from '../address/AddressState';
4
4
  import { IdLabelConditional } from '../dto/IdLabelDto';
@@ -7,32 +7,28 @@ import { BaseApi } from './BaseApi';
7
7
  * Address Api
8
8
  */
9
9
  export declare class AddressApi extends BaseApi {
10
- private languageLabels;
11
- /**
12
- * Get address labels
13
- * @param language Language
14
- * @returns Result
15
- */
16
- getLabels(language?: string): Promise<DataTypes.StringRecord>;
17
10
  /**
18
11
  * Get all continents
19
- * @param language Language
20
12
  * @param isNumberKey Is number key or key as id
21
13
  * @returns Continents
22
14
  */
23
- continents<T extends boolean>(language?: string, isNumberKey?: T): Promise<IdLabelConditional<T>>;
15
+ continents<T extends boolean>(isNumberKey?: T): Promise<IdLabelConditional<T>>;
16
+ /**
17
+ * Get continent label
18
+ * @param id Region id
19
+ * @returns Label
20
+ */
21
+ getContinentLabel(id: AddressContinent | string): string;
24
22
  /**
25
- * Get region list from database
26
- * @param language Language
23
+ * Get region list
27
24
  * @param isLocal Is local version
28
25
  * @returns Result
29
26
  */
30
- regions<T extends boolean = true>(language?: string, isLocal?: T): Promise<T extends true | undefined ? AddressRegion[] : AddressRegionDb[] | undefined>;
27
+ regions<T extends boolean = true>(isLocal?: T): Promise<T extends true | undefined ? AddressRegion[] : AddressRegionDb[] | undefined>;
31
28
  /**
32
- * Get state list from database
29
+ * Get state list
33
30
  * @param regionId Region id
34
- * @param language Language
35
31
  * @returns Result
36
32
  */
37
- states(regionId: string, language?: string): Promise<AddressState[] | undefined>;
33
+ states(regionId: string): Promise<AddressState[] | undefined>;
38
34
  }
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports.AddressApi = void 0;
27
4
  const shared_1 = require("@etsoo/shared");
@@ -32,71 +9,51 @@ const BaseApi_1 = require("./BaseApi");
32
9
  * Address Api
33
10
  */
34
11
  class AddressApi extends BaseApi_1.BaseApi {
35
- constructor() {
36
- super(...arguments);
37
- this.languageLabels = {};
38
- }
39
- /**
40
- * Get address labels
41
- * @param language Language
42
- * @returns Result
43
- */
44
- async getLabels(language) {
45
- const l = this.app.checkLanguage(language);
46
- let labels = this.languageLabels[l];
47
- if (labels == null) {
48
- labels = await Promise.resolve().then(() => __importStar(require(`./../i18n/address.${l}.json`)));
49
- // Cache
50
- this.languageLabels[l] = labels;
51
- }
52
- return labels;
53
- }
54
12
  /**
55
13
  * Get all continents
56
- * @param language Language
57
14
  * @param isNumberKey Is number key or key as id
58
15
  * @returns Continents
59
16
  */
60
- async continents(language, isNumberKey = false) {
61
- const labels = await this.getLabels(language);
62
- return shared_1.DataTypes.getEnumKeys(AddressContinent_1.AddressContinent).map((key) => {
63
- var _a;
64
- return ({
65
- id: isNumberKey
66
- ? shared_1.DataTypes.getEnumByKey(AddressContinent_1.AddressContinent, key)
67
- : key.toString(),
68
- label: (_a = labels['continent' + key]) !== null && _a !== void 0 ? _a : key
69
- });
70
- });
17
+ async continents(isNumberKey = false) {
18
+ return shared_1.DataTypes.getEnumKeys(AddressContinent_1.AddressContinent).map((key) => ({
19
+ id: isNumberKey
20
+ ? shared_1.DataTypes.getEnumByKey(AddressContinent_1.AddressContinent, key)
21
+ : key.toString(),
22
+ label: this.getContinentLabel(key)
23
+ }));
24
+ }
25
+ /**
26
+ * Get continent label
27
+ * @param id Region id
28
+ * @returns Label
29
+ */
30
+ getContinentLabel(id) {
31
+ var _a;
32
+ return (_a = this.app.get('continent' + id)) !== null && _a !== void 0 ? _a : id;
71
33
  }
72
34
  /**
73
- * Get region list from database
74
- * @param language Language
35
+ * Get region list
75
36
  * @param isLocal Is local version
76
37
  * @returns Result
77
38
  */
78
- async regions(language, isLocal) {
79
- language = this.app.checkLanguage(language);
39
+ async regions(isLocal) {
80
40
  if (isLocal == null || isLocal) {
81
- const labels = await this.getLabels(language);
82
41
  return AddressRegion_1.AddressRegion.all.map((region) => {
83
- region.label = labels['region' + region.id];
42
+ region.label = this.app.getRegionLabel(region.id);
84
43
  return { ...region };
85
44
  });
86
45
  }
87
46
  else {
88
- return (await this.app.api.get(`Address/RegionList?language=${language}`, undefined, { defaultValue: [] }));
47
+ return (await this.app.api.get(`Address/RegionList?language=${this.app.culture}`, undefined, { defaultValue: [] }));
89
48
  }
90
49
  }
91
50
  /**
92
- * Get state list from database
51
+ * Get state list
93
52
  * @param regionId Region id
94
- * @param language Language
95
53
  * @returns Result
96
54
  */
97
- states(regionId, language) {
98
- language = this.app.checkLanguage(language);
99
- return this.app.api.get(`Address/StateList?regionId=${regionId}&language=${language}`, undefined, { defaultValue: [] });
55
+ states(regionId) {
56
+ return this.app.api.get(`Address/StateList?regionId=${regionId}&language=${this.app.culture}`, undefined, { defaultValue: [] });
100
57
  }
101
58
  }
102
59
  exports.AddressApi = AddressApi;
@@ -15,6 +15,13 @@
15
15
  "confirm": "Confirm",
16
16
  "confirmAction": "Are you sure you want to {0}?",
17
17
  "completeTip": "{0} completed",
18
+ "continentAF": "Africa",
19
+ "continentAN": "Antarctica",
20
+ "continentAS": "Asia",
21
+ "continentEU": "Europe",
22
+ "continentNA": "North America",
23
+ "continentOC": "Oceania",
24
+ "continentSA": "South America",
18
25
  "copy": "Copy",
19
26
  "creation": "Creation",
20
27
  "currentPassword": "Current password",
@@ -106,6 +113,18 @@
106
113
  "refresh": "Refresh",
107
114
  "refreshing": "Refreshing",
108
115
  "releaseToRefresh": "Release to refresh",
116
+ "regionAU": "Australia",
117
+ "regionCA": "Canada",
118
+ "regionCN": "Mainland China",
119
+ "regionDE": "Germany",
120
+ "regionFR": "France",
121
+ "regionGB": "United Kingdom",
122
+ "regionHK": "Hong Kong, China",
123
+ "regionIE": "Ireland",
124
+ "regionJP": "Japan",
125
+ "regionNZ": "New Zealand",
126
+ "regionSG": "Singapore",
127
+ "regionUS": "United States",
109
128
  "reloginTip": "Please enter your password, resubmit the data after successful login",
110
129
  "remove": "Remove",
111
130
  "renew": "Renew",
@@ -15,6 +15,13 @@
15
15
  "confirm": "确认",
16
16
  "confirmAction": "确定要{0}吗?",
17
17
  "completeTip": "已完成 {0}",
18
+ "continentAF": "非洲",
19
+ "continentAN": "南极洲",
20
+ "continentAS": "亚洲",
21
+ "continentEU": "欧洲",
22
+ "continentNA": "北美洲",
23
+ "continentOC": "大洋洲",
24
+ "continentSA": "南美洲",
18
25
  "copy": "复制",
19
26
  "creation": "登记时间",
20
27
  "currentPassword": "当前密码",
@@ -105,6 +112,18 @@
105
112
  "record": "记录",
106
113
  "refresh": "刷新",
107
114
  "refreshing": "正在刷新",
115
+ "regionAU": "澳大利亚",
116
+ "regionCA": "加拿大",
117
+ "regionCN": "中国大陆",
118
+ "regionDE": "德国",
119
+ "regionFR": "法国",
120
+ "regionGB": "英国",
121
+ "regionHK": "中国香港",
122
+ "regionIE": "爱尔兰",
123
+ "regionJP": "日本",
124
+ "regionNZ": "新西兰",
125
+ "regionSG": "新加坡",
126
+ "regionUS": "美国",
108
127
  "releaseToRefresh": "释放刷新",
109
128
  "reloginTip": "请输入您的登录密码,登录成功后请重新提交数据",
110
129
  "remove": "移除",
@@ -15,6 +15,13 @@
15
15
  "confirm": "確認",
16
16
  "confirmAction": "確定要{0}嗎?",
17
17
  "completeTip": "已完成 {0}",
18
+ "continentAF": "非洲",
19
+ "continentAN": "南極洲",
20
+ "continentAS": "亞洲",
21
+ "continentEU": "歐洲",
22
+ "continentNA": "北美洲",
23
+ "continentOC": "大洋洲",
24
+ "continentSA": "南美洲",
18
25
  "copy": "複製",
19
26
  "creation": "登記時間",
20
27
  "currentPassword": "當前密碼",
@@ -105,6 +112,18 @@
105
112
  "record": "記錄",
106
113
  "refresh": "刷新",
107
114
  "refreshing": "正在刷新",
115
+ "regionAU": "澳大利亞",
116
+ "regionCA": "加拿大",
117
+ "regionCN": "中國大陸",
118
+ "regionDE": "德國",
119
+ "regionFR": "法國",
120
+ "regionGB": "英國",
121
+ "regionHK": "中國香港",
122
+ "regionIE": "愛爾蘭",
123
+ "regionJP": "日本",
124
+ "regionNZ": "新西蘭",
125
+ "regionSG": "新加坡",
126
+ "regionUS": "美國",
108
127
  "releaseToRefresh": "釋放刷新",
109
128
  "reloginTip": "請輸入您的登錄密碼,登錄成功後請重新提交數據",
110
129
  "remove": "移除",
@@ -216,6 +216,10 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
216
216
  * @param culture New culture definition
217
217
  */
218
218
  changeCulture(culture: DataTypes.CultureDefinition): void;
219
+ /**
220
+ * Update current region label
221
+ */
222
+ protected updateRegionLabel(): void;
219
223
  /**
220
224
  * Check language is supported or not, return a valid language when supported
221
225
  * @param language Language
@@ -360,6 +364,12 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
360
364
  * @returns List
361
365
  */
362
366
  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): ListType1[];
367
+ /**
368
+ * Get region label
369
+ * @param id Region id
370
+ * @returns Label
371
+ */
372
+ getRegionLabel(id: string): string;
363
373
  /**
364
374
  * Get all regions
365
375
  * @returns Regions
@@ -484,6 +484,7 @@ export class CoreApp {
484
484
  this._region = regionId;
485
485
  // Hold the current country or region
486
486
  this.settings.currentRegion = regionItem;
487
+ this.updateRegionLabel();
487
488
  }
488
489
  /**
489
490
  * Change culture
@@ -504,6 +505,14 @@ export class CoreApp {
504
505
  this._culture = name;
505
506
  // Hold the current resources
506
507
  this.settings.currentCulture = culture;
508
+ this.updateRegionLabel();
509
+ }
510
+ /**
511
+ * Update current region label
512
+ */
513
+ updateRegionLabel() {
514
+ const region = this.settings.currentRegion;
515
+ region.label = this.getRegionLabel(region.id);
507
516
  }
508
517
  /**
509
518
  * Check language is supported or not, return a valid language when supported
@@ -891,6 +900,15 @@ export class CoreApp {
891
900
  }
892
901
  return list;
893
902
  }
903
+ /**
904
+ * Get region label
905
+ * @param id Region id
906
+ * @returns Label
907
+ */
908
+ getRegionLabel(id) {
909
+ var _a;
910
+ return (_a = this.get('region' + id)) !== null && _a !== void 0 ? _a : id;
911
+ }
894
912
  /**
895
913
  * Get all regions
896
914
  * @returns Regions
@@ -284,6 +284,12 @@ export interface IApp {
284
284
  * @returns Cached token
285
285
  */
286
286
  getCacheToken(): string | undefined;
287
+ /**
288
+ * Get region label
289
+ * @param id Region id
290
+ * @returns Label
291
+ */
292
+ getRegionLabel(id: string): string;
287
293
  /**
288
294
  * Get all regions
289
295
  * @returns Regions
@@ -1,4 +1,4 @@
1
- import { DataTypes } from '@etsoo/shared';
1
+ import { AddressContinent } from '../address/AddressContinent';
2
2
  import { AddressRegion, AddressRegionDb } from '../address/AddressRegion';
3
3
  import { AddressState } from '../address/AddressState';
4
4
  import { IdLabelConditional } from '../dto/IdLabelDto';
@@ -7,32 +7,28 @@ import { BaseApi } from './BaseApi';
7
7
  * Address Api
8
8
  */
9
9
  export declare class AddressApi extends BaseApi {
10
- private languageLabels;
11
- /**
12
- * Get address labels
13
- * @param language Language
14
- * @returns Result
15
- */
16
- getLabels(language?: string): Promise<DataTypes.StringRecord>;
17
10
  /**
18
11
  * Get all continents
19
- * @param language Language
20
12
  * @param isNumberKey Is number key or key as id
21
13
  * @returns Continents
22
14
  */
23
- continents<T extends boolean>(language?: string, isNumberKey?: T): Promise<IdLabelConditional<T>>;
15
+ continents<T extends boolean>(isNumberKey?: T): Promise<IdLabelConditional<T>>;
16
+ /**
17
+ * Get continent label
18
+ * @param id Region id
19
+ * @returns Label
20
+ */
21
+ getContinentLabel(id: AddressContinent | string): string;
24
22
  /**
25
- * Get region list from database
26
- * @param language Language
23
+ * Get region list
27
24
  * @param isLocal Is local version
28
25
  * @returns Result
29
26
  */
30
- regions<T extends boolean = true>(language?: string, isLocal?: T): Promise<T extends true | undefined ? AddressRegion[] : AddressRegionDb[] | undefined>;
27
+ regions<T extends boolean = true>(isLocal?: T): Promise<T extends true | undefined ? AddressRegion[] : AddressRegionDb[] | undefined>;
31
28
  /**
32
- * Get state list from database
29
+ * Get state list
33
30
  * @param regionId Region id
34
- * @param language Language
35
31
  * @returns Result
36
32
  */
37
- states(regionId: string, language?: string): Promise<AddressState[] | undefined>;
33
+ states(regionId: string): Promise<AddressState[] | undefined>;
38
34
  }
@@ -6,70 +6,50 @@ import { BaseApi } from './BaseApi';
6
6
  * Address Api
7
7
  */
8
8
  export class AddressApi extends BaseApi {
9
- constructor() {
10
- super(...arguments);
11
- this.languageLabels = {};
12
- }
13
- /**
14
- * Get address labels
15
- * @param language Language
16
- * @returns Result
17
- */
18
- async getLabels(language) {
19
- const l = this.app.checkLanguage(language);
20
- let labels = this.languageLabels[l];
21
- if (labels == null) {
22
- labels = await import(`./../i18n/address.${l}.json`);
23
- // Cache
24
- this.languageLabels[l] = labels;
25
- }
26
- return labels;
27
- }
28
9
  /**
29
10
  * Get all continents
30
- * @param language Language
31
11
  * @param isNumberKey Is number key or key as id
32
12
  * @returns Continents
33
13
  */
34
- async continents(language, isNumberKey = false) {
35
- const labels = await this.getLabels(language);
36
- return DataTypes.getEnumKeys(AddressContinent).map((key) => {
37
- var _a;
38
- return ({
39
- id: isNumberKey
40
- ? DataTypes.getEnumByKey(AddressContinent, key)
41
- : key.toString(),
42
- label: (_a = labels['continent' + key]) !== null && _a !== void 0 ? _a : key
43
- });
44
- });
14
+ async continents(isNumberKey = false) {
15
+ return DataTypes.getEnumKeys(AddressContinent).map((key) => ({
16
+ id: isNumberKey
17
+ ? DataTypes.getEnumByKey(AddressContinent, key)
18
+ : key.toString(),
19
+ label: this.getContinentLabel(key)
20
+ }));
21
+ }
22
+ /**
23
+ * Get continent label
24
+ * @param id Region id
25
+ * @returns Label
26
+ */
27
+ getContinentLabel(id) {
28
+ var _a;
29
+ return (_a = this.app.get('continent' + id)) !== null && _a !== void 0 ? _a : id;
45
30
  }
46
31
  /**
47
- * Get region list from database
48
- * @param language Language
32
+ * Get region list
49
33
  * @param isLocal Is local version
50
34
  * @returns Result
51
35
  */
52
- async regions(language, isLocal) {
53
- language = this.app.checkLanguage(language);
36
+ async regions(isLocal) {
54
37
  if (isLocal == null || isLocal) {
55
- const labels = await this.getLabels(language);
56
38
  return AddressRegion.all.map((region) => {
57
- region.label = labels['region' + region.id];
39
+ region.label = this.app.getRegionLabel(region.id);
58
40
  return { ...region };
59
41
  });
60
42
  }
61
43
  else {
62
- return (await this.app.api.get(`Address/RegionList?language=${language}`, undefined, { defaultValue: [] }));
44
+ return (await this.app.api.get(`Address/RegionList?language=${this.app.culture}`, undefined, { defaultValue: [] }));
63
45
  }
64
46
  }
65
47
  /**
66
- * Get state list from database
48
+ * Get state list
67
49
  * @param regionId Region id
68
- * @param language Language
69
50
  * @returns Result
70
51
  */
71
- states(regionId, language) {
72
- language = this.app.checkLanguage(language);
73
- return this.app.api.get(`Address/StateList?regionId=${regionId}&language=${language}`, undefined, { defaultValue: [] });
52
+ states(regionId) {
53
+ return this.app.api.get(`Address/StateList?regionId=${regionId}&language=${this.app.culture}`, undefined, { defaultValue: [] });
74
54
  }
75
55
  }
@@ -15,6 +15,13 @@
15
15
  "confirm": "Confirm",
16
16
  "confirmAction": "Are you sure you want to {0}?",
17
17
  "completeTip": "{0} completed",
18
+ "continentAF": "Africa",
19
+ "continentAN": "Antarctica",
20
+ "continentAS": "Asia",
21
+ "continentEU": "Europe",
22
+ "continentNA": "North America",
23
+ "continentOC": "Oceania",
24
+ "continentSA": "South America",
18
25
  "copy": "Copy",
19
26
  "creation": "Creation",
20
27
  "currentPassword": "Current password",
@@ -106,6 +113,18 @@
106
113
  "refresh": "Refresh",
107
114
  "refreshing": "Refreshing",
108
115
  "releaseToRefresh": "Release to refresh",
116
+ "regionAU": "Australia",
117
+ "regionCA": "Canada",
118
+ "regionCN": "Mainland China",
119
+ "regionDE": "Germany",
120
+ "regionFR": "France",
121
+ "regionGB": "United Kingdom",
122
+ "regionHK": "Hong Kong, China",
123
+ "regionIE": "Ireland",
124
+ "regionJP": "Japan",
125
+ "regionNZ": "New Zealand",
126
+ "regionSG": "Singapore",
127
+ "regionUS": "United States",
109
128
  "reloginTip": "Please enter your password, resubmit the data after successful login",
110
129
  "remove": "Remove",
111
130
  "renew": "Renew",
@@ -15,6 +15,13 @@
15
15
  "confirm": "确认",
16
16
  "confirmAction": "确定要{0}吗?",
17
17
  "completeTip": "已完成 {0}",
18
+ "continentAF": "非洲",
19
+ "continentAN": "南极洲",
20
+ "continentAS": "亚洲",
21
+ "continentEU": "欧洲",
22
+ "continentNA": "北美洲",
23
+ "continentOC": "大洋洲",
24
+ "continentSA": "南美洲",
18
25
  "copy": "复制",
19
26
  "creation": "登记时间",
20
27
  "currentPassword": "当前密码",
@@ -105,6 +112,18 @@
105
112
  "record": "记录",
106
113
  "refresh": "刷新",
107
114
  "refreshing": "正在刷新",
115
+ "regionAU": "澳大利亚",
116
+ "regionCA": "加拿大",
117
+ "regionCN": "中国大陆",
118
+ "regionDE": "德国",
119
+ "regionFR": "法国",
120
+ "regionGB": "英国",
121
+ "regionHK": "中国香港",
122
+ "regionIE": "爱尔兰",
123
+ "regionJP": "日本",
124
+ "regionNZ": "新西兰",
125
+ "regionSG": "新加坡",
126
+ "regionUS": "美国",
108
127
  "releaseToRefresh": "释放刷新",
109
128
  "reloginTip": "请输入您的登录密码,登录成功后请重新提交数据",
110
129
  "remove": "移除",
@@ -15,6 +15,13 @@
15
15
  "confirm": "確認",
16
16
  "confirmAction": "確定要{0}嗎?",
17
17
  "completeTip": "已完成 {0}",
18
+ "continentAF": "非洲",
19
+ "continentAN": "南極洲",
20
+ "continentAS": "亞洲",
21
+ "continentEU": "歐洲",
22
+ "continentNA": "北美洲",
23
+ "continentOC": "大洋洲",
24
+ "continentSA": "南美洲",
18
25
  "copy": "複製",
19
26
  "creation": "登記時間",
20
27
  "currentPassword": "當前密碼",
@@ -105,6 +112,18 @@
105
112
  "record": "記錄",
106
113
  "refresh": "刷新",
107
114
  "refreshing": "正在刷新",
115
+ "regionAU": "澳大利亞",
116
+ "regionCA": "加拿大",
117
+ "regionCN": "中國大陸",
118
+ "regionDE": "德國",
119
+ "regionFR": "法國",
120
+ "regionGB": "英國",
121
+ "regionHK": "中國香港",
122
+ "regionIE": "愛爾蘭",
123
+ "regionJP": "日本",
124
+ "regionNZ": "新西蘭",
125
+ "regionSG": "新加坡",
126
+ "regionUS": "美國",
108
127
  "releaseToRefresh": "釋放刷新",
109
128
  "reloginTip": "請輸入您的登錄密碼,登錄成功後請重新提交數據",
110
129
  "remove": "移除",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -70,8 +70,8 @@
70
70
  "eslint": "^8.25.0",
71
71
  "eslint-config-airbnb-base": "^15.0.0",
72
72
  "eslint-plugin-import": "^2.26.0",
73
- "jest": "^29.1.2",
74
- "jest-environment-jsdom": "^29.1.2",
73
+ "jest": "^29.2.0",
74
+ "jest-environment-jsdom": "^29.2.0",
75
75
  "ts-jest": "^29.0.3",
76
76
  "typescript": "^4.8.4"
77
77
  }
@@ -30,6 +30,7 @@ import {
30
30
  SHA3
31
31
  } from 'crypto-js';
32
32
  import { AddressRegion } from '../address/AddressRegion';
33
+ import { AddressUtils } from '../address/AddressUtils';
33
34
  import { BridgeUtils } from '../bridges/BridgeUtils';
34
35
  import { EntityStatus } from '../business/EntityStatus';
35
36
  import { InitCallDto } from '../dto/InitCallDto';
@@ -718,6 +719,7 @@ export abstract class CoreApp<
718
719
 
719
720
  // Hold the current country or region
720
721
  this.settings.currentRegion = regionItem;
722
+ this.updateRegionLabel();
721
723
  }
722
724
 
723
725
  /**
@@ -743,6 +745,16 @@ export abstract class CoreApp<
743
745
 
744
746
  // Hold the current resources
745
747
  this.settings.currentCulture = culture;
748
+
749
+ this.updateRegionLabel();
750
+ }
751
+
752
+ /**
753
+ * Update current region label
754
+ */
755
+ protected updateRegionLabel() {
756
+ const region = this.settings.currentRegion;
757
+ region.label = this.getRegionLabel(region.id);
746
758
  }
747
759
 
748
760
  /**
@@ -1217,6 +1229,15 @@ export abstract class CoreApp<
1217
1229
  return list;
1218
1230
  }
1219
1231
 
1232
+ /**
1233
+ * Get region label
1234
+ * @param id Region id
1235
+ * @returns Label
1236
+ */
1237
+ getRegionLabel(id: string) {
1238
+ return this.get('region' + id) ?? id;
1239
+ }
1240
+
1220
1241
  /**
1221
1242
  * Get all regions
1222
1243
  * @returns Regions
package/src/app/IApp.ts CHANGED
@@ -375,6 +375,13 @@ export interface IApp {
375
375
  */
376
376
  getCacheToken(): string | undefined;
377
377
 
378
+ /**
379
+ * Get region label
380
+ * @param id Region id
381
+ * @returns Label
382
+ */
383
+ getRegionLabel(id: string): string;
384
+
378
385
  /**
379
386
  * Get all regions
380
387
  * @returns Regions
@@ -9,71 +9,53 @@ import { BaseApi } from './BaseApi';
9
9
  * Address Api
10
10
  */
11
11
  export class AddressApi extends BaseApi {
12
- private languageLabels: Record<string, DataTypes.StringRecord | undefined> =
13
- {};
14
-
15
- /**
16
- * Get address labels
17
- * @param language Language
18
- * @returns Result
19
- */
20
- async getLabels(language?: string) {
21
- const l = this.app.checkLanguage(language);
22
- let labels = this.languageLabels[l];
23
- if (labels == null) {
24
- labels = await import(`./../i18n/address.${l}.json`);
25
-
26
- // Cache
27
- this.languageLabels[l] = labels;
28
- }
29
- return labels!;
30
- }
31
-
32
12
  /**
33
13
  * Get all continents
34
- * @param language Language
35
14
  * @param isNumberKey Is number key or key as id
36
15
  * @returns Continents
37
16
  */
38
17
  async continents<T extends boolean>(
39
- language?: string,
40
18
  isNumberKey = <T>false
41
19
  ): Promise<IdLabelConditional<T>> {
42
- const labels = await this.getLabels(language);
43
20
  return <IdLabelConditional<T>>DataTypes.getEnumKeys(
44
21
  AddressContinent
45
22
  ).map((key) => ({
46
23
  id: isNumberKey
47
24
  ? <number>DataTypes.getEnumByKey(AddressContinent, key)!
48
25
  : key.toString(),
49
- label: labels['continent' + key] ?? key
26
+ label: this.getContinentLabel(key)
50
27
  }));
51
28
  }
52
29
 
53
30
  /**
54
- * Get region list from database
55
- * @param language Language
31
+ * Get continent label
32
+ * @param id Region id
33
+ * @returns Label
34
+ */
35
+ getContinentLabel(id: AddressContinent | string) {
36
+ return this.app.get('continent' + id) ?? (id as string);
37
+ }
38
+
39
+ /**
40
+ * Get region list
56
41
  * @param isLocal Is local version
57
42
  * @returns Result
58
43
  */
59
44
  async regions<T extends boolean = true>(
60
- language?: string,
61
45
  isLocal?: T
62
46
  ): Promise<
63
47
  T extends true | undefined
64
48
  ? AddressRegion[]
65
49
  : AddressRegionDb[] | undefined
66
50
  > {
67
- language = this.app.checkLanguage(language);
68
51
  if (isLocal == null || isLocal) {
69
- const labels = await this.getLabels(language);
70
52
  return AddressRegion.all.map((region) => {
71
- region.label = labels['region' + region.id] as string;
53
+ region.label = this.app.getRegionLabel(region.id);
72
54
  return { ...region };
73
55
  });
74
56
  } else {
75
57
  return (await this.app.api.get<AddressRegionDb[]>(
76
- `Address/RegionList?language=${language}`,
58
+ `Address/RegionList?language=${this.app.culture}`,
77
59
  undefined,
78
60
  { defaultValue: [] }
79
61
  )) as any;
@@ -81,15 +63,13 @@ export class AddressApi extends BaseApi {
81
63
  }
82
64
 
83
65
  /**
84
- * Get state list from database
66
+ * Get state list
85
67
  * @param regionId Region id
86
- * @param language Language
87
68
  * @returns Result
88
69
  */
89
- states(regionId: string, language?: string) {
90
- language = this.app.checkLanguage(language);
70
+ states(regionId: string) {
91
71
  return this.app.api.get<AddressState[]>(
92
- `Address/StateList?regionId=${regionId}&language=${language}`,
72
+ `Address/StateList?regionId=${regionId}&language=${this.app.culture}`,
93
73
  undefined,
94
74
  { defaultValue: [] }
95
75
  );
@@ -15,6 +15,13 @@
15
15
  "confirm": "Confirm",
16
16
  "confirmAction": "Are you sure you want to {0}?",
17
17
  "completeTip": "{0} completed",
18
+ "continentAF": "Africa",
19
+ "continentAN": "Antarctica",
20
+ "continentAS": "Asia",
21
+ "continentEU": "Europe",
22
+ "continentNA": "North America",
23
+ "continentOC": "Oceania",
24
+ "continentSA": "South America",
18
25
  "copy": "Copy",
19
26
  "creation": "Creation",
20
27
  "currentPassword": "Current password",
@@ -106,6 +113,18 @@
106
113
  "refresh": "Refresh",
107
114
  "refreshing": "Refreshing",
108
115
  "releaseToRefresh": "Release to refresh",
116
+ "regionAU": "Australia",
117
+ "regionCA": "Canada",
118
+ "regionCN": "Mainland China",
119
+ "regionDE": "Germany",
120
+ "regionFR": "France",
121
+ "regionGB": "United Kingdom",
122
+ "regionHK": "Hong Kong, China",
123
+ "regionIE": "Ireland",
124
+ "regionJP": "Japan",
125
+ "regionNZ": "New Zealand",
126
+ "regionSG": "Singapore",
127
+ "regionUS": "United States",
109
128
  "reloginTip": "Please enter your password, resubmit the data after successful login",
110
129
  "remove": "Remove",
111
130
  "renew": "Renew",
@@ -15,6 +15,13 @@
15
15
  "confirm": "确认",
16
16
  "confirmAction": "确定要{0}吗?",
17
17
  "completeTip": "已完成 {0}",
18
+ "continentAF": "非洲",
19
+ "continentAN": "南极洲",
20
+ "continentAS": "亚洲",
21
+ "continentEU": "欧洲",
22
+ "continentNA": "北美洲",
23
+ "continentOC": "大洋洲",
24
+ "continentSA": "南美洲",
18
25
  "copy": "复制",
19
26
  "creation": "登记时间",
20
27
  "currentPassword": "当前密码",
@@ -105,6 +112,18 @@
105
112
  "record": "记录",
106
113
  "refresh": "刷新",
107
114
  "refreshing": "正在刷新",
115
+ "regionAU": "澳大利亚",
116
+ "regionCA": "加拿大",
117
+ "regionCN": "中国大陆",
118
+ "regionDE": "德国",
119
+ "regionFR": "法国",
120
+ "regionGB": "英国",
121
+ "regionHK": "中国香港",
122
+ "regionIE": "爱尔兰",
123
+ "regionJP": "日本",
124
+ "regionNZ": "新西兰",
125
+ "regionSG": "新加坡",
126
+ "regionUS": "美国",
108
127
  "releaseToRefresh": "释放刷新",
109
128
  "reloginTip": "请输入您的登录密码,登录成功后请重新提交数据",
110
129
  "remove": "移除",
@@ -15,6 +15,13 @@
15
15
  "confirm": "確認",
16
16
  "confirmAction": "確定要{0}嗎?",
17
17
  "completeTip": "已完成 {0}",
18
+ "continentAF": "非洲",
19
+ "continentAN": "南極洲",
20
+ "continentAS": "亞洲",
21
+ "continentEU": "歐洲",
22
+ "continentNA": "北美洲",
23
+ "continentOC": "大洋洲",
24
+ "continentSA": "南美洲",
18
25
  "copy": "複製",
19
26
  "creation": "登記時間",
20
27
  "currentPassword": "當前密碼",
@@ -105,6 +112,18 @@
105
112
  "record": "記錄",
106
113
  "refresh": "刷新",
107
114
  "refreshing": "正在刷新",
115
+ "regionAU": "澳大利亞",
116
+ "regionCA": "加拿大",
117
+ "regionCN": "中國大陸",
118
+ "regionDE": "德國",
119
+ "regionFR": "法國",
120
+ "regionGB": "英國",
121
+ "regionHK": "中國香港",
122
+ "regionIE": "愛爾蘭",
123
+ "regionJP": "日本",
124
+ "regionNZ": "新西蘭",
125
+ "regionSG": "新加坡",
126
+ "regionUS": "美國",
108
127
  "releaseToRefresh": "釋放刷新",
109
128
  "reloginTip": "請輸入您的登錄密碼,登錄成功後請重新提交數據",
110
129
  "remove": "移除",
@@ -1,21 +0,0 @@
1
- {
2
- "continentAF": "Africa",
3
- "continentAN": "Antarctica",
4
- "continentAS": "Asia",
5
- "continentEU": "Europe",
6
- "continentNA": "North America",
7
- "continentOC": "Oceania",
8
- "continentSA": "South America",
9
- "regionAU": "Australia",
10
- "regionCA": "Canada",
11
- "regionCN": "Mainland China",
12
- "regionDE": "Germany",
13
- "regionFR": "France",
14
- "regionGB": "United Kingdom",
15
- "regionHK": "Hong Kong, China",
16
- "regionIE": "Ireland",
17
- "regionJP": "Japan",
18
- "regionNZ": "New Zealand",
19
- "regionSG": "Singapore",
20
- "regionUS": "United States"
21
- }
@@ -1,21 +0,0 @@
1
- {
2
- "continentAF": "非洲",
3
- "continentAN": "南极洲",
4
- "continentAS": "亚洲",
5
- "continentEU": "欧洲",
6
- "continentNA": "北美洲",
7
- "continentOC": "大洋洲",
8
- "continentSA": "南美洲",
9
- "regionAU": "澳大利亚",
10
- "regionCA": "加拿大",
11
- "regionCN": "中国大陆",
12
- "regionDE": "德国",
13
- "regionFR": "法国",
14
- "regionGB": "英国",
15
- "regionHK": "中国香港",
16
- "regionIE": "爱尔兰",
17
- "regionJP": "日本",
18
- "regionNZ": "新西兰",
19
- "regionSG": "新加坡",
20
- "regionUS": "美国"
21
- }
@@ -1,21 +0,0 @@
1
- {
2
- "continentAF": "非洲",
3
- "continentAN": "南極洲",
4
- "continentAS": "亞洲",
5
- "continentEU": "歐洲",
6
- "continentNA": "北美洲",
7
- "continentOC": "大洋洲",
8
- "continentSA": "南美洲",
9
- "regionAU": "澳大利亞",
10
- "regionCA": "加拿大",
11
- "regionCN": "中國大陸",
12
- "regionDE": "德國",
13
- "regionFR": "法國",
14
- "regionGB": "英國",
15
- "regionHK": "中國香港",
16
- "regionIE": "愛爾蘭",
17
- "regionJP": "日本",
18
- "regionNZ": "新西蘭",
19
- "regionSG": "新加坡",
20
- "regionUS": "美國"
21
- }