@antcde/component-library 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1660 -1658
- package/dist/types/components/TasksFlow/useTaskFlow.d.ts +0 -1
- package/lib/DocumentManager/DocumentManager.vue +10 -5
- package/lib/TableViewer/TableViewer.vue +51 -177
- package/lib/TableViewer/composables/columns.ts +51 -0
- package/lib/TableViewer/composables/records.ts +18 -1
- package/lib/TableViewer/composables/relations.ts +8 -0
- package/lib/TableViewer/core/Columns/ColumnForm.vue +403 -190
- package/lib/TableViewer/core/Columns/ColumnItem.vue +225 -0
- package/lib/TableViewer/core/Columns/ColumnsList.vue +142 -0
- package/lib/TableViewer/core/Columns/ForeignKeyColumnItem.vue +165 -0
- package/lib/TableViewer/core/Columns/ForeignKeyColumnsList.vue +55 -0
- package/lib/TableViewer/core/Dialog/DeleteConfirmationDialog.vue +63 -0
- package/lib/TableViewer/core/Filters/ConditionItem.vue +133 -0
- package/lib/TableViewer/core/Filters/ConditionsList.vue +53 -0
- package/lib/TableViewer/core/Filters/FiltersEditor.vue +48 -0
- package/lib/TableViewer/core/Filters/QueriesList.vue +63 -0
- package/lib/TableViewer/core/{Queries → Filters}/QueryItem.vue +3 -3
- package/lib/TableViewer/core/Records/RecordCell.vue +32 -42
- package/lib/TableViewer/core/Records/RecordForm.vue +146 -0
- package/lib/TableViewer/core/Records/RecordHeader.vue +60 -153
- package/lib/TableViewer/core/Records/RecordInput.vue +65 -14
- package/lib/TableViewer/core/Records/RecordValue.vue +67 -20
- package/lib/TableViewer/core/Records/RecordsTable.vue +97 -56
- package/lib/TableViewer/core/Records/RecordsTableToolbar.vue +42 -142
- package/lib/TableViewer/core/Revisions/RevisionHistory.vue +25 -7
- package/lib/TableViewer/core/Tables/TableEditor.vue +136 -0
- package/lib/TableViewer/core/Tables/TableItem.vue +162 -0
- package/lib/TableViewer/core/Tables/TableViewer.vue +28 -0
- package/lib/TableViewer/core/Tables/TablesList.vue +116 -0
- package/lib/TableViewer/stores/columnRelation.ts +106 -0
- package/lib/TableViewer/stores/columns.ts +56 -37
- package/lib/TableViewer/stores/conditions.ts +44 -46
- package/lib/TableViewer/stores/records.ts +73 -4
- package/lib/TableViewer/stores/table.ts +48 -52
- package/lib/TableViewer/stores/tables.ts +1 -1
- package/lib/TableViewer/types/column.d.ts +2 -2
- package/lib/TableViewer/types/relations.d.ts +7 -0
- package/package.json +2 -2
- package/lib/DocumentManager/hooks/useDarkMode.ts +0 -17
- package/lib/TableViewer/TableView.vue +0 -39
- package/lib/TableViewer/core/Columns/ColumnsConfiguration.vue +0 -99
- package/lib/TableViewer/core/Columns/ColumnsConfigurationTable.vue +0 -186
- package/lib/TableViewer/core/Columns/ColumnsTable.vue +0 -165
- package/lib/TableViewer/core/Permissions/PermissionDialog.vue +0 -149
- package/lib/TableViewer/core/Permissions/PermissionForm.vue +0 -117
- package/lib/TableViewer/core/Permissions/PermissionsConfiguration.vue +0 -55
- package/lib/TableViewer/core/Permissions/PermissionsConfigurationTable.vue +0 -185
- package/lib/TableViewer/core/Permissions/PermissionsTable.vue +0 -207
- package/lib/TableViewer/core/Queries/QueriesMenu.vue +0 -75
- package/lib/TableViewer/core/Records/RecordDialog.vue +0 -128
- package/lib/TableViewer/core/Relations/RelationForm.vue +0 -154
- package/lib/TableViewer/core/Relations/RelationsConfiguration.vue +0 -32
- package/lib/TableViewer/core/Relations/RelationsConfigurationTable.vue +0 -146
- package/lib/TableViewer/core/Relations/RelationsTable.vue +0 -129
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import type { TableList } from '@antcde/connect-ts'
|
|
3
|
+
import DeleteConfirmationDialog from '../Dialog/DeleteConfirmationDialog.vue'
|
|
4
|
+
import { ref } from 'vue'
|
|
5
|
+
import { storeToRefs } from 'pinia'
|
|
6
|
+
import { useTableStore } from '../../stores/table'
|
|
7
|
+
import { useRecordStore } from '../../stores/records'
|
|
8
|
+
|
|
9
|
+
const emit = defineEmits<{
|
|
10
|
+
(e: 'edit'): void
|
|
11
|
+
}>()
|
|
12
|
+
|
|
13
|
+
defineProps<{
|
|
14
|
+
table: TableList
|
|
15
|
+
selectedTable: TableList | null
|
|
16
|
+
permissions: {
|
|
17
|
+
canCreate: boolean
|
|
18
|
+
canUpdate: boolean
|
|
19
|
+
canDelete: boolean
|
|
20
|
+
canConfigure: boolean
|
|
21
|
+
}
|
|
22
|
+
}>()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
const tableStore = useTableStore()
|
|
26
|
+
|
|
27
|
+
const recordStore = useRecordStore()
|
|
28
|
+
const { selectedRecords } = storeToRefs(recordStore)
|
|
29
|
+
|
|
30
|
+
const showDeleteConfirmation = ref(false)
|
|
31
|
+
const showDeleteAllConfirmation = ref(false)
|
|
32
|
+
const showDeleteSelectedConfirmation = ref(false)
|
|
33
|
+
|
|
34
|
+
const fileInputRef = ref<HTMLInputElement | null>(null) // Ref for hidden input
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
// Handle CSV file change and process API call
|
|
38
|
+
async function handleFileChange(event: Event) {
|
|
39
|
+
const target = event.target as HTMLInputElement
|
|
40
|
+
if (!target.files || target.files.length === 0) {
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const file = target.files[0]
|
|
45
|
+
if (file) {
|
|
46
|
+
await recordStore.importRecords(file)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Clear the input value so the same file can be uploaded again
|
|
50
|
+
target.value = ''
|
|
51
|
+
}
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<template>
|
|
55
|
+
<delete-confirmation-dialog
|
|
56
|
+
v-model="showDeleteConfirmation"
|
|
57
|
+
:message="`Are you sure you want to delete the table ${table.name}? This action cannot be undone.`"
|
|
58
|
+
@confirm="tableStore.deleteTable"
|
|
59
|
+
/>
|
|
60
|
+
|
|
61
|
+
<delete-confirmation-dialog
|
|
62
|
+
v-model="showDeleteSelectedConfirmation"
|
|
63
|
+
:message="`Are you sure you want to delete selected records in the table ${table.name}? This action cannot be undone.`"
|
|
64
|
+
@confirm="recordStore.deleteSelectedRecords"
|
|
65
|
+
/>
|
|
66
|
+
|
|
67
|
+
<delete-confirmation-dialog
|
|
68
|
+
v-model="showDeleteAllConfirmation"
|
|
69
|
+
:message="`Are you sure you want to delete all records in the table ${table.name}? This action cannot be undone.`"
|
|
70
|
+
@confirm="recordStore.deleteAllRecords"
|
|
71
|
+
/>
|
|
72
|
+
|
|
73
|
+
<input
|
|
74
|
+
ref="fileInputRef"
|
|
75
|
+
type="file"
|
|
76
|
+
accept=".csv"
|
|
77
|
+
@change="handleFileChange"
|
|
78
|
+
class="hidden"
|
|
79
|
+
/>
|
|
80
|
+
|
|
81
|
+
<v-list-item
|
|
82
|
+
:active="selectedTable?.id === table?.id"
|
|
83
|
+
color="primary"
|
|
84
|
+
rounded="shaped"
|
|
85
|
+
:title="table.name"
|
|
86
|
+
@click="() => selectedTable?.id === table.id ? null : tableStore.fetchTable(table.id)"
|
|
87
|
+
>
|
|
88
|
+
<template v-if="selectedTable?.id === table?.id && permissions.canConfigure" #append>
|
|
89
|
+
<v-list-item-action class="flex-column align-end">
|
|
90
|
+
<v-menu position="start">
|
|
91
|
+
<template #activator="{ props: activatorProps }">
|
|
92
|
+
<v-btn
|
|
93
|
+
v-bind="activatorProps"
|
|
94
|
+
variant="text"
|
|
95
|
+
icon="mdi-dots-horizontal"
|
|
96
|
+
size="small"
|
|
97
|
+
color="primary"
|
|
98
|
+
/>
|
|
99
|
+
</template>
|
|
100
|
+
<v-card width="300" class="px-2">
|
|
101
|
+
<v-list>
|
|
102
|
+
<v-list-item
|
|
103
|
+
color="primary"
|
|
104
|
+
title="Edit Table"
|
|
105
|
+
density="compact"
|
|
106
|
+
prepend-icon="mdi-table-edit"
|
|
107
|
+
rounded="shaped"
|
|
108
|
+
@click="emit('edit')"
|
|
109
|
+
/>
|
|
110
|
+
<v-divider />
|
|
111
|
+
<v-list-item
|
|
112
|
+
color="primary"
|
|
113
|
+
title="Import Records"
|
|
114
|
+
density="compact"
|
|
115
|
+
prepend-icon="mdi-import"
|
|
116
|
+
rounded="shaped"
|
|
117
|
+
@click="fileInputRef?.click()"
|
|
118
|
+
/>
|
|
119
|
+
|
|
120
|
+
<v-list-item
|
|
121
|
+
color="primary"
|
|
122
|
+
title="Export Records"
|
|
123
|
+
density="compact"
|
|
124
|
+
prepend-icon="mdi-export"
|
|
125
|
+
rounded="shaped"
|
|
126
|
+
@click="recordStore.exportTableRecords"
|
|
127
|
+
/>
|
|
128
|
+
<v-divider />
|
|
129
|
+
|
|
130
|
+
<v-list-item
|
|
131
|
+
color="danger"
|
|
132
|
+
:disabled="!selectedRecords.length"
|
|
133
|
+
title="Delete selected Records"
|
|
134
|
+
prepend-icon="mdi-table-off"
|
|
135
|
+
density="compact"
|
|
136
|
+
rounded="shaped"
|
|
137
|
+
@click="() => (showDeleteSelectedConfirmation = true)"
|
|
138
|
+
/>
|
|
139
|
+
|
|
140
|
+
<v-list-item
|
|
141
|
+
color="danger"
|
|
142
|
+
title="Delete all Records"
|
|
143
|
+
prepend-icon="mdi-table-off"
|
|
144
|
+
density="compact"
|
|
145
|
+
rounded="shaped"
|
|
146
|
+
@click="() => (showDeleteAllConfirmation = true)"
|
|
147
|
+
/>
|
|
148
|
+
<v-list-item
|
|
149
|
+
color="error"
|
|
150
|
+
title="Delete Table"
|
|
151
|
+
density="compact"
|
|
152
|
+
prepend-icon="mdi-table-remove"
|
|
153
|
+
rounded="shaped"
|
|
154
|
+
@click="() => (showDeleteConfirmation = true)"
|
|
155
|
+
/>
|
|
156
|
+
</v-list>
|
|
157
|
+
</v-card>
|
|
158
|
+
</v-menu>
|
|
159
|
+
</v-list-item-action>
|
|
160
|
+
</template>
|
|
161
|
+
</v-list-item>
|
|
162
|
+
</template>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import type { ApplicationProps } from '../../types/app'
|
|
3
|
+
import { storeToRefs } from 'pinia'
|
|
4
|
+
import RecordsTable from '../Records/RecordsTable.vue'
|
|
5
|
+
import RevisionComparisonTable from '../Revisions/RevisionComparisonTable.vue'
|
|
6
|
+
import { useClientStore } from '../../stores/client'
|
|
7
|
+
import { useRevisionStore } from '../../stores/revisions'
|
|
8
|
+
import { useTableStore } from '../../stores/table'
|
|
9
|
+
|
|
10
|
+
const { client } = defineProps<ApplicationProps>()
|
|
11
|
+
|
|
12
|
+
const clientStore = useClientStore()
|
|
13
|
+
clientStore.setClient(client)
|
|
14
|
+
|
|
15
|
+
const tableStore = useTableStore()
|
|
16
|
+
|
|
17
|
+
const revisionStore = useRevisionStore()
|
|
18
|
+
const { inComparisonMode } = storeToRefs(revisionStore)
|
|
19
|
+
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<template>
|
|
23
|
+
<v-skeleton-loader v-if="tableStore.isFetching" type="table" />
|
|
24
|
+
<records-table v-else />
|
|
25
|
+
<!-- <template v-else>
|
|
26
|
+
<revision-comparison-table v-if="inComparisonMode" />
|
|
27
|
+
</template> -->
|
|
28
|
+
</template>
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { TableList } from '@antcde/connect-ts'
|
|
3
|
+
import { storeToRefs } from 'pinia'
|
|
4
|
+
import { computed, ref } from 'vue'
|
|
5
|
+
import { useTableStore } from '../../stores/table'
|
|
6
|
+
import { useTablesStore } from '../../stores/tables'
|
|
7
|
+
import TableItem from './TableItem.vue'
|
|
8
|
+
import { useRecordStore } from '../../stores/records'
|
|
9
|
+
|
|
10
|
+
const props = defineProps<{
|
|
11
|
+
tables: TableList[]
|
|
12
|
+
canCreate: boolean
|
|
13
|
+
}>()
|
|
14
|
+
|
|
15
|
+
const emit = defineEmits<{
|
|
16
|
+
(e: 'table:edit'): void
|
|
17
|
+
}>()
|
|
18
|
+
|
|
19
|
+
const tableStore = useTableStore()
|
|
20
|
+
|
|
21
|
+
const { table: selectedTable, isCreating, permissions } = storeToRefs(tableStore)
|
|
22
|
+
|
|
23
|
+
const searchTerm = ref('')
|
|
24
|
+
|
|
25
|
+
const tableData = ref({
|
|
26
|
+
name: ''
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const displayedTables = computed(() =>
|
|
30
|
+
props.tables.filter((table) => table.name.toLowerCase().includes(searchTerm.value.toLowerCase()))
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
function createTable() {
|
|
34
|
+
if (tableData.value.name.length === 0) {
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
tableStore.createTable(tableData.value.name).then(() => {
|
|
38
|
+
tableData.value.name = ''
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<template>
|
|
44
|
+
<v-list>
|
|
45
|
+
<v-list-item class="" color="info" rounded="lg">
|
|
46
|
+
<v-text-field
|
|
47
|
+
v-model="searchTerm"
|
|
48
|
+
class="w-full"
|
|
49
|
+
variant="outlined"
|
|
50
|
+
density="compact"
|
|
51
|
+
color="primary"
|
|
52
|
+
placeholder="Search..."
|
|
53
|
+
hide-details
|
|
54
|
+
>
|
|
55
|
+
<template v-if="canCreate" #append>
|
|
56
|
+
<v-menu :close-on-content-click="false" offset-y transition="slide-y-transition">
|
|
57
|
+
<template #activator="{ props: activatorProps }">
|
|
58
|
+
<v-btn
|
|
59
|
+
v-bind="activatorProps"
|
|
60
|
+
class="!h-full"
|
|
61
|
+
prepend-icon="mdi-plus"
|
|
62
|
+
size="small"
|
|
63
|
+
color="primary"
|
|
64
|
+
variant="tonal"
|
|
65
|
+
text="New Table"
|
|
66
|
+
density="default"
|
|
67
|
+
/>
|
|
68
|
+
</template>
|
|
69
|
+
<v-card width="300">
|
|
70
|
+
<v-card-item>
|
|
71
|
+
<v-sheet class="d-flex flex-column">
|
|
72
|
+
<v-label class="mr-2 font-semibold"> Table Name </v-label>
|
|
73
|
+
<v-text-field
|
|
74
|
+
v-model="tableData.name"
|
|
75
|
+
variant="outlined"
|
|
76
|
+
color="primary"
|
|
77
|
+
density="compact"
|
|
78
|
+
placeholder="Table Name"
|
|
79
|
+
hint="Press enter to create"
|
|
80
|
+
persistent-hint
|
|
81
|
+
@keydown.enter="createTable"
|
|
82
|
+
/>
|
|
83
|
+
</v-sheet>
|
|
84
|
+
<v-divider class="my-4" />
|
|
85
|
+
<v-sheet class="d-flex gap-4 justify-end">
|
|
86
|
+
<v-btn
|
|
87
|
+
color="primary"
|
|
88
|
+
variant="tonal"
|
|
89
|
+
:disabled="isCreating || tableData.name.length === 0"
|
|
90
|
+
@click="createTable"
|
|
91
|
+
>
|
|
92
|
+
Create
|
|
93
|
+
</v-btn>
|
|
94
|
+
</v-sheet>
|
|
95
|
+
</v-card-item>
|
|
96
|
+
</v-card>
|
|
97
|
+
</v-menu>
|
|
98
|
+
</template>
|
|
99
|
+
</v-text-field>
|
|
100
|
+
</v-list-item>
|
|
101
|
+
|
|
102
|
+
<v-divider class="my-4" />
|
|
103
|
+
|
|
104
|
+
<table-item
|
|
105
|
+
v-for="table in displayedTables"
|
|
106
|
+
:key="table.id"
|
|
107
|
+
:table="table"
|
|
108
|
+
:selected-table="selectedTable"
|
|
109
|
+
:permissions="permissions"
|
|
110
|
+
@edit="emit('table:edit')"
|
|
111
|
+
/>
|
|
112
|
+
|
|
113
|
+
</v-list>
|
|
114
|
+
</template>
|
|
115
|
+
|
|
116
|
+
<style scoped></style>
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { ColumnRelation, StoreRelationRequestData } from '@antcde/connect-ts/services/Table/ColumnRelationService'
|
|
2
|
+
import { defineStore, storeToRefs } from 'pinia'
|
|
3
|
+
import qs from 'qs'
|
|
4
|
+
import { computed } from 'vue'
|
|
5
|
+
import { useClientStore } from './client'
|
|
6
|
+
import { useColumnStore } from './columns'
|
|
7
|
+
import { useTablesStore } from './tables'
|
|
8
|
+
|
|
9
|
+
export const useColumnRelationStore = defineStore('ant.apps.table.viewer.columns.relation', () => {
|
|
10
|
+
const clientStore = useClientStore()
|
|
11
|
+
const columnStore = useColumnStore()
|
|
12
|
+
const tablesStore = useTablesStore()
|
|
13
|
+
|
|
14
|
+
const { client } = clientStore
|
|
15
|
+
const { tables } = storeToRefs(tablesStore)
|
|
16
|
+
|
|
17
|
+
const connect = computed(() => client?.connect)
|
|
18
|
+
const context = computed(() => client?.context)
|
|
19
|
+
|
|
20
|
+
const license = computed(() => context.value?.license)
|
|
21
|
+
const project = computed(() => context.value?.project)
|
|
22
|
+
|
|
23
|
+
async function addColumnRelation(columnId: string, data: StoreRelationRequestData) {
|
|
24
|
+
const columnRelation = await connect.value?.columnRelations.addColumnRelation(
|
|
25
|
+
columnId,
|
|
26
|
+
data,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
if (!columnRelation) {
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
columnStore.setColumnRelation(columnId, columnRelation?.data)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function deleteColumnRelation(columnId: string, columnRelationId: string) {
|
|
37
|
+
await connect.value?.columnRelations.deleteColumnRelation(columnId, columnRelationId)
|
|
38
|
+
columnStore.setColumnRelation(columnId, null)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function updateColumnRelation(columnId: string, columnRelationId: string, data: Partial<ColumnRelation>) {
|
|
42
|
+
const columnRelation = await connect.value?.columnRelations.updateColumnRelation(columnId, columnRelationId, data)
|
|
43
|
+
|
|
44
|
+
if (!columnRelation) {
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
columnStore.setColumnRelation(columnId, columnRelation?.data)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function prepareTaskQueryPayload(projectId: string, searchTerm: string) {
|
|
52
|
+
return qs.stringify({
|
|
53
|
+
filters: {
|
|
54
|
+
project: {
|
|
55
|
+
$eq: projectId,
|
|
56
|
+
},
|
|
57
|
+
title: {
|
|
58
|
+
$contains: searchTerm,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
fields: {
|
|
62
|
+
tasks: ['id', 'title'].join(','),
|
|
63
|
+
},
|
|
64
|
+
sort: ['title'],
|
|
65
|
+
per_page: 10,
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function getRelationOptions(relation: ColumnRelation, searchTerm: string) {
|
|
70
|
+
if (!license.value || !project.value) {
|
|
71
|
+
return Promise.resolve([])
|
|
72
|
+
}
|
|
73
|
+
const { related_entity, related_table_id } = relation
|
|
74
|
+
switch (related_entity) {
|
|
75
|
+
case 'project':
|
|
76
|
+
return connect.value?.projects.getProjects(license.value.id, {
|
|
77
|
+
filters: searchTerm ? { name: searchTerm } : {},
|
|
78
|
+
})
|
|
79
|
+
case 'task':
|
|
80
|
+
return (await connect.value?.tasks.getV2Tasks(
|
|
81
|
+
license.value.id,
|
|
82
|
+
prepareTaskQueryPayload(project.value.id, searchTerm),
|
|
83
|
+
))?.data || []
|
|
84
|
+
case 'user':
|
|
85
|
+
return (await connect.value?.projectUsers.fetchUsers(project.value.id))?.data || []
|
|
86
|
+
case 'table':
|
|
87
|
+
return tables.value
|
|
88
|
+
case 'table_record':
|
|
89
|
+
return (await connect.value?.records.getRecords(project.value.id, related_table_id ?? '', {
|
|
90
|
+
searchFields: ['id', relation.display_label ?? 'id'],
|
|
91
|
+
search: {
|
|
92
|
+
phrase: searchTerm,
|
|
93
|
+
},
|
|
94
|
+
}))?.records || []
|
|
95
|
+
default:
|
|
96
|
+
break
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
getRelationOptions,
|
|
102
|
+
addColumnRelation,
|
|
103
|
+
deleteColumnRelation,
|
|
104
|
+
updateColumnRelation,
|
|
105
|
+
}
|
|
106
|
+
})
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { Column } from '@antcde/connect-ts/services/ColumnService'
|
|
2
|
+
import type { ColumnRelation } from '@antcde/connect-ts/services/Table/ColumnRelationService'
|
|
2
3
|
import { defineStore } from 'pinia'
|
|
3
|
-
import { ref } from 'vue'
|
|
4
|
+
import { computed, ref } from 'vue'
|
|
4
5
|
import { useClientStore } from './client'
|
|
5
6
|
import { useConditionStore } from './conditions'
|
|
6
7
|
import { useTableStore } from './table'
|
|
8
|
+
import type { ColumnRequestBody } from '../types/column'
|
|
7
9
|
|
|
8
10
|
export const useColumnStore = defineStore('ant.apps.table.viewer.columns', () => {
|
|
9
11
|
const isFetching = ref(false)
|
|
@@ -23,6 +25,8 @@ export const useColumnStore = defineStore('ant.apps.table.viewer.columns', () =>
|
|
|
23
25
|
const tableStore = useTableStore()
|
|
24
26
|
const conditionStore = useConditionStore()
|
|
25
27
|
|
|
28
|
+
const columnsConfiguration = computed(() => getColumnsConfiguration())
|
|
29
|
+
|
|
26
30
|
async function fetchColumns() {
|
|
27
31
|
if (!tableStore.table || !connect) {
|
|
28
32
|
return
|
|
@@ -31,18 +35,29 @@ export const useColumnStore = defineStore('ant.apps.table.viewer.columns', () =>
|
|
|
31
35
|
try {
|
|
32
36
|
isFetching.value = true
|
|
33
37
|
columns.value = (await connect.columns.getColumns(tableStore.table.id)) ?? []
|
|
34
|
-
}
|
|
35
|
-
finally {
|
|
38
|
+
} finally {
|
|
36
39
|
isFetching.value = false
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
|
|
43
|
+
async function fetchTableColumns(tableId: string) {
|
|
44
|
+
if (!connect) {
|
|
45
|
+
return []
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (await connect.columns.getColumns(tableId)) ?? []
|
|
49
|
+
}
|
|
50
|
+
|
|
40
51
|
function getColumnsConfiguration() {
|
|
41
52
|
return columns.value.map((column: Column) => {
|
|
42
53
|
return {
|
|
43
54
|
name: column.name,
|
|
44
55
|
as: columnsAlias.value[column.id] ?? column.name,
|
|
45
56
|
conditions: conditionStore.getApplicableConditions(column),
|
|
57
|
+
relation: {
|
|
58
|
+
include: !!column.column_relation,
|
|
59
|
+
fields: ['id', column.column_relation?.display_label]
|
|
60
|
+
}
|
|
46
61
|
}
|
|
47
62
|
})
|
|
48
63
|
}
|
|
@@ -58,7 +73,7 @@ export const useColumnStore = defineStore('ant.apps.table.viewer.columns', () =>
|
|
|
58
73
|
function setColumnAlias(column: Column, alias: string) {
|
|
59
74
|
columnsAlias.value = {
|
|
60
75
|
...columnsAlias.value,
|
|
61
|
-
[column.id]: alias
|
|
76
|
+
[column.id]: alias
|
|
62
77
|
}
|
|
63
78
|
}
|
|
64
79
|
|
|
@@ -69,56 +84,57 @@ export const useColumnStore = defineStore('ant.apps.table.viewer.columns', () =>
|
|
|
69
84
|
try {
|
|
70
85
|
isCreating.value = true
|
|
71
86
|
const newColumn = await connect.columns.createColumn({
|
|
72
|
-
|
|
73
|
-
|
|
87
|
+
name: column.name,
|
|
88
|
+
type: column.type,
|
|
89
|
+
default_value: column.default_value,
|
|
90
|
+
options_value: column.options_value,
|
|
91
|
+
order: column.order,
|
|
92
|
+
required: column.required,
|
|
93
|
+
is_unique: column.is_unique,
|
|
94
|
+
table: tableStore.table.id
|
|
74
95
|
})
|
|
75
96
|
columns.value.push(newColumn)
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
catch (e) {
|
|
79
|
-
return Promise.reject(e)
|
|
80
|
-
}
|
|
81
|
-
finally {
|
|
97
|
+
} finally {
|
|
82
98
|
isCreating.value = false
|
|
83
99
|
}
|
|
84
100
|
}
|
|
85
101
|
|
|
86
|
-
async function updateColumn(column:
|
|
87
|
-
if (!connect)
|
|
88
|
-
return
|
|
102
|
+
async function updateColumn(columnId: string, column: ColumnRequestBody) {
|
|
103
|
+
if (!connect) return
|
|
89
104
|
try {
|
|
90
105
|
isUpdating.value = true
|
|
91
|
-
|
|
92
|
-
default_value: column.default_value,
|
|
106
|
+
await connect.columns.updateColumn(columnId, {
|
|
93
107
|
name: column.name,
|
|
94
|
-
options_value: column.options_value,
|
|
95
|
-
order: column.order,
|
|
96
108
|
required: column.required,
|
|
109
|
+
default_value: column.default_value
|
|
97
110
|
})
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return Promise.reject(e)
|
|
107
|
-
}
|
|
108
|
-
finally {
|
|
111
|
+
const columnIndex = columns.value.findIndex((item: Column) => item.id === columnId)
|
|
112
|
+
columns.value.splice(columnIndex, 1, {
|
|
113
|
+
...columns.value[columnIndex],
|
|
114
|
+
name: column.name,
|
|
115
|
+
required: column.required,
|
|
116
|
+
default_value: column.default_value
|
|
117
|
+
})
|
|
118
|
+
} finally {
|
|
109
119
|
isUpdating.value = false
|
|
110
120
|
}
|
|
111
121
|
}
|
|
112
122
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
123
|
+
function setColumnRelation(columnId: string, relation: ColumnRelation | null) {
|
|
124
|
+
const columnIndex = columns.value.findIndex((item: Column) => item.id === columnId)
|
|
125
|
+
columns.value.splice(columnIndex, 1, {
|
|
126
|
+
...columns.value[columnIndex],
|
|
127
|
+
column_relation: relation
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function deleteColumn(columnId: string) {
|
|
132
|
+
if (!connect) return
|
|
116
133
|
try {
|
|
117
134
|
isDeleting.value = true
|
|
118
|
-
await connect.columns.deleteColumn(
|
|
119
|
-
columns.value = columns.value.filter((item: Column) => item.id !==
|
|
120
|
-
}
|
|
121
|
-
finally {
|
|
135
|
+
await connect.columns.deleteColumn(columnId)
|
|
136
|
+
columns.value = columns.value.filter((item: Column) => item.id !== columnId)
|
|
137
|
+
} finally {
|
|
122
138
|
isDeleting.value = false
|
|
123
139
|
}
|
|
124
140
|
}
|
|
@@ -139,6 +155,7 @@ export const useColumnStore = defineStore('ant.apps.table.viewer.columns', () =>
|
|
|
139
155
|
isUpdating,
|
|
140
156
|
isDeleting,
|
|
141
157
|
columnsAlias,
|
|
158
|
+
columnsConfiguration,
|
|
142
159
|
reset,
|
|
143
160
|
getColumn,
|
|
144
161
|
getColumnIndex,
|
|
@@ -148,5 +165,7 @@ export const useColumnStore = defineStore('ant.apps.table.viewer.columns', () =>
|
|
|
148
165
|
fetchColumns,
|
|
149
166
|
setColumnAlias,
|
|
150
167
|
getColumnsConfiguration,
|
|
168
|
+
setColumnRelation,
|
|
169
|
+
fetchTableColumns
|
|
151
170
|
}
|
|
152
171
|
})
|