lupine.api 1.1.57 → 1.1.59
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/README.md +3 -3
- package/admin/admin-about.tsx +12 -16
- package/admin/admin-config.tsx +47 -44
- package/admin/admin-css.tsx +3 -3
- package/admin/admin-db.tsx +75 -75
- package/admin/admin-frame-helper.tsx +364 -364
- package/admin/admin-frame.tsx +164 -164
- package/admin/admin-index.tsx +65 -65
- package/admin/admin-login.tsx +111 -111
- package/admin/admin-menu-edit.tsx +637 -637
- package/admin/admin-menu-list.tsx +87 -87
- package/admin/admin-page-edit.tsx +564 -564
- package/admin/admin-page-list.tsx +83 -83
- package/admin/admin-performance.tsx +28 -28
- package/admin/admin-release.tsx +427 -404
- package/admin/admin-resources.tsx +382 -382
- package/admin/admin-shell.tsx +89 -89
- package/admin/admin-table-data.tsx +146 -146
- package/admin/admin-table-list.tsx +230 -230
- package/admin/admin-test-animations.tsx +395 -395
- package/admin/admin-test-component.tsx +823 -808
- package/admin/admin-test-edit.tsx +319 -319
- package/admin/admin-test-themes.tsx +56 -56
- package/admin/admin-tokens.tsx +338 -338
- package/admin/design/admin-design.tsx +174 -174
- package/admin/design/block-grid.tsx +36 -36
- package/admin/design/block-grid1.tsx +21 -21
- package/admin/design/block-paragraph.tsx +19 -19
- package/admin/design/block-title.tsx +19 -19
- package/admin/design/design-block-box.tsx +140 -140
- package/admin/design/drag-data.tsx +24 -24
- package/admin/index.ts +9 -9
- package/admin/package.json +15 -15
- package/admin/tsconfig.json +127 -127
- package/dev/copy-folder.js +32 -32
- package/dev/cp-index-html.js +69 -69
- package/dev/file-utils.js +12 -12
- package/dev/index.js +18 -19
- package/dev/package.json +12 -12
- package/dev/plugin-ifelse.js +168 -168
- package/dev/plugin-ifelse.test.js +37 -37
- package/dev/run-cmd.js +14 -14
- package/dev/send-request.js +12 -12
- package/package.json +55 -55
- package/src/admin-api/admin-api-helper.ts +210 -205
- package/src/admin-api/admin-api.ts +65 -65
- package/src/admin-api/admin-auth.ts +152 -146
- package/src/admin-api/admin-config.ts +94 -84
- package/src/admin-api/admin-csv.ts +94 -94
- package/src/admin-api/admin-db.ts +269 -269
- package/src/admin-api/admin-menu.ts +135 -135
- package/src/admin-api/admin-page.ts +135 -135
- package/src/admin-api/admin-performance.ts +128 -128
- package/src/admin-api/admin-release.ts +703 -700
- package/src/admin-api/admin-resources.ts +318 -318
- package/src/admin-api/admin-token-helper.ts +82 -79
- package/src/admin-api/admin-tokens.ts +90 -90
- package/src/admin-api/index.ts +2 -2
- package/src/admin-api/web-config-api.ts +19 -19
- package/src/api/api-cache.ts +103 -103
- package/src/api/api-helper.ts +44 -44
- package/src/api/api-module.ts +67 -60
- package/src/api/api-router.ts +177 -177
- package/src/api/api-shared-storage.ts +64 -64
- package/src/api/async-storage.ts +5 -5
- package/src/api/debug-service.ts +56 -56
- package/src/api/encode-html.ts +27 -27
- package/src/api/handle-status.ts +75 -75
- package/src/api/index.ts +15 -16
- package/src/api/mini-web-socket.ts +270 -270
- package/src/api/server-content-type.ts +82 -82
- package/src/api/server-render.ts +235 -215
- package/src/api/shell-service.ts +74 -74
- package/src/api/simple-storage.ts +80 -80
- package/src/api/static-server.ts +128 -125
- package/src/api/to-client-delivery.ts +26 -26
- package/src/app/app-cache.ts +55 -55
- package/src/app/app-helper.ts +62 -62
- package/src/app/app-message.ts +109 -109
- package/src/app/app-shared-storage.ts +363 -363
- package/src/app/app-start.ts +136 -136
- package/src/app/cleanup-exit.ts +16 -16
- package/src/app/host-to-path.ts +38 -38
- package/src/app/index.ts +11 -11
- package/src/app/process-dev-requests.ts +130 -130
- package/src/app/web-listener.ts +294 -294
- package/src/app/web-processor.ts +47 -42
- package/src/app/web-server.ts +100 -100
- package/src/common-js/web-env.js +104 -104
- package/src/index.ts +7 -7
- package/src/lang/api-lang-en.ts +26 -26
- package/src/lang/api-lang-zh-cn.ts +27 -27
- package/src/lang/index.ts +2 -2
- package/src/lang/lang-helper.ts +76 -76
- package/src/lang/lang-props.ts +6 -6
- package/src/lib/db/db-helper.ts +23 -23
- package/src/lib/db/db-mysql.ts +249 -250
- package/src/lib/db/db-sqlite.ts +101 -101
- package/src/lib/db/db.spec.ts +28 -28
- package/src/lib/db/db.ts +325 -325
- package/src/lib/db/index.ts +5 -5
- package/src/lib/index.ts +3 -3
- package/src/lib/logger.spec.ts +214 -214
- package/src/lib/logger.ts +281 -281
- package/src/lib/runtime-require.ts +37 -37
- package/src/lib/utils/cookie-util.ts +34 -34
- package/src/lib/utils/crypto.ts +58 -58
- package/src/lib/utils/date-utils.ts +317 -317
- package/src/lib/utils/deep-merge.ts +37 -37
- package/src/lib/utils/delay.ts +12 -12
- package/src/lib/utils/file-setting.ts +55 -55
- package/src/lib/utils/format-bytes.ts +11 -11
- package/src/lib/utils/fs-utils.ts +158 -158
- package/src/lib/utils/get-env.ts +27 -27
- package/src/lib/utils/index.ts +12 -12
- package/src/lib/utils/is-type.ts +48 -48
- package/src/lib/utils/load-env.ts +14 -14
- package/src/lib/utils/pad.ts +6 -6
- package/src/models/api-base.ts +5 -5
- package/src/models/api-module-props.ts +10 -11
- package/src/models/api-router-props.ts +26 -26
- package/src/models/app-cache-props.ts +33 -33
- package/src/models/app-data-props.ts +10 -10
- package/src/models/app-helper-props.ts +6 -6
- package/src/models/app-shared-storage-props.ts +38 -38
- package/src/models/app-start-props.ts +18 -18
- package/src/models/async-storage-props.ts +13 -13
- package/src/models/db-config.ts +30 -30
- package/src/models/host-to-path-props.ts +12 -12
- package/src/models/index.ts +16 -16
- package/src/models/json-object.ts +8 -8
- package/src/models/locals-props.ts +36 -36
- package/src/models/logger-props.ts +84 -84
- package/src/models/simple-storage-props.ts +13 -14
- package/src/models/to-client-delivery-props.ts +6 -6
- package/tsconfig.json +115 -115
- package/dev/plugin-gen-versions.js +0 -20
|
@@ -1,230 +1,230 @@
|
|
|
1
|
-
import {
|
|
2
|
-
NotificationColor,
|
|
3
|
-
NotificationMessage,
|
|
4
|
-
CssProps,
|
|
5
|
-
RefProps,
|
|
6
|
-
getRenderPageProps,
|
|
7
|
-
mountInnerComponent,
|
|
8
|
-
downloadLink,
|
|
9
|
-
} from 'lupine.components';
|
|
10
|
-
import { TableDataPage } from './admin-table-data';
|
|
11
|
-
import { adminFrameHelper } from './admin-frame-helper';
|
|
12
|
-
|
|
13
|
-
const fetchTableList = async () => {
|
|
14
|
-
const data = await getRenderPageProps().renderPageFunctions.fetchData('/api/admin/db/tables/list');
|
|
15
|
-
return data.json;
|
|
16
|
-
};
|
|
17
|
-
const fetchTableDrop = async (tableName: string) => {
|
|
18
|
-
const data = await getRenderPageProps().renderPageFunctions.fetchData(`/api/admin/db/table/drop/${tableName}`);
|
|
19
|
-
return data.json;
|
|
20
|
-
};
|
|
21
|
-
const fetchTableTruncate = async (tableName: string) => {
|
|
22
|
-
const data = await getRenderPageProps().renderPageFunctions.fetchData('/api/admin/db/table/truncate/' + tableName);
|
|
23
|
-
return data.json;
|
|
24
|
-
};
|
|
25
|
-
const fetchTableTruncateAll = async () => {
|
|
26
|
-
const data = await getRenderPageProps().renderPageFunctions.fetchData('/api/admin/db/tables/truncate');
|
|
27
|
-
return data.json;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const TableListPage = () => {
|
|
31
|
-
const refUpdate = adminFrameHelper.getTabsHook();
|
|
32
|
-
|
|
33
|
-
const openTablePanel = async (tableName: string) => {
|
|
34
|
-
if (refUpdate?.getCount && refUpdate.getCount() > adminFrameHelper.getMaxTabsCount()) {
|
|
35
|
-
alert('You are opening too many pages');
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (refUpdate?.findAndActivate && refUpdate.findAndActivate('Table: ' + tableName)) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
refUpdate?.newPage && (await refUpdate.newPage('Table: ' + tableName, TableDataPage(tableName)));
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const onDelete = async (tableName: string) => {
|
|
45
|
-
if (!confirm(`Are you really Deleting ${tableName}?`)) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const json = await fetchTableDrop(tableName);
|
|
49
|
-
console.log('====fetchTableDelete', json);
|
|
50
|
-
NotificationMessage.sendMessage('Deleted: ' + tableName);
|
|
51
|
-
onClick();
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const onDownload = async (tableName: string) => {
|
|
55
|
-
downloadLink('/api/admin/db/table/download/' + tableName);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const onTruncate = async (tableName: string) => {
|
|
59
|
-
if (!confirm(`Are you really Removing all data for ${tableName}?`)) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const json = await fetchTableTruncate(tableName);
|
|
63
|
-
console.log('====fetchTableTruncate', json);
|
|
64
|
-
NotificationMessage.sendMessage('Truncated: ' + tableName);
|
|
65
|
-
onClick();
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const onDownloadAll = async () => {
|
|
69
|
-
downloadLink('/api/admin/db/tables/download');
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const onTruncateAll = async () => {
|
|
73
|
-
if (!confirm(`Are you really Removing all data for all tables? You can't revert it! (first confirm)`)) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (
|
|
77
|
-
!confirm(`Are you really Removing all data for all tables? You may not be able to login again! (last confirm)`)
|
|
78
|
-
) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
await fetchTableTruncateAll();
|
|
82
|
-
NotificationMessage.sendMessage('Truncated all tables!');
|
|
83
|
-
onClick();
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const onDropAll = async () => {
|
|
87
|
-
if (!confirm(`Are you really Dropping all tables? You can't revert it! (first confirm)`)) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
if (!confirm(`Are you really Dropping all tables? You may not be able to login again! (last confirm)`)) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const data = await getRenderPageProps().renderPageFunctions.fetchData('/api/admin/db/tables/drop');
|
|
94
|
-
NotificationMessage.sendMessage('Dropped all tables!' + JSON.stringify(data.json, null, ' '));
|
|
95
|
-
onClick();
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const onClick = async () => {
|
|
99
|
-
const search = refInput.current.value;
|
|
100
|
-
const json = await fetchTableList();
|
|
101
|
-
console.log('====fetchTableList', json);
|
|
102
|
-
|
|
103
|
-
if (!json || json.status !== 'ok') {
|
|
104
|
-
NotificationMessage.sendMessage(json.message, NotificationColor.Error);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const dom =
|
|
108
|
-
json && json.status === 'ok' && json.result.length > 0 ? (
|
|
109
|
-
<div>
|
|
110
|
-
{json.result
|
|
111
|
-
.filter((item: { tbl_name: string | any[] }) => {
|
|
112
|
-
return !search || item.tbl_name.indexOf(search) >= 0;
|
|
113
|
-
})
|
|
114
|
-
.map((item: any, index: number) => {
|
|
115
|
-
return (
|
|
116
|
-
<div class={'row-' + (index % 2)}>
|
|
117
|
-
<a href='javascript:void(0);' onClick={() => openTablePanel(item.tbl_name)}>
|
|
118
|
-
{item.tbl_name}
|
|
119
|
-
</a>
|
|
120
|
-
, count: {item.count}
|
|
121
|
-
<div>sql: {item.sql},</div>
|
|
122
|
-
<div class={'row-box'}>
|
|
123
|
-
<button onClick={() => openTablePanel(item.tbl_name)} class='button-base button-s'>
|
|
124
|
-
Browse
|
|
125
|
-
</button>
|
|
126
|
-
<button onClick={() => onDownload(item.tbl_name)} class='button-base button-s'>
|
|
127
|
-
Download
|
|
128
|
-
</button>
|
|
129
|
-
<button onClick={() => onTruncate(item.tbl_name)} class='button-base button-s red'>
|
|
130
|
-
Truncate
|
|
131
|
-
</button>
|
|
132
|
-
<button onClick={() => onDelete(item.tbl_name)} class='button-base button-s red'>
|
|
133
|
-
Drop
|
|
134
|
-
</button>
|
|
135
|
-
</div>
|
|
136
|
-
</div>
|
|
137
|
-
);
|
|
138
|
-
})}
|
|
139
|
-
</div>
|
|
140
|
-
) : (
|
|
141
|
-
<div>No Result</div>
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
await mountInnerComponent(document.querySelector('.admin-table-list'), dom);
|
|
145
|
-
};
|
|
146
|
-
const onUpload = async () => {
|
|
147
|
-
const domFile = document.querySelector('#upload_data') as HTMLInputElement;
|
|
148
|
-
if (!domFile.files || domFile.files.length !== 1) {
|
|
149
|
-
alert('Please select one and only one file.');
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const data = await fetch('/api/admin/db/tables/upload', {
|
|
154
|
-
method: 'POST',
|
|
155
|
-
body: new Uint8Array(await domFile.files[0].arrayBuffer()),
|
|
156
|
-
headers: {
|
|
157
|
-
'Content-type': domFile.files[0].type,
|
|
158
|
-
},
|
|
159
|
-
});
|
|
160
|
-
const result = await data.json();
|
|
161
|
-
domFile.value = '';
|
|
162
|
-
onClick();
|
|
163
|
-
// document.querySelector('.admin-table-log')!.innerHTML = JSON.stringify(result, null, ' ');
|
|
164
|
-
NotificationMessage.sendMessage(JSON.stringify(result, null, ' '), NotificationColor.Info, true);
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
const css: CssProps = {
|
|
168
|
-
'.admin-table-list > div > div': {
|
|
169
|
-
backgroundColor: 'var(--row-1-bg-color)', //'#95c998',
|
|
170
|
-
marginTop: '16px',
|
|
171
|
-
},
|
|
172
|
-
'.admin-table-list .row-1': {
|
|
173
|
-
backgroundColor: 'var(--row-2-bg-color)', //'#e8f8e8', //#95c998
|
|
174
|
-
},
|
|
175
|
-
'.admin-table-list > div > div:hover': {
|
|
176
|
-
backgroundColor: 'var(--row-hover-bg-color)',
|
|
177
|
-
},
|
|
178
|
-
'.admin-table-log': {
|
|
179
|
-
display: 'block',
|
|
180
|
-
unicodeBidi: 'embed',
|
|
181
|
-
fontFamily: 'monospace',
|
|
182
|
-
whiteSpace: 'pre',
|
|
183
|
-
},
|
|
184
|
-
};
|
|
185
|
-
let timeoutID: NodeJS.Timeout | undefined = undefined;
|
|
186
|
-
const refInput: RefProps = {};
|
|
187
|
-
const ref: RefProps = {
|
|
188
|
-
onLoad: onClick,
|
|
189
|
-
};
|
|
190
|
-
const onInput = () => {
|
|
191
|
-
if (timeoutID) {
|
|
192
|
-
clearTimeout(timeoutID);
|
|
193
|
-
}
|
|
194
|
-
timeoutID = setTimeout(() => {
|
|
195
|
-
onClick();
|
|
196
|
-
}, 500);
|
|
197
|
-
};
|
|
198
|
-
return (
|
|
199
|
-
<div css={css} ref={ref}>
|
|
200
|
-
<div class='admin-sub-title'>Table List</div>
|
|
201
|
-
<div class='row-box'>
|
|
202
|
-
<div>
|
|
203
|
-
<input type='text' ref={refInput} class='input-base' placeholder='Search' onInput={onInput} />
|
|
204
|
-
</div>
|
|
205
|
-
<button onClick={onClick} class='button-base'>
|
|
206
|
-
Refresh List
|
|
207
|
-
</button>
|
|
208
|
-
<button onClick={onDownloadAll} class='button-base'>
|
|
209
|
-
Download all data
|
|
210
|
-
</button>
|
|
211
|
-
<button onClick={onTruncateAll} class='button-base red'>
|
|
212
|
-
Truncate all data
|
|
213
|
-
</button>
|
|
214
|
-
<button onClick={onDropAll} class='button-base red'>
|
|
215
|
-
Drop all table
|
|
216
|
-
</button>
|
|
217
|
-
</div>
|
|
218
|
-
<div class='row-box mt1'>
|
|
219
|
-
<div>
|
|
220
|
-
<input type='file' id='upload_data' class='input-base' />
|
|
221
|
-
</div>
|
|
222
|
-
<button onClick={onUpload} class='button-base'>
|
|
223
|
-
Upload
|
|
224
|
-
</button>
|
|
225
|
-
</div>
|
|
226
|
-
<div class='admin-table-log'></div>
|
|
227
|
-
<div class='admin-table-list'>(Table list)</div>
|
|
228
|
-
</div>
|
|
229
|
-
);
|
|
230
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
NotificationColor,
|
|
3
|
+
NotificationMessage,
|
|
4
|
+
CssProps,
|
|
5
|
+
RefProps,
|
|
6
|
+
getRenderPageProps,
|
|
7
|
+
mountInnerComponent,
|
|
8
|
+
downloadLink,
|
|
9
|
+
} from 'lupine.components';
|
|
10
|
+
import { TableDataPage } from './admin-table-data';
|
|
11
|
+
import { adminFrameHelper } from './admin-frame-helper';
|
|
12
|
+
|
|
13
|
+
const fetchTableList = async () => {
|
|
14
|
+
const data = await getRenderPageProps().renderPageFunctions.fetchData('/api/admin/db/tables/list');
|
|
15
|
+
return data.json;
|
|
16
|
+
};
|
|
17
|
+
const fetchTableDrop = async (tableName: string) => {
|
|
18
|
+
const data = await getRenderPageProps().renderPageFunctions.fetchData(`/api/admin/db/table/drop/${tableName}`);
|
|
19
|
+
return data.json;
|
|
20
|
+
};
|
|
21
|
+
const fetchTableTruncate = async (tableName: string) => {
|
|
22
|
+
const data = await getRenderPageProps().renderPageFunctions.fetchData('/api/admin/db/table/truncate/' + tableName);
|
|
23
|
+
return data.json;
|
|
24
|
+
};
|
|
25
|
+
const fetchTableTruncateAll = async () => {
|
|
26
|
+
const data = await getRenderPageProps().renderPageFunctions.fetchData('/api/admin/db/tables/truncate');
|
|
27
|
+
return data.json;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const TableListPage = () => {
|
|
31
|
+
const refUpdate = adminFrameHelper.getTabsHook();
|
|
32
|
+
|
|
33
|
+
const openTablePanel = async (tableName: string) => {
|
|
34
|
+
if (refUpdate?.getCount && refUpdate.getCount() > adminFrameHelper.getMaxTabsCount()) {
|
|
35
|
+
alert('You are opening too many pages');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (refUpdate?.findAndActivate && refUpdate.findAndActivate('Table: ' + tableName)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
refUpdate?.newPage && (await refUpdate.newPage('Table: ' + tableName, TableDataPage(tableName)));
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const onDelete = async (tableName: string) => {
|
|
45
|
+
if (!confirm(`Are you really Deleting ${tableName}?`)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const json = await fetchTableDrop(tableName);
|
|
49
|
+
console.log('====fetchTableDelete', json);
|
|
50
|
+
NotificationMessage.sendMessage('Deleted: ' + tableName);
|
|
51
|
+
onClick();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const onDownload = async (tableName: string) => {
|
|
55
|
+
downloadLink('/api/admin/db/table/download/' + tableName);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const onTruncate = async (tableName: string) => {
|
|
59
|
+
if (!confirm(`Are you really Removing all data for ${tableName}?`)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const json = await fetchTableTruncate(tableName);
|
|
63
|
+
console.log('====fetchTableTruncate', json);
|
|
64
|
+
NotificationMessage.sendMessage('Truncated: ' + tableName);
|
|
65
|
+
onClick();
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const onDownloadAll = async () => {
|
|
69
|
+
downloadLink('/api/admin/db/tables/download');
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const onTruncateAll = async () => {
|
|
73
|
+
if (!confirm(`Are you really Removing all data for all tables? You can't revert it! (first confirm)`)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (
|
|
77
|
+
!confirm(`Are you really Removing all data for all tables? You may not be able to login again! (last confirm)`)
|
|
78
|
+
) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
await fetchTableTruncateAll();
|
|
82
|
+
NotificationMessage.sendMessage('Truncated all tables!');
|
|
83
|
+
onClick();
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const onDropAll = async () => {
|
|
87
|
+
if (!confirm(`Are you really Dropping all tables? You can't revert it! (first confirm)`)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (!confirm(`Are you really Dropping all tables? You may not be able to login again! (last confirm)`)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const data = await getRenderPageProps().renderPageFunctions.fetchData('/api/admin/db/tables/drop');
|
|
94
|
+
NotificationMessage.sendMessage('Dropped all tables!' + JSON.stringify(data.json, null, ' '));
|
|
95
|
+
onClick();
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const onClick = async () => {
|
|
99
|
+
const search = refInput.current.value;
|
|
100
|
+
const json = await fetchTableList();
|
|
101
|
+
console.log('====fetchTableList', json);
|
|
102
|
+
|
|
103
|
+
if (!json || json.status !== 'ok') {
|
|
104
|
+
NotificationMessage.sendMessage(json.message, NotificationColor.Error);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const dom =
|
|
108
|
+
json && json.status === 'ok' && json.result.length > 0 ? (
|
|
109
|
+
<div>
|
|
110
|
+
{json.result
|
|
111
|
+
.filter((item: { tbl_name: string | any[] }) => {
|
|
112
|
+
return !search || item.tbl_name.indexOf(search) >= 0;
|
|
113
|
+
})
|
|
114
|
+
.map((item: any, index: number) => {
|
|
115
|
+
return (
|
|
116
|
+
<div class={'row-' + (index % 2)}>
|
|
117
|
+
<a href='javascript:void(0);' onClick={() => openTablePanel(item.tbl_name)}>
|
|
118
|
+
{item.tbl_name}
|
|
119
|
+
</a>
|
|
120
|
+
, count: {item.count}
|
|
121
|
+
<div>sql: {item.sql},</div>
|
|
122
|
+
<div class={'row-box'}>
|
|
123
|
+
<button onClick={() => openTablePanel(item.tbl_name)} class='button-base button-s'>
|
|
124
|
+
Browse
|
|
125
|
+
</button>
|
|
126
|
+
<button onClick={() => onDownload(item.tbl_name)} class='button-base button-s'>
|
|
127
|
+
Download
|
|
128
|
+
</button>
|
|
129
|
+
<button onClick={() => onTruncate(item.tbl_name)} class='button-base button-s red'>
|
|
130
|
+
Truncate
|
|
131
|
+
</button>
|
|
132
|
+
<button onClick={() => onDelete(item.tbl_name)} class='button-base button-s red'>
|
|
133
|
+
Drop
|
|
134
|
+
</button>
|
|
135
|
+
</div>
|
|
136
|
+
</div>
|
|
137
|
+
);
|
|
138
|
+
})}
|
|
139
|
+
</div>
|
|
140
|
+
) : (
|
|
141
|
+
<div>No Result</div>
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
await mountInnerComponent(document.querySelector('.admin-table-list'), dom);
|
|
145
|
+
};
|
|
146
|
+
const onUpload = async () => {
|
|
147
|
+
const domFile = document.querySelector('#upload_data') as HTMLInputElement;
|
|
148
|
+
if (!domFile.files || domFile.files.length !== 1) {
|
|
149
|
+
alert('Please select one and only one file.');
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const data = await fetch('/api/admin/db/tables/upload', {
|
|
154
|
+
method: 'POST',
|
|
155
|
+
body: new Uint8Array(await domFile.files[0].arrayBuffer()),
|
|
156
|
+
headers: {
|
|
157
|
+
'Content-type': domFile.files[0].type,
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
const result = await data.json();
|
|
161
|
+
domFile.value = '';
|
|
162
|
+
onClick();
|
|
163
|
+
// document.querySelector('.admin-table-log')!.innerHTML = JSON.stringify(result, null, ' ');
|
|
164
|
+
NotificationMessage.sendMessage(JSON.stringify(result, null, ' '), NotificationColor.Info, true);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const css: CssProps = {
|
|
168
|
+
'.admin-table-list > div > div': {
|
|
169
|
+
backgroundColor: 'var(--row-1-bg-color)', //'#95c998',
|
|
170
|
+
marginTop: '16px',
|
|
171
|
+
},
|
|
172
|
+
'.admin-table-list .row-1': {
|
|
173
|
+
backgroundColor: 'var(--row-2-bg-color)', //'#e8f8e8', //#95c998
|
|
174
|
+
},
|
|
175
|
+
'.admin-table-list > div > div:hover': {
|
|
176
|
+
backgroundColor: 'var(--row-hover-bg-color)',
|
|
177
|
+
},
|
|
178
|
+
'.admin-table-log': {
|
|
179
|
+
display: 'block',
|
|
180
|
+
unicodeBidi: 'embed',
|
|
181
|
+
fontFamily: 'monospace',
|
|
182
|
+
whiteSpace: 'pre',
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
let timeoutID: NodeJS.Timeout | undefined = undefined;
|
|
186
|
+
const refInput: RefProps = {};
|
|
187
|
+
const ref: RefProps = {
|
|
188
|
+
onLoad: onClick,
|
|
189
|
+
};
|
|
190
|
+
const onInput = () => {
|
|
191
|
+
if (timeoutID) {
|
|
192
|
+
clearTimeout(timeoutID);
|
|
193
|
+
}
|
|
194
|
+
timeoutID = setTimeout(() => {
|
|
195
|
+
onClick();
|
|
196
|
+
}, 500);
|
|
197
|
+
};
|
|
198
|
+
return (
|
|
199
|
+
<div css={css} ref={ref}>
|
|
200
|
+
<div class='admin-sub-title'>Table List</div>
|
|
201
|
+
<div class='row-box'>
|
|
202
|
+
<div>
|
|
203
|
+
<input type='text' ref={refInput} class='input-base' placeholder='Search' onInput={onInput} />
|
|
204
|
+
</div>
|
|
205
|
+
<button onClick={onClick} class='button-base'>
|
|
206
|
+
Refresh List
|
|
207
|
+
</button>
|
|
208
|
+
<button onClick={onDownloadAll} class='button-base'>
|
|
209
|
+
Download all data
|
|
210
|
+
</button>
|
|
211
|
+
<button onClick={onTruncateAll} class='button-base red'>
|
|
212
|
+
Truncate all data
|
|
213
|
+
</button>
|
|
214
|
+
<button onClick={onDropAll} class='button-base red'>
|
|
215
|
+
Drop all table
|
|
216
|
+
</button>
|
|
217
|
+
</div>
|
|
218
|
+
<div class='row-box mt1'>
|
|
219
|
+
<div>
|
|
220
|
+
<input type='file' id='upload_data' class='input-base' />
|
|
221
|
+
</div>
|
|
222
|
+
<button onClick={onUpload} class='button-base'>
|
|
223
|
+
Upload
|
|
224
|
+
</button>
|
|
225
|
+
</div>
|
|
226
|
+
<div class='admin-table-log'></div>
|
|
227
|
+
<div class='admin-table-list'>(Table list)</div>
|
|
228
|
+
</div>
|
|
229
|
+
);
|
|
230
|
+
};
|