underpost 2.7.1 → 2.7.2

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 (213) hide show
  1. package/.dockerignore +13 -13
  2. package/.env.development +7 -7
  3. package/.env.production +7 -7
  4. package/.env.test +7 -7
  5. package/.github/workflows/publish.yml +26 -0
  6. package/.nycrc +9 -9
  7. package/.prettierignore +12 -12
  8. package/.prettierrc +9 -9
  9. package/.vscode/extensions.json +72 -72
  10. package/.vscode/settings.json +100 -99
  11. package/Dockerfile +89 -89
  12. package/LICENSE +21 -21
  13. package/README.md +96 -96
  14. package/bin/db.js +172 -119
  15. package/bin/deploy.js +582 -661
  16. package/bin/dns.js +1 -1
  17. package/bin/file.js +92 -92
  18. package/bin/index.js +53 -53
  19. package/bin/install.js +398 -357
  20. package/bin/shortcut.js +44 -44
  21. package/bin/ssl.js +65 -64
  22. package/bin/util.js +182 -182
  23. package/bin/vs.js +35 -35
  24. package/conf.js +251 -249
  25. package/docker-compose.yml +67 -67
  26. package/jsconfig.json +7 -7
  27. package/jsdoc.json +32 -32
  28. package/nodemon.json +6 -6
  29. package/package.json +137 -132
  30. package/prometheus.yml +36 -36
  31. package/setup.sh +24 -24
  32. package/src/api/core/core.controller.js +69 -69
  33. package/src/api/core/core.model.js +11 -11
  34. package/src/api/core/core.router.js +23 -23
  35. package/src/api/core/core.service.js +29 -29
  36. package/src/api/crypto/crypto.controller.js +51 -51
  37. package/src/api/crypto/crypto.model.js +23 -23
  38. package/src/api/crypto/crypto.router.js +20 -20
  39. package/src/api/crypto/crypto.service.js +64 -64
  40. package/src/api/default/default.controller.js +69 -69
  41. package/src/api/default/default.model.js +20 -20
  42. package/src/api/default/default.router.js +23 -23
  43. package/src/api/default/default.service.js +31 -31
  44. package/src/api/file/file.controller.js +53 -51
  45. package/src/api/file/file.model.js +19 -19
  46. package/src/api/file/file.router.js +21 -20
  47. package/src/api/file/file.service.js +76 -70
  48. package/src/api/instance/instance.controller.js +69 -69
  49. package/src/api/instance/instance.model.js +36 -36
  50. package/src/api/instance/instance.router.js +33 -33
  51. package/src/api/instance/instance.service.js +48 -48
  52. package/src/api/test/test.controller.js +59 -59
  53. package/src/api/test/test.model.js +14 -14
  54. package/src/api/test/test.router.js +21 -21
  55. package/src/api/test/test.service.js +35 -35
  56. package/src/api/user/user.build.js +16 -0
  57. package/src/api/user/user.controller.js +70 -70
  58. package/src/api/user/user.model.js +65 -65
  59. package/src/api/user/user.router.js +345 -345
  60. package/src/api/user/user.service.js +479 -479
  61. package/src/api.js +23 -23
  62. package/src/client/Default.index.js +40 -40
  63. package/src/client/components/core/Account.js +290 -290
  64. package/src/client/components/core/AgGrid.js +160 -160
  65. package/src/client/components/core/Auth.js +19 -19
  66. package/src/client/components/core/Badge.js +32 -32
  67. package/src/client/components/core/BlockChain.js +41 -41
  68. package/src/client/components/core/Blog.js +9 -9
  69. package/src/client/components/core/BtnIcon.js +101 -94
  70. package/src/client/components/core/CalendarCore.js +458 -319
  71. package/src/client/components/core/Chat.js +64 -64
  72. package/src/client/components/core/ColorPalette.js +5267 -5267
  73. package/src/client/components/core/CommonJs.js +735 -732
  74. package/src/client/components/core/Content.js +193 -49
  75. package/src/client/components/core/Css.js +1064 -1027
  76. package/src/client/components/core/CssCore.js +817 -796
  77. package/src/client/components/core/D3Chart.js +44 -44
  78. package/src/client/components/core/Docs.js +229 -229
  79. package/src/client/components/core/DropDown.js +164 -164
  80. package/src/client/components/core/EventsUI.js +46 -54
  81. package/src/client/components/core/FileExplorer.js +699 -624
  82. package/src/client/components/core/FullScreen.js +45 -45
  83. package/src/client/components/core/Input.js +346 -259
  84. package/src/client/components/core/JoyStick.js +77 -77
  85. package/src/client/components/core/Keyboard.js +73 -73
  86. package/src/client/components/core/LoadingAnimation.js +179 -157
  87. package/src/client/components/core/LogIn.js +187 -181
  88. package/src/client/components/core/LogOut.js +58 -52
  89. package/src/client/components/core/Logger.js +26 -26
  90. package/src/client/components/core/Modal.js +1612 -1596
  91. package/src/client/components/core/NotificationManager.js +84 -84
  92. package/src/client/components/core/Panel.js +613 -413
  93. package/src/client/components/core/PanelForm.js +468 -0
  94. package/src/client/components/core/Polyhedron.js +162 -162
  95. package/src/client/components/core/Recover.js +204 -204
  96. package/src/client/components/core/Responsive.js +53 -53
  97. package/src/client/components/core/RichText.js +51 -27
  98. package/src/client/components/core/Router.js +76 -77
  99. package/src/client/components/core/Scroll.js +34 -0
  100. package/src/client/components/core/SignUp.js +125 -125
  101. package/src/client/components/core/SocketIo.js +72 -72
  102. package/src/client/components/core/Stream.js +113 -113
  103. package/src/client/components/core/ToggleSwitch.js +87 -87
  104. package/src/client/components/core/ToolTip.js +26 -26
  105. package/src/client/components/core/Translate.js +437 -408
  106. package/src/client/components/core/Validator.js +100 -100
  107. package/src/client/components/core/VanillaJs.js +460 -457
  108. package/src/client/components/core/Wallet.js +106 -106
  109. package/src/client/components/core/Webhook.js +25 -25
  110. package/src/client/components/core/Worker.js +272 -272
  111. package/src/client/components/default/CommonDefault.js +29 -29
  112. package/src/client/components/default/CssDefault.js +13 -13
  113. package/src/client/components/default/ElementsDefault.js +38 -38
  114. package/src/client/components/default/LogInDefault.js +41 -41
  115. package/src/client/components/default/LogOutDefault.js +28 -28
  116. package/src/client/components/default/MenuDefault.js +389 -389
  117. package/src/client/components/default/RoutesDefault.js +48 -48
  118. package/src/client/components/default/SettingsDefault.js +16 -16
  119. package/src/client/components/default/SignUpDefault.js +9 -9
  120. package/src/client/components/default/SocketIoDefault.js +54 -54
  121. package/src/client/components/default/TranslateDefault.js +7 -7
  122. package/src/client/public/default/assets/mailer/api-user-check.png +0 -0
  123. package/src/client/public/default/assets/mailer/api-user-invalid-token.png +0 -0
  124. package/src/client/public/default/assets/mailer/api-user-recover.png +0 -0
  125. package/src/client/public/default/browserconfig.xml +11 -11
  126. package/src/client/public/default/manifest.webmanifest +68 -68
  127. package/src/client/public/default/plantuml/client-conf.svg +1 -0
  128. package/src/client/public/default/plantuml/client-schema.svg +1 -0
  129. package/src/client/public/default/plantuml/cron-conf.svg +1 -0
  130. package/src/client/public/default/plantuml/cron-schema.svg +1 -0
  131. package/src/client/public/default/plantuml/server-conf.svg +1 -0
  132. package/src/client/public/default/plantuml/server-schema.svg +1 -0
  133. package/src/client/public/default/plantuml/ssr-conf.svg +1 -0
  134. package/src/client/public/default/plantuml/ssr-schema.svg +1 -0
  135. package/src/client/public/default/sitemap +147 -147
  136. package/src/client/public/default/yandex-browser-manifest.json +8 -8
  137. package/src/client/public/doc/sitemap +147 -147
  138. package/src/client/public/test/sitemap +147 -147
  139. package/src/client/services/core/core.service.js +170 -152
  140. package/src/client/services/crypto/crypto.service.js +70 -70
  141. package/src/client/services/default/default.management.js +345 -345
  142. package/src/client/services/default/default.service.js +89 -89
  143. package/src/client/services/file/file.service.js +70 -70
  144. package/src/client/services/instance/instance.management.js +74 -74
  145. package/src/client/services/instance/instance.service.js +89 -89
  146. package/src/client/services/test/test.service.js +70 -70
  147. package/src/client/services/user/user.management.js +50 -50
  148. package/src/client/services/user/user.service.js +89 -89
  149. package/src/client/ssr/Render.js +16 -16
  150. package/src/client/ssr/body-components/CacheControl.js +114 -113
  151. package/src/client/ssr/body-components/DefaultSplashScreen.js +79 -79
  152. package/src/client/ssr/email-components/DefaultRecoverEmail.js +21 -21
  153. package/src/client/ssr/email-components/DefaultVerifyEmail.js +17 -17
  154. package/src/client/ssr/head-components/Css.js +241 -241
  155. package/src/client/ssr/head-components/DefaultScripts.js +3 -3
  156. package/src/client/ssr/head-components/Microdata.js +11 -11
  157. package/src/client/ssr/head-components/Production.js +1 -1
  158. package/src/client/ssr/head-components/PwaDefault.js +59 -59
  159. package/src/client/ssr/head-components/Seo.js +14 -14
  160. package/src/client/sw/default.sw.js +201 -201
  161. package/src/client/sw/template.sw.js +84 -84
  162. package/src/client.build.js +22 -22
  163. package/src/client.dev.js +21 -21
  164. package/src/cron.js +25 -25
  165. package/src/db/DataBaseProvider.js +34 -34
  166. package/src/db/mariadb/MariaDB.js +33 -33
  167. package/src/db/mongo/MongooseDB.js +46 -46
  168. package/src/dns.js +22 -22
  169. package/src/index.js +42 -29
  170. package/src/mailer/EmailRender.js +69 -69
  171. package/src/mailer/MailerProvider.js +96 -96
  172. package/src/proxy.js +22 -22
  173. package/src/runtime/lampp/Lampp.js +69 -44
  174. package/src/runtime/nginx/Nginx.js +3 -3
  175. package/src/runtime/xampp/Xampp.js +49 -49
  176. package/src/server/auth.js +235 -204
  177. package/src/server/backup.js +101 -94
  178. package/src/server/client-build-live.js +72 -72
  179. package/src/server/client-build.js +705 -699
  180. package/src/server/client-dev-server.js +60 -58
  181. package/src/server/client-formatted.js +48 -48
  182. package/src/server/client-icons.js +149 -150
  183. package/src/server/conf.js +860 -611
  184. package/src/server/dns.js +98 -98
  185. package/src/server/downloader.js +42 -42
  186. package/src/server/logger.js +180 -180
  187. package/src/server/network.js +122 -122
  188. package/src/server/peer.js +33 -33
  189. package/src/server/process.js +66 -66
  190. package/src/server/prompt-optimizer.js +28 -28
  191. package/src/server/proxy.js +118 -118
  192. package/src/server/runtime.js +444 -393
  193. package/src/server/ssl.js +109 -107
  194. package/src/server.js +25 -25
  195. package/src/ws/IoInterface.js +45 -45
  196. package/src/ws/IoServer.js +39 -39
  197. package/src/ws/core/channels/core.ws.chat.js +23 -23
  198. package/src/ws/core/channels/core.ws.mailer.js +35 -35
  199. package/src/ws/core/channels/core.ws.stream.js +31 -31
  200. package/src/ws/core/core.ws.connection.js +28 -28
  201. package/src/ws/core/core.ws.emit.js +14 -14
  202. package/src/ws/core/core.ws.server.js +24 -24
  203. package/src/ws/core/management/core.ws.chat.js +8 -8
  204. package/src/ws/core/management/core.ws.mailer.js +16 -16
  205. package/src/ws/core/management/core.ws.stream.js +8 -8
  206. package/src/ws/default/channels/default.ws.main.js +16 -16
  207. package/src/ws/default/default.ws.connection.js +22 -22
  208. package/src/ws/default/default.ws.emit.js +14 -14
  209. package/src/ws/default/default.ws.server.js +20 -20
  210. package/src/ws/default/management/default.ws.main.js +8 -8
  211. package/startup.js +11 -11
  212. package/supervisord-openssh-server.conf +4 -4
  213. package/test/api.test.js +60 -60
@@ -1,624 +1,699 @@
1
- import { DocumentService } from '../../services/document/document.service.js';
2
- import { FileService } from '../../services/file/file.service.js';
3
- import { AgGrid } from './AgGrid.js';
4
- import { BtnIcon } from './BtnIcon.js';
5
- import { getSubpaths, uniqueArray } from './CommonJs.js';
6
- import { darkTheme } from './Css.js';
7
- import { EventsUI } from './EventsUI.js';
8
- import { fileFormDataFactory, Input, InputFile } from './Input.js';
9
- import { Modal } from './Modal.js';
10
- import { NotificationManager } from './NotificationManager.js';
11
- import { RouterEvents } from './Router.js';
12
- import { Translate } from './Translate.js';
13
- import { Validator } from './Validator.js';
14
- import { copyData, downloadFile, getProxyPath, getQueryParams, s, setPath } from './VanillaJs.js';
15
-
16
- class LoadFolderRenderer {
17
- eGui;
18
-
19
- async init(params) {
20
- console.log('LoadFolderRenderer created', params);
21
- // params.data._id
22
-
23
- this.eGui = document.createElement('div');
24
- this.eGui.innerHTML = html`<i class="fas fa-folder"></i> ${params.data.location}`;
25
- }
26
-
27
- getGui() {
28
- return this.eGui;
29
- }
30
-
31
- refresh(params) {
32
- console.log('LoadFolderRenderer refreshed', params);
33
- return true;
34
- }
35
- }
36
-
37
- class LoadFileNameRenderer {
38
- eGui;
39
-
40
- async init(params) {
41
- console.log('LoadFileNameRenderer created', params);
42
- // params.data._id
43
-
44
- this.eGui = document.createElement('div');
45
- this.eGui.innerHTML = html`<i class="fas fa-file"></i> ${params.data.name}`;
46
- }
47
-
48
- getGui() {
49
- return this.eGui;
50
- }
51
-
52
- refresh(params) {
53
- console.log('LoadFileNameRenderer refreshed', params);
54
- return true;
55
- }
56
- }
57
-
58
- class FolderHeaderComp {
59
- eGui;
60
-
61
- async init(params) {
62
- console.log('FolderHeaderComp created', params);
63
- // params.data._id
64
-
65
- this.eGui = document.createElement('div');
66
- this.eGui.innerHTML = html`<i class="fas fa-file"></i>`;
67
- }
68
-
69
- getGui() {
70
- return this.eGui;
71
- }
72
-
73
- refresh(params) {
74
- console.log('FolderHeaderComp refreshed', params);
75
- return true;
76
- }
77
- }
78
-
79
- const FileExplorer = {
80
- Render: async function () {
81
- const gridFolderId = 'folder-explorer-grid';
82
- const gridFileId = 'file-explorer-grid';
83
- const idDropFileInput = 'file-explorer';
84
- let formBodyFiles;
85
- const query = getQueryParams();
86
- let location = query?.location ? this.locationFormat({ f: query }) : '/';
87
- let files = [];
88
- let folders = [];
89
- let documentId = '';
90
- let documentInstance = [];
91
-
92
- RouterEvents['file-explorer'] = ({ path, pushPath, route }) => {
93
- if (route === 'cloud') {
94
- setTimeout(() => {
95
- const query = getQueryParams();
96
- location = query?.location ? this.locationFormat({ f: query }) : '/';
97
- if (!s(`.file-explorer-query-nav`)) return;
98
- s(`.file-explorer-query-nav`).value = location;
99
- const format = this.documentDataFormat({ document: documentInstance, location });
100
- files = format.files;
101
- folders = format.folders;
102
- AgGrid.grids[gridFileId].setGridOption('rowData', files);
103
- AgGrid.grids[gridFolderId].setGridOption('rowData', folders);
104
- });
105
- }
106
- };
107
-
108
- try {
109
- const { status, data: document } = await DocumentService.get();
110
- const format = this.documentDataFormat({ document, location });
111
- files = format.files;
112
- documentId = format.documentId;
113
- folders = format.folders;
114
- documentInstance = document;
115
- } catch (error) {
116
- console.error(error);
117
- }
118
-
119
- console.log({ location, documentId, folders, files });
120
-
121
- setTimeout(async () => {
122
- const formData = [
123
- {
124
- model: 'location',
125
- id: `file-explorer-query-nav`,
126
- rules: [], // { type: 'isEmpty' }
127
- },
128
- ];
129
- const validators = await Validator.instance(formData);
130
-
131
- EventsUI.onClick(`.btn-input-file-explorer`, async (e) => {
132
- e.preventDefault();
133
- const { errorMessage } = await validators();
134
- if (!formBodyFiles)
135
- return NotificationManager.Push({
136
- html: Translate.Render(`warning-upload-no-selects-file`),
137
- status: 'warning',
138
- });
139
- if (errorMessage) return;
140
- let fileData;
141
- {
142
- const { status, data } = await FileService.post({ body: formBodyFiles });
143
- fileData = data;
144
- }
145
- {
146
- // const body = {};
147
- // for (const inputData of formData) {
148
- // if ('model' in inputData) body[inputData.model] = s(`.${inputData.id}`).value;
149
- // }
150
- location = this.locationFormat({ f: { location: s(`.file-explorer-query-nav`).value } });
151
- let status = 'success';
152
- for (const file of fileData) {
153
- const result = await DocumentService.post({
154
- body: {
155
- fileId: file._id,
156
- location,
157
- },
158
- });
159
- if (result.status === 'success') documentInstance.push({ ...result.data, fileId: file });
160
- else if (status !== 'error') status = 'error';
161
- }
162
- const format = this.documentDataFormat({ document: documentInstance, location });
163
- files = format.files;
164
- folders = format.folders;
165
- AgGrid.grids[gridFileId].setGridOption('rowData', files);
166
- AgGrid.grids[gridFolderId].setGridOption('rowData', folders);
167
- NotificationManager.Push({
168
- html: Translate.Render(`${status}-upload-file`),
169
- status,
170
- });
171
- if (status === 'success') {
172
- s(`.btn-input-home-directory`).click();
173
- s(`.btn-clear-input-file-${idDropFileInput}`).click();
174
- }
175
- }
176
- });
177
-
178
- EventsUI.onClick(`.btn-input-go-explorer`, async (e) => {
179
- e.preventDefault();
180
- const newLocation = this.locationFormat({ f: { location: s(`.file-explorer-query-nav`).value } });
181
- if (newLocation === location) return;
182
- location = newLocation;
183
- setPath(`${window.location.pathname}?location=${location}`);
184
- s(`.file-explorer-query-nav`).value = location;
185
- const format = this.documentDataFormat({ document: documentInstance, location });
186
- files = format.files;
187
- folders = format.folders;
188
- AgGrid.grids[gridFileId].setGridOption('rowData', files);
189
- AgGrid.grids[gridFolderId].setGridOption('rowData', folders);
190
- });
191
- EventsUI.onClick(`.btn-input-home-directory`, async (e) => {
192
- e.preventDefault();
193
- let newLocation = '/';
194
- if (s(`.file-explorer-uploader`).style.display !== 'none') {
195
- s(`.file-explorer-uploader`).style.display = 'none';
196
- s(`.file-explorer-nav`).style.display = 'block';
197
- } else if (newLocation === location) return;
198
- else location = newLocation;
199
- setPath(`${window.location.pathname}?location=${location}`);
200
- s(`.file-explorer-query-nav`).value = location;
201
- const format = this.documentDataFormat({ document: documentInstance, location });
202
- files = format.files;
203
- folders = format.folders;
204
- AgGrid.grids[gridFileId].setGridOption('rowData', files);
205
- AgGrid.grids[gridFolderId].setGridOption('rowData', folders);
206
- });
207
- EventsUI.onClick(`.btn-input-copy-directory`, async (e) => {
208
- e.preventDefault();
209
- await copyData(window.location.href);
210
- NotificationManager.Push({
211
- html: Translate.Render('success-copy-data'),
212
- status: 'success',
213
- });
214
- });
215
- EventsUI.onClick(`.btn-input-back-explorer`, async (e) => {
216
- e.preventDefault();
217
- window.history.back();
218
- });
219
- EventsUI.onClick(`.btn-input-forward-explorer`, async (e) => {
220
- e.preventDefault();
221
- window.history.forward();
222
- });
223
- EventsUI.onClick(`.btn-input-upload-file`, async (e) => {
224
- e.preventDefault();
225
- s(`.file-explorer-nav`).style.display = 'none';
226
- s(`.file-explorer-uploader`).style.display = 'block';
227
- });
228
- });
229
-
230
- class LoadFileActionsRenderer {
231
- eGui;
232
-
233
- async init(params) {
234
- console.log('LoadFileActionsRenderer created', params);
235
- // params.data._id
236
-
237
- this.eGui = document.createElement('div');
238
- this.eGui.innerHTML = html`
239
- ${await BtnIcon.Render({
240
- class: `in btn-file-download-${params.data._id}`,
241
- label: html` <i class="fas fa-download"></i>`,
242
- type: 'button',
243
- })}
244
- ${await BtnIcon.Render({
245
- class: `in btn-file-delete-${params.data._id}`,
246
- label: html` <i class="fa-solid fa-circle-xmark"></i>`,
247
- type: 'button',
248
- })}
249
- ${await BtnIcon.Render({
250
- class: `in btn-file-view-${params.data._id}`,
251
- label: html` <i class="fas fa-eye"></i>`,
252
- type: 'button',
253
- })}
254
- ${await BtnIcon.Render({
255
- class: `in btn-file-copy-content-link-${params.data._id}`,
256
- label: html`<i class="fas fa-copy"></i>`,
257
- type: 'button',
258
- })}
259
- `;
260
-
261
- setTimeout(() => {
262
- const uri = `${getProxyPath()}content/?id=${params.data.fileId}`;
263
- const url = `${window.location.origin}${uri}`;
264
-
265
- // ${window.location.origin[window.location.origin.length - 1] === '/' ? '' : '/'}
266
-
267
- console.log({ url, uri });
268
-
269
- EventsUI.onClick(`.btn-file-view-${params.data._id}`, async (e) => {
270
- e.preventDefault();
271
- if (location.href !== url) {
272
- setPath(uri);
273
- s(`.main-btn-content`).click();
274
- }
275
- });
276
-
277
- EventsUI.onClick(`.btn-file-copy-content-link-${params.data._id}`, async (e) => {
278
- e.preventDefault();
279
- await copyData(url);
280
- NotificationManager.Push({
281
- html: Translate.Render('success-copy-data'),
282
- status: 'success',
283
- });
284
- });
285
-
286
- EventsUI.onClick(`.btn-file-download-${params.data._id}`, async (e) => {
287
- e.preventDefault();
288
- console.log(params);
289
- const {
290
- data: [file],
291
- status,
292
- } = await FileService.get({ id: params.data.fileId });
293
-
294
- downloadFile(new Blob([new Uint8Array(file.data.data)], { type: params.data.mimetype }), params.data.name);
295
- });
296
- EventsUI.onClick(`.btn-file-delete-${params.data._id}`, async (e) => {
297
- e.preventDefault();
298
- {
299
- const { data, status, message } = await FileService.delete({
300
- id: params.data.fileId,
301
- });
302
- NotificationManager.Push({
303
- html: status,
304
- status,
305
- });
306
- if (status === 'error') return;
307
- }
308
- const { data, status, message } = await DocumentService.delete({
309
- id: params.data._id,
310
- });
311
- NotificationManager.Push({
312
- html: status,
313
- status,
314
- });
315
- if (status === 'error') return;
316
-
317
- documentInstance = documentInstance.filter((f) => f._id !== params.data._id);
318
- const format = FileExplorer.documentDataFormat({ document: documentInstance, location });
319
- files = format.files;
320
- folders = format.folders;
321
- // AgGrid.grids[gridFileId].setGridOption('rowData', files);
322
- // const selectedData = gridApi.getSelectedRows();
323
- AgGrid.grids[gridFileId].applyTransaction({ remove: [params.data] });
324
- AgGrid.grids[gridFolderId].setGridOption('rowData', folders);
325
- });
326
- });
327
- }
328
-
329
- getGui() {
330
- return this.eGui;
331
- }
332
-
333
- refresh(params) {
334
- console.log('LoadFileActionsRenderer refreshed', params);
335
- return true;
336
- }
337
- }
338
-
339
- class LoadFolderActionsRenderer {
340
- eGui;
341
-
342
- async init(params) {
343
- console.log('LoadFolderActionsRenderer created', params);
344
- // params.data._id
345
- const id = params.data.locationId;
346
-
347
- this.eGui = document.createElement('div');
348
- this.eGui.innerHTML = html`
349
- ${await BtnIcon.Render({
350
- class: `in btn-folder-delete-${id}`,
351
- label: html` <i class="fa-solid fa-circle-xmark"></i>`,
352
- type: 'button',
353
- })}
354
- `;
355
-
356
- setTimeout(() => {
357
- EventsUI.onClick(`.btn-folder-delete-${id}`, async (e) => {
358
- e.preventDefault();
359
- const idFilesDelete = [];
360
- for (const file of documentInstance.filter(
361
- (f) => FileExplorer.locationFormat({ f }) === params.data.location, // .startsWith(params.data.location),
362
- )) {
363
- {
364
- const { data, status, message } = await FileService.delete({
365
- id: file.fileId._id,
366
- });
367
- }
368
- {
369
- idFilesDelete.push(file._id);
370
- const { data, status, message } = await DocumentService.delete({
371
- id: file._id,
372
- });
373
- }
374
- }
375
- NotificationManager.Push({
376
- html: Translate.Render('success-delete'),
377
- status: 'success',
378
- });
379
- documentInstance = documentInstance.filter((f) => !idFilesDelete.includes(f._id));
380
- const format = FileExplorer.documentDataFormat({ document: documentInstance, location });
381
- files = format.files;
382
- folders = format.folders;
383
- AgGrid.grids[gridFileId].setGridOption('rowData', files);
384
- AgGrid.grids[gridFolderId].setGridOption('rowData', folders);
385
- });
386
- });
387
- }
388
-
389
- getGui() {
390
- return this.eGui;
391
- }
392
-
393
- refresh(params) {
394
- console.log('LoadFolderActionsRenderer refreshed', params);
395
- return true;
396
- }
397
- }
398
-
399
- return html`
400
- <form>
401
- <div class="in">
402
- ${await BtnIcon.Render({
403
- class: 'inl tool-btn-file-explorer btn-input-home-directory',
404
- label: html`<i class="fas fa-home"></i>
405
- <!-- ${Translate.Render('home-directory')} -->`,
406
- type: 'button',
407
- })}
408
- ${await BtnIcon.Render({
409
- class: 'inl tool-btn-file-explorer btn-input-back-explorer',
410
- label: html` <i class="fa-solid fa-circle-left"></i>
411
- <!-- ${Translate.Render('go')} -->`,
412
- type: 'button',
413
- })}
414
- ${await BtnIcon.Render({
415
- class: 'inl tool-btn-file-explorer btn-input-forward-explorer',
416
- label: html` <i class="fa-solid fa-circle-right"></i>
417
- <!-- ${Translate.Render('go')} -->`,
418
- type: 'button',
419
- })}
420
- ${await BtnIcon.Render({
421
- class: 'inl tool-btn-file-explorer btn-input-go-explorer',
422
- label: html`<i class="fas fa-sync-alt"></i>
423
- <!-- ${Translate.Render('go')} -->`,
424
- type: 'submit',
425
- })}
426
- ${await BtnIcon.Render({
427
- class: 'inl tool-btn-file-explorer btn-input-copy-directory',
428
- label: html`<i class="fas fa-copy"></i>
429
- <!-- ${Translate.Render('home-directory')} -->`,
430
- type: 'button',
431
- })}
432
- ${await BtnIcon.Render({
433
- class: 'inl tool-btn-file-explorer btn-input-upload-file',
434
- label: html`<i class="fa-solid fa-cloud-arrow-up"></i>
435
- <!-- ${Translate.Render('home-directory')} -->`,
436
- type: 'button',
437
- })}
438
- </div>
439
- <div class="in">
440
- ${await Input.Render({
441
- id: `file-explorer-query-nav`,
442
- type: 'text',
443
- label: html`<i class="fab fa-wpexplorer"></i> ${Translate.Render('current-path')}`,
444
- containerClass: 'in section-mp input-container-width',
445
- placeholder: true,
446
- value: location,
447
- })}
448
- </div>
449
- </form>
450
- <div class="fl file-explorer-nav">
451
- <div class="in fll explorer-file-col">
452
- <div class="in explorer-file-sub-col section-mp">
453
- <div class="in">
454
- ${await AgGrid.Render({
455
- id: gridFolderId,
456
- darkTheme,
457
- // style: {
458
- // height: '200px',
459
- // },
460
- gridOptions: {
461
- defaultColDef: {
462
- editable: false,
463
- minWidth: 100,
464
- filter: true,
465
- autoHeight: true,
466
- },
467
- rowData: folders,
468
- columnDefs: [
469
- {
470
- field: 'location',
471
- headerName: 'Folder',
472
- minWidth: 200,
473
- flex: 1,
474
- cellStyle: function (params) {
475
- return { cursor: 'pointer' };
476
- },
477
- cellRenderer: LoadFolderRenderer,
478
- onCellClicked: (event) => {
479
- // console.warn('onCellClicked', event);
480
- const newLocation = event.data.location;
481
- if (newLocation === location) return;
482
- location = newLocation;
483
- setPath(`${window.location.pathname}?location=${location}`);
484
- s(`.file-explorer-query-nav`).value = location;
485
- const format = this.documentDataFormat({ document: documentInstance, location });
486
- files = format.files;
487
- folders = format.folders;
488
- AgGrid.grids[gridFileId].setGridOption('rowData', files);
489
- AgGrid.grids[gridFolderId].setGridOption('rowData', folders);
490
- },
491
- },
492
- {
493
- // suppressHeaderMenuButton: true,
494
- // sortable: false,
495
- field: 'fileCount',
496
- headerName: '🗎',
497
- width: 60,
498
- cellStyle: function (params) {
499
- return { cursor: 'pointer' };
500
- },
501
- // headerComponent: FolderHeaderComp,
502
- // headerComponentParams: {
503
- // menuIcon: 'fa-bars',
504
- // template: `test`,
505
- // },
506
- },
507
- { headerName: '', width: 60, cellRenderer: LoadFolderActionsRenderer },
508
- ],
509
- rowSelection: 'single',
510
- onSelectionChanged: (event) => {
511
- return;
512
- const selectedRows = AgGrid.grids[gridFolderId].getSelectedRows();
513
- console.log('selectedRows', { event, selectedRows });
514
- if (selectedRows[0]) {
515
- const newLocation = selectedRows[0].location;
516
- if (newLocation === location) return;
517
- location = newLocation;
518
- setPath(`${window.location.pathname}?location=${location}`);
519
- s(`.file-explorer-query-nav`).value = location;
520
- const format = this.documentDataFormat({ document: documentInstance, location });
521
- files = format.files;
522
- folders = format.folders;
523
- AgGrid.grids[gridFileId].setGridOption('rowData', files);
524
- AgGrid.grids[gridFolderId].setGridOption('rowData', folders);
525
- }
526
- },
527
- },
528
- })}
529
- </div>
530
- </div>
531
- </div>
532
- <div class="in fll explorer-file-col">
533
- <div class="in explorer-file-sub-col section-mp">
534
- <div class="in">
535
- ${await AgGrid.Render({
536
- id: gridFileId,
537
- darkTheme,
538
- // style: {
539
- // height: '200px',
540
- // },
541
- gridOptions: {
542
- defaultColDef: {
543
- editable: false,
544
- minWidth: 100,
545
- filter: true,
546
- autoHeight: true,
547
- },
548
- rowData: files,
549
- columnDefs: [
550
- { field: 'name', flex: 2, headerName: 'Name', cellRenderer: LoadFileNameRenderer },
551
- { field: 'mimetype', flex: 1, headerName: 'Type' },
552
- { headerName: '', width: 80, cellRenderer: LoadFileActionsRenderer },
553
- ],
554
- },
555
- })}
556
- </div>
557
- </div>
558
- </div>
559
- </div>
560
- <form class="file-explorer-uploader" style="display: none">
561
- <div class="in">
562
- ${await BtnIcon.Render({
563
- class: 'wfa section-mp btn-input-file-explorer',
564
- label: html`<i class="fas fa-upload"></i> ${Translate.Render('upload')}`,
565
- type: 'submit',
566
- })}
567
- </div>
568
- ${await InputFile.Render(
569
- {
570
- id: idDropFileInput,
571
- multiple: true,
572
- },
573
- {
574
- clear: () => {
575
- console.log('file explorer clear file');
576
- formBodyFiles = undefined;
577
- },
578
- change: (e) => {
579
- console.log('file explorer change file', e);
580
- formBodyFiles = fileFormDataFactory(e);
581
- },
582
- },
583
- )}
584
- </form>
585
- `;
586
- },
587
- locationFormat: function ({ f }) {
588
- if (f.location[0] !== '/') f.location = `/${f.location}`;
589
- if (f.location !== '/' && f.location[f.location.length - 1] === '/') f.location = f.location.slice(0, -1);
590
- return f.location;
591
- },
592
- documentDataFormat: function ({ document, location }) {
593
- let files = document.map((f) => {
594
- return {
595
- location: this.locationFormat({ f }),
596
- name: f.fileId.name,
597
- mimetype: f.fileId.mimetype,
598
- fileId: f.fileId._id,
599
- _id: f._id,
600
- };
601
- });
602
- let documentId = document._id;
603
- let folders = [];
604
- for (const folderPath of uniqueArray(files.map((f) => f.location)))
605
- folders = ['/'].concat(folders.concat(getSubpaths(folderPath)));
606
- folders = uniqueArray(folders).map((f, i) => {
607
- return {
608
- location: f,
609
- locationId: `loc-${i}`,
610
- };
611
- });
612
- files = files.filter((f) => f.location === location);
613
- folders = folders
614
- .filter((f) => f.location.startsWith(location))
615
- .map((f) => {
616
- f.fileCount = document.filter((file) => file.location === f.location).length;
617
- return f;
618
- })
619
- .filter((f) => f.fileCount > 0);
620
- return { files, documentId, folders };
621
- },
622
- };
623
-
624
- export { FileExplorer };
1
+ import { getApiBaseUrl } from '../../services/core/core.service.js';
2
+ import { DocumentService } from '../../services/document/document.service.js';
3
+ import { FileService } from '../../services/file/file.service.js';
4
+ import { AgGrid } from './AgGrid.js';
5
+ import { Auth } from './Auth.js';
6
+ import { BtnIcon } from './BtnIcon.js';
7
+ import { getSubpaths, timer, uniqueArray } from './CommonJs.js';
8
+ import { Content } from './Content.js';
9
+ import { darkTheme, renderCssAttr } from './Css.js';
10
+ import { EventsUI } from './EventsUI.js';
11
+ import { fileFormDataFactory, Input, InputFile } from './Input.js';
12
+ import { loggerFactory } from './Logger.js';
13
+ import { Modal } from './Modal.js';
14
+ import { NotificationManager } from './NotificationManager.js';
15
+ import { RouterEvents } from './Router.js';
16
+ import { Translate } from './Translate.js';
17
+ import { Validator } from './Validator.js';
18
+ import { copyData, downloadFile, getProxyPath, getQueryParams, s, setPath } from './VanillaJs.js';
19
+
20
+ const logger = loggerFactory(import.meta);
21
+
22
+ class LoadFolderRenderer {
23
+ eGui;
24
+
25
+ async init(params) {
26
+ console.log('LoadFolderRenderer created', params);
27
+ // params.data._id
28
+
29
+ this.eGui = document.createElement('div');
30
+ this.eGui.innerHTML = html`<i class="fas fa-folder"></i> ${params.data.location}`;
31
+ }
32
+
33
+ getGui() {
34
+ return this.eGui;
35
+ }
36
+
37
+ refresh(params) {
38
+ console.log('LoadFolderRenderer refreshed', params);
39
+ return true;
40
+ }
41
+ }
42
+
43
+ class LoadFileNameRenderer {
44
+ eGui;
45
+
46
+ async init(params) {
47
+ console.log('LoadFileNameRenderer created', params);
48
+ // params.data._id
49
+
50
+ this.eGui = document.createElement('div');
51
+ this.eGui.innerHTML = html`<i class="fas fa-file"></i> ${params.data.name}`;
52
+ }
53
+
54
+ getGui() {
55
+ return this.eGui;
56
+ }
57
+
58
+ refresh(params) {
59
+ console.log('LoadFileNameRenderer refreshed', params);
60
+ return true;
61
+ }
62
+ }
63
+
64
+ class FolderHeaderComp {
65
+ eGui;
66
+
67
+ async init(params) {
68
+ console.log('FolderHeaderComp created', params);
69
+ // params.data._id
70
+
71
+ this.eGui = document.createElement('div');
72
+ this.eGui.innerHTML = html`<i class="fas fa-file"></i>`;
73
+ }
74
+
75
+ getGui() {
76
+ return this.eGui;
77
+ }
78
+
79
+ refresh(params) {
80
+ console.log('FolderHeaderComp refreshed', params);
81
+ return true;
82
+ }
83
+ }
84
+
85
+ const FileExplorer = {
86
+ Api: {},
87
+ Render: async function (options = { idModal: '' }) {
88
+ const { idModal } = options;
89
+ FileExplorer.Api[idModal] = options;
90
+ const gridFolderId = 'folder-explorer-grid';
91
+ const gridFileId = 'file-explorer-grid';
92
+ const idDropFileInput = 'file-explorer';
93
+ let formBodyFiles;
94
+ const query = getQueryParams();
95
+ let location = query?.location ? this.locationFormat({ f: query }) : '/';
96
+ let files, folders, documentId, documentInstance;
97
+ const cleanData = () => {
98
+ files = [];
99
+ folders = [];
100
+ documentId = '';
101
+ documentInstance = [];
102
+ };
103
+ cleanData();
104
+ FileExplorer.Api[idModal].displayList = async () => {
105
+ if (!s(`.${idModal}`)) return;
106
+ const query = getQueryParams();
107
+ location = query?.location ? this.locationFormat({ f: query }) : '/';
108
+ s(`.file-explorer-query-nav`).value = location;
109
+ const format = this.documentDataFormat({ document: documentInstance, location });
110
+ files = format.files;
111
+ folders = format.folders;
112
+ AgGrid.grids[gridFileId].setGridOption('rowData', files);
113
+ AgGrid.grids[gridFolderId].setGridOption('rowData', folders);
114
+ };
115
+ FileExplorer.Api[idModal].updateData = async (optionsUpdate = { display: false }) => {
116
+ if (!s(`.${idModal}`)) return;
117
+ if (Auth.getToken()) {
118
+ try {
119
+ const { status, data: document } = await DocumentService.get();
120
+ const format = this.documentDataFormat({ document, location });
121
+ files = format.files;
122
+ documentId = format.documentId;
123
+ folders = format.folders;
124
+ documentInstance = document;
125
+ } catch (error) {
126
+ logger.error(error);
127
+ NotificationManager.Push({
128
+ html: error.message,
129
+ status: 'error',
130
+ });
131
+ }
132
+ } else cleanData();
133
+ setTimeout(async () => {
134
+ if (s(`.${idModal}`) && optionsUpdate && optionsUpdate.display) await FileExplorer.Api[idModal].displayList();
135
+ });
136
+ };
137
+
138
+ RouterEvents['file-explorer'] = ({ path, pushPath, route }) => {
139
+ if (route === 'cloud')
140
+ setTimeout(async () => {
141
+ // await this.Api[idModal].updateData();
142
+ await FileExplorer.Api[idModal].displayList();
143
+ });
144
+ };
145
+
146
+ setTimeout(async () => {
147
+ FileExplorer.Api[idModal].updateData({ display: true });
148
+ const formData = [
149
+ {
150
+ model: 'location',
151
+ id: `file-explorer-query-nav`,
152
+ rules: [], // { type: 'isEmpty' }
153
+ },
154
+ ];
155
+ const validators = await Validator.instance(formData);
156
+
157
+ EventsUI.onClick(`.btn-input-file-explorer`, async (e) => {
158
+ e.preventDefault();
159
+ const { errorMessage } = await validators();
160
+ if (!formBodyFiles)
161
+ return NotificationManager.Push({
162
+ html: Translate.Render(`warning-upload-no-selects-file`),
163
+ status: 'warning',
164
+ });
165
+ if (errorMessage) return;
166
+ let fileData;
167
+ {
168
+ const { status, data } = await FileService.post({ body: formBodyFiles });
169
+ fileData = data;
170
+ }
171
+ {
172
+ // const body = {};
173
+ // for (const inputData of formData) {
174
+ // if ('model' in inputData) body[inputData.model] = s(`.${inputData.id}`).value;
175
+ // }
176
+ location = this.locationFormat({ f: { location: s(`.file-explorer-query-nav`).value } });
177
+ let status = 'success';
178
+ for (const file of fileData) {
179
+ const result = await DocumentService.post({
180
+ body: {
181
+ fileId: file._id,
182
+ location,
183
+ title: file.name,
184
+ },
185
+ });
186
+ if (result.status === 'success') documentInstance.push({ ...result.data, fileId: file });
187
+ else if (status !== 'error') status = 'error';
188
+ }
189
+ const format = this.documentDataFormat({ document: documentInstance, location });
190
+ files = format.files;
191
+ folders = format.folders;
192
+ AgGrid.grids[gridFileId].setGridOption('rowData', files);
193
+ AgGrid.grids[gridFolderId].setGridOption('rowData', folders);
194
+ NotificationManager.Push({
195
+ html: Translate.Render(`${status}-upload-file`),
196
+ status,
197
+ });
198
+ if (status === 'success') {
199
+ s(`.btn-input-home-directory`).click();
200
+ s(`.btn-clear-input-file-${idDropFileInput}`).click();
201
+ }
202
+ }
203
+ });
204
+
205
+ EventsUI.onClick(`.btn-input-go-explorer`, async (e) => {
206
+ e.preventDefault();
207
+ const newLocation = this.locationFormat({ f: { location: s(`.file-explorer-query-nav`).value } });
208
+ if (newLocation === location) return;
209
+ location = newLocation;
210
+ setPath(`${window.location.pathname}?location=${location}`);
211
+ s(`.file-explorer-query-nav`).value = location;
212
+ // const format = this.documentDataFormat({ document: documentInstance, location });
213
+ await FileExplorer.Api[idModal].updateData({ display: true });
214
+ });
215
+ EventsUI.onClick(`.btn-input-home-directory`, async (e) => {
216
+ e.preventDefault();
217
+ let newLocation = '/';
218
+ if (s(`.file-explorer-uploader`).style.display !== 'none') {
219
+ s(`.file-explorer-uploader`).style.display = 'none';
220
+ s(`.file-explorer-nav`).style.display = 'block';
221
+ } else if (newLocation === location) return;
222
+ else location = newLocation;
223
+ setPath(`${window.location.pathname}?location=${location}`);
224
+ s(`.file-explorer-query-nav`).value = location;
225
+ const format = this.documentDataFormat({ document: documentInstance, location });
226
+ files = format.files;
227
+ folders = format.folders;
228
+ AgGrid.grids[gridFileId].setGridOption('rowData', files);
229
+ AgGrid.grids[gridFolderId].setGridOption('rowData', folders);
230
+ });
231
+ EventsUI.onClick(`.btn-input-copy-directory`, async (e) => {
232
+ e.preventDefault();
233
+ await copyData(window.location.href);
234
+ NotificationManager.Push({
235
+ html: Translate.Render('success-copy-data'),
236
+ status: 'success',
237
+ });
238
+ });
239
+ EventsUI.onClick(`.btn-input-back-explorer`, async (e) => {
240
+ e.preventDefault();
241
+ window.history.back();
242
+ });
243
+ EventsUI.onClick(`.btn-input-forward-explorer`, async (e) => {
244
+ e.preventDefault();
245
+ window.history.forward();
246
+ });
247
+ EventsUI.onClick(`.btn-input-upload-file`, async (e) => {
248
+ e.preventDefault();
249
+ s(`.file-explorer-nav`).style.display = 'none';
250
+ s(`.file-explorer-uploader`).style.display = 'block';
251
+ });
252
+ });
253
+
254
+ class LoadFileActionsRenderer {
255
+ eGui;
256
+
257
+ async init(params) {
258
+ console.log('LoadFileActionsRenderer created', params);
259
+ // params.data._id
260
+
261
+ this.eGui = document.createElement('div');
262
+ this.eGui.innerHTML = html`
263
+ <div class="fl">
264
+ ${await BtnIcon.Render({
265
+ class: `in fll management-table-btn-mini btn-file-download-${params.data._id}`,
266
+ label: html` <i class="fas fa-download"></i>`,
267
+ type: 'button',
268
+ })}
269
+ ${await BtnIcon.Render({
270
+ class: `in fll management-table-btn-mini btn-file-delete-${params.data._id}`,
271
+ label: html` <i class="fa-solid fa-circle-xmark"></i>`,
272
+ type: 'button',
273
+ })}
274
+ ${await BtnIcon.Render({
275
+ class: `in fll management-table-btn-mini btn-file-view-${params.data._id}`,
276
+ label: html` <i class="fas fa-eye"></i>`,
277
+ type: 'button',
278
+ })}
279
+ ${await BtnIcon.Render({
280
+ class: `in fll management-table-btn-mini btn-file-copy-content-link-${params.data._id}`,
281
+ label: html`<i class="fas fa-copy"></i>`,
282
+ type: 'button',
283
+ })}
284
+ </div>
285
+ `;
286
+
287
+ setTimeout(() => {
288
+ const uri = `${getProxyPath()}content/?cid=${params.data._id}`;
289
+ const url = `${window.location.origin}${uri}`;
290
+
291
+ const originObj = documentInstance.find((d) => d._id === params.data._id);
292
+ const blobUri = originObj ? getApiBaseUrl({ id: originObj.fileId._id, endpoint: 'file/blob' }) : undefined;
293
+
294
+ if (!originObj) {
295
+ s(`.btn-file-view-${params.data._id}`).classList.add('hide');
296
+ s(`.btn-file-copy-content-link-${params.data._id}`).classList.add('hide');
297
+ }
298
+
299
+ EventsUI.onClick(`.btn-file-view-${params.data._id}`, async (e) => {
300
+ e.preventDefault();
301
+ if (location.href !== url) {
302
+ setPath(uri);
303
+ s(`.main-btn-content`).click();
304
+ }
305
+ });
306
+
307
+ EventsUI.onClick(`.btn-file-copy-content-link-${params.data._id}`, async (e) => {
308
+ e.preventDefault();
309
+ await copyData(blobUri);
310
+ NotificationManager.Push({
311
+ html: Translate.Render('success-copy-data'),
312
+ status: 'success',
313
+ });
314
+ });
315
+
316
+ EventsUI.onClick(`.btn-file-download-${params.data._id}`, async (e) => {
317
+ e.preventDefault();
318
+ console.log(params);
319
+ const {
320
+ data: [file],
321
+ status,
322
+ } = await FileService.get({ id: params.data.fileId });
323
+
324
+ downloadFile(new Blob([new Uint8Array(file.data.data)], { type: params.data.mimetype }), params.data.name);
325
+ });
326
+ EventsUI.onClick(`.btn-file-delete-${params.data._id}`, async (e) => {
327
+ e.preventDefault();
328
+ {
329
+ const confirmResult = await Modal.RenderConfirm({
330
+ html: async () => {
331
+ return html`
332
+ <div class="in section-mp" style="text-align: center">
333
+ ${Translate.Render('confirm-delete-item')}
334
+ <br />
335
+ "${params.data.title}"
336
+ </div>
337
+ `;
338
+ },
339
+ id: `delete-${params.data._id}`,
340
+ });
341
+ if (confirmResult.status !== 'confirm') return;
342
+
343
+ const { data, status, message } = await FileService.delete({
344
+ id: params.data.fileId,
345
+ });
346
+ NotificationManager.Push({
347
+ html: status,
348
+ status,
349
+ });
350
+ if (status === 'error') return;
351
+ }
352
+ const { data, status, message } = await DocumentService.delete({
353
+ id: params.data._id,
354
+ });
355
+ NotificationManager.Push({
356
+ html: status,
357
+ status,
358
+ });
359
+ if (status === 'error') return;
360
+
361
+ documentInstance = documentInstance.filter((f) => f._id !== params.data._id);
362
+ const format = FileExplorer.documentDataFormat({ document: documentInstance, location });
363
+ files = format.files;
364
+ folders = format.folders;
365
+ // AgGrid.grids[gridFileId].setGridOption('rowData', files);
366
+ // const selectedData = gridApi.getSelectedRows();
367
+ AgGrid.grids[gridFileId].applyTransaction({ remove: [params.data] });
368
+ AgGrid.grids[gridFolderId].setGridOption('rowData', folders);
369
+ });
370
+ });
371
+ }
372
+
373
+ getGui() {
374
+ return this.eGui;
375
+ }
376
+
377
+ refresh(params) {
378
+ console.log('LoadFileActionsRenderer refreshed', params);
379
+ return true;
380
+ }
381
+ }
382
+
383
+ class LoadFolderActionsRenderer {
384
+ eGui;
385
+
386
+ async init(params) {
387
+ console.log('LoadFolderActionsRenderer created', params);
388
+ // params.data._id
389
+ const id = params.data.locationId;
390
+
391
+ this.eGui = document.createElement('div');
392
+ this.eGui.innerHTML = html`
393
+ <div class="fl">
394
+ ${await BtnIcon.Render({
395
+ class: `in fll management-table-btn-mini btn-folder-delete-${id}`,
396
+ label: html` <i class="fa-solid fa-circle-xmark"></i>`,
397
+ type: 'button',
398
+ })}
399
+ </div>
400
+ `;
401
+
402
+ setTimeout(() => {
403
+ EventsUI.onClick(`.btn-folder-delete-${id}`, async (e) => {
404
+ const confirmResult = await Modal.RenderConfirm({
405
+ html: async () => {
406
+ return html`
407
+ <div class="in section-mp" style="text-align: center">
408
+ ${Translate.Render('confirm-delete-item')}
409
+ <br />
410
+ "${params.data.location}"
411
+ </div>
412
+ `;
413
+ },
414
+ id: `delete-${id}`,
415
+ });
416
+ if (confirmResult.status !== 'confirm') return;
417
+
418
+ e.preventDefault();
419
+ const idFilesDelete = [];
420
+ for (const file of documentInstance.filter(
421
+ (f) => FileExplorer.locationFormat({ f }) === params.data.location, // .startsWith(params.data.location),
422
+ )) {
423
+ {
424
+ const { data, status, message } = await FileService.delete({
425
+ id: file.fileId._id,
426
+ });
427
+ }
428
+ {
429
+ idFilesDelete.push(file._id);
430
+ const { data, status, message } = await DocumentService.delete({
431
+ id: file._id,
432
+ });
433
+ }
434
+ }
435
+ NotificationManager.Push({
436
+ html: Translate.Render('success-delete'),
437
+ status: 'success',
438
+ });
439
+ documentInstance = documentInstance.filter((f) => !idFilesDelete.includes(f._id));
440
+ const format = FileExplorer.documentDataFormat({ document: documentInstance, location });
441
+ files = format.files;
442
+ folders = format.folders;
443
+ AgGrid.grids[gridFileId].setGridOption('rowData', files);
444
+ AgGrid.grids[gridFolderId].setGridOption('rowData', folders);
445
+ });
446
+ });
447
+ }
448
+
449
+ getGui() {
450
+ return this.eGui;
451
+ }
452
+
453
+ refresh(params) {
454
+ console.log('LoadFolderActionsRenderer refreshed', params);
455
+ return true;
456
+ }
457
+ }
458
+
459
+ return html`
460
+ <form>
461
+ <div class="fl">
462
+ ${await BtnIcon.Render({
463
+ class: 'in fll management-table-btn-mini btn-input-home-directory',
464
+ label: html`<i class="fas fa-home"></i>
465
+ <!-- ${Translate.Render('home-directory')} -->`,
466
+ type: 'button',
467
+ })}
468
+ ${await BtnIcon.Render({
469
+ class: 'in fll management-table-btn-mini btn-input-back-explorer',
470
+ label: html` <i class="fa-solid fa-circle-left"></i>
471
+ <!-- ${Translate.Render('go')} -->`,
472
+ type: 'button',
473
+ })}
474
+ ${await BtnIcon.Render({
475
+ class: 'in fll management-table-btn-mini btn-input-forward-explorer',
476
+ label: html` <i class="fa-solid fa-circle-right"></i>
477
+ <!-- ${Translate.Render('go')} -->`,
478
+ type: 'button',
479
+ })}
480
+ ${await BtnIcon.Render({
481
+ class: 'in fll management-table-btn-mini btn-input-go-explorer',
482
+ label: html`<i class="fas fa-sync-alt"></i>
483
+ <!-- ${Translate.Render('go')} -->`,
484
+ type: 'submit',
485
+ })}
486
+ ${await BtnIcon.Render({
487
+ class: 'in fll management-table-btn-mini btn-input-copy-directory',
488
+ label: html`<i class="fas fa-copy"></i>
489
+ <!-- ${Translate.Render('home-directory')} -->`,
490
+ type: 'button',
491
+ })}
492
+ ${await BtnIcon.Render({
493
+ class: 'in fll management-table-btn-mini btn-input-upload-file',
494
+ label: html`<i class="fa-solid fa-cloud-arrow-up"></i>
495
+ <!-- ${Translate.Render('home-directory')} -->`,
496
+ type: 'button',
497
+ })}
498
+ </div>
499
+ <div class="in">
500
+ ${await Input.Render({
501
+ id: `file-explorer-query-nav`,
502
+ type: 'text',
503
+ label: html`<i class="fab fa-wpexplorer"></i> ${Translate.Render('current-path')}`,
504
+ containerClass: 'in section-mp input-container-width',
505
+ placeholder: true,
506
+ value: location,
507
+ })}
508
+ </div>
509
+ </form>
510
+ <div class="fl file-explorer-nav">
511
+ <div class="in fll explorer-file-col">
512
+ <div class="in explorer-file-sub-col section-mp">
513
+ <div class="in">
514
+ ${await AgGrid.Render({
515
+ id: gridFolderId,
516
+ darkTheme,
517
+ // style: {
518
+ // height: '200px',
519
+ // },
520
+ gridOptions: {
521
+ defaultColDef: {
522
+ editable: false,
523
+ minWidth: 100,
524
+ filter: true,
525
+ autoHeight: true,
526
+ },
527
+ rowData: folders,
528
+ columnDefs: [
529
+ {
530
+ field: 'location',
531
+ headerName: 'Folder',
532
+ minWidth: 200,
533
+ flex: 1,
534
+ cellStyle: function (params) {
535
+ return { cursor: 'pointer' };
536
+ },
537
+ cellRenderer: LoadFolderRenderer,
538
+ onCellClicked: (event) => {
539
+ // console.warn('onCellClicked', event);
540
+ const newLocation = event.data.location;
541
+ if (newLocation === location) return;
542
+ location = newLocation;
543
+ setPath(`${window.location.pathname}?location=${location}`);
544
+ s(`.file-explorer-query-nav`).value = location;
545
+ const format = this.documentDataFormat({ document: documentInstance, location });
546
+ files = format.files;
547
+ folders = format.folders;
548
+ AgGrid.grids[gridFileId].setGridOption('rowData', files);
549
+ AgGrid.grids[gridFolderId].setGridOption('rowData', folders);
550
+ },
551
+ },
552
+ {
553
+ // suppressHeaderMenuButton: true,
554
+ // sortable: false,
555
+ field: 'fileCount',
556
+ headerName: '🗎',
557
+ width: 60,
558
+ cellStyle: function (params) {
559
+ return { cursor: 'pointer' };
560
+ },
561
+ // headerComponent: FolderHeaderComp,
562
+ // headerComponentParams: {
563
+ // menuIcon: 'fa-bars',
564
+ // template: `test`,
565
+ // },
566
+ },
567
+ { headerName: '', width: 60, cellRenderer: LoadFolderActionsRenderer },
568
+ ],
569
+ rowSelection: 'single',
570
+ onSelectionChanged: (event) => {
571
+ return;
572
+ const selectedRows = AgGrid.grids[gridFolderId].getSelectedRows();
573
+ console.log('selectedRows', { event, selectedRows });
574
+ if (selectedRows[0]) {
575
+ const newLocation = selectedRows[0].location;
576
+ if (newLocation === location) return;
577
+ location = newLocation;
578
+ setPath(`${window.location.pathname}?location=${location}`);
579
+ s(`.file-explorer-query-nav`).value = location;
580
+ const format = this.documentDataFormat({ document: documentInstance, location });
581
+ files = format.files;
582
+ folders = format.folders;
583
+ AgGrid.grids[gridFileId].setGridOption('rowData', files);
584
+ AgGrid.grids[gridFolderId].setGridOption('rowData', folders);
585
+ }
586
+ },
587
+ },
588
+ })}
589
+ </div>
590
+ </div>
591
+ </div>
592
+ <div class="in fll explorer-file-col">
593
+ <div class="in explorer-file-sub-col section-mp">
594
+ <div class="in">
595
+ ${await AgGrid.Render({
596
+ id: gridFileId,
597
+ darkTheme,
598
+ // style: {
599
+ // height: '200px',
600
+ // },
601
+ gridOptions: {
602
+ defaultColDef: {
603
+ editable: false,
604
+ minWidth: 100,
605
+ filter: true,
606
+ autoHeight: true,
607
+ },
608
+ // rowData: files,
609
+ rowData: undefined,
610
+ columnDefs: [
611
+ { field: 'name', flex: 2, headerName: 'Name', cellRenderer: LoadFileNameRenderer },
612
+ { field: 'mimetype', flex: 1, headerName: 'Type' },
613
+ { headerName: '', width: 80, cellRenderer: LoadFileActionsRenderer },
614
+ ],
615
+ },
616
+ })}
617
+ </div>
618
+ </div>
619
+ </div>
620
+ </div>
621
+ <form class="file-explorer-uploader" style="display: none">
622
+ ${await InputFile.Render(
623
+ {
624
+ id: idDropFileInput,
625
+ multiple: true,
626
+ },
627
+ {
628
+ clear: () => {
629
+ console.log('file explorer clear file');
630
+ formBodyFiles = undefined;
631
+ },
632
+ change: (e) => {
633
+ console.log('file explorer change file', e);
634
+ formBodyFiles = fileFormDataFactory(e);
635
+ },
636
+ },
637
+ )}
638
+ <div class="in">
639
+ ${await BtnIcon.Render({
640
+ class: 'wfa section-mp btn-input-file-explorer',
641
+ style: renderCssAttr({
642
+ style: {
643
+ 'font-size': '25px',
644
+ 'text-align': 'center',
645
+ padding: '20px',
646
+ },
647
+ }),
648
+ label: html`<i class="fa-solid fa-cloud-arrow-up"></i> ${Translate.Render('upload')}`,
649
+ type: 'submit',
650
+ })}
651
+ </div>
652
+ </form>
653
+ `;
654
+ },
655
+ locationFormat: function ({ f }) {
656
+ if (f.location[0] !== '/') f.location = `/${f.location}`;
657
+ if (f.location !== '/' && f.location[f.location.length - 1] === '/') f.location = f.location.slice(0, -1);
658
+ return f.location;
659
+ },
660
+ documentDataFormat: function ({ document, location }) {
661
+ let files = document.map((f) => {
662
+ if (!f.fileId)
663
+ f.fileId = {
664
+ name: f.title + '.md',
665
+ mimetype: 'text/markdown',
666
+ _id: f.mdFileId,
667
+ };
668
+ return {
669
+ location: this.locationFormat({ f }),
670
+ name: f.fileId.name,
671
+ mimetype: f.fileId.mimetype,
672
+ fileId: f.fileId._id,
673
+ _id: f._id,
674
+ title: f.title,
675
+ };
676
+ });
677
+ let documentId = document._id;
678
+ let folders = [];
679
+ for (const folderPath of uniqueArray(files.map((f) => f.location)))
680
+ folders = ['/'].concat(folders.concat(getSubpaths(folderPath)));
681
+ folders = uniqueArray(folders).map((f, i) => {
682
+ return {
683
+ location: f,
684
+ locationId: `loc-${i}`,
685
+ };
686
+ });
687
+ files = files.filter((f) => f.location === location);
688
+ folders = folders
689
+ .filter((f) => f.location.startsWith(location))
690
+ .map((f) => {
691
+ f.fileCount = document.filter((file) => file.location === f.location).length;
692
+ return f;
693
+ })
694
+ .filter((f) => f.fileCount > 0);
695
+ return { files, documentId, folders };
696
+ },
697
+ };
698
+
699
+ export { FileExplorer };