@etsoo/react 1.5.78 → 1.5.81

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.
Files changed (255) hide show
  1. package/README.md +7 -2
  2. package/__tests__/ReactUtils.ts +6 -0
  3. package/lib/{mu → components}/DnDList.d.ts +1 -14
  4. package/lib/{mu → components}/DnDList.js +1 -24
  5. package/lib/components/GridMethodRef.d.ts +11 -0
  6. package/lib/{mu → components}/GridMethodRef.js +0 -0
  7. package/lib/components/ScrollerGrid.d.ts +6 -6
  8. package/lib/components/ScrollerList.d.ts +3 -3
  9. package/lib/index.d.ts +2 -74
  10. package/lib/index.js +2 -75
  11. package/lib/notifier/Notifier.d.ts +2 -3
  12. package/lib/uses/useWindowScroll.d.ts +10 -0
  13. package/lib/uses/useWindowScroll.js +46 -0
  14. package/lib/uses/useWindowSize.js +11 -5
  15. package/package.json +9 -21
  16. package/src/{mu → components}/DnDList.tsx +11 -34
  17. package/src/components/GridMethodRef.ts +12 -0
  18. package/src/components/ScrollerGrid.tsx +6 -6
  19. package/src/components/ScrollerList.tsx +5 -3
  20. package/src/index.ts +2 -78
  21. package/src/notifier/Notifier.ts +2 -3
  22. package/src/uses/useWindowScroll.ts +60 -0
  23. package/src/uses/useWindowSize.ts +14 -5
  24. package/__tests__/mu/MUGlobalTests.tsx +0 -58
  25. package/__tests__/mu/NotifierMUTests.tsx +0 -213
  26. package/lib/app/CommonApp.d.ts +0 -39
  27. package/lib/app/CommonApp.js +0 -149
  28. package/lib/app/IServiceAppSettings.d.ts +0 -11
  29. package/lib/app/IServiceAppSettings.js +0 -1
  30. package/lib/app/IServicePage.d.ts +0 -6
  31. package/lib/app/IServicePage.js +0 -1
  32. package/lib/app/IServiceUser.d.ts +0 -14
  33. package/lib/app/IServiceUser.js +0 -1
  34. package/lib/app/ISmartERPUser.d.ts +0 -14
  35. package/lib/app/ISmartERPUser.js +0 -1
  36. package/lib/app/Labels.d.ts +0 -65
  37. package/lib/app/Labels.js +0 -62
  38. package/lib/app/ReactApp.d.ts +0 -194
  39. package/lib/app/ReactApp.js +0 -298
  40. package/lib/app/ServiceApp.d.ts +0 -78
  41. package/lib/app/ServiceApp.js +0 -244
  42. package/lib/components/ShowDataComparison.d.ts +0 -20
  43. package/lib/components/ShowDataComparison.js +0 -60
  44. package/lib/mu/AuditDisplay.d.ts +0 -33
  45. package/lib/mu/AuditDisplay.js +0 -52
  46. package/lib/mu/AutocompleteExtendedProps.d.ts +0 -66
  47. package/lib/mu/AutocompleteExtendedProps.js +0 -1
  48. package/lib/mu/BackButton.d.ts +0 -13
  49. package/lib/mu/BackButton.js +0 -33
  50. package/lib/mu/BridgeCloseButton.d.ts +0 -23
  51. package/lib/mu/BridgeCloseButton.js +0 -32
  52. package/lib/mu/ButtonLink.d.ts +0 -17
  53. package/lib/mu/ButtonLink.js +0 -19
  54. package/lib/mu/ComboBox.d.ts +0 -40
  55. package/lib/mu/ComboBox.js +0 -108
  56. package/lib/mu/CountdownButton.d.ts +0 -23
  57. package/lib/mu/CountdownButton.js +0 -81
  58. package/lib/mu/CustomFabProps.d.ts +0 -27
  59. package/lib/mu/CustomFabProps.js +0 -1
  60. package/lib/mu/DataGridEx.d.ts +0 -96
  61. package/lib/mu/DataGridEx.js +0 -331
  62. package/lib/mu/DataGridRenderers.d.ts +0 -22
  63. package/lib/mu/DataGridRenderers.js +0 -99
  64. package/lib/mu/DialogButton.d.ts +0 -54
  65. package/lib/mu/DialogButton.js +0 -45
  66. package/lib/mu/DraggablePaperComponent.d.ts +0 -8
  67. package/lib/mu/DraggablePaperComponent.js +0 -12
  68. package/lib/mu/EmailInput.d.ts +0 -11
  69. package/lib/mu/EmailInput.js +0 -15
  70. package/lib/mu/FabBox.d.ts +0 -21
  71. package/lib/mu/FabBox.js +0 -31
  72. package/lib/mu/FlexBox.d.ts +0 -14
  73. package/lib/mu/FlexBox.js +0 -18
  74. package/lib/mu/GridDataFormat.d.ts +0 -10
  75. package/lib/mu/GridDataFormat.js +0 -43
  76. package/lib/mu/GridMethodRef.d.ts +0 -11
  77. package/lib/mu/IconButtonLink.d.ts +0 -17
  78. package/lib/mu/IconButtonLink.js +0 -16
  79. package/lib/mu/InputField.d.ts +0 -21
  80. package/lib/mu/InputField.js +0 -39
  81. package/lib/mu/ItemList.d.ts +0 -55
  82. package/lib/mu/ItemList.js +0 -77
  83. package/lib/mu/ListItemRightIcon.d.ts +0 -4
  84. package/lib/mu/ListItemRightIcon.js +0 -8
  85. package/lib/mu/ListMoreDisplay.d.ts +0 -35
  86. package/lib/mu/ListMoreDisplay.js +0 -99
  87. package/lib/mu/LoadingButton.d.ts +0 -16
  88. package/lib/mu/LoadingButton.js +0 -41
  89. package/lib/mu/MUGlobal.d.ts +0 -102
  90. package/lib/mu/MUGlobal.js +0 -184
  91. package/lib/mu/MaskInput.d.ts +0 -34
  92. package/lib/mu/MaskInput.js +0 -43
  93. package/lib/mu/MobileListItemRenderer.d.ts +0 -17
  94. package/lib/mu/MobileListItemRenderer.js +0 -35
  95. package/lib/mu/MoreFab.d.ts +0 -45
  96. package/lib/mu/MoreFab.js +0 -95
  97. package/lib/mu/NotifierMU.d.ts +0 -47
  98. package/lib/mu/NotifierMU.js +0 -387
  99. package/lib/mu/NotifierPromptProps.d.ts +0 -22
  100. package/lib/mu/NotifierPromptProps.js +0 -1
  101. package/lib/mu/OptionGroup.d.ts +0 -62
  102. package/lib/mu/OptionGroup.js +0 -81
  103. package/lib/mu/PList.d.ts +0 -15
  104. package/lib/mu/PList.js +0 -12
  105. package/lib/mu/ProgressCount.d.ts +0 -44
  106. package/lib/mu/ProgressCount.js +0 -79
  107. package/lib/mu/PullToRefreshUI.d.ts +0 -9
  108. package/lib/mu/PullToRefreshUI.js +0 -18
  109. package/lib/mu/RLink.d.ts +0 -14
  110. package/lib/mu/RLink.js +0 -37
  111. package/lib/mu/ResponsibleContainer.d.ts +0 -89
  112. package/lib/mu/ResponsibleContainer.js +0 -159
  113. package/lib/mu/ScrollTopFab.d.ts +0 -7
  114. package/lib/mu/ScrollTopFab.js +0 -25
  115. package/lib/mu/ScrollerListEx.d.ts +0 -81
  116. package/lib/mu/ScrollerListEx.js +0 -167
  117. package/lib/mu/SearchBar.d.ts +0 -29
  118. package/lib/mu/SearchBar.js +0 -262
  119. package/lib/mu/SearchField.d.ts +0 -21
  120. package/lib/mu/SearchField.js +0 -39
  121. package/lib/mu/SearchOptionGroup.d.ts +0 -9
  122. package/lib/mu/SearchOptionGroup.js +0 -14
  123. package/lib/mu/SelectBool.d.ts +0 -14
  124. package/lib/mu/SelectBool.js +0 -22
  125. package/lib/mu/SelectEx.d.ts +0 -54
  126. package/lib/mu/SelectEx.js +0 -156
  127. package/lib/mu/Switch.d.ts +0 -29
  128. package/lib/mu/Switch.js +0 -34
  129. package/lib/mu/SwitchAnt.d.ts +0 -25
  130. package/lib/mu/SwitchAnt.js +0 -40
  131. package/lib/mu/TabBox.d.ts +0 -54
  132. package/lib/mu/TabBox.js +0 -31
  133. package/lib/mu/TableEx.d.ts +0 -68
  134. package/lib/mu/TableEx.js +0 -271
  135. package/lib/mu/TextFieldEx.d.ts +0 -101
  136. package/lib/mu/TextFieldEx.js +0 -127
  137. package/lib/mu/Tiplist.d.ts +0 -18
  138. package/lib/mu/Tiplist.js +0 -158
  139. package/lib/mu/TooltipClick.d.ts +0 -15
  140. package/lib/mu/TooltipClick.js +0 -40
  141. package/lib/mu/UserAvatar.d.ts +0 -24
  142. package/lib/mu/UserAvatar.js +0 -25
  143. package/lib/mu/UserAvatarEditor.d.ts +0 -53
  144. package/lib/mu/UserAvatarEditor.js +0 -129
  145. package/lib/mu/pages/CommonPage.d.ts +0 -11
  146. package/lib/mu/pages/CommonPage.js +0 -60
  147. package/lib/mu/pages/CommonPageProps.d.ts +0 -60
  148. package/lib/mu/pages/CommonPageProps.js +0 -1
  149. package/lib/mu/pages/DataGridPage.d.ts +0 -9
  150. package/lib/mu/pages/DataGridPage.js +0 -81
  151. package/lib/mu/pages/DataGridPageProps.d.ts +0 -17
  152. package/lib/mu/pages/DataGridPageProps.js +0 -1
  153. package/lib/mu/pages/EditPage.d.ts +0 -33
  154. package/lib/mu/pages/EditPage.js +0 -29
  155. package/lib/mu/pages/FixedListPage.d.ts +0 -15
  156. package/lib/mu/pages/FixedListPage.js +0 -72
  157. package/lib/mu/pages/ListPage.d.ts +0 -9
  158. package/lib/mu/pages/ListPage.js +0 -51
  159. package/lib/mu/pages/ListPageProps.d.ts +0 -7
  160. package/lib/mu/pages/ListPageProps.js +0 -1
  161. package/lib/mu/pages/ResponsivePage.d.ts +0 -9
  162. package/lib/mu/pages/ResponsivePage.js +0 -45
  163. package/lib/mu/pages/ResponsivePageProps.d.ts +0 -39
  164. package/lib/mu/pages/ResponsivePageProps.js +0 -1
  165. package/lib/mu/pages/SearchPageProps.d.ts +0 -30
  166. package/lib/mu/pages/SearchPageProps.js +0 -1
  167. package/lib/mu/pages/TablePage.d.ts +0 -9
  168. package/lib/mu/pages/TablePage.js +0 -71
  169. package/lib/mu/pages/TablePageProps.d.ts +0 -7
  170. package/lib/mu/pages/TablePageProps.js +0 -1
  171. package/lib/mu/pages/ViewPage.d.ts +0 -66
  172. package/lib/mu/pages/ViewPage.js +0 -105
  173. package/lib/mu/texts/DateText.d.ts +0 -34
  174. package/lib/mu/texts/DateText.js +0 -25
  175. package/lib/mu/texts/MoneyText.d.ts +0 -21
  176. package/lib/mu/texts/MoneyText.js +0 -14
  177. package/lib/mu/texts/NumberText.d.ts +0 -25
  178. package/lib/mu/texts/NumberText.js +0 -14
  179. package/src/app/CommonApp.ts +0 -225
  180. package/src/app/IServiceAppSettings.ts +0 -13
  181. package/src/app/IServicePage.ts +0 -6
  182. package/src/app/IServiceUser.ts +0 -17
  183. package/src/app/ISmartERPUser.ts +0 -16
  184. package/src/app/Labels.ts +0 -77
  185. package/src/app/ReactApp.ts +0 -500
  186. package/src/app/ServiceApp.ts +0 -353
  187. package/src/components/ShowDataComparison.tsx +0 -108
  188. package/src/mu/AuditDisplay.tsx +0 -117
  189. package/src/mu/AutocompleteExtendedProps.ts +0 -84
  190. package/src/mu/BackButton.tsx +0 -55
  191. package/src/mu/BridgeCloseButton.tsx +0 -69
  192. package/src/mu/ButtonLink.tsx +0 -32
  193. package/src/mu/ComboBox.tsx +0 -244
  194. package/src/mu/CountdownButton.tsx +0 -119
  195. package/src/mu/CustomFabProps.ts +0 -32
  196. package/src/mu/DataGridEx.tsx +0 -712
  197. package/src/mu/DataGridRenderers.tsx +0 -140
  198. package/src/mu/DialogButton.tsx +0 -163
  199. package/src/mu/DraggablePaperComponent.tsx +0 -19
  200. package/src/mu/EmailInput.tsx +0 -24
  201. package/src/mu/FabBox.tsx +0 -51
  202. package/src/mu/FlexBox.tsx +0 -20
  203. package/src/mu/GridDataFormat.tsx +0 -77
  204. package/src/mu/GridMethodRef.ts +0 -12
  205. package/src/mu/IconButtonLink.tsx +0 -29
  206. package/src/mu/InputField.tsx +0 -82
  207. package/src/mu/ItemList.tsx +0 -201
  208. package/src/mu/ListItemRightIcon.tsx +0 -9
  209. package/src/mu/ListMoreDisplay.tsx +0 -205
  210. package/src/mu/LoadingButton.tsx +0 -75
  211. package/src/mu/MUGlobal.ts +0 -220
  212. package/src/mu/MaskInput.tsx +0 -107
  213. package/src/mu/MobileListItemRenderer.tsx +0 -79
  214. package/src/mu/MoreFab.tsx +0 -211
  215. package/src/mu/NotifierMU.tsx +0 -654
  216. package/src/mu/NotifierPromptProps.ts +0 -26
  217. package/src/mu/OptionGroup.tsx +0 -218
  218. package/src/mu/PList.tsx +0 -27
  219. package/src/mu/ProgressCount.tsx +0 -166
  220. package/src/mu/PullToRefreshUI.tsx +0 -21
  221. package/src/mu/RLink.tsx +0 -64
  222. package/src/mu/ResponsibleContainer.tsx +0 -394
  223. package/src/mu/ScrollTopFab.tsx +0 -34
  224. package/src/mu/ScrollerListEx.tsx +0 -387
  225. package/src/mu/SearchBar.tsx +0 -398
  226. package/src/mu/SearchField.tsx +0 -82
  227. package/src/mu/SearchOptionGroup.tsx +0 -25
  228. package/src/mu/SelectBool.tsx +0 -40
  229. package/src/mu/SelectEx.tsx +0 -285
  230. package/src/mu/Switch.tsx +0 -94
  231. package/src/mu/SwitchAnt.tsx +0 -95
  232. package/src/mu/TabBox.tsx +0 -118
  233. package/src/mu/TableEx.tsx +0 -561
  234. package/src/mu/TextFieldEx.tsx +0 -250
  235. package/src/mu/Tiplist.tsx +0 -304
  236. package/src/mu/TooltipClick.tsx +0 -84
  237. package/src/mu/UserAvatar.tsx +0 -64
  238. package/src/mu/UserAvatarEditor.tsx +0 -287
  239. package/src/mu/pages/CommonPage.tsx +0 -128
  240. package/src/mu/pages/CommonPageProps.ts +0 -71
  241. package/src/mu/pages/DataGridPage.tsx +0 -137
  242. package/src/mu/pages/DataGridPageProps.ts +0 -24
  243. package/src/mu/pages/EditPage.tsx +0 -114
  244. package/src/mu/pages/FixedListPage.tsx +0 -134
  245. package/src/mu/pages/ListPage.tsx +0 -86
  246. package/src/mu/pages/ListPageProps.ts +0 -11
  247. package/src/mu/pages/ResponsivePage.tsx +0 -68
  248. package/src/mu/pages/ResponsivePageProps.ts +0 -57
  249. package/src/mu/pages/SearchPageProps.ts +0 -39
  250. package/src/mu/pages/TablePage.tsx +0 -119
  251. package/src/mu/pages/TablePageProps.ts +0 -11
  252. package/src/mu/pages/ViewPage.tsx +0 -285
  253. package/src/mu/texts/DateText.tsx +0 -74
  254. package/src/mu/texts/MoneyText.tsx +0 -49
  255. package/src/mu/texts/NumberText.tsx +0 -40
@@ -1,298 +0,0 @@
1
- import { BridgeUtils, CoreApp, createClient } from '@etsoo/appscript';
2
- import { NotificationMessageType } from '@etsoo/notificationbase';
3
- import { WindowStorage } from '@etsoo/shared';
4
- import React from 'react';
5
- import { NotifierMU } from '../mu/NotifierMU';
6
- import { ProgressCount } from '../mu/ProgressCount';
7
- import { CultureState } from '../states/CultureState';
8
- import { PageActionType, PageState } from '../states/PageState';
9
- import { UserActionType, UserState } from '../states/UserState';
10
- import { Labels } from './Labels';
11
- import { createBrowserHistory, createMemoryHistory } from 'history';
12
- /**
13
- * Global application
14
- */
15
- export let globalApp;
16
- /**
17
- * React app state detector
18
- * Case 1: undefined, when refresh the whole page
19
- * Case 2: false, unauthorized
20
- * Case 3: true, authorized or considered as authorized (maynot, like token expiry)
21
- * Case 4: property or properties changed
22
- * @param props Props
23
- * @returns Component
24
- */
25
- export function ReactAppStateDetector(props) {
26
- // Destruct
27
- const { targetFields, update } = props;
28
- // Context
29
- const { state = {} } = globalApp == null
30
- ? {}
31
- : React.useContext(globalApp.userState.context);
32
- // Ready
33
- React.useEffect(() => {
34
- // Match fields
35
- const changedFields = state.lastChangedFields;
36
- let matchedFields;
37
- if (targetFields == null || changedFields == null) {
38
- matchedFields = changedFields;
39
- }
40
- else {
41
- matchedFields = [];
42
- targetFields.forEach((targetField) => {
43
- if (changedFields.includes(targetField))
44
- matchedFields === null || matchedFields === void 0 ? void 0 : matchedFields.push(targetField);
45
- });
46
- }
47
- // Callback
48
- update(state.authorized, matchedFields);
49
- }, [state]);
50
- // return
51
- return React.createElement(React.Fragment);
52
- }
53
- /**
54
- * React application
55
- */
56
- export class ReactApp extends CoreApp {
57
- /**
58
- * Constructor
59
- * @param settings Settings
60
- * @param name Application name
61
- */
62
- constructor(settings, name) {
63
- super(settings, ReactApp.createApi(settings), ReactApp.createNotifier(), new WindowStorage(), name);
64
- /**
65
- * User state
66
- */
67
- this.userState = new UserState();
68
- if (BridgeUtils.host) {
69
- const startUrl = BridgeUtils.host.getStartUrl();
70
- this.history = createMemoryHistory({
71
- initialEntries: startUrl == null ? undefined : [startUrl]
72
- });
73
- BridgeUtils.host.onUpdate((app, version) => {
74
- this.notifier.message(NotificationMessageType.Success, this.get('updateTip') + `(${[app, version].join(', ')})`, this.get('updateReady'));
75
- });
76
- }
77
- else {
78
- this.history = createBrowserHistory();
79
- }
80
- this.cultureState = new CultureState(settings.currentCulture);
81
- this.pageState = new PageState();
82
- globalApp = this;
83
- }
84
- /**
85
- * Get notifier provider
86
- */
87
- static get notifierProvider() {
88
- return this._notifierProvider;
89
- }
90
- static createApi(settings) {
91
- // API
92
- // Support to replace {hostname} with current hostname
93
- const api = createClient();
94
- api.baseUrl = settings.endpoint;
95
- return api;
96
- }
97
- static createNotifier() {
98
- // Notifier
99
- ReactApp._notifierProvider = NotifierMU.setup();
100
- return NotifierMU.instance;
101
- }
102
- /**
103
- * Override alert action result
104
- * @param result Action result
105
- * @param callback Callback
106
- */
107
- alertResult(result, callback) {
108
- const message = this.formatResult(result);
109
- if (message.endsWith(')')) {
110
- const startPos = message.lastIndexOf('(');
111
- if (startPos > 0) {
112
- const main = message.substring(0, startPos).trim();
113
- const tip = message.substring(startPos);
114
- const titleNode = React.createElement(React.Fragment, null, main, React.createElement('br'), React.createElement('span', { style: { fontSize: '9px' } }, tip));
115
- this.notifier.alert(titleNode, callback);
116
- return;
117
- }
118
- }
119
- this.notifier.alert(message, callback);
120
- }
121
- /**
122
- * Change culture
123
- * @param culture New culture definition
124
- */
125
- changeCulture(culture) {
126
- var _a, _b;
127
- // Super call to update cultrue
128
- super.changeCulture(culture);
129
- // Update component labels
130
- Labels.setLabels(culture.resources, {
131
- notificationMU: {
132
- alertTitle: 'warning',
133
- alertOK: 'ok',
134
- confirmTitle: 'confirm',
135
- confirmYes: 'ok',
136
- confirmNo: 'cancel',
137
- promptTitle: 'prompt',
138
- promptCancel: 'cancel',
139
- promptOK: 'ok'
140
- }
141
- });
142
- // Notify host
143
- (_a = BridgeUtils.host) === null || _a === void 0 ? void 0 : _a.changeCulture(culture.name);
144
- // Document title
145
- document.title = (_b = this.get(this.name)) !== null && _b !== void 0 ? _b : this.name;
146
- }
147
- /**
148
- * Change culture extended
149
- * @param dispatch Dispatch method
150
- * @param culture New culture definition
151
- */
152
- changeCultureEx(dispatch, culture) {
153
- // Same?
154
- if (culture.name === this.culture)
155
- return;
156
- // Dispatch action
157
- dispatch(culture);
158
- // Super call
159
- this.changeCulture(culture);
160
- }
161
- /**
162
- * Get date format props
163
- * @returns Props
164
- */
165
- getDateFormatProps() {
166
- return { culture: this.culture, timeZone: this.getTimeZone() };
167
- }
168
- /**
169
- * Get money format props
170
- * @param currency Currency, if undefined, default currency applied
171
- * @returns Props
172
- */
173
- getMoneyFormatProps(currency) {
174
- return { culture: this.culture, currency: currency !== null && currency !== void 0 ? currency : this.currency };
175
- }
176
- /**
177
- * Fresh countdown UI
178
- * @param callback Callback
179
- */
180
- freshCountdownUI(callback) {
181
- // Labels
182
- const labels = this.getLabels('cancel', 'tokenExpiry');
183
- // Progress
184
- const progress = React.createElement(ProgressCount, {
185
- seconds: 30,
186
- valueUnit: 's',
187
- onComplete: () => {
188
- // Stop the progress
189
- return false;
190
- }
191
- });
192
- // Popup
193
- this.notifier.alert(labels.tokenExpiry, async () => {
194
- if (callback)
195
- await callback();
196
- else
197
- await this.tryLogin();
198
- }, undefined, {
199
- okLabel: labels.cancel,
200
- primaryButton: { fullWidth: true, autoFocus: false },
201
- inputs: progress
202
- });
203
- }
204
- /**
205
- * Redirect to the Url
206
- * @param url Url
207
- */
208
- redirectTo(url) {
209
- this.history.push(url);
210
- }
211
- /**
212
- * Set page data
213
- * @param data Page data
214
- */
215
- setPageData(data) {
216
- // Dispatch the change
217
- if (this.pageStateDispatch != null) {
218
- this.pageStateDispatch({
219
- type: PageActionType.Data,
220
- data
221
- });
222
- }
223
- }
224
- /**
225
- * Set page title and data
226
- * @param title Page title
227
- */
228
- setPageTitle(title) {
229
- // Data
230
- const data = { title };
231
- // Dispatch the change
232
- if (this.pageStateDispatch != null) {
233
- this.pageStateDispatch({
234
- type: PageActionType.Title,
235
- data
236
- });
237
- }
238
- }
239
- /**
240
- * Set page title and data
241
- * @param key Page title resource key
242
- */
243
- setPageKey(key) {
244
- var _a;
245
- this.setPageTitle((_a = this.get(key)) !== null && _a !== void 0 ? _a : '');
246
- }
247
- /**
248
- * Show input dialog
249
- * @param props Props
250
- */
251
- showInputDialog({ title, message, callback, ...rest }) {
252
- return this.notifier.prompt(message, callback, title, rest);
253
- }
254
- /**
255
- * User login extended
256
- * @param user New user
257
- * @param refreshToken Refresh token
258
- * @param keep Keep in local storage or not
259
- * @param dispatch User state dispatch
260
- */
261
- userLogin(user, refreshToken, keep, dispatch) {
262
- // Super call, set token
263
- super.userLogin(user, refreshToken, keep);
264
- // Dispatch action
265
- if (this.userStateDispatch != null && dispatch !== false)
266
- this.userStateDispatch({
267
- type: UserActionType.Login,
268
- user
269
- });
270
- }
271
- /**
272
- * User logout
273
- * @param clearToken Clear refresh token or not
274
- */
275
- userLogout(clearToken = true) {
276
- // Super call
277
- super.userLogout(clearToken);
278
- // Dispatch action
279
- if (this.userStateDispatch != null)
280
- this.userStateDispatch({
281
- type: UserActionType.Logout
282
- });
283
- }
284
- /**
285
- * User unauthorized
286
- */
287
- userUnauthorized() {
288
- // Super call
289
- super.userUnauthorized();
290
- if (this.userStateDispatch != null) {
291
- // There is delay during state update
292
- // Not a good idea to try login multiple times with API calls
293
- this.userStateDispatch({
294
- type: UserActionType.Unauthorized
295
- });
296
- }
297
- }
298
- }
@@ -1,78 +0,0 @@
1
- import { IApi, RefreshTokenProps } from '@etsoo/appscript';
2
- import { IServiceAppSettings } from './IServiceAppSettings';
3
- import { IServicePageData } from './IServicePage';
4
- import { IServiceUser } from './IServiceUser';
5
- import { ISmartERPUser } from './ISmartERPUser';
6
- import { ReactApp } from './ReactApp';
7
- import { RefreshTokenRQ } from './RefreshTokenRQ';
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
- }
@@ -1,244 +0,0 @@
1
- import { BridgeUtils, createClient } from '@etsoo/appscript';
2
- import { DomUtils } from '@etsoo/shared';
3
- import { CoreConstants } from './CoreConstants';
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
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * Audit line update data model
3
- */
4
- export interface AuditLineUpdateData {
5
- oldData: Record<string, unknown>;
6
- newData: Record<string, unknown>;
7
- }
8
- /**
9
- * Check obj is instance of AuditLineUpdateData
10
- * @param obj Input
11
- * @returns Result
12
- */
13
- export declare function IsAuditLineUpdateData(obj: any): obj is AuditLineUpdateData;
14
- /**
15
- * Show data comparison
16
- * @param data Data
17
- * @param modelTitle Model window title
18
- * @param getLabel Get label callback
19
- */
20
- export declare const ShowDataComparison: (data: AuditLineUpdateData, modelTitle?: string, getLabel?: ((field: string) => string) | undefined) => void;
@@ -1,60 +0,0 @@
1
- import { NotificationMessageType } from '@etsoo/notificationbase';
2
- import { Utils } from '@etsoo/shared';
3
- import { Table, TableBody, TableCell, TableHead, TableRow } from '@mui/material';
4
- import React from 'react';
5
- import { globalApp } from '../app/ReactApp';
6
- /**
7
- * Check obj is instance of AuditLineUpdateData
8
- * @param obj Input
9
- * @returns Result
10
- */
11
- export function IsAuditLineUpdateData(obj) {
12
- return (typeof obj === 'object' &&
13
- 'oldData' in obj &&
14
- typeof obj.oldData === 'object' &&
15
- 'newData' in obj &&
16
- typeof obj.newData === 'object');
17
- }
18
- // Format value
19
- const formatValue = (value) => {
20
- if (value == null)
21
- return '';
22
- if (value instanceof Date && typeof globalApp !== 'undefined')
23
- return globalApp.formatDate(value, 'ds');
24
- return `${value}`;
25
- };
26
- /**
27
- * Show data comparison
28
- * @param data Data
29
- * @param modelTitle Model window title
30
- * @param getLabel Get label callback
31
- */
32
- export const ShowDataComparison = (data, modelTitle, getLabel) => {
33
- if (typeof globalApp === 'undefined')
34
- return;
35
- modelTitle !== null && modelTitle !== void 0 ? modelTitle : (modelTitle = globalApp.get('dataComparison'));
36
- getLabel !== null && getLabel !== void 0 ? getLabel : (getLabel = (key) => {
37
- var _a;
38
- return (_a = globalApp.get(Utils.formatInitial(key))) !== null && _a !== void 0 ? _a : key;
39
- });
40
- const keys = new Set([
41
- ...Object.keys(data.oldData),
42
- ...Object.keys(data.newData)
43
- ]);
44
- const rows = Array.from(keys).map((field) => ({
45
- field,
46
- oldValue: data.oldData[field],
47
- newValue: data.newData[field]
48
- }));
49
- const inputs = (React.createElement(Table, null,
50
- React.createElement(TableHead, null,
51
- React.createElement(TableRow, null,
52
- React.createElement(TableCell, { width: "18%" }, getLabel('field')),
53
- React.createElement(TableCell, { width: "41%", align: "right" }, getLabel('oldValue')),
54
- React.createElement(TableCell, { width: "41%", align: "right" }, getLabel('newValue')))),
55
- React.createElement(TableBody, null, rows.map((row) => (React.createElement(TableRow, { key: row.field },
56
- React.createElement(TableCell, null, getLabel(row.field)),
57
- React.createElement(TableCell, { align: "right" }, formatValue(row.oldValue)),
58
- React.createElement(TableCell, { align: "right" }, formatValue(row.newValue))))))));
59
- globalApp.notifier.alert([undefined, modelTitle], undefined, NotificationMessageType.Info, { fullScreen: globalApp.smDown, inputs });
60
- };