@etsoo/appscript 1.1.0 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/app/CoreApp.d.ts +31 -8
- package/lib/cjs/app/CoreApp.js +32 -1
- package/lib/mjs/app/CoreApp.d.ts +31 -8
- package/lib/mjs/app/CoreApp.js +32 -1
- package/package.json +3 -3
- package/src/app/CoreApp.ts +66 -10
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { INotifier } from '@etsoo/notificationbase';
|
|
1
|
+
import { INotifier, NotificationCallProps } from '@etsoo/notificationbase';
|
|
2
2
|
import { ApiDataError, IApi, IPData } from '@etsoo/restclient';
|
|
3
3
|
import { DataTypes, DateUtils } from '@etsoo/shared';
|
|
4
4
|
import { AddressRegion } from '../address/AddressRegion';
|
|
@@ -14,7 +14,7 @@ export interface IDetectIPCallback {
|
|
|
14
14
|
/**
|
|
15
15
|
* Core application interface
|
|
16
16
|
*/
|
|
17
|
-
export interface ICoreApp<S extends IAppSettings, N> {
|
|
17
|
+
export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallProps> {
|
|
18
18
|
/**
|
|
19
19
|
* Settings
|
|
20
20
|
*/
|
|
@@ -26,7 +26,11 @@ export interface ICoreApp<S extends IAppSettings, N> {
|
|
|
26
26
|
/**
|
|
27
27
|
* Notifier
|
|
28
28
|
*/
|
|
29
|
-
readonly notifier: INotifier<N>;
|
|
29
|
+
readonly notifier: INotifier<N, C>;
|
|
30
|
+
/**
|
|
31
|
+
* Label delegate
|
|
32
|
+
*/
|
|
33
|
+
readonly labelDelegate: <T extends DataTypes.SimpleType = string>(key: string) => T | undefined;
|
|
30
34
|
/**
|
|
31
35
|
* Culture, like zh-CN
|
|
32
36
|
*/
|
|
@@ -39,6 +43,10 @@ export interface ICoreApp<S extends IAppSettings, N> {
|
|
|
39
43
|
* Country or region, like CN
|
|
40
44
|
*/
|
|
41
45
|
readonly region: string;
|
|
46
|
+
/**
|
|
47
|
+
* Is current authorized
|
|
48
|
+
*/
|
|
49
|
+
readonly authorized: boolean;
|
|
42
50
|
/**
|
|
43
51
|
* IP data
|
|
44
52
|
*/
|
|
@@ -145,6 +153,10 @@ export interface ICoreApp<S extends IAppSettings, N> {
|
|
|
145
153
|
* @returns Transformed url
|
|
146
154
|
*/
|
|
147
155
|
transformUrl(url: string): string;
|
|
156
|
+
/**
|
|
157
|
+
* Try login, returning false means is loading
|
|
158
|
+
*/
|
|
159
|
+
tryLogin(): boolean;
|
|
148
160
|
/**
|
|
149
161
|
* User login
|
|
150
162
|
* @param user User data
|
|
@@ -160,7 +172,7 @@ export interface ICoreApp<S extends IAppSettings, N> {
|
|
|
160
172
|
/**
|
|
161
173
|
* Core application
|
|
162
174
|
*/
|
|
163
|
-
export declare abstract class CoreApp<S extends IAppSettings, N> implements ICoreApp<S, N> {
|
|
175
|
+
export declare abstract class CoreApp<S extends IAppSettings, N, C extends NotificationCallProps> implements ICoreApp<S, N, C> {
|
|
164
176
|
/**
|
|
165
177
|
* Settings
|
|
166
178
|
*/
|
|
@@ -172,7 +184,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N> implements ICor
|
|
|
172
184
|
/**
|
|
173
185
|
* Notifier
|
|
174
186
|
*/
|
|
175
|
-
readonly notifier: INotifier<N>;
|
|
187
|
+
readonly notifier: INotifier<N, C>;
|
|
176
188
|
private _culture;
|
|
177
189
|
/**
|
|
178
190
|
* Culture, like zh-CN
|
|
@@ -188,6 +200,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N> implements ICor
|
|
|
188
200
|
* Country or region, like CN
|
|
189
201
|
*/
|
|
190
202
|
get region(): string;
|
|
203
|
+
/**
|
|
204
|
+
* Label delegate
|
|
205
|
+
*/
|
|
206
|
+
get labelDelegate(): <T extends DataTypes.SimpleType = string>(key: string) => T | undefined;
|
|
191
207
|
/**
|
|
192
208
|
* IP data
|
|
193
209
|
*/
|
|
@@ -205,13 +221,20 @@ export declare abstract class CoreApp<S extends IAppSettings, N> implements ICor
|
|
|
205
221
|
* Search input element
|
|
206
222
|
*/
|
|
207
223
|
searchInput?: HTMLInputElement;
|
|
224
|
+
private _authorized;
|
|
225
|
+
/**
|
|
226
|
+
* Is current authorized
|
|
227
|
+
*/
|
|
228
|
+
get authorized(): boolean;
|
|
229
|
+
private set authorized(value);
|
|
230
|
+
private _isTryingLogin;
|
|
208
231
|
/**
|
|
209
232
|
* Protected constructor
|
|
210
233
|
* @param settings Settings
|
|
211
234
|
* @param api API
|
|
212
235
|
* @param notifier Notifier
|
|
213
236
|
*/
|
|
214
|
-
protected constructor(settings: S, api: IApi, notifier: INotifier<N>);
|
|
237
|
+
protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>);
|
|
215
238
|
/**
|
|
216
239
|
* Alert action result
|
|
217
240
|
* @param result Action result
|
|
@@ -318,9 +341,9 @@ export declare abstract class CoreApp<S extends IAppSettings, N> implements ICor
|
|
|
318
341
|
*/
|
|
319
342
|
transformUrl(url: string): string;
|
|
320
343
|
/**
|
|
321
|
-
* Try login
|
|
344
|
+
* Try login, returning false means is loading
|
|
322
345
|
*/
|
|
323
|
-
|
|
346
|
+
tryLogin(): boolean;
|
|
324
347
|
/**
|
|
325
348
|
* User login
|
|
326
349
|
* @param user User data
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -19,6 +19,8 @@ class CoreApp {
|
|
|
19
19
|
* Response token header field name
|
|
20
20
|
*/
|
|
21
21
|
this.headerTokenField = 'SmartERPRefreshToken';
|
|
22
|
+
this._authorized = false;
|
|
23
|
+
this._isTryingLogin = false;
|
|
22
24
|
// onRequest, show loading or not, rewrite the property to override default action
|
|
23
25
|
api.onRequest = (data) => {
|
|
24
26
|
if (data.showLoading == null || data.showLoading) {
|
|
@@ -73,6 +75,21 @@ class CoreApp {
|
|
|
73
75
|
get region() {
|
|
74
76
|
return this._region;
|
|
75
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Label delegate
|
|
80
|
+
*/
|
|
81
|
+
get labelDelegate() {
|
|
82
|
+
return this.get.bind(this);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Is current authorized
|
|
86
|
+
*/
|
|
87
|
+
get authorized() {
|
|
88
|
+
return this._authorized;
|
|
89
|
+
}
|
|
90
|
+
set authorized(value) {
|
|
91
|
+
this._authorized = value;
|
|
92
|
+
}
|
|
76
93
|
/**
|
|
77
94
|
* Alert action result
|
|
78
95
|
* @param result Action result
|
|
@@ -87,10 +104,15 @@ class CoreApp {
|
|
|
87
104
|
* @param keep Keep in local storage or not
|
|
88
105
|
*/
|
|
89
106
|
authorize(token, refreshToken, keep = false) {
|
|
107
|
+
// State, when token is null, means logout
|
|
108
|
+
this.authorized = token != null;
|
|
109
|
+
// Token
|
|
90
110
|
this.api.authorize(this.settings.authScheme, token);
|
|
91
111
|
// Cover the current value
|
|
92
112
|
shared_1.StorageUtils.setLocalData(this.headerTokenField, keep ? refreshToken : undefined);
|
|
93
113
|
shared_1.StorageUtils.setSessionData(this.headerTokenField, keep ? undefined : refreshToken);
|
|
114
|
+
// Reset tryLogin state
|
|
115
|
+
this._isTryingLogin = false;
|
|
94
116
|
}
|
|
95
117
|
/**
|
|
96
118
|
* Change country or region
|
|
@@ -195,7 +217,7 @@ class CoreApp {
|
|
|
195
217
|
* @returns Result
|
|
196
218
|
*/
|
|
197
219
|
formatMoney(input, isInteger = false, options) {
|
|
198
|
-
return shared_1.NumberUtils.formatMoney(input, this.
|
|
220
|
+
return shared_1.NumberUtils.formatMoney(input, this.currency, this.culture, isInteger, options);
|
|
199
221
|
}
|
|
200
222
|
/**
|
|
201
223
|
* Format number
|
|
@@ -306,6 +328,15 @@ class CoreApp {
|
|
|
306
328
|
// To /a/b/../ => /a
|
|
307
329
|
return pathname.endsWith('/') ? pathname + url : pathname + '/' + url;
|
|
308
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* Try login, returning false means is loading
|
|
333
|
+
*/
|
|
334
|
+
tryLogin() {
|
|
335
|
+
if (this._isTryingLogin)
|
|
336
|
+
return false;
|
|
337
|
+
this._isTryingLogin = true;
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
309
340
|
/**
|
|
310
341
|
* User login
|
|
311
342
|
* @param user User data
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { INotifier } from '@etsoo/notificationbase';
|
|
1
|
+
import { INotifier, NotificationCallProps } from '@etsoo/notificationbase';
|
|
2
2
|
import { ApiDataError, IApi, IPData } from '@etsoo/restclient';
|
|
3
3
|
import { DataTypes, DateUtils } from '@etsoo/shared';
|
|
4
4
|
import { AddressRegion } from '../address/AddressRegion';
|
|
@@ -14,7 +14,7 @@ export interface IDetectIPCallback {
|
|
|
14
14
|
/**
|
|
15
15
|
* Core application interface
|
|
16
16
|
*/
|
|
17
|
-
export interface ICoreApp<S extends IAppSettings, N> {
|
|
17
|
+
export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallProps> {
|
|
18
18
|
/**
|
|
19
19
|
* Settings
|
|
20
20
|
*/
|
|
@@ -26,7 +26,11 @@ export interface ICoreApp<S extends IAppSettings, N> {
|
|
|
26
26
|
/**
|
|
27
27
|
* Notifier
|
|
28
28
|
*/
|
|
29
|
-
readonly notifier: INotifier<N>;
|
|
29
|
+
readonly notifier: INotifier<N, C>;
|
|
30
|
+
/**
|
|
31
|
+
* Label delegate
|
|
32
|
+
*/
|
|
33
|
+
readonly labelDelegate: <T extends DataTypes.SimpleType = string>(key: string) => T | undefined;
|
|
30
34
|
/**
|
|
31
35
|
* Culture, like zh-CN
|
|
32
36
|
*/
|
|
@@ -39,6 +43,10 @@ export interface ICoreApp<S extends IAppSettings, N> {
|
|
|
39
43
|
* Country or region, like CN
|
|
40
44
|
*/
|
|
41
45
|
readonly region: string;
|
|
46
|
+
/**
|
|
47
|
+
* Is current authorized
|
|
48
|
+
*/
|
|
49
|
+
readonly authorized: boolean;
|
|
42
50
|
/**
|
|
43
51
|
* IP data
|
|
44
52
|
*/
|
|
@@ -145,6 +153,10 @@ export interface ICoreApp<S extends IAppSettings, N> {
|
|
|
145
153
|
* @returns Transformed url
|
|
146
154
|
*/
|
|
147
155
|
transformUrl(url: string): string;
|
|
156
|
+
/**
|
|
157
|
+
* Try login, returning false means is loading
|
|
158
|
+
*/
|
|
159
|
+
tryLogin(): boolean;
|
|
148
160
|
/**
|
|
149
161
|
* User login
|
|
150
162
|
* @param user User data
|
|
@@ -160,7 +172,7 @@ export interface ICoreApp<S extends IAppSettings, N> {
|
|
|
160
172
|
/**
|
|
161
173
|
* Core application
|
|
162
174
|
*/
|
|
163
|
-
export declare abstract class CoreApp<S extends IAppSettings, N> implements ICoreApp<S, N> {
|
|
175
|
+
export declare abstract class CoreApp<S extends IAppSettings, N, C extends NotificationCallProps> implements ICoreApp<S, N, C> {
|
|
164
176
|
/**
|
|
165
177
|
* Settings
|
|
166
178
|
*/
|
|
@@ -172,7 +184,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N> implements ICor
|
|
|
172
184
|
/**
|
|
173
185
|
* Notifier
|
|
174
186
|
*/
|
|
175
|
-
readonly notifier: INotifier<N>;
|
|
187
|
+
readonly notifier: INotifier<N, C>;
|
|
176
188
|
private _culture;
|
|
177
189
|
/**
|
|
178
190
|
* Culture, like zh-CN
|
|
@@ -188,6 +200,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N> implements ICor
|
|
|
188
200
|
* Country or region, like CN
|
|
189
201
|
*/
|
|
190
202
|
get region(): string;
|
|
203
|
+
/**
|
|
204
|
+
* Label delegate
|
|
205
|
+
*/
|
|
206
|
+
get labelDelegate(): <T extends DataTypes.SimpleType = string>(key: string) => T | undefined;
|
|
191
207
|
/**
|
|
192
208
|
* IP data
|
|
193
209
|
*/
|
|
@@ -205,13 +221,20 @@ export declare abstract class CoreApp<S extends IAppSettings, N> implements ICor
|
|
|
205
221
|
* Search input element
|
|
206
222
|
*/
|
|
207
223
|
searchInput?: HTMLInputElement;
|
|
224
|
+
private _authorized;
|
|
225
|
+
/**
|
|
226
|
+
* Is current authorized
|
|
227
|
+
*/
|
|
228
|
+
get authorized(): boolean;
|
|
229
|
+
private set authorized(value);
|
|
230
|
+
private _isTryingLogin;
|
|
208
231
|
/**
|
|
209
232
|
* Protected constructor
|
|
210
233
|
* @param settings Settings
|
|
211
234
|
* @param api API
|
|
212
235
|
* @param notifier Notifier
|
|
213
236
|
*/
|
|
214
|
-
protected constructor(settings: S, api: IApi, notifier: INotifier<N>);
|
|
237
|
+
protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>);
|
|
215
238
|
/**
|
|
216
239
|
* Alert action result
|
|
217
240
|
* @param result Action result
|
|
@@ -318,9 +341,9 @@ export declare abstract class CoreApp<S extends IAppSettings, N> implements ICor
|
|
|
318
341
|
*/
|
|
319
342
|
transformUrl(url: string): string;
|
|
320
343
|
/**
|
|
321
|
-
* Try login
|
|
344
|
+
* Try login, returning false means is loading
|
|
322
345
|
*/
|
|
323
|
-
|
|
346
|
+
tryLogin(): boolean;
|
|
324
347
|
/**
|
|
325
348
|
* User login
|
|
326
349
|
* @param user User data
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -16,6 +16,8 @@ export class CoreApp {
|
|
|
16
16
|
* Response token header field name
|
|
17
17
|
*/
|
|
18
18
|
this.headerTokenField = 'SmartERPRefreshToken';
|
|
19
|
+
this._authorized = false;
|
|
20
|
+
this._isTryingLogin = false;
|
|
19
21
|
// onRequest, show loading or not, rewrite the property to override default action
|
|
20
22
|
api.onRequest = (data) => {
|
|
21
23
|
if (data.showLoading == null || data.showLoading) {
|
|
@@ -70,6 +72,21 @@ export class CoreApp {
|
|
|
70
72
|
get region() {
|
|
71
73
|
return this._region;
|
|
72
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Label delegate
|
|
77
|
+
*/
|
|
78
|
+
get labelDelegate() {
|
|
79
|
+
return this.get.bind(this);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Is current authorized
|
|
83
|
+
*/
|
|
84
|
+
get authorized() {
|
|
85
|
+
return this._authorized;
|
|
86
|
+
}
|
|
87
|
+
set authorized(value) {
|
|
88
|
+
this._authorized = value;
|
|
89
|
+
}
|
|
73
90
|
/**
|
|
74
91
|
* Alert action result
|
|
75
92
|
* @param result Action result
|
|
@@ -84,10 +101,15 @@ export class CoreApp {
|
|
|
84
101
|
* @param keep Keep in local storage or not
|
|
85
102
|
*/
|
|
86
103
|
authorize(token, refreshToken, keep = false) {
|
|
104
|
+
// State, when token is null, means logout
|
|
105
|
+
this.authorized = token != null;
|
|
106
|
+
// Token
|
|
87
107
|
this.api.authorize(this.settings.authScheme, token);
|
|
88
108
|
// Cover the current value
|
|
89
109
|
StorageUtils.setLocalData(this.headerTokenField, keep ? refreshToken : undefined);
|
|
90
110
|
StorageUtils.setSessionData(this.headerTokenField, keep ? undefined : refreshToken);
|
|
111
|
+
// Reset tryLogin state
|
|
112
|
+
this._isTryingLogin = false;
|
|
91
113
|
}
|
|
92
114
|
/**
|
|
93
115
|
* Change country or region
|
|
@@ -192,7 +214,7 @@ export class CoreApp {
|
|
|
192
214
|
* @returns Result
|
|
193
215
|
*/
|
|
194
216
|
formatMoney(input, isInteger = false, options) {
|
|
195
|
-
return NumberUtils.formatMoney(input, this.
|
|
217
|
+
return NumberUtils.formatMoney(input, this.currency, this.culture, isInteger, options);
|
|
196
218
|
}
|
|
197
219
|
/**
|
|
198
220
|
* Format number
|
|
@@ -303,6 +325,15 @@ export class CoreApp {
|
|
|
303
325
|
// To /a/b/../ => /a
|
|
304
326
|
return pathname.endsWith('/') ? pathname + url : pathname + '/' + url;
|
|
305
327
|
}
|
|
328
|
+
/**
|
|
329
|
+
* Try login, returning false means is loading
|
|
330
|
+
*/
|
|
331
|
+
tryLogin() {
|
|
332
|
+
if (this._isTryingLogin)
|
|
333
|
+
return false;
|
|
334
|
+
this._isTryingLogin = true;
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
306
337
|
/**
|
|
307
338
|
* User login
|
|
308
339
|
* @param user User data
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/appscript",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "Applications shared TypeScript framework",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
},
|
|
48
48
|
"homepage": "https://github.com/ETSOO/NotificationBase#readme",
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@etsoo/notificationbase": "^1.0.
|
|
50
|
+
"@etsoo/notificationbase": "^1.0.79",
|
|
51
51
|
"@etsoo/restclient": "^1.0.51",
|
|
52
|
-
"@etsoo/shared": "^1.0.
|
|
52
|
+
"@etsoo/shared": "^1.0.46"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@babel/cli": "^7.15.7",
|
package/src/app/CoreApp.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { INotifier } from '@etsoo/notificationbase';
|
|
1
|
+
import { INotifier, NotificationCallProps } from '@etsoo/notificationbase';
|
|
2
2
|
import { ApiDataError, IApi, IPData } from '@etsoo/restclient';
|
|
3
3
|
import {
|
|
4
4
|
DataTypes,
|
|
@@ -23,7 +23,11 @@ export interface IDetectIPCallback {
|
|
|
23
23
|
/**
|
|
24
24
|
* Core application interface
|
|
25
25
|
*/
|
|
26
|
-
export interface ICoreApp<
|
|
26
|
+
export interface ICoreApp<
|
|
27
|
+
S extends IAppSettings,
|
|
28
|
+
N,
|
|
29
|
+
C extends NotificationCallProps
|
|
30
|
+
> {
|
|
27
31
|
/**
|
|
28
32
|
* Settings
|
|
29
33
|
*/
|
|
@@ -37,7 +41,14 @@ export interface ICoreApp<S extends IAppSettings, N> {
|
|
|
37
41
|
/**
|
|
38
42
|
* Notifier
|
|
39
43
|
*/
|
|
40
|
-
readonly notifier: INotifier<N>;
|
|
44
|
+
readonly notifier: INotifier<N, C>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Label delegate
|
|
48
|
+
*/
|
|
49
|
+
readonly labelDelegate: <T extends DataTypes.SimpleType = string>(
|
|
50
|
+
key: string
|
|
51
|
+
) => T | undefined;
|
|
41
52
|
|
|
42
53
|
/**
|
|
43
54
|
* Culture, like zh-CN
|
|
@@ -54,6 +65,11 @@ export interface ICoreApp<S extends IAppSettings, N> {
|
|
|
54
65
|
*/
|
|
55
66
|
readonly region: string;
|
|
56
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Is current authorized
|
|
70
|
+
*/
|
|
71
|
+
readonly authorized: boolean;
|
|
72
|
+
|
|
57
73
|
/**
|
|
58
74
|
* IP data
|
|
59
75
|
*/
|
|
@@ -188,6 +204,11 @@ export interface ICoreApp<S extends IAppSettings, N> {
|
|
|
188
204
|
*/
|
|
189
205
|
transformUrl(url: string): string;
|
|
190
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Try login, returning false means is loading
|
|
209
|
+
*/
|
|
210
|
+
tryLogin(): boolean;
|
|
211
|
+
|
|
191
212
|
/**
|
|
192
213
|
* User login
|
|
193
214
|
* @param user User data
|
|
@@ -205,8 +226,11 @@ export interface ICoreApp<S extends IAppSettings, N> {
|
|
|
205
226
|
/**
|
|
206
227
|
* Core application
|
|
207
228
|
*/
|
|
208
|
-
export abstract class CoreApp<
|
|
209
|
-
|
|
229
|
+
export abstract class CoreApp<
|
|
230
|
+
S extends IAppSettings,
|
|
231
|
+
N,
|
|
232
|
+
C extends NotificationCallProps
|
|
233
|
+
> implements ICoreApp<S, N, C>
|
|
210
234
|
{
|
|
211
235
|
/**
|
|
212
236
|
* Settings
|
|
@@ -221,7 +245,7 @@ export abstract class CoreApp<S extends IAppSettings, N>
|
|
|
221
245
|
/**
|
|
222
246
|
* Notifier
|
|
223
247
|
*/
|
|
224
|
-
readonly notifier: INotifier<N>;
|
|
248
|
+
readonly notifier: INotifier<N, C>;
|
|
225
249
|
|
|
226
250
|
private _culture!: string;
|
|
227
251
|
/**
|
|
@@ -247,6 +271,13 @@ export abstract class CoreApp<S extends IAppSettings, N>
|
|
|
247
271
|
return this._region;
|
|
248
272
|
}
|
|
249
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Label delegate
|
|
276
|
+
*/
|
|
277
|
+
get labelDelegate() {
|
|
278
|
+
return this.get.bind(this);
|
|
279
|
+
}
|
|
280
|
+
|
|
250
281
|
/**
|
|
251
282
|
* IP data
|
|
252
283
|
*/
|
|
@@ -270,13 +301,27 @@ export abstract class CoreApp<S extends IAppSettings, N>
|
|
|
270
301
|
*/
|
|
271
302
|
searchInput?: HTMLInputElement;
|
|
272
303
|
|
|
304
|
+
private _authorized: boolean = false;
|
|
305
|
+
/**
|
|
306
|
+
* Is current authorized
|
|
307
|
+
*/
|
|
308
|
+
get authorized() {
|
|
309
|
+
return this._authorized;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
private set authorized(value: boolean) {
|
|
313
|
+
this._authorized = value;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
private _isTryingLogin = false;
|
|
317
|
+
|
|
273
318
|
/**
|
|
274
319
|
* Protected constructor
|
|
275
320
|
* @param settings Settings
|
|
276
321
|
* @param api API
|
|
277
322
|
* @param notifier Notifier
|
|
278
323
|
*/
|
|
279
|
-
protected constructor(settings: S, api: IApi, notifier: INotifier<N>) {
|
|
324
|
+
protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>) {
|
|
280
325
|
// onRequest, show loading or not, rewrite the property to override default action
|
|
281
326
|
api.onRequest = (data) => {
|
|
282
327
|
if (data.showLoading == null || data.showLoading) {
|
|
@@ -334,6 +379,10 @@ export abstract class CoreApp<S extends IAppSettings, N>
|
|
|
334
379
|
* @param keep Keep in local storage or not
|
|
335
380
|
*/
|
|
336
381
|
authorize(token?: string, refreshToken?: string, keep: boolean = false) {
|
|
382
|
+
// State, when token is null, means logout
|
|
383
|
+
this.authorized = token != null;
|
|
384
|
+
|
|
385
|
+
// Token
|
|
337
386
|
this.api.authorize(this.settings.authScheme, token);
|
|
338
387
|
|
|
339
388
|
// Cover the current value
|
|
@@ -345,6 +394,9 @@ export abstract class CoreApp<S extends IAppSettings, N>
|
|
|
345
394
|
this.headerTokenField,
|
|
346
395
|
keep ? undefined : refreshToken
|
|
347
396
|
);
|
|
397
|
+
|
|
398
|
+
// Reset tryLogin state
|
|
399
|
+
this._isTryingLogin = false;
|
|
348
400
|
}
|
|
349
401
|
|
|
350
402
|
/**
|
|
@@ -477,7 +529,7 @@ export abstract class CoreApp<S extends IAppSettings, N>
|
|
|
477
529
|
) {
|
|
478
530
|
return NumberUtils.formatMoney(
|
|
479
531
|
input,
|
|
480
|
-
this.
|
|
532
|
+
this.currency,
|
|
481
533
|
this.culture,
|
|
482
534
|
isInteger,
|
|
483
535
|
options
|
|
@@ -611,9 +663,13 @@ export abstract class CoreApp<S extends IAppSettings, N>
|
|
|
611
663
|
}
|
|
612
664
|
|
|
613
665
|
/**
|
|
614
|
-
* Try login
|
|
666
|
+
* Try login, returning false means is loading
|
|
615
667
|
*/
|
|
616
|
-
|
|
668
|
+
tryLogin() {
|
|
669
|
+
if (this._isTryingLogin) return false;
|
|
670
|
+
this._isTryingLogin = true;
|
|
671
|
+
return true;
|
|
672
|
+
}
|
|
617
673
|
|
|
618
674
|
/**
|
|
619
675
|
* User login
|