Skip to content

Commit 7d5f0d3

Browse files
authored
feat: expose Purge table button in Table's Meta section (#455)
1 parent 974efc6 commit 7d5f0d3

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

views/meta.ejs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
<main class="flex-fill d-flex flex-column">
4646
<div style="margin: 16px 0;">
47+
<button id="purgeTable" type="button" class="btn btn-warning">Purge table</button>
4748
<button id="deleteTable" type="button" class="btn btn-danger">Delete table</button>
4849
</div>
4950
<div
@@ -54,7 +55,27 @@
5455
</div>
5556
</main>
5657
<script>
58+
document.querySelector('#purgeTable').addEventListener('click', () => {
59+
if (!confirm(`Are you sure you want to purge all records from table "<%= Table.TableName %>"?`)) {
60+
return
61+
}
62+
fetch('/tables/<%= encodeURIComponent(Table.TableName) %>/all', {
63+
method: 'delete'
64+
}).then(async (response) => {
65+
if (!response.ok) {
66+
const responseText = await response.text()
67+
throw new Error(JSON.parse(responseText).message)
68+
}
69+
window.location.href = '/tables/<%= encodeURIComponent(Table.TableName) %>'
70+
}).catch((error) => {
71+
handleError(error.message)
72+
})
73+
});
74+
5775
document.querySelector('#deleteTable').addEventListener('click', () => {
76+
if (!confirm(`Are you sure you want to delete table "<%= Table.TableName %>"?`)) {
77+
return
78+
}
5879
fetch('/tables/<%= encodeURIComponent(Table.TableName) %>', {
5980
method: 'delete'
6081
}).then(async (response) => {

views/tables.ejs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@
5454
}
5555
5656
function deleteTable(TableName) {
57-
if (!confirm(`Are you sure you want to delete table "${TableName}" ?`)) {
57+
if (!confirm(`Are you sure you want to delete table "${TableName}"?`)) {
5858
return
5959
}
6060
61-
fetch(`/tables/${TableName}`, {
61+
fetch(`/tables/${encodeURIComponent(TableName)}`, {
6262
method: 'delete'
6363
})
6464
.then(async (response) => {
@@ -74,11 +74,11 @@
7474
}
7575
7676
function purgeTable(TableName) {
77-
if (!confirm(`Are you sure you want to purge all records from table "${TableName}" ?`)) {
77+
if (!confirm(`Are you sure you want to purge all records from table "${TableName}"?`)) {
7878
return
7979
}
8080
81-
fetch(`/tables/${TableName}/all`, {
81+
fetch(`/tables/${encodeURIComponent(TableName)}/all`, {
8282
method: 'delete'
8383
}).then(async (response) => {
8484
if (!response.ok) {

0 commit comments

Comments
 (0)