@antcde/component-library 0.1.0 → 0.1.2
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/README.md +6 -0
- package/dist/component-library.css +1 -1
- package/dist/index.js +16719 -17759
- package/dist/types/components/BaseAppCard.vue.d.ts +18 -4
- package/dist/types/components/BaseAppCardSkeleton.vue.d.ts +2 -0
- package/dist/types/components/BaseDeleteDialog.vue.d.ts +20 -7
- package/dist/types/components/RBAC/Permissions/PermissionCard.vue.d.ts +1 -1
- package/dist/types/components/TasksFlow/useTaskFlow.d.ts +7 -6
- package/dist/types/index.d.ts +3 -1
- package/lib/DocumentManager/DocumentDrop.vue +2 -6
- package/lib/DocumentManager/DocumentManager.vue +48 -41
- package/lib/DocumentManager/hooks/useDms.ts +1 -3
- package/lib/DocumentManager/index.ts +1 -1
- package/lib/DocumentManager/lang/translations/de.json +36 -0
- package/lib/DocumentManager/lang/translations/en.json +38 -0
- package/lib/DocumentManager/lang/translations/nl.json +36 -0
- package/lib/DocumentManager/utils.ts +1 -1
- package/lib/ForgeViewer/ForgeViewer.vue +6 -5
- package/lib/ForgeViewer/lang/translations/de.json +6 -0
- package/lib/ForgeViewer/lang/translations/en.json +6 -0
- package/lib/ForgeViewer/lang/translations/nl.json +6 -0
- package/lib/ForgeViewer/useForgeViewer.ts +0 -1
- package/lib/GisViewer/GisViewer.vue +14 -8
- package/lib/GisViewer/useGisViewer.ts +3 -3
- package/package.json +4 -3
- package/lib/DocumentManager/hooks/useDarkMode.ts +0 -17
- package/lib/TableViewer/TableView.vue +0 -39
- package/lib/TableViewer/TableViewer.vue +0 -205
- package/lib/TableViewer/composables/records.ts +0 -53
- package/lib/TableViewer/composables/useFile.ts +0 -20
- package/lib/TableViewer/core/Columns/ColumnForm.vue +0 -230
- 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/Queries/QueryItem.vue +0 -112
- package/lib/TableViewer/core/Records/RecordCell.vue +0 -118
- package/lib/TableViewer/core/Records/RecordDialog.vue +0 -128
- package/lib/TableViewer/core/Records/RecordHeader.vue +0 -175
- package/lib/TableViewer/core/Records/RecordInput.vue +0 -183
- package/lib/TableViewer/core/Records/RecordValue.vue +0 -123
- package/lib/TableViewer/core/Records/RecordsTable.vue +0 -233
- package/lib/TableViewer/core/Records/RecordsTableToolbar.vue +0 -310
- 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
- package/lib/TableViewer/core/Revisions/RevisionComparisonCell.vue +0 -50
- package/lib/TableViewer/core/Revisions/RevisionComparisonTable.vue +0 -98
- package/lib/TableViewer/core/Revisions/RevisionHistory.vue +0 -138
- package/lib/TableViewer/core/Revisions/RevisionSelector.vue +0 -140
- package/lib/TableViewer/index.ts +0 -4
- package/lib/TableViewer/services/file-handler.ts +0 -84
- package/lib/TableViewer/stores/client.ts +0 -18
- package/lib/TableViewer/stores/columns.ts +0 -152
- package/lib/TableViewer/stores/conditions.ts +0 -88
- package/lib/TableViewer/stores/permissions.ts +0 -102
- package/lib/TableViewer/stores/queries.ts +0 -80
- package/lib/TableViewer/stores/records.ts +0 -256
- package/lib/TableViewer/stores/relations.ts +0 -89
- package/lib/TableViewer/stores/revisions.ts +0 -194
- package/lib/TableViewer/stores/roles.ts +0 -109
- package/lib/TableViewer/stores/table.ts +0 -134
- package/lib/TableViewer/stores/tables.ts +0 -65
- package/lib/TableViewer/types/app.d.ts +0 -5
- package/lib/TableViewer/types/column.d.ts +0 -28
- package/lib/TableViewer/types/permission.d.ts +0 -12
- package/lib/TableViewer/types/project.d.ts +0 -37
- package/lib/TableViewer/types/tables.d.ts +0 -69
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import type { TableRecord } from '@antcde/connect-ts/services/TableService'
|
|
3
|
-
import dayjs from 'dayjs'
|
|
4
|
-
import { storeToRefs } from 'pinia'
|
|
5
|
-
import { computed, ref, watch } from 'vue'
|
|
6
|
-
import { useI18n } from 'vue-i18n'
|
|
7
|
-
import { useColumnStore } from '../../stores/columns'
|
|
8
|
-
import { useRecordStore } from '../../stores/records'
|
|
9
|
-
import RecordValue from '../Records/RecordValue.vue'
|
|
10
|
-
|
|
11
|
-
const props = defineProps<{
|
|
12
|
-
displayed: boolean
|
|
13
|
-
headers: any[]
|
|
14
|
-
record?: TableRecord | null
|
|
15
|
-
}>()
|
|
16
|
-
|
|
17
|
-
const emit = defineEmits(['close'])
|
|
18
|
-
|
|
19
|
-
const { t } = useI18n()
|
|
20
|
-
|
|
21
|
-
const recordStore = useRecordStore()
|
|
22
|
-
const columnStore = useColumnStore()
|
|
23
|
-
|
|
24
|
-
const records = ref<TableRecord[]>([])
|
|
25
|
-
const isFetching = ref(false)
|
|
26
|
-
const { columns } = storeToRefs(columnStore)
|
|
27
|
-
|
|
28
|
-
const historyTableHeaders = computed(() => {
|
|
29
|
-
return [
|
|
30
|
-
{
|
|
31
|
-
id: null,
|
|
32
|
-
key: 'user',
|
|
33
|
-
name: 'User',
|
|
34
|
-
sortable: false,
|
|
35
|
-
align: 'start',
|
|
36
|
-
},
|
|
37
|
-
...props.headers,
|
|
38
|
-
{
|
|
39
|
-
id: 'revisioned',
|
|
40
|
-
key: 'revisioned',
|
|
41
|
-
name: 'Revisioned',
|
|
42
|
-
sortable: false,
|
|
43
|
-
align: 'start',
|
|
44
|
-
width: 180,
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
id: 'created_at',
|
|
48
|
-
key: 'created_at',
|
|
49
|
-
name: 'Created At',
|
|
50
|
-
sortable: false,
|
|
51
|
-
align: 'start',
|
|
52
|
-
width: 180,
|
|
53
|
-
},
|
|
54
|
-
]
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
watch(
|
|
58
|
-
() => props.displayed,
|
|
59
|
-
async (newVal) => {
|
|
60
|
-
if (newVal) {
|
|
61
|
-
isFetching.value = true
|
|
62
|
-
records.value = props.record ? await recordStore.fetchRecordHistory(props.record) as TableRecord[] : []
|
|
63
|
-
isFetching.value = false
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
)
|
|
67
|
-
</script>
|
|
68
|
-
|
|
69
|
-
<template>
|
|
70
|
-
<v-dialog :width="columns.length * 120 + 536" min-width="50%" max-height="80%" :model-value="displayed" @update:model-value="emit('close')">
|
|
71
|
-
<v-card>
|
|
72
|
-
<v-toolbar color="primary" class="px-0" density="compact">
|
|
73
|
-
<v-toolbar-title>{{ t('project.records.recordHistory') }}</v-toolbar-title>
|
|
74
|
-
<v-spacer />
|
|
75
|
-
|
|
76
|
-
<v-toolbar-items>
|
|
77
|
-
<v-btn
|
|
78
|
-
v-tooltip="t('system.buttons.close')"
|
|
79
|
-
icon="mdi-close"
|
|
80
|
-
@click="emit('close')"
|
|
81
|
-
/>
|
|
82
|
-
</v-toolbar-items>
|
|
83
|
-
</v-toolbar>
|
|
84
|
-
</v-card>
|
|
85
|
-
<v-data-table
|
|
86
|
-
fixed-header
|
|
87
|
-
hide-default-footer
|
|
88
|
-
:items="records"
|
|
89
|
-
:loading="isFetching"
|
|
90
|
-
:items-length="records.length"
|
|
91
|
-
:headers="historyTableHeaders"
|
|
92
|
-
>
|
|
93
|
-
<template #loading>
|
|
94
|
-
<v-skeleton-loader type="table-row@4" />
|
|
95
|
-
</template>
|
|
96
|
-
|
|
97
|
-
<template
|
|
98
|
-
v-for="header in historyTableHeaders"
|
|
99
|
-
:key="header.key"
|
|
100
|
-
#[`header.${header.key}`]
|
|
101
|
-
>
|
|
102
|
-
{{ header.name }}
|
|
103
|
-
</template>
|
|
104
|
-
|
|
105
|
-
<template
|
|
106
|
-
v-for="header in headers.filter(h => h.column)"
|
|
107
|
-
:key="header.key"
|
|
108
|
-
#[`item.${header.key}`]="{ item }"
|
|
109
|
-
>
|
|
110
|
-
<record-value
|
|
111
|
-
:value="item[header.name]"
|
|
112
|
-
:column="header.column"
|
|
113
|
-
:record-id="item.id"
|
|
114
|
-
/>
|
|
115
|
-
</template>
|
|
116
|
-
|
|
117
|
-
<template #[`item.revisioned`]="{ item }">
|
|
118
|
-
<div class="fs-12 text-muted">
|
|
119
|
-
{{ item.revisioned ? dayjs(item.revisioned ?? new Date()).format('YYYY-MM-DD HH:mm:ss') : '-' }}
|
|
120
|
-
</div>
|
|
121
|
-
</template>
|
|
122
|
-
|
|
123
|
-
<template #[`item.created_at`]="{ item }">
|
|
124
|
-
<div class="fs-12 text-muted">
|
|
125
|
-
{{ item.created_at ? dayjs(item.created_at ?? new Date()).format('YYYY-MM-DD HH:mm:ss') : '-' }}
|
|
126
|
-
</div>
|
|
127
|
-
</template>
|
|
128
|
-
|
|
129
|
-
<template #[`item.user`]="{ item }">
|
|
130
|
-
<v-avatar v-if="item.user_name" class="mr-2" color="primary" size="40">
|
|
131
|
-
<span class="white--text uppercase">
|
|
132
|
-
{{ item.user_name[0] + item.user_name[1] }}
|
|
133
|
-
</span>
|
|
134
|
-
</v-avatar>
|
|
135
|
-
</template>
|
|
136
|
-
</v-data-table>
|
|
137
|
-
</v-dialog>
|
|
138
|
-
</template>
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import dayjs from 'dayjs'
|
|
3
|
-
import { storeToRefs } from 'pinia'
|
|
4
|
-
import { computed, ref } from 'vue'
|
|
5
|
-
|
|
6
|
-
import { useI18n } from 'vue-i18n'
|
|
7
|
-
import { useRevisionStore } from '../../stores/revisions'
|
|
8
|
-
|
|
9
|
-
const { t } = useI18n()
|
|
10
|
-
|
|
11
|
-
const props = defineProps<{
|
|
12
|
-
showAddRevision: boolean
|
|
13
|
-
hideCurrent: boolean
|
|
14
|
-
selected: any
|
|
15
|
-
}>()
|
|
16
|
-
|
|
17
|
-
const emit = defineEmits(['select'])
|
|
18
|
-
|
|
19
|
-
const newRevisionReason = ref('')
|
|
20
|
-
|
|
21
|
-
const revisionStore = useRevisionStore()
|
|
22
|
-
|
|
23
|
-
const { sortedRevisions, isCreating, isFetching } = storeToRefs(revisionStore)
|
|
24
|
-
|
|
25
|
-
async function addRevision() {
|
|
26
|
-
if (newRevisionReason.value) {
|
|
27
|
-
newRevisionReason.value = ''
|
|
28
|
-
await revisionStore.addRevision(newRevisionReason.value)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const revisions = computed(() => {
|
|
33
|
-
if (props.hideCurrent) {
|
|
34
|
-
return sortedRevisions.value
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return [
|
|
38
|
-
{
|
|
39
|
-
id: null,
|
|
40
|
-
reason: 'Actual',
|
|
41
|
-
timestamp: new Date(),
|
|
42
|
-
version: 'Actual',
|
|
43
|
-
},
|
|
44
|
-
...sortedRevisions.value,
|
|
45
|
-
]
|
|
46
|
-
})
|
|
47
|
-
</script>
|
|
48
|
-
|
|
49
|
-
<template>
|
|
50
|
-
<v-menu :close-on-content-click="!showAddRevision" width="300">
|
|
51
|
-
<template #activator="{ props: activatorProps }">
|
|
52
|
-
<v-card variant="tonal" density="compact" v-bind="activatorProps">
|
|
53
|
-
<v-card-text>
|
|
54
|
-
<span class="d-block font-italic" style="font-size: 12px; white-space: nowrap">
|
|
55
|
-
{{ dayjs(selected?.timestamp ?? new Date()).format('YYYY-MM-DD HH:mm') }}
|
|
56
|
-
</span>
|
|
57
|
-
<span class="text-subtitle text-[10px]">
|
|
58
|
-
Version:
|
|
59
|
-
{{ selected?.version ?? 'Actual' }}
|
|
60
|
-
</span>
|
|
61
|
-
</v-card-text>
|
|
62
|
-
</v-card>
|
|
63
|
-
</template>
|
|
64
|
-
|
|
65
|
-
<v-card>
|
|
66
|
-
<v-text-field
|
|
67
|
-
v-if="showAddRevision"
|
|
68
|
-
v-model="newRevisionReason"
|
|
69
|
-
:disabled="isCreating"
|
|
70
|
-
label="Create Revision"
|
|
71
|
-
placeholder="Revision reason"
|
|
72
|
-
hide-details dense
|
|
73
|
-
@keydown.enter="addRevision"
|
|
74
|
-
>
|
|
75
|
-
<template #prepend-inner>
|
|
76
|
-
<v-icon icon="mdi-timeline-outline" />
|
|
77
|
-
</template>
|
|
78
|
-
<template v-if="isCreating" #append-inner>
|
|
79
|
-
<v-progress-circular size="24" color="grey-darken-2" indeterminate />
|
|
80
|
-
</template>
|
|
81
|
-
</v-text-field>
|
|
82
|
-
|
|
83
|
-
<v-skeleton-loader v-if="isFetching" type="list-item@4" />
|
|
84
|
-
|
|
85
|
-
<v-timeline
|
|
86
|
-
v-else-if="revisions.length > 0"
|
|
87
|
-
side="end"
|
|
88
|
-
align="center"
|
|
89
|
-
dot-color="transparent"
|
|
90
|
-
class="overflow-auto revisions-timeline h-auto max-h-[370px] pl-2 pr-4"
|
|
91
|
-
density="compact"
|
|
92
|
-
hide-opposite
|
|
93
|
-
size="small"
|
|
94
|
-
>
|
|
95
|
-
<v-timeline-item v-for="(revision, index) in revisions" :key="index" small>
|
|
96
|
-
<template #icon>
|
|
97
|
-
<v-btn
|
|
98
|
-
v-tooltip="revision.reason ?? 'No reason'"
|
|
99
|
-
size="small"
|
|
100
|
-
variant="text"
|
|
101
|
-
icon="mdi-compare"
|
|
102
|
-
tooltip-location="bottom"
|
|
103
|
-
:color="revision.id === selected?.id ? 'primary' : 'grey'"
|
|
104
|
-
@click="() => emit('select', revision.id ? revision : null)"
|
|
105
|
-
/>
|
|
106
|
-
</template>
|
|
107
|
-
<div class="d-flex align-center">
|
|
108
|
-
<span class="font-italic flex-grow-1" style="font-size: 12px; white-space: nowrap">
|
|
109
|
-
{{ dayjs(revision.timestamp).format('YYYY-MM-DD HH:mm') }}
|
|
110
|
-
</span>
|
|
111
|
-
</div>
|
|
112
|
-
<div class="text-subtitle text-[10px]">
|
|
113
|
-
Version: {{ revision.version }}
|
|
114
|
-
</div>
|
|
115
|
-
</v-timeline-item>
|
|
116
|
-
</v-timeline>
|
|
117
|
-
|
|
118
|
-
<v-empty-state
|
|
119
|
-
v-else
|
|
120
|
-
icon="mdi-timeline-outline"
|
|
121
|
-
text="No revisions available"
|
|
122
|
-
/>
|
|
123
|
-
</v-card>
|
|
124
|
-
</v-menu>
|
|
125
|
-
</template>
|
|
126
|
-
|
|
127
|
-
<style lang="scss">
|
|
128
|
-
.revisions-timeline {
|
|
129
|
-
.v-timeline-item:first-child:not(:last-child) .v-timeline-divider {
|
|
130
|
-
.v-timeline-divider__before {
|
|
131
|
-
display: none !important;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
.v-timeline-item:last-child:not(:first-child) .v-timeline-divider {
|
|
135
|
-
.v-timeline-divider__after {
|
|
136
|
-
display: none !important;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
</style>
|
package/lib/TableViewer/index.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type { FileResponse } from '@antcde/connect-ts/services/ProjectService'
|
|
2
|
-
import type { FileInRequest } from '@antcde/connect-ts/services/UserService'
|
|
3
|
-
|
|
4
|
-
const FileHandler = {
|
|
5
|
-
handleFile(file: File): Promise<FileInRequest> | undefined {
|
|
6
|
-
if (typeof file === 'object') {
|
|
7
|
-
const selectedFile = file
|
|
8
|
-
const apiObject: FileInRequest = {
|
|
9
|
-
name: '',
|
|
10
|
-
extension: '',
|
|
11
|
-
data: '',
|
|
12
|
-
}
|
|
13
|
-
apiObject.name = this.getFileName(selectedFile.name)
|
|
14
|
-
apiObject.extension = this.getFileExtension(selectedFile.name)
|
|
15
|
-
|
|
16
|
-
return new Promise((resolve) => {
|
|
17
|
-
const reader = new FileReader()
|
|
18
|
-
reader.readAsDataURL(file)
|
|
19
|
-
reader.onloadend = (e) => {
|
|
20
|
-
const re = /(?:base64,(.*))?$/
|
|
21
|
-
apiObject.data = re.exec(e.target.result)[1]
|
|
22
|
-
|
|
23
|
-
resolve(apiObject)
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
getFileExtension(fileName: string) {
|
|
29
|
-
const re = /(?:\.([^.]+))?$/
|
|
30
|
-
|
|
31
|
-
return re.exec(fileName)[1]
|
|
32
|
-
},
|
|
33
|
-
getFileName(fileName: string) {
|
|
34
|
-
const extension = fileName.substring(fileName.lastIndexOf('.'))
|
|
35
|
-
return fileName.replace(extension, '')
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
async downloadFile(file: File | Uint8Array | string, fileName: string, fileType: string) {
|
|
39
|
-
const blob = new Blob([file], { type: fileType })
|
|
40
|
-
const url = window.URL.createObjectURL(blob)
|
|
41
|
-
const link = document.createElement('a')
|
|
42
|
-
|
|
43
|
-
link.setAttribute('href', url)
|
|
44
|
-
link.setAttribute('download', `${fileName}.${fileType}`)
|
|
45
|
-
link.style.visibility = 'hidden'
|
|
46
|
-
document.body.appendChild(link)
|
|
47
|
-
link.click()
|
|
48
|
-
document.body.removeChild(link)
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
async b64toUint8Array(base64Data: string) {
|
|
52
|
-
const byteCharacters = atob(base64Data)
|
|
53
|
-
const byteNumbers = new Array(byteCharacters.length)
|
|
54
|
-
|
|
55
|
-
for (let i = 0; i < byteCharacters.length; i++) {
|
|
56
|
-
byteNumbers[i] = byteCharacters.charCodeAt(i)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return new Uint8Array(byteNumbers)
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
async downloadRecordDocument(projectId: string, tableId: string, documentId: string, connect: any) {
|
|
63
|
-
if (!connect)
|
|
64
|
-
return
|
|
65
|
-
const response: FileResponse = await connect.records.getRecordDocument(
|
|
66
|
-
projectId,
|
|
67
|
-
tableId,
|
|
68
|
-
documentId,
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
const element = document.createElement('a')
|
|
72
|
-
element.setAttribute('href', `data:${response.mimetype};base64,${response.file}`)
|
|
73
|
-
element.setAttribute('download', `${response.name}.${response.extension}`)
|
|
74
|
-
|
|
75
|
-
element.style.display = 'none'
|
|
76
|
-
document.body.appendChild(element)
|
|
77
|
-
|
|
78
|
-
element.click()
|
|
79
|
-
|
|
80
|
-
document.body.removeChild(element)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export default FileHandler
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { UseCommsClient } from '@antcde/vue-utils'
|
|
2
|
-
import { defineStore } from 'pinia'
|
|
3
|
-
import { ref } from 'vue'
|
|
4
|
-
|
|
5
|
-
export const useClientStore = defineStore('ant.apps.table.viewer.client', () => {
|
|
6
|
-
const client = ref<UseCommsClient | null>(null)
|
|
7
|
-
|
|
8
|
-
function setClient(appClient: UseCommsClient) {
|
|
9
|
-
if (!client.value) {
|
|
10
|
-
client.value = appClient
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
client,
|
|
16
|
-
setClient,
|
|
17
|
-
}
|
|
18
|
-
})
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import type { Column } from '@antcde/connect-ts/services/ColumnService'
|
|
2
|
-
import { defineStore } from 'pinia'
|
|
3
|
-
import { ref } from 'vue'
|
|
4
|
-
import { useClientStore } from './client'
|
|
5
|
-
import { useConditionStore } from './conditions'
|
|
6
|
-
import { useTableStore } from './table'
|
|
7
|
-
|
|
8
|
-
export const useColumnStore = defineStore('ant.apps.table.viewer.columns', () => {
|
|
9
|
-
const isFetching = ref(false)
|
|
10
|
-
const isCreating = ref(false)
|
|
11
|
-
const isUpdating = ref(false)
|
|
12
|
-
const isDeleting = ref(false)
|
|
13
|
-
|
|
14
|
-
const columns = ref<Column[]>([])
|
|
15
|
-
const columnsAlias = ref<{
|
|
16
|
-
[key: string]: any
|
|
17
|
-
}>({})
|
|
18
|
-
|
|
19
|
-
const clientStore = useClientStore()
|
|
20
|
-
const { client } = clientStore
|
|
21
|
-
const connect = client?.connect
|
|
22
|
-
|
|
23
|
-
const tableStore = useTableStore()
|
|
24
|
-
const conditionStore = useConditionStore()
|
|
25
|
-
|
|
26
|
-
async function fetchColumns() {
|
|
27
|
-
if (!tableStore.table || !connect) {
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
isFetching.value = true
|
|
33
|
-
columns.value = (await connect.columns.getColumns(tableStore.table.id)) ?? []
|
|
34
|
-
}
|
|
35
|
-
finally {
|
|
36
|
-
isFetching.value = false
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function getColumnsConfiguration() {
|
|
41
|
-
return columns.value.map((column: Column) => {
|
|
42
|
-
return {
|
|
43
|
-
name: column.name,
|
|
44
|
-
as: columnsAlias.value[column.id] ?? column.name,
|
|
45
|
-
conditions: conditionStore.getApplicableConditions(column),
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function getColumn(id: string) {
|
|
51
|
-
return columns.value.find((column: Column) => column.id === id)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function getColumnIndex(id: string) {
|
|
55
|
-
return columns.value.findIndex((column: Column) => column.id === id)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function setColumnAlias(column: Column, alias: string) {
|
|
59
|
-
columnsAlias.value = {
|
|
60
|
-
...columnsAlias.value,
|
|
61
|
-
[column.id]: alias,
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async function addColumn(column: Column) {
|
|
66
|
-
if (!tableStore.table?.id || !connect) {
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
isCreating.value = true
|
|
71
|
-
const newColumn = await connect.columns.createColumn({
|
|
72
|
-
...column,
|
|
73
|
-
table: tableStore.table.id,
|
|
74
|
-
})
|
|
75
|
-
columns.value.push(newColumn)
|
|
76
|
-
return Promise.resolve(newColumn)
|
|
77
|
-
}
|
|
78
|
-
catch (e) {
|
|
79
|
-
return Promise.reject(e)
|
|
80
|
-
}
|
|
81
|
-
finally {
|
|
82
|
-
isCreating.value = false
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async function updateColumn(column: Column) {
|
|
87
|
-
if (!connect)
|
|
88
|
-
return
|
|
89
|
-
try {
|
|
90
|
-
isUpdating.value = true
|
|
91
|
-
const updatedColumn = await connect.columns.updateColumn(column.id, {
|
|
92
|
-
default_value: column.default_value,
|
|
93
|
-
name: column.name,
|
|
94
|
-
options_value: column.options_value,
|
|
95
|
-
order: column.order,
|
|
96
|
-
required: column.required,
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
const columnIndex = columns.value.findIndex((item: Column) => item.id === column.id)
|
|
100
|
-
|
|
101
|
-
columns.value.splice(columnIndex, 1, updatedColumn)
|
|
102
|
-
|
|
103
|
-
return Promise.resolve(updateColumn)
|
|
104
|
-
}
|
|
105
|
-
catch (e) {
|
|
106
|
-
return Promise.reject(e)
|
|
107
|
-
}
|
|
108
|
-
finally {
|
|
109
|
-
isUpdating.value = false
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async function deleteColumn(column: Column) {
|
|
114
|
-
if (!column || !connect)
|
|
115
|
-
return
|
|
116
|
-
try {
|
|
117
|
-
isDeleting.value = true
|
|
118
|
-
await connect.columns.deleteColumn(column.id)
|
|
119
|
-
columns.value = columns.value.filter((item: Column) => item.id !== column.id)
|
|
120
|
-
}
|
|
121
|
-
finally {
|
|
122
|
-
isDeleting.value = false
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function reset() {
|
|
127
|
-
columns.value = []
|
|
128
|
-
columnsAlias.value = {}
|
|
129
|
-
isFetching.value = false
|
|
130
|
-
isCreating.value = false
|
|
131
|
-
isUpdating.value = false
|
|
132
|
-
isDeleting.value = false
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
columns,
|
|
137
|
-
isFetching,
|
|
138
|
-
isCreating,
|
|
139
|
-
isUpdating,
|
|
140
|
-
isDeleting,
|
|
141
|
-
columnsAlias,
|
|
142
|
-
reset,
|
|
143
|
-
getColumn,
|
|
144
|
-
getColumnIndex,
|
|
145
|
-
addColumn,
|
|
146
|
-
updateColumn,
|
|
147
|
-
deleteColumn,
|
|
148
|
-
fetchColumns,
|
|
149
|
-
setColumnAlias,
|
|
150
|
-
getColumnsConfiguration,
|
|
151
|
-
}
|
|
152
|
-
})
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { Column } from '../types/column'
|
|
2
|
-
import { defineStore } from 'pinia'
|
|
3
|
-
import { ref } from 'vue'
|
|
4
|
-
import { useRecordStore } from './records'
|
|
5
|
-
|
|
6
|
-
export interface Condition {
|
|
7
|
-
id: string
|
|
8
|
-
column: string
|
|
9
|
-
applied?: boolean
|
|
10
|
-
operator?: string
|
|
11
|
-
boolean?: string
|
|
12
|
-
value?: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const useConditionStore = defineStore('ant.apps.table.viewer.conditions', () => {
|
|
16
|
-
const conditions = ref<Condition[]>([])
|
|
17
|
-
|
|
18
|
-
const recordStore = useRecordStore()
|
|
19
|
-
|
|
20
|
-
function addCondition(column: Column) {
|
|
21
|
-
const newColumn = {
|
|
22
|
-
id: Math.random().toString(36),
|
|
23
|
-
column: column.id,
|
|
24
|
-
}
|
|
25
|
-
conditions.value.push(newColumn)
|
|
26
|
-
return newColumn
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function removeCondition(id: string) {
|
|
30
|
-
conditions.value = conditions.value.filter(c => c.id !== id)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function applyColumnConditions(column: Column) {
|
|
34
|
-
conditions.value.forEach((c) => {
|
|
35
|
-
if (c.column === column.id) {
|
|
36
|
-
c.applied = true
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
recordStore.fetchRecords()
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function clearColumnConditions(column: Column) {
|
|
43
|
-
conditions.value = conditions.value.filter(
|
|
44
|
-
(condition: Condition) => condition.column !== column.id,
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function getColumnConditions(column: Column) {
|
|
49
|
-
const columnConditions = conditions.value.filter(
|
|
50
|
-
(condition: Condition) => condition.column === column.id,
|
|
51
|
-
)
|
|
52
|
-
if (columnConditions.length === 0) {
|
|
53
|
-
columnConditions.push(addCondition(column))
|
|
54
|
-
}
|
|
55
|
-
return columnConditions
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function getApplicableConditions(column: Column) {
|
|
59
|
-
return conditions.value.filter(
|
|
60
|
-
(condition: Condition) =>
|
|
61
|
-
condition.column === column.id
|
|
62
|
-
&& !!condition.applied
|
|
63
|
-
&& !!condition.value
|
|
64
|
-
&& !!condition.operator,
|
|
65
|
-
).map((condition) => {
|
|
66
|
-
return {
|
|
67
|
-
operator: condition.operator,
|
|
68
|
-
value: condition.value,
|
|
69
|
-
column: column.id,
|
|
70
|
-
}
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function reset() {
|
|
75
|
-
conditions.value = []
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
conditions,
|
|
80
|
-
reset,
|
|
81
|
-
addCondition,
|
|
82
|
-
removeCondition,
|
|
83
|
-
getColumnConditions,
|
|
84
|
-
clearColumnConditions,
|
|
85
|
-
applyColumnConditions,
|
|
86
|
-
getApplicableConditions,
|
|
87
|
-
}
|
|
88
|
-
})
|