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 { TableField, QueryResult } from 'common/interfaces/antares';
|
||||||
import { TableUpdateParams } from 'common/interfaces/tableApis';
|
import { TableUpdateParams } from 'common/interfaces/tableApis';
|
||||||
import { jsonToSqlInsert } from 'common/libs/sqlUtils';
|
import { jsonToSqlInsert } from 'common/libs/sqlUtils';
|
||||||
|
import { unproxify } from '@/libs/unproxify';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
|
@ -415,20 +416,38 @@ const copyCell = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const copyRow = (format: string) => {
|
const copyRow = (format: string) => {
|
||||||
const row = localResults.value.find((row: any) => selectedRows.value.includes(row._antares_id));
|
let contentToCopy;
|
||||||
const rowToCopy = JSON.parse(JSON.stringify(row));
|
|
||||||
delete rowToCopy._antares_id;
|
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')
|
if (format === 'json')
|
||||||
navigator.clipboard.writeText(JSON.stringify(rowToCopy));
|
navigator.clipboard.writeText(JSON.stringify(contentToCopy));
|
||||||
else if (format === 'sql') {
|
else if (format === 'sql') {
|
||||||
navigator.clipboard.writeText(jsonToSqlInsert({
|
const sqlInserts = [];
|
||||||
json: rowToCopy,
|
if (!Array.isArray(contentToCopy)) contentToCopy = [contentToCopy];
|
||||||
client: workspaceClient.value,
|
|
||||||
fields: fieldsObj.value as {
|
for (const row of contentToCopy) {
|
||||||
[key: string]: {type: string; datePrecision: number};
|
sqlInserts.push(jsonToSqlInsert({
|
||||||
},
|
json: row,
|
||||||
table: getTable(resultsetIndex.value)
|
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"
|
:context-event="contextEvent"
|
||||||
@close-context="closeContext"
|
@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>
|
<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" />
|
<i class="mdi mdi-18px mdi-chevron-right text-light pl-1" />
|
||||||
<div class="context-submenu">
|
<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) }}
|
<i class="mdi mdi-18px mdi-numeric-0 mdi-rotate-90 text-light pr-1" /> {{ t('word.cell', 1) }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div class="context-element" @click="copyRow('json')">
|
||||||
v-if="selectedRows.length === 1"
|
|
||||||
class="context-element"
|
|
||||||
@click="copyRow('json')"
|
|
||||||
>
|
|
||||||
<span class="d-flex">
|
<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>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div class="context-element" @click="copyRow('sql')">
|
||||||
v-if="selectedRows.length === 1"
|
|
||||||
class="context-element"
|
|
||||||
@click="copyRow('sql')"
|
|
||||||
>
|
|
||||||
<span class="d-flex">
|
<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>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue