mirror of https://github.com/Fabio286/antares.git
feat: ability to copy multiple selected rows
This commit is contained in:
parent
1ead76c028
commit
9551afbd2d
|
@ -132,6 +132,7 @@ import { useI18n } from 'vue-i18n';
|
|||
import { TableField, QueryResult } from 'common/interfaces/antares';
|
||||
import { TableUpdateParams } from 'common/interfaces/tableApis';
|
||||
import { jsonToSqlInsert } from 'common/libs/sqlUtils';
|
||||
import { unproxify } from '@/libs/unproxify';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
|
@ -415,20 +416,38 @@ const copyCell = () => {
|
|||
};
|
||||
|
||||
const copyRow = (format: string) => {
|
||||
const row = localResults.value.find((row: any) => selectedRows.value.includes(row._antares_id));
|
||||
const rowToCopy = JSON.parse(JSON.stringify(row));
|
||||
delete rowToCopy._antares_id;
|
||||
let contentToCopy;
|
||||
|
||||
if (selectedRows.value.length === 1) {
|
||||
const row = localResults.value.find((row: any) => selectedRows.value.includes(row._antares_id));
|
||||
const rowToCopy = unproxify(row);
|
||||
delete rowToCopy._antares_id;
|
||||
contentToCopy = rowToCopy;
|
||||
}
|
||||
else {
|
||||
contentToCopy = unproxify(localResults.value).filter((row: any) => selectedRows.value.includes(row._antares_id)).map((row: any) => {
|
||||
delete row._antares_id;
|
||||
return row;
|
||||
});
|
||||
}
|
||||
|
||||
if (format === 'json')
|
||||
navigator.clipboard.writeText(JSON.stringify(rowToCopy));
|
||||
navigator.clipboard.writeText(JSON.stringify(contentToCopy));
|
||||
else if (format === 'sql') {
|
||||
navigator.clipboard.writeText(jsonToSqlInsert({
|
||||
json: rowToCopy,
|
||||
client: workspaceClient.value,
|
||||
fields: fieldsObj.value as {
|
||||
[key: string]: {type: string; datePrecision: number};
|
||||
},
|
||||
table: getTable(resultsetIndex.value)
|
||||
}));
|
||||
const sqlInserts = [];
|
||||
if (!Array.isArray(contentToCopy)) contentToCopy = [contentToCopy];
|
||||
|
||||
for (const row of contentToCopy) {
|
||||
sqlInserts.push(jsonToSqlInsert({
|
||||
json: row,
|
||||
client: workspaceClient.value,
|
||||
fields: fieldsObj.value as {
|
||||
[key: string]: {type: string; datePrecision: number};
|
||||
},
|
||||
table: getTable(resultsetIndex.value)
|
||||
}));
|
||||
}
|
||||
navigator.clipboard.writeText(sqlInserts.join('\n'));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
:context-event="contextEvent"
|
||||
@close-context="closeContext"
|
||||
>
|
||||
<div v-if="selectedRows.length === 1" class="context-element">
|
||||
<div class="context-element">
|
||||
<span class="d-flex"><i class="mdi mdi-18px mdi-content-copy text-light pr-1" /> {{ t('word.copy') }}</span>
|
||||
<i class="mdi mdi-18px mdi-chevron-right text-light pl-1" />
|
||||
<div class="context-submenu">
|
||||
|
@ -16,22 +16,14 @@
|
|||
<i class="mdi mdi-18px mdi-numeric-0 mdi-rotate-90 text-light pr-1" /> {{ t('word.cell', 1) }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="selectedRows.length === 1"
|
||||
class="context-element"
|
||||
@click="copyRow('json')"
|
||||
>
|
||||
<div class="context-element" @click="copyRow('json')">
|
||||
<span class="d-flex">
|
||||
<i class="mdi mdi-18px mdi-table-row text-light pr-1" /> {{ t('word.row', 1) }} (JSON)
|
||||
<i class="mdi mdi-18px mdi-table-row text-light pr-1" /> {{ t('word.row', selectedRows.length) }} (JSON)
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="selectedRows.length === 1"
|
||||
class="context-element"
|
||||
@click="copyRow('sql')"
|
||||
>
|
||||
<div class="context-element" @click="copyRow('sql')">
|
||||
<span class="d-flex">
|
||||
<i class="mdi mdi-18px mdi-table-row text-light pr-1" /> {{ t('word.row', 1) }} (SQL INSERT)
|
||||
<i class="mdi mdi-18px mdi-table-row text-light pr-1" /> {{ t('word.row', selectedRows.length) }} (SQL INSERT)
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue