@etsoo/materialui 1.0.1
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/.eslintignore +3 -0
- package/.eslintrc.json +38 -0
- package/.gitattributes +2 -0
- package/.github/workflows/main.yml +48 -0
- package/.prettierignore +5 -0
- package/.prettierrc +6 -0
- package/LICENSE +21 -0
- package/README.md +16 -0
- package/__tests__/ComboBox.tsx +30 -0
- package/__tests__/MUGlobalTests.tsx +58 -0
- package/__tests__/NotifierMUTests.tsx +217 -0
- package/__tests__/SelectEx.tsx +26 -0
- package/__tests__/tsconfig.json +19 -0
- package/babel.config.json +11 -0
- package/lib/AuditDisplay.d.ts +33 -0
- package/lib/AuditDisplay.js +52 -0
- package/lib/AutocompleteExtendedProps.d.ts +64 -0
- package/lib/AutocompleteExtendedProps.js +1 -0
- package/lib/BackButton.d.ts +13 -0
- package/lib/BackButton.js +33 -0
- package/lib/BridgeCloseButton.d.ts +23 -0
- package/lib/BridgeCloseButton.js +32 -0
- package/lib/ButtonLink.d.ts +17 -0
- package/lib/ButtonLink.js +19 -0
- package/lib/ComboBox.d.ts +38 -0
- package/lib/ComboBox.js +108 -0
- package/lib/CountdownButton.d.ts +23 -0
- package/lib/CountdownButton.js +81 -0
- package/lib/CustomFabProps.d.ts +27 -0
- package/lib/CustomFabProps.js +1 -0
- package/lib/DataGridEx.d.ts +94 -0
- package/lib/DataGridEx.js +329 -0
- package/lib/DataGridRenderers.d.ts +22 -0
- package/lib/DataGridRenderers.js +99 -0
- package/lib/DialogButton.d.ts +54 -0
- package/lib/DialogButton.js +45 -0
- package/lib/DnDList.d.ts +87 -0
- package/lib/DnDList.js +153 -0
- package/lib/DraggablePaperComponent.d.ts +8 -0
- package/lib/DraggablePaperComponent.js +12 -0
- package/lib/EmailInput.d.ts +11 -0
- package/lib/EmailInput.js +15 -0
- package/lib/FabBox.d.ts +21 -0
- package/lib/FabBox.js +31 -0
- package/lib/FlexBox.d.ts +14 -0
- package/lib/FlexBox.js +18 -0
- package/lib/GridDataFormat.d.ts +10 -0
- package/lib/GridDataFormat.js +43 -0
- package/lib/IconButtonLink.d.ts +17 -0
- package/lib/IconButtonLink.js +16 -0
- package/lib/InputField.d.ts +21 -0
- package/lib/InputField.js +39 -0
- package/lib/ItemList.d.ts +56 -0
- package/lib/ItemList.js +69 -0
- package/lib/ListItemRightIcon.d.ts +4 -0
- package/lib/ListItemRightIcon.js +8 -0
- package/lib/ListMoreDisplay.d.ts +35 -0
- package/lib/ListMoreDisplay.js +99 -0
- package/lib/LoadingButton.d.ts +16 -0
- package/lib/LoadingButton.js +41 -0
- package/lib/MUGlobal.d.ts +102 -0
- package/lib/MUGlobal.js +184 -0
- package/lib/MaskInput.d.ts +34 -0
- package/lib/MaskInput.js +43 -0
- package/lib/MobileListItemRenderer.d.ts +17 -0
- package/lib/MobileListItemRenderer.js +35 -0
- package/lib/MoreFab.d.ts +45 -0
- package/lib/MoreFab.js +95 -0
- package/lib/NotifierMU.d.ts +47 -0
- package/lib/NotifierMU.js +387 -0
- package/lib/NotifierPromptProps.d.ts +22 -0
- package/lib/NotifierPromptProps.js +1 -0
- package/lib/OptionGroup.d.ts +58 -0
- package/lib/OptionGroup.js +81 -0
- package/lib/PList.d.ts +15 -0
- package/lib/PList.js +12 -0
- package/lib/ProgressCount.d.ts +44 -0
- package/lib/ProgressCount.js +79 -0
- package/lib/PullToRefreshUI.d.ts +9 -0
- package/lib/PullToRefreshUI.js +18 -0
- package/lib/RLink.d.ts +14 -0
- package/lib/RLink.js +37 -0
- package/lib/ResponsibleContainer.d.ts +87 -0
- package/lib/ResponsibleContainer.js +156 -0
- package/lib/ScrollTopFab.d.ts +7 -0
- package/lib/ScrollTopFab.js +25 -0
- package/lib/ScrollerListEx.d.ts +81 -0
- package/lib/ScrollerListEx.js +167 -0
- package/lib/SearchBar.d.ts +29 -0
- package/lib/SearchBar.js +260 -0
- package/lib/SearchField.d.ts +21 -0
- package/lib/SearchField.js +39 -0
- package/lib/SearchOptionGroup.d.ts +9 -0
- package/lib/SearchOptionGroup.js +14 -0
- package/lib/SelectBool.d.ts +13 -0
- package/lib/SelectBool.js +22 -0
- package/lib/SelectEx.d.ts +50 -0
- package/lib/SelectEx.js +156 -0
- package/lib/ShowDataComparison.d.ts +20 -0
- package/lib/ShowDataComparison.js +58 -0
- package/lib/Switch.d.ts +29 -0
- package/lib/Switch.js +34 -0
- package/lib/SwitchAnt.d.ts +25 -0
- package/lib/SwitchAnt.js +40 -0
- package/lib/TabBox.d.ts +54 -0
- package/lib/TabBox.js +31 -0
- package/lib/TableEx.d.ts +65 -0
- package/lib/TableEx.js +270 -0
- package/lib/TextFieldEx.d.ts +101 -0
- package/lib/TextFieldEx.js +126 -0
- package/lib/Tiplist.d.ts +18 -0
- package/lib/Tiplist.js +157 -0
- package/lib/TooltipClick.d.ts +15 -0
- package/lib/TooltipClick.js +40 -0
- package/lib/UserAvatar.d.ts +24 -0
- package/lib/UserAvatar.js +25 -0
- package/lib/UserAvatarEditor.d.ts +53 -0
- package/lib/UserAvatarEditor.js +129 -0
- package/lib/app/CommonApp.d.ts +38 -0
- package/lib/app/CommonApp.js +149 -0
- package/lib/app/IServiceAppSettings.d.ts +11 -0
- package/lib/app/IServiceAppSettings.js +1 -0
- package/lib/app/IServicePage.d.ts +6 -0
- package/lib/app/IServicePage.js +1 -0
- package/lib/app/IServiceUser.d.ts +14 -0
- package/lib/app/IServiceUser.js +1 -0
- package/lib/app/ISmartERPUser.d.ts +14 -0
- package/lib/app/ISmartERPUser.js +1 -0
- package/lib/app/Labels.d.ts +65 -0
- package/lib/app/Labels.js +62 -0
- package/lib/app/ReactApp.d.ts +195 -0
- package/lib/app/ReactApp.js +296 -0
- package/lib/app/ServiceApp.d.ts +78 -0
- package/lib/app/ServiceApp.js +244 -0
- package/lib/index.d.ts +74 -0
- package/lib/index.js +74 -0
- package/lib/pages/CommonPage.d.ts +11 -0
- package/lib/pages/CommonPage.js +60 -0
- package/lib/pages/CommonPageProps.d.ts +59 -0
- package/lib/pages/CommonPageProps.js +1 -0
- package/lib/pages/DataGridPage.d.ts +9 -0
- package/lib/pages/DataGridPage.js +79 -0
- package/lib/pages/DataGridPageProps.d.ts +17 -0
- package/lib/pages/DataGridPageProps.js +1 -0
- package/lib/pages/EditPage.d.ts +33 -0
- package/lib/pages/EditPage.js +29 -0
- package/lib/pages/FixedListPage.d.ts +15 -0
- package/lib/pages/FixedListPage.js +70 -0
- package/lib/pages/ListPage.d.ts +9 -0
- package/lib/pages/ListPage.js +50 -0
- package/lib/pages/ListPageProps.d.ts +7 -0
- package/lib/pages/ListPageProps.js +1 -0
- package/lib/pages/ResponsivePage.d.ts +9 -0
- package/lib/pages/ResponsivePage.js +45 -0
- package/lib/pages/ResponsivePageProps.d.ts +39 -0
- package/lib/pages/ResponsivePageProps.js +1 -0
- package/lib/pages/SearchPageProps.d.ts +30 -0
- package/lib/pages/SearchPageProps.js +1 -0
- package/lib/pages/TablePage.d.ts +9 -0
- package/lib/pages/TablePage.js +69 -0
- package/lib/pages/TablePageProps.d.ts +7 -0
- package/lib/pages/TablePageProps.js +1 -0
- package/lib/pages/ViewPage.d.ts +66 -0
- package/lib/pages/ViewPage.js +105 -0
- package/lib/texts/DateText.d.ts +34 -0
- package/lib/texts/DateText.js +25 -0
- package/lib/texts/MoneyText.d.ts +21 -0
- package/lib/texts/MoneyText.js +14 -0
- package/lib/texts/NumberText.d.ts +25 -0
- package/lib/texts/NumberText.js +14 -0
- package/package.json +97 -0
- package/src/AuditDisplay.tsx +114 -0
- package/src/AutocompleteExtendedProps.ts +83 -0
- package/src/BackButton.tsx +55 -0
- package/src/BridgeCloseButton.tsx +69 -0
- package/src/ButtonLink.tsx +32 -0
- package/src/ComboBox.tsx +251 -0
- package/src/CountdownButton.tsx +119 -0
- package/src/CustomFabProps.ts +32 -0
- package/src/DataGridEx.tsx +713 -0
- package/src/DataGridRenderers.tsx +140 -0
- package/src/DialogButton.tsx +163 -0
- package/src/DnDList.tsx +344 -0
- package/src/DraggablePaperComponent.tsx +19 -0
- package/src/EmailInput.tsx +24 -0
- package/src/FabBox.tsx +51 -0
- package/src/FlexBox.tsx +20 -0
- package/src/GridDataFormat.tsx +77 -0
- package/src/IconButtonLink.tsx +29 -0
- package/src/InputField.tsx +82 -0
- package/src/ItemList.tsx +204 -0
- package/src/ListItemRightIcon.tsx +9 -0
- package/src/ListMoreDisplay.tsx +205 -0
- package/src/LoadingButton.tsx +75 -0
- package/src/MUGlobal.ts +220 -0
- package/src/MaskInput.tsx +107 -0
- package/src/MobileListItemRenderer.tsx +79 -0
- package/src/MoreFab.tsx +211 -0
- package/src/NotifierMU.tsx +654 -0
- package/src/NotifierPromptProps.ts +24 -0
- package/src/OptionGroup.tsx +223 -0
- package/src/PList.tsx +27 -0
- package/src/ProgressCount.tsx +166 -0
- package/src/PullToRefreshUI.tsx +21 -0
- package/src/RLink.tsx +64 -0
- package/src/ResponsibleContainer.tsx +394 -0
- package/src/ScrollTopFab.tsx +34 -0
- package/src/ScrollerListEx.tsx +387 -0
- package/src/SearchBar.tsx +396 -0
- package/src/SearchField.tsx +82 -0
- package/src/SearchOptionGroup.tsx +31 -0
- package/src/SelectBool.tsx +33 -0
- package/src/SelectEx.tsx +290 -0
- package/src/ShowDataComparison.tsx +106 -0
- package/src/Switch.tsx +94 -0
- package/src/SwitchAnt.tsx +95 -0
- package/src/TabBox.tsx +118 -0
- package/src/TableEx.tsx +558 -0
- package/src/TextFieldEx.tsx +249 -0
- package/src/Tiplist.tsx +303 -0
- package/src/TooltipClick.tsx +84 -0
- package/src/UserAvatar.tsx +64 -0
- package/src/UserAvatarEditor.tsx +287 -0
- package/src/app/CommonApp.ts +223 -0
- package/src/app/IServiceAppSettings.ts +13 -0
- package/src/app/IServicePage.ts +6 -0
- package/src/app/IServiceUser.ts +17 -0
- package/src/app/ISmartERPUser.ts +16 -0
- package/src/app/Labels.ts +77 -0
- package/src/app/ReactApp.ts +504 -0
- package/src/app/ServiceApp.ts +352 -0
- package/src/index.ts +77 -0
- package/src/pages/CommonPage.tsx +128 -0
- package/src/pages/CommonPageProps.ts +70 -0
- package/src/pages/DataGridPage.tsx +140 -0
- package/src/pages/DataGridPageProps.ts +24 -0
- package/src/pages/EditPage.tsx +114 -0
- package/src/pages/FixedListPage.tsx +141 -0
- package/src/pages/ListPage.tsx +90 -0
- package/src/pages/ListPageProps.ts +12 -0
- package/src/pages/ResponsivePage.tsx +68 -0
- package/src/pages/ResponsivePageProps.ts +57 -0
- package/src/pages/SearchPageProps.ts +39 -0
- package/src/pages/TablePage.tsx +126 -0
- package/src/pages/TablePageProps.ts +12 -0
- package/src/pages/ViewPage.tsx +282 -0
- package/src/texts/DateText.tsx +74 -0
- package/src/texts/MoneyText.tsx +49 -0
- package/src/texts/NumberText.tsx +40 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { IApi, RefreshTokenProps } from '@etsoo/appscript';
|
|
2
|
+
import { RefreshTokenRQ } from '@etsoo/react';
|
|
3
|
+
import { IServiceAppSettings } from './IServiceAppSettings';
|
|
4
|
+
import { IServicePageData } from './IServicePage';
|
|
5
|
+
import { IServiceUser } from './IServiceUser';
|
|
6
|
+
import { ISmartERPUser } from './ISmartERPUser';
|
|
7
|
+
import { ReactApp } from './ReactApp';
|
|
8
|
+
/**
|
|
9
|
+
* Core Service App
|
|
10
|
+
* Service login to core system, get the refesh token and access token
|
|
11
|
+
* Use the acess token to the service api, get a service access token
|
|
12
|
+
* Use the new acess token and refresh token to login
|
|
13
|
+
*/
|
|
14
|
+
export declare class ServiceApp<U extends IServiceUser = IServiceUser, P extends IServicePageData = IServicePageData, S extends IServiceAppSettings = IServiceAppSettings> extends ReactApp<S, ISmartERPUser, P> {
|
|
15
|
+
/**
|
|
16
|
+
* Service API
|
|
17
|
+
*/
|
|
18
|
+
readonly serviceApi: IApi;
|
|
19
|
+
private _serviceUser?;
|
|
20
|
+
/**
|
|
21
|
+
* Service user
|
|
22
|
+
*/
|
|
23
|
+
get serviceUser(): U | undefined;
|
|
24
|
+
protected set serviceUser(value: U | undefined);
|
|
25
|
+
/**
|
|
26
|
+
* Service passphrase
|
|
27
|
+
*/
|
|
28
|
+
protected servicePassphrase: string;
|
|
29
|
+
/**
|
|
30
|
+
* Constructor
|
|
31
|
+
* @param settings Settings
|
|
32
|
+
* @param name Application name
|
|
33
|
+
*/
|
|
34
|
+
constructor(settings: S, name: string);
|
|
35
|
+
/**
|
|
36
|
+
* Load SmartERP core
|
|
37
|
+
*/
|
|
38
|
+
loadSmartERP(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Go to the login page
|
|
41
|
+
* @param tryLogin Try to login again
|
|
42
|
+
*/
|
|
43
|
+
toLoginPage(tryLogin?: boolean): void;
|
|
44
|
+
/**
|
|
45
|
+
* Refresh token
|
|
46
|
+
* @param props Props
|
|
47
|
+
*/
|
|
48
|
+
refreshToken<D extends object = RefreshTokenRQ>(props?: RefreshTokenProps<D>): Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Service decrypt message
|
|
51
|
+
* @param messageEncrypted Encrypted message
|
|
52
|
+
* @param passphrase Secret passphrase
|
|
53
|
+
* @returns Pure text
|
|
54
|
+
*/
|
|
55
|
+
serviceDecrypt(messageEncrypted: string, passphrase?: string): string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Service encrypt message
|
|
58
|
+
* @param message Message
|
|
59
|
+
* @param passphrase Secret passphrase
|
|
60
|
+
* @param iterations Iterations, 1000 times, 1 - 99
|
|
61
|
+
* @returns Result
|
|
62
|
+
*/
|
|
63
|
+
serviceEncrypt(message: string, passphrase?: string, iterations?: number): string;
|
|
64
|
+
/**
|
|
65
|
+
* Try login
|
|
66
|
+
* @param data Additional data
|
|
67
|
+
* @param showLoading Show loading bar or not
|
|
68
|
+
* @returns Result
|
|
69
|
+
*/
|
|
70
|
+
tryLogin<D extends object = {}>(data?: D, showLoading?: boolean): Promise<boolean>;
|
|
71
|
+
/**
|
|
72
|
+
* User login extended
|
|
73
|
+
* @param user Core system user
|
|
74
|
+
* @param refreshToken Refresh token
|
|
75
|
+
* @param serviceUser Service user
|
|
76
|
+
*/
|
|
77
|
+
userLoginEx(user: ISmartERPUser, refreshToken: string, serviceUser: U): void;
|
|
78
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { BridgeUtils, createClient } from '@etsoo/appscript';
|
|
2
|
+
import { CoreConstants } from '@etsoo/react';
|
|
3
|
+
import { DomUtils } from '@etsoo/shared';
|
|
4
|
+
import { ReactApp } from './ReactApp';
|
|
5
|
+
/**
|
|
6
|
+
* Core Service App
|
|
7
|
+
* Service login to core system, get the refesh token and access token
|
|
8
|
+
* Use the acess token to the service api, get a service access token
|
|
9
|
+
* Use the new acess token and refresh token to login
|
|
10
|
+
*/
|
|
11
|
+
export class ServiceApp extends ReactApp {
|
|
12
|
+
/**
|
|
13
|
+
* Constructor
|
|
14
|
+
* @param settings Settings
|
|
15
|
+
* @param name Application name
|
|
16
|
+
*/
|
|
17
|
+
constructor(settings, name) {
|
|
18
|
+
super(settings, name);
|
|
19
|
+
/**
|
|
20
|
+
* Service passphrase
|
|
21
|
+
*/
|
|
22
|
+
this.servicePassphrase = '';
|
|
23
|
+
// Check
|
|
24
|
+
if (settings.serviceId == null || settings.serviceEndpoint == null) {
|
|
25
|
+
throw new Error('No service settings');
|
|
26
|
+
}
|
|
27
|
+
// Service API
|
|
28
|
+
const api = createClient();
|
|
29
|
+
api.baseUrl = settings.serviceEndpoint;
|
|
30
|
+
this.setApi(api);
|
|
31
|
+
this.serviceApi = api;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Service user
|
|
35
|
+
*/
|
|
36
|
+
get serviceUser() {
|
|
37
|
+
return this._serviceUser;
|
|
38
|
+
}
|
|
39
|
+
set serviceUser(value) {
|
|
40
|
+
this._serviceUser = value;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Load SmartERP core
|
|
44
|
+
*/
|
|
45
|
+
loadSmartERP() {
|
|
46
|
+
if (BridgeUtils.host == null) {
|
|
47
|
+
window.location.href = this.settings.webUrl;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
BridgeUtils.host.loadApp('core');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Go to the login page
|
|
55
|
+
* @param tryLogin Try to login again
|
|
56
|
+
*/
|
|
57
|
+
toLoginPage(tryLogin) {
|
|
58
|
+
const parameters = `?serviceId=${this.settings.serviceId}&${DomUtils.CultureField}=${this.culture}${tryLogin ? '' : '&tryLogin=false'}`;
|
|
59
|
+
if (BridgeUtils.host == null) {
|
|
60
|
+
const coreUrl = this.settings.webUrl;
|
|
61
|
+
window.location.href = coreUrl + parameters;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
BridgeUtils.host.loadApp('core', parameters);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Refresh token
|
|
69
|
+
* @param props Props
|
|
70
|
+
*/
|
|
71
|
+
async refreshToken(props) {
|
|
72
|
+
// Destruct
|
|
73
|
+
const { callback, data, relogin = false, showLoading = false } = props !== null && props !== void 0 ? props : {};
|
|
74
|
+
// Token
|
|
75
|
+
const token = this.getCacheToken();
|
|
76
|
+
if (token == null || token === '') {
|
|
77
|
+
if (callback)
|
|
78
|
+
callback(false);
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
// Reqest data
|
|
82
|
+
// Merge additional data passed
|
|
83
|
+
const rq = {
|
|
84
|
+
deviceId: this.deviceId,
|
|
85
|
+
timezone: this.getTimeZone(),
|
|
86
|
+
...data
|
|
87
|
+
};
|
|
88
|
+
// Payload
|
|
89
|
+
const payload = {
|
|
90
|
+
showLoading,
|
|
91
|
+
config: { headers: { [CoreConstants.TokenHeaderRefresh]: token } },
|
|
92
|
+
onError: (error) => {
|
|
93
|
+
if (callback)
|
|
94
|
+
callback(error);
|
|
95
|
+
// Prevent further processing
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
// Success callback
|
|
100
|
+
const success = async (result, failCallback) => {
|
|
101
|
+
// Token
|
|
102
|
+
const refreshToken = this.getResponseToken(payload.response);
|
|
103
|
+
if (refreshToken == null || result.data == null) {
|
|
104
|
+
if (failCallback)
|
|
105
|
+
failCallback(this.get('noData'));
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
// User data
|
|
109
|
+
const userData = result.data;
|
|
110
|
+
// Use core system access token to service api to exchange service access token
|
|
111
|
+
const serviceResult = await this.serviceApi.put('Auth/ExchangeToken', {
|
|
112
|
+
token: this.encryptEnhanced(userData.token, this.settings.serviceId.toString())
|
|
113
|
+
}, {
|
|
114
|
+
showLoading,
|
|
115
|
+
onError: (error) => {
|
|
116
|
+
if (failCallback)
|
|
117
|
+
failCallback(error);
|
|
118
|
+
// Prevent further processing
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
if (serviceResult == null)
|
|
123
|
+
return false;
|
|
124
|
+
if (!serviceResult.ok) {
|
|
125
|
+
if (failCallback)
|
|
126
|
+
failCallback(serviceResult);
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
if (serviceResult.data == null) {
|
|
130
|
+
if (failCallback)
|
|
131
|
+
failCallback(this.get('noData'));
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
// Login
|
|
135
|
+
this.userLoginEx(userData, refreshToken, serviceResult.data);
|
|
136
|
+
// Success callback
|
|
137
|
+
if (failCallback)
|
|
138
|
+
failCallback(true);
|
|
139
|
+
return true;
|
|
140
|
+
};
|
|
141
|
+
// Call API
|
|
142
|
+
const result = await this.api.put('Auth/RefreshToken', rq, payload);
|
|
143
|
+
if (result == null)
|
|
144
|
+
return false;
|
|
145
|
+
if (!result.ok) {
|
|
146
|
+
if (result.type === 'TokenExpired' && relogin) {
|
|
147
|
+
// Try login
|
|
148
|
+
// Dialog to receive password
|
|
149
|
+
var labels = this.getLabels('reloginTip', 'login');
|
|
150
|
+
this.notifier.prompt(labels.reloginTip, async (pwd) => {
|
|
151
|
+
if (pwd == null) {
|
|
152
|
+
this.toLoginPage();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
// Set password for the action
|
|
156
|
+
rq.pwd = this.encrypt(this.hash(pwd));
|
|
157
|
+
// Submit again
|
|
158
|
+
const result = await this.api.put('Auth/RefreshToken', rq, payload);
|
|
159
|
+
if (result == null)
|
|
160
|
+
return;
|
|
161
|
+
if (result.ok) {
|
|
162
|
+
await success(result, (loginResult) => {
|
|
163
|
+
if (loginResult === true) {
|
|
164
|
+
if (callback)
|
|
165
|
+
callback(true);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const message = this.formatRefreshTokenResult(loginResult);
|
|
169
|
+
if (message)
|
|
170
|
+
this.notifier.alert(message);
|
|
171
|
+
});
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
// Popup message
|
|
175
|
+
this.alertResult(result);
|
|
176
|
+
return false;
|
|
177
|
+
}, labels.login, { type: 'password' });
|
|
178
|
+
// Fake truth to avoid reloading
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
if (callback)
|
|
182
|
+
callback(result);
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
return await success(result, callback);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Service decrypt message
|
|
189
|
+
* @param messageEncrypted Encrypted message
|
|
190
|
+
* @param passphrase Secret passphrase
|
|
191
|
+
* @returns Pure text
|
|
192
|
+
*/
|
|
193
|
+
serviceDecrypt(messageEncrypted, passphrase) {
|
|
194
|
+
return this.decrypt(messageEncrypted, passphrase !== null && passphrase !== void 0 ? passphrase : this.servicePassphrase);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Service encrypt message
|
|
198
|
+
* @param message Message
|
|
199
|
+
* @param passphrase Secret passphrase
|
|
200
|
+
* @param iterations Iterations, 1000 times, 1 - 99
|
|
201
|
+
* @returns Result
|
|
202
|
+
*/
|
|
203
|
+
serviceEncrypt(message, passphrase, iterations) {
|
|
204
|
+
return this.encrypt(message, passphrase !== null && passphrase !== void 0 ? passphrase : this.servicePassphrase, iterations);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Try login
|
|
208
|
+
* @param data Additional data
|
|
209
|
+
* @param showLoading Show loading bar or not
|
|
210
|
+
* @returns Result
|
|
211
|
+
*/
|
|
212
|
+
async tryLogin(data, showLoading) {
|
|
213
|
+
// Reset user state
|
|
214
|
+
const result = await super.tryLogin(data, showLoading);
|
|
215
|
+
if (!result)
|
|
216
|
+
return false;
|
|
217
|
+
// Refresh token
|
|
218
|
+
return await this.refreshToken({
|
|
219
|
+
callback: (result) => this.doRefreshTokenResult(result),
|
|
220
|
+
data,
|
|
221
|
+
showLoading,
|
|
222
|
+
relogin: true
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* User login extended
|
|
227
|
+
* @param user Core system user
|
|
228
|
+
* @param refreshToken Refresh token
|
|
229
|
+
* @param serviceUser Service user
|
|
230
|
+
*/
|
|
231
|
+
userLoginEx(user, refreshToken, serviceUser) {
|
|
232
|
+
var _a;
|
|
233
|
+
// Service user login
|
|
234
|
+
this.servicePassphrase =
|
|
235
|
+
(_a = this.decrypt(serviceUser.serviceDeviceId, this.settings.serviceId.toString())) !== null && _a !== void 0 ? _a : '';
|
|
236
|
+
// Service user
|
|
237
|
+
this.serviceUser = serviceUser;
|
|
238
|
+
// Service API token
|
|
239
|
+
this.serviceApi.authorize(this.settings.authScheme, serviceUser.token);
|
|
240
|
+
// Keep = true, means service could hold the refresh token for long access
|
|
241
|
+
// Trigger Context change and serviceUser is ready then
|
|
242
|
+
super.userLogin(user, refreshToken, true);
|
|
243
|
+
}
|
|
244
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export * from './app/CommonApp';
|
|
2
|
+
export * from './app/IServiceAppSettings';
|
|
3
|
+
export * from './app/IServicePage';
|
|
4
|
+
export * from './app/IServiceUser';
|
|
5
|
+
export * from './app/ISmartERPUser';
|
|
6
|
+
export * from './app/Labels';
|
|
7
|
+
export * from './app/ReactApp';
|
|
8
|
+
export * from './app/ServiceApp';
|
|
9
|
+
export * from './pages/CommonPage';
|
|
10
|
+
export * from './pages/CommonPageProps';
|
|
11
|
+
export * from './pages/DataGridPage';
|
|
12
|
+
export * from './pages/DataGridPageProps';
|
|
13
|
+
export * from './pages/EditPage';
|
|
14
|
+
export * from './pages/FixedListPage';
|
|
15
|
+
export * from './pages/ListPage';
|
|
16
|
+
export * from './pages/ListPageProps';
|
|
17
|
+
export * from './pages/ResponsivePage';
|
|
18
|
+
export * from './pages/ResponsivePageProps';
|
|
19
|
+
export * from './pages/SearchPageProps';
|
|
20
|
+
export * from './pages/TablePage';
|
|
21
|
+
export * from './pages/ViewPage';
|
|
22
|
+
export * from './texts/DateText';
|
|
23
|
+
export * from './texts/MoneyText';
|
|
24
|
+
export * from './texts/NumberText';
|
|
25
|
+
export * from './AuditDisplay';
|
|
26
|
+
export * from './BackButton';
|
|
27
|
+
export * from './BridgeCloseButton';
|
|
28
|
+
export * from './ButtonLink';
|
|
29
|
+
export * from './ComboBox';
|
|
30
|
+
export * from './CountdownButton';
|
|
31
|
+
export * from './CustomFabProps';
|
|
32
|
+
export * from './DataGridEx';
|
|
33
|
+
export * from './DataGridRenderers';
|
|
34
|
+
export * from './DialogButton';
|
|
35
|
+
export * from './DnDList';
|
|
36
|
+
export * from './DraggablePaperComponent';
|
|
37
|
+
export * from './EmailInput';
|
|
38
|
+
export * from './FabBox';
|
|
39
|
+
export * from './FlexBox';
|
|
40
|
+
export * from './GridDataFormat';
|
|
41
|
+
export * from './IconButtonLink';
|
|
42
|
+
export * from './InputField';
|
|
43
|
+
export * from './ItemList';
|
|
44
|
+
export * from './ListItemRightIcon';
|
|
45
|
+
export * from './ListMoreDisplay';
|
|
46
|
+
export * from './LoadingButton';
|
|
47
|
+
export * from './MaskInput';
|
|
48
|
+
export * from './MobileListItemRenderer';
|
|
49
|
+
export * from './MoreFab';
|
|
50
|
+
export * from './MUGlobal';
|
|
51
|
+
export * from './NotifierMU';
|
|
52
|
+
export * from './OptionGroup';
|
|
53
|
+
export * from './PList';
|
|
54
|
+
export * from './ProgressCount';
|
|
55
|
+
export * from './PullToRefreshUI';
|
|
56
|
+
export * from './ResponsibleContainer';
|
|
57
|
+
export * from './RLink';
|
|
58
|
+
export * from './ScrollerListEx';
|
|
59
|
+
export * from './ScrollTopFab';
|
|
60
|
+
export * from './SearchBar';
|
|
61
|
+
export * from './SearchField';
|
|
62
|
+
export * from './SearchOptionGroup';
|
|
63
|
+
export * from './SelectBool';
|
|
64
|
+
export * from './SelectEx';
|
|
65
|
+
export * from './ShowDataComparison';
|
|
66
|
+
export * from './Switch';
|
|
67
|
+
export * from './SwitchAnt';
|
|
68
|
+
export * from './TabBox';
|
|
69
|
+
export * from './TableEx';
|
|
70
|
+
export * from './TextFieldEx';
|
|
71
|
+
export * from './Tiplist';
|
|
72
|
+
export * from './TooltipClick';
|
|
73
|
+
export * from './UserAvatar';
|
|
74
|
+
export * from './UserAvatarEditor';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export * from './app/CommonApp';
|
|
2
|
+
export * from './app/IServiceAppSettings';
|
|
3
|
+
export * from './app/IServicePage';
|
|
4
|
+
export * from './app/IServiceUser';
|
|
5
|
+
export * from './app/ISmartERPUser';
|
|
6
|
+
export * from './app/Labels';
|
|
7
|
+
export * from './app/ReactApp';
|
|
8
|
+
export * from './app/ServiceApp';
|
|
9
|
+
export * from './pages/CommonPage';
|
|
10
|
+
export * from './pages/CommonPageProps';
|
|
11
|
+
export * from './pages/DataGridPage';
|
|
12
|
+
export * from './pages/DataGridPageProps';
|
|
13
|
+
export * from './pages/EditPage';
|
|
14
|
+
export * from './pages/FixedListPage';
|
|
15
|
+
export * from './pages/ListPage';
|
|
16
|
+
export * from './pages/ListPageProps';
|
|
17
|
+
export * from './pages/ResponsivePage';
|
|
18
|
+
export * from './pages/ResponsivePageProps';
|
|
19
|
+
export * from './pages/SearchPageProps';
|
|
20
|
+
export * from './pages/TablePage';
|
|
21
|
+
export * from './pages/ViewPage';
|
|
22
|
+
export * from './texts/DateText';
|
|
23
|
+
export * from './texts/MoneyText';
|
|
24
|
+
export * from './texts/NumberText';
|
|
25
|
+
export * from './AuditDisplay';
|
|
26
|
+
export * from './BackButton';
|
|
27
|
+
export * from './BridgeCloseButton';
|
|
28
|
+
export * from './ButtonLink';
|
|
29
|
+
export * from './ComboBox';
|
|
30
|
+
export * from './CountdownButton';
|
|
31
|
+
export * from './CustomFabProps';
|
|
32
|
+
export * from './DataGridEx';
|
|
33
|
+
export * from './DataGridRenderers';
|
|
34
|
+
export * from './DialogButton';
|
|
35
|
+
export * from './DnDList';
|
|
36
|
+
export * from './DraggablePaperComponent';
|
|
37
|
+
export * from './EmailInput';
|
|
38
|
+
export * from './FabBox';
|
|
39
|
+
export * from './FlexBox';
|
|
40
|
+
export * from './GridDataFormat';
|
|
41
|
+
export * from './IconButtonLink';
|
|
42
|
+
export * from './InputField';
|
|
43
|
+
export * from './ItemList';
|
|
44
|
+
export * from './ListItemRightIcon';
|
|
45
|
+
export * from './ListMoreDisplay';
|
|
46
|
+
export * from './LoadingButton';
|
|
47
|
+
export * from './MaskInput';
|
|
48
|
+
export * from './MobileListItemRenderer';
|
|
49
|
+
export * from './MoreFab';
|
|
50
|
+
export * from './MUGlobal';
|
|
51
|
+
export * from './NotifierMU';
|
|
52
|
+
export * from './OptionGroup';
|
|
53
|
+
export * from './PList';
|
|
54
|
+
export * from './ProgressCount';
|
|
55
|
+
export * from './PullToRefreshUI';
|
|
56
|
+
export * from './ResponsibleContainer';
|
|
57
|
+
export * from './RLink';
|
|
58
|
+
export * from './ScrollerListEx';
|
|
59
|
+
export * from './ScrollTopFab';
|
|
60
|
+
export * from './SearchBar';
|
|
61
|
+
export * from './SearchField';
|
|
62
|
+
export * from './SearchOptionGroup';
|
|
63
|
+
export * from './SelectBool';
|
|
64
|
+
export * from './SelectEx';
|
|
65
|
+
export * from './ShowDataComparison';
|
|
66
|
+
export * from './Switch';
|
|
67
|
+
export * from './SwitchAnt';
|
|
68
|
+
export * from './TabBox';
|
|
69
|
+
export * from './TableEx';
|
|
70
|
+
export * from './TextFieldEx';
|
|
71
|
+
export * from './Tiplist';
|
|
72
|
+
export * from './TooltipClick';
|
|
73
|
+
export * from './UserAvatar';
|
|
74
|
+
export * from './UserAvatarEditor';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CommonPageProps } from './CommonPageProps';
|
|
3
|
+
/**
|
|
4
|
+
* Default scroll container
|
|
5
|
+
*/
|
|
6
|
+
export declare const CommonPageScrollContainer: typeof globalThis;
|
|
7
|
+
/**
|
|
8
|
+
* Common page
|
|
9
|
+
* @param props Props
|
|
10
|
+
*/
|
|
11
|
+
export declare function CommonPage(props: CommonPageProps): JSX.Element;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FabBox } from '../FabBox';
|
|
3
|
+
import { ScrollTopFab } from '../ScrollTopFab';
|
|
4
|
+
import { MUGlobal } from '../MUGlobal';
|
|
5
|
+
import { MoreFab } from '../MoreFab';
|
|
6
|
+
import { Container, Fab } from '@mui/material';
|
|
7
|
+
import RefreshIcon from '@mui/icons-material/Refresh';
|
|
8
|
+
import { BackButton } from '../BackButton';
|
|
9
|
+
import { Labels } from '../app/Labels';
|
|
10
|
+
import { ReactAppStateDetector } from '../app/ReactApp';
|
|
11
|
+
/**
|
|
12
|
+
* Default scroll container
|
|
13
|
+
*/
|
|
14
|
+
export const CommonPageScrollContainer = global;
|
|
15
|
+
/**
|
|
16
|
+
* Common page
|
|
17
|
+
* @param props Props
|
|
18
|
+
*/
|
|
19
|
+
export function CommonPage(props) {
|
|
20
|
+
// Destruct
|
|
21
|
+
const { children, disableGutters = true, fabButtons, fabColumnDirection, fabPaddingAdjust = 1.5, fabSize = 'small', maxWidth = false, moreActions, onRefresh, onUpdate, onUpdateAll, paddings = MUGlobal.pagePaddings, scrollContainer, supportBack = false, targetFields, sx = {}, ...rest } = props;
|
|
22
|
+
// Fab padding
|
|
23
|
+
const fabPadding = MUGlobal.increase(MUGlobal.pagePaddings, fabPaddingAdjust);
|
|
24
|
+
if (typeof sx === 'object' && sx != null && !Reflect.has(sx, 'padding')) {
|
|
25
|
+
// Set default padding
|
|
26
|
+
Reflect.set(sx, 'padding', paddings);
|
|
27
|
+
}
|
|
28
|
+
// Labels
|
|
29
|
+
const labels = Labels.CommonPage;
|
|
30
|
+
// Update
|
|
31
|
+
const update = onUpdateAll
|
|
32
|
+
? onUpdateAll
|
|
33
|
+
: onUpdate
|
|
34
|
+
? (authorized) => {
|
|
35
|
+
if (authorized == null || authorized)
|
|
36
|
+
onUpdate();
|
|
37
|
+
}
|
|
38
|
+
: onRefresh
|
|
39
|
+
? (authorized) => {
|
|
40
|
+
if (authorized)
|
|
41
|
+
onRefresh();
|
|
42
|
+
}
|
|
43
|
+
: undefined;
|
|
44
|
+
// Return the UI
|
|
45
|
+
return (React.createElement(React.Fragment, null,
|
|
46
|
+
update && (React.createElement(ReactAppStateDetector, { targetFields: targetFields, update: update })),
|
|
47
|
+
React.createElement(Container, { disableGutters: disableGutters, maxWidth: maxWidth, sx: sx, id: "page-container", ...rest },
|
|
48
|
+
React.createElement(FabBox, { sx: {
|
|
49
|
+
zIndex: 1,
|
|
50
|
+
bottom: (theme) => MUGlobal.updateWithTheme(fabPadding, theme.spacing),
|
|
51
|
+
right: (theme) => MUGlobal.updateWithTheme(fabPadding, theme.spacing)
|
|
52
|
+
}, columnDirection: fabColumnDirection },
|
|
53
|
+
scrollContainer && (React.createElement(ScrollTopFab, { size: fabSize, target: scrollContainer, title: labels.scrollTop })),
|
|
54
|
+
fabButtons,
|
|
55
|
+
onRefresh != null && (React.createElement(Fab, { title: labels.refresh, size: fabSize, onClick: onRefresh, sx: { display: { xs: 'none', md: 'inherit' } } },
|
|
56
|
+
React.createElement(RefreshIcon, null))),
|
|
57
|
+
React.createElement(MoreFab, { size: fabSize, title: labels.more, actions: moreActions }),
|
|
58
|
+
supportBack && (React.createElement(BackButton, { title: labels.back, size: fabSize }))),
|
|
59
|
+
children)));
|
|
60
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { UserKey } from '@etsoo/appscript';
|
|
3
|
+
import { IStateUpdate, ListItemReact } from '@etsoo/react';
|
|
4
|
+
import { ContainerProps } from '@mui/material';
|
|
5
|
+
import { CustomFabSize } from '../CustomFabProps';
|
|
6
|
+
/**
|
|
7
|
+
* Common page props
|
|
8
|
+
* Default container id is 'pageContainer'
|
|
9
|
+
*/
|
|
10
|
+
export interface CommonPageProps extends Omit<ContainerProps, 'id'> {
|
|
11
|
+
/**
|
|
12
|
+
* Fab buttons
|
|
13
|
+
*/
|
|
14
|
+
fabButtons?: React.ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Fab size
|
|
17
|
+
*/
|
|
18
|
+
fabSize?: CustomFabSize;
|
|
19
|
+
/**
|
|
20
|
+
* Fab flex column direction, undefined to hide it
|
|
21
|
+
*/
|
|
22
|
+
fabColumnDirection?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Fab padding adjust
|
|
25
|
+
*/
|
|
26
|
+
fabPaddingAdjust?: number;
|
|
27
|
+
/**
|
|
28
|
+
* More actions
|
|
29
|
+
*/
|
|
30
|
+
moreActions?: ListItemReact[];
|
|
31
|
+
/**
|
|
32
|
+
* On refresh callback, only when authorized = true
|
|
33
|
+
*/
|
|
34
|
+
onRefresh?: () => void | PromiseLike<void>;
|
|
35
|
+
/**
|
|
36
|
+
* On page update, when authorized = null or true case, may uses onRefresh
|
|
37
|
+
*/
|
|
38
|
+
onUpdate?: () => void | PromiseLike<void>;
|
|
39
|
+
/**
|
|
40
|
+
* On page update, all cases with authorized
|
|
41
|
+
*/
|
|
42
|
+
onUpdateAll?: IStateUpdate;
|
|
43
|
+
/**
|
|
44
|
+
* Paddings
|
|
45
|
+
*/
|
|
46
|
+
paddings?: Record<string, string | number>;
|
|
47
|
+
/**
|
|
48
|
+
* Scroll container
|
|
49
|
+
*/
|
|
50
|
+
scrollContainer?: HTMLElement | object;
|
|
51
|
+
/**
|
|
52
|
+
* Support back click
|
|
53
|
+
*/
|
|
54
|
+
supportBack?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* State last changed fields
|
|
57
|
+
*/
|
|
58
|
+
targetFields?: UserKey[];
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { DataTypes, IdDefaultType } from '@etsoo/shared';
|
|
3
|
+
import { DataGridPageProps } from './DataGridPageProps';
|
|
4
|
+
/**
|
|
5
|
+
* DataGrid page
|
|
6
|
+
* @param props Props
|
|
7
|
+
* @returns Component
|
|
8
|
+
*/
|
|
9
|
+
export declare function DataGridPage<T extends object, F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate, D extends DataTypes.Keys<T> = IdDefaultType<T>>(props: DataGridPageProps<T, F, D>): JSX.Element;
|