diff --git a/src/common/fieldTypes.ts b/src/common/fieldTypes.ts index 25ffdfaf..332c0411 100644 --- a/src/common/fieldTypes.ts +++ b/src/common/fieldTypes.ts @@ -29,7 +29,6 @@ export const NUMBER = [ 'SMALLINT', 'MEDIUMINT', 'BIGINT', - 'DECIMAL', 'NUMERIC', 'INTEGER', 'SMALLSERIAL', diff --git a/src/renderer/components/WorkspaceTabQueryTable.vue b/src/renderer/components/WorkspaceTabQueryTable.vue index defcd351..b886d795 100644 --- a/src/renderer/components/WorkspaceTabQueryTable.vue +++ b/src/renderer/components/WorkspaceTabQueryTable.vue @@ -18,6 +18,7 @@ @show-delete-modal="showDeleteConfirmModal" @set-null="setNull" @copy-cell="copyCell" + @fill-cell="fillCell" @copy-row="copyRow" @duplicate-row="duplicateRow" @close-context="closeContext" @@ -122,7 +123,7 @@ import { useSettingsStore } from '@/stores/settings'; import { useWorkspacesStore } from '@/stores/workspaces'; import { useConsoleStore } from '@/stores/console'; import { exportRows } from '../libs/exportRows'; -import { TEXT, LONG_TEXT, BLOB } from 'common/fieldTypes'; +import { TEXT, LONG_TEXT, BLOB, DATE, DATETIME, TIME } from 'common/fieldTypes'; import BaseVirtualScroll from '@/components/BaseVirtualScroll.vue'; import WorkspaceTabQueryTableRow from '@/components/WorkspaceTabQueryTableRow.vue'; import TableContext from '@/components/WorkspaceTabQueryTableContext.vue'; @@ -133,6 +134,7 @@ import { TableField, QueryResult } from 'common/interfaces/antares'; import { TableUpdateParams } from 'common/interfaces/tableApis'; import { jsonToSqlInsert } from 'common/libs/sqlUtils'; import { unproxify } from '@/libs/unproxify'; +import faker from '@faker-js/faker'; const { t } = useI18n(); @@ -463,6 +465,53 @@ const copyRow = (format: string) => { } }; +const fillCell = (event: { name: string; group: string; type: string }) => { + const row = localResults.value.find((row: any) => selectedRows.value.includes(row._antares_id)); + let fakeValue; + let datePrecision = ''; + + if (['datetime', 'time'].includes(event.group)) { + for (let i = 0; i < selectedCell.value.length; i++) + datePrecision += i === 0 ? '.S' : 'S'; + } + + if (event.group === 'custom') { + if (event.type === 'time' && event.name === 'now') + fakeValue = moment().format(`HH:mm:ss${datePrecision}`); + else if (event.type === 'time' && event.name === 'random') + fakeValue = moment(faker.date.recent()).format(`HH:mm:ss${datePrecision}`); + else if (event.type === 'datetime' && event.name === 'now') + fakeValue = moment().format(`YYYY-MM-DD HH:mm:ss${datePrecision}`); + } + else { + fakeValue = (faker as any)[event.group][event.name](); + if (['string', 'number'].includes(typeof fakeValue)) { + if (typeof fakeValue === 'number') + fakeValue = String(fakeValue); + + if (selectedCell.value.length) + fakeValue = fakeValue.substring(0, selectedCell.value.length < 1024 ? Number(selectedCell.value.length) : 1024); + } + else if ([...DATE, ...DATETIME].includes(selectedCell.value.type)) + fakeValue = moment(fakeValue).format(`YYYY-MM-DD HH:mm:ss${datePrecision}`); + else if (TIME.includes(selectedCell.value.type)) + fakeValue = moment(fakeValue).format(`HH:mm:ss${datePrecision}`); + } + + const params = { + primary: primaryField.value?.name, + schema: getSchema(resultsetIndex.value), + table: getTable(resultsetIndex.value), + id: getPrimaryValue(row), + row, + orgRow: row, + field: selectedCell.value.field, + content: fakeValue + }; + + emit('update-field', params); +}; + const duplicateRow = () => { const row = localResults.value.find((row: any) => selectedRows.value.includes(row._antares_id)); const rowToDuplicate = JSON.parse(JSON.stringify(row)); diff --git a/src/renderer/components/WorkspaceTabQueryTableContext.vue b/src/renderer/components/WorkspaceTabQueryTableContext.vue index dbd978fd..de9e303b 100644 --- a/src/renderer/components/WorkspaceTabQueryTableContext.vue +++ b/src/renderer/components/WorkspaceTabQueryTableContext.vue @@ -42,6 +42,27 @@ {{ t('word.duplicate') }} +
+ + {{ t('message.fillCell') }} + + +
+
+ + {{ t(`faker.${method.name}`) }} + +
+
+
diff --git a/src/renderer/components/WorkspaceTabQueryTableRow.vue b/src/renderer/components/WorkspaceTabQueryTableRow.vue index 79eaef12..cfb9e8ff 100644 --- a/src/renderer/components/WorkspaceTabQueryTableRow.vue +++ b/src/renderer/components/WorkspaceTabQueryTableRow.vue @@ -11,7 +11,12 @@ :class="{selected: selectedCell === cKey}" @click="selectRow($event, cKey)" - @contextmenu.prevent="openContext($event, { id: row._antares_id, orgField: cKey })" + @contextmenu.prevent="openContext($event, { + id: row._antares_id, + orgField: cKey, + type: fields[cKey].type, + length: fields[cKey].charLength || fields[cKey].length + })" >