bulk deletes on grid
This commit is contained in:
parent
04f5e9e9ea
commit
34bfef5661
|
@ -44,7 +44,10 @@
|
||||||
|
|
||||||
function checkValid(evt) {
|
function checkValid(evt) {
|
||||||
const tableName = evt.target.value
|
const tableName = evt.target.value
|
||||||
if (originalName !== tableName && $backendUiStore.models?.some(model => model.name === tableName)) {
|
if (
|
||||||
|
originalName !== tableName &&
|
||||||
|
$backendUiStore.models?.some(model => model.name === tableName)
|
||||||
|
) {
|
||||||
error = `Table with name ${tableName} already exists. Please choose another name.`
|
error = `Table with name ${tableName} already exists. Please choose another name.`
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -60,10 +63,11 @@
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<h5>Edit Table</h5>
|
<h5>Edit Table</h5>
|
||||||
<Input
|
<Input
|
||||||
label="Table Name" thin bind:value={table.name}
|
label="Table Name"
|
||||||
|
thin
|
||||||
|
bind:value={table.name}
|
||||||
on:input={checkValid}
|
on:input={checkValid}
|
||||||
{error}
|
{error} />
|
||||||
/>
|
|
||||||
<Select
|
<Select
|
||||||
label="Primary Display Column"
|
label="Primary Display Column"
|
||||||
thin
|
thin
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
<Label extraSmall grey>Current Users</Label>
|
<Label extraSmall grey>Current Users</Label>
|
||||||
{#await fetchUsersPromise}
|
{#await fetchUsersPromise}
|
||||||
Loading...
|
Loading...
|
||||||
{:then users}
|
{:then [object Object]}
|
||||||
<ul>
|
<ul>
|
||||||
{#each users as user}
|
{#each users as user}
|
||||||
<li>
|
<li>
|
||||||
|
@ -83,7 +83,7 @@
|
||||||
<li>No Users found</li>
|
<li>No Users found</li>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
{:catch error}
|
{:catch [object Object]}
|
||||||
Something went wrong when trying to fetch users. Please refresh (CMD + R /
|
Something went wrong when trying to fetch users. Please refresh (CMD + R /
|
||||||
CTRL + R) the page and try again.
|
CTRL + R) the page and try again.
|
||||||
{/await}
|
{/await}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
<div class="spinner-container">
|
<div class="spinner-container">
|
||||||
<Spinner size="30" />
|
<Spinner size="30" />
|
||||||
</div>
|
</div>
|
||||||
{:then apps}
|
{:then [object Object]}
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{:catch err}
|
{:catch [object Object]}
|
||||||
<h1 style="color:red">{err}</h1>
|
<h1 style="color:red">{err}</h1>
|
||||||
{/await}
|
{/await}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<div class="spinner-container">
|
<div class="spinner-container">
|
||||||
<Spinner size="30" />
|
<Spinner size="30" />
|
||||||
</div>
|
</div>
|
||||||
{:then templates}
|
{:then [object Object]}
|
||||||
<div class="templates">
|
<div class="templates">
|
||||||
{#each templates as template}
|
{#each templates as template}
|
||||||
<div class="templates-card">
|
<div class="templates-card">
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{:catch err}
|
{:catch [object Object]}
|
||||||
<h1 style="color:red">{err}</h1>
|
<h1 style="color:red">{err}</h1>
|
||||||
{/await}
|
{/await}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -77,9 +77,9 @@
|
||||||
{#await promise}
|
{#await promise}
|
||||||
<!-- This should probably be some kind of loading state? -->
|
<!-- This should probably be some kind of loading state? -->
|
||||||
<div />
|
<div />
|
||||||
{:then _}
|
{:then [object Object]}
|
||||||
<slot />
|
<slot />
|
||||||
{:catch error}
|
{:catch [object Object]}
|
||||||
<p>Something went wrong: {error.message}</p>
|
<p>Something went wrong: {error.message}</p>
|
||||||
{/await}
|
{/await}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -73,6 +73,12 @@ exports.save = async function(ctx) {
|
||||||
let row = ctx.request.body
|
let row = ctx.request.body
|
||||||
row.tableId = ctx.params.tableId
|
row.tableId = ctx.params.tableId
|
||||||
|
|
||||||
|
if (ctx.request.body.type === "delete") {
|
||||||
|
await bulkDelete(ctx)
|
||||||
|
ctx.body = ctx.request.body.rows
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (!row._rev && !row._id) {
|
if (!row._rev && !row._id) {
|
||||||
row._id = generateRowID(row.tableId)
|
row._id = generateRowID(row.tableId)
|
||||||
}
|
}
|
||||||
|
@ -101,7 +107,7 @@ exports.save = async function(ctx) {
|
||||||
// make sure link rows are up to date
|
// make sure link rows are up to date
|
||||||
row = await linkRows.updateLinks({
|
row = await linkRows.updateLinks({
|
||||||
instanceId,
|
instanceId,
|
||||||
eventType: linkRows.EventType.ROW_SAVE,
|
eventType: linkRows.EventType.RECORD_SAVE,
|
||||||
row,
|
row,
|
||||||
tableId: row.tableId,
|
tableId: row.tableId,
|
||||||
table,
|
table,
|
||||||
|
@ -348,3 +354,25 @@ const TYPE_TRANSFORM_MAP = {
|
||||||
false: false,
|
false: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function bulkDelete(ctx) {
|
||||||
|
const instanceId = ctx.user.instanceId
|
||||||
|
const { rows } = ctx.request.body
|
||||||
|
const db = new CouchDB(instanceId)
|
||||||
|
|
||||||
|
const linkUpdates = rows.map(row =>
|
||||||
|
linkRows.updateLinks({
|
||||||
|
instanceId,
|
||||||
|
eventType: linkRows.EventType.ROW_DELETE,
|
||||||
|
row,
|
||||||
|
tableId: row.tableId,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
await db.bulkDocs(rows.map(row => ({ ...row, _deleted: true })))
|
||||||
|
await Promise.all(linkUpdates)
|
||||||
|
|
||||||
|
rows.forEach(row => {
|
||||||
|
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, instanceId, row)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
{#await _appPromise}
|
{#await _appPromise}
|
||||||
loading
|
loading
|
||||||
{:then _bb}
|
{:then [object Object]}
|
||||||
<div id="current_component" bind:this={currentComponent} />
|
<div id="current_component" bind:this={currentComponent} />
|
||||||
{/await}
|
{/await}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue