@etsoo/appscript 1.1.15 → 1.1.19

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.
@@ -22,5 +22,5 @@ test('Tests for ActionResultError.format', () => {
22
22
 
23
23
  // Assert
24
24
  expect(error.name).toBe('ActionResultError');
25
- expect(error.message).toBe(`${message}(${status}, ApiError)`);
25
+ expect(error.message).toBe(`${message} (${status}, ApiError)`);
26
26
  });
@@ -109,6 +109,17 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
109
109
  * @returns Result
110
110
  */
111
111
  formatNumber(input?: number | bigint, options?: Intl.NumberFormatOptions): string | undefined;
112
+ /**
113
+ * Format result text
114
+ * @param result Action result
115
+ * @param forceToLocal Force to local labels
116
+ */
117
+ formatResult(result: IActionResult, forceToLocal?: boolean): void;
118
+ /**
119
+ * Fresh countdown UI
120
+ * @param callback Callback
121
+ */
122
+ freshCountdownUI(callback: () => void): void;
112
123
  /**
113
124
  * Get culture resource
114
125
  * @param key key
@@ -147,11 +158,6 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
147
158
  * Callback where exit a page
148
159
  */
149
160
  pageExit(): void;
150
- /**
151
- * Fresh countdown UI
152
- * @param callback Callback
153
- */
154
- freshCountdownUI(callback: () => void): void;
155
161
  /**
156
162
  * Refresh token
157
163
  */
@@ -303,6 +309,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
303
309
  * @returns Error message
304
310
  */
305
311
  formatError(error: ApiDataError): string;
312
+ /**
313
+ * Format result text
314
+ * @param result Action result
315
+ * @param forceToLocal Force to local labels
316
+ */
317
+ formatResult(result: IActionResult, forceToLocal?: boolean): void;
306
318
  /**
307
319
  * Get culture resource
308
320
  * @param key key
@@ -98,6 +98,7 @@ class CoreApp {
98
98
  * @param result Action result
99
99
  */
100
100
  alertResult(result) {
101
+ this.formatResult(result);
101
102
  this.notifier.alert(ActionResultError_1.ActionResultError.format(result));
102
103
  }
103
104
  /**
@@ -244,6 +245,17 @@ class CoreApp {
244
245
  formatError(error) {
245
246
  return error.toString();
246
247
  }
248
+ /**
249
+ * Format result text
250
+ * @param result Action result
251
+ * @param forceToLocal Force to local labels
252
+ */
253
+ formatResult(result, forceToLocal) {
254
+ if ((result.title == null || forceToLocal) && result.type != null) {
255
+ const key = shared_1.Utils.formatLowerLetter(result.type);
256
+ result.title = this.get(key);
257
+ }
258
+ }
247
259
  /**
248
260
  * Get culture resource
249
261
  * @param key key
@@ -28,7 +28,7 @@ class ActionResultError extends Error {
28
28
  addtions.push(result.status);
29
29
  if (result.type && result.type != 'about:blank')
30
30
  addtions.push(result.type);
31
- var add = addtions.length > 0 ? `(${addtions.join(', ')})` : '';
31
+ var add = addtions.length > 0 ? ` (${addtions.join(', ')})` : '';
32
32
  return `${result.title || 'Error'}${add}`;
33
33
  }
34
34
  }
@@ -40,11 +40,11 @@ export interface IActionResult<D extends IResultData = IResultData> {
40
40
  /**
41
41
  * Title
42
42
  */
43
- readonly title?: string;
43
+ title?: string;
44
44
  /**
45
45
  * Detail
46
46
  */
47
- readonly detail?: string;
47
+ detail?: string;
48
48
  /**
49
49
  * Trace id
50
50
  */
@@ -109,6 +109,17 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
109
109
  * @returns Result
110
110
  */
111
111
  formatNumber(input?: number | bigint, options?: Intl.NumberFormatOptions): string | undefined;
112
+ /**
113
+ * Format result text
114
+ * @param result Action result
115
+ * @param forceToLocal Force to local labels
116
+ */
117
+ formatResult(result: IActionResult, forceToLocal?: boolean): void;
118
+ /**
119
+ * Fresh countdown UI
120
+ * @param callback Callback
121
+ */
122
+ freshCountdownUI(callback: () => void): void;
112
123
  /**
113
124
  * Get culture resource
114
125
  * @param key key
@@ -147,11 +158,6 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
147
158
  * Callback where exit a page
148
159
  */
149
160
  pageExit(): void;
150
- /**
151
- * Fresh countdown UI
152
- * @param callback Callback
153
- */
154
- freshCountdownUI(callback: () => void): void;
155
161
  /**
156
162
  * Refresh token
157
163
  */
@@ -303,6 +309,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
303
309
  * @returns Error message
304
310
  */
305
311
  formatError(error: ApiDataError): string;
312
+ /**
313
+ * Format result text
314
+ * @param result Action result
315
+ * @param forceToLocal Force to local labels
316
+ */
317
+ formatResult(result: IActionResult, forceToLocal?: boolean): void;
306
318
  /**
307
319
  * Get culture resource
308
320
  * @param key key
@@ -1,4 +1,4 @@
1
- import { DateUtils, DomUtils, NumberUtils, StorageUtils } from '@etsoo/shared';
1
+ import { DateUtils, DomUtils, NumberUtils, StorageUtils, Utils } from '@etsoo/shared';
2
2
  import { AddressRegion } from '../address/AddressRegion';
3
3
  import { ActionResultError } from '../result/ActionResultError';
4
4
  /**
@@ -95,6 +95,7 @@ export class CoreApp {
95
95
  * @param result Action result
96
96
  */
97
97
  alertResult(result) {
98
+ this.formatResult(result);
98
99
  this.notifier.alert(ActionResultError.format(result));
99
100
  }
100
101
  /**
@@ -241,6 +242,17 @@ export class CoreApp {
241
242
  formatError(error) {
242
243
  return error.toString();
243
244
  }
245
+ /**
246
+ * Format result text
247
+ * @param result Action result
248
+ * @param forceToLocal Force to local labels
249
+ */
250
+ formatResult(result, forceToLocal) {
251
+ if ((result.title == null || forceToLocal) && result.type != null) {
252
+ const key = Utils.formatLowerLetter(result.type);
253
+ result.title = this.get(key);
254
+ }
255
+ }
244
256
  /**
245
257
  * Get culture resource
246
258
  * @param key key
@@ -25,7 +25,7 @@ export class ActionResultError extends Error {
25
25
  addtions.push(result.status);
26
26
  if (result.type && result.type != 'about:blank')
27
27
  addtions.push(result.type);
28
- var add = addtions.length > 0 ? `(${addtions.join(', ')})` : '';
28
+ var add = addtions.length > 0 ? ` (${addtions.join(', ')})` : '';
29
29
  return `${result.title || 'Error'}${add}`;
30
30
  }
31
31
  }
@@ -40,11 +40,11 @@ export interface IActionResult<D extends IResultData = IResultData> {
40
40
  /**
41
41
  * Title
42
42
  */
43
- readonly title?: string;
43
+ title?: string;
44
44
  /**
45
45
  * Detail
46
46
  */
47
- readonly detail?: string;
47
+ detail?: string;
48
48
  /**
49
49
  * Trace id
50
50
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.1.15",
3
+ "version": "1.1.19",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -34,22 +34,27 @@
34
34
  },
35
35
  "repository": {
36
36
  "type": "git",
37
- "url": "git+https://github.com/ETSOO/NotificationBase.git"
37
+ "url": "git+https://github.com/ETSOO/AppScript.git"
38
38
  },
39
39
  "keywords": [
40
40
  "notification",
41
- "TypeScript"
41
+ "TypeScript",
42
+ "ETSOO",
43
+ "SmartERP",
44
+ "司友云平台",
45
+ "青岛亿速思维",
46
+ "上海亿商"
42
47
  ],
43
48
  "author": "Garry Xiao",
44
49
  "license": "MIT",
45
50
  "bugs": {
46
- "url": "https://github.com/ETSOO/NotificationBase/issues"
51
+ "url": "https://github.com/ETSOO/AppScript/issues"
47
52
  },
48
- "homepage": "https://github.com/ETSOO/NotificationBase#readme",
53
+ "homepage": "https://github.com/ETSOO/AppScript#readme",
49
54
  "dependencies": {
50
- "@etsoo/notificationbase": "^1.0.87",
51
- "@etsoo/restclient": "^1.0.55",
52
- "@etsoo/shared": "^1.0.53"
55
+ "@etsoo/notificationbase": "^1.0.88",
56
+ "@etsoo/restclient": "^1.0.56",
57
+ "@etsoo/shared": "^1.0.57"
53
58
  },
54
59
  "devDependencies": {
55
60
  "@babel/cli": "^7.15.7",
@@ -63,7 +68,7 @@
63
68
  "eslint": "^8.0.1",
64
69
  "eslint-config-airbnb-base": "^14.2.1",
65
70
  "eslint-plugin-import": "^2.25.2",
66
- "jest": "^27.3.0",
71
+ "jest": "^27.3.1",
67
72
  "ts-jest": "^27.0.7",
68
73
  "typescript": "^4.4.4"
69
74
  }
@@ -5,7 +5,8 @@ import {
5
5
  DateUtils,
6
6
  DomUtils,
7
7
  NumberUtils,
8
- StorageUtils
8
+ StorageUtils,
9
+ Utils
9
10
  } from '@etsoo/shared';
10
11
  import { AddressRegion } from '../address/AddressRegion';
11
12
  import { ActionResultError } from '../result/ActionResultError';
@@ -152,6 +153,19 @@ export interface ICoreApp<
152
153
  options?: Intl.NumberFormatOptions
153
154
  ): string | undefined;
154
155
 
156
+ /**
157
+ * Format result text
158
+ * @param result Action result
159
+ * @param forceToLocal Force to local labels
160
+ */
161
+ formatResult(result: IActionResult, forceToLocal?: boolean): void;
162
+
163
+ /**
164
+ * Fresh countdown UI
165
+ * @param callback Callback
166
+ */
167
+ freshCountdownUI(callback: () => void): void;
168
+
155
169
  /**
156
170
  * Get culture resource
157
171
  * @param key key
@@ -195,12 +209,6 @@ export interface ICoreApp<
195
209
  */
196
210
  pageExit(): void;
197
211
 
198
- /**
199
- * Fresh countdown UI
200
- * @param callback Callback
201
- */
202
- freshCountdownUI(callback: () => void): void;
203
-
204
212
  /**
205
213
  * Refresh token
206
214
  */
@@ -382,6 +390,7 @@ export abstract class CoreApp<
382
390
  * @param result Action result
383
391
  */
384
392
  alertResult(result: IActionResult) {
393
+ this.formatResult(result);
385
394
  this.notifier.alert(ActionResultError.format(result));
386
395
  }
387
396
 
@@ -572,6 +581,18 @@ export abstract class CoreApp<
572
581
  return error.toString();
573
582
  }
574
583
 
584
+ /**
585
+ * Format result text
586
+ * @param result Action result
587
+ * @param forceToLocal Force to local labels
588
+ */
589
+ formatResult(result: IActionResult, forceToLocal?: boolean) {
590
+ if ((result.title == null || forceToLocal) && result.type != null) {
591
+ const key = Utils.formatLowerLetter(result.type);
592
+ result.title = this.get(key);
593
+ }
594
+ }
595
+
575
596
  /**
576
597
  * Get culture resource
577
598
  * @param key key
@@ -15,7 +15,7 @@ export class ActionResultError extends Error {
15
15
  if (result.type && result.type != 'about:blank')
16
16
  addtions.push(result.type);
17
17
 
18
- var add = addtions.length > 0 ? `(${addtions.join(', ')})` : '';
18
+ var add = addtions.length > 0 ? ` (${addtions.join(', ')})` : '';
19
19
 
20
20
  return `${result.title || 'Error'}${add}`;
21
21
  }
@@ -46,12 +46,12 @@ export interface IActionResult<D extends IResultData = IResultData> {
46
46
  /**
47
47
  * Title
48
48
  */
49
- readonly title?: string;
49
+ title?: string;
50
50
 
51
51
  /**
52
52
  * Detail
53
53
  */
54
- readonly detail?: string;
54
+ detail?: string;
55
55
 
56
56
  /**
57
57
  * Trace id