From 21e31f9c008b03488131b436a2b033b9c7aaffe4 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Tue, 2 Aug 2022 23:43:43 +0200 Subject: [PATCH] feat(gui-v2,deps): add attachment views carousel --- packages/nc-gui-v2/components.d.ts | 1 + .../components/cell/attachment/Carousel.vue | 128 ++++++++++++++++++ .../components/cell/attachment/Modal.vue | 2 +- .../components/cell/attachment/index.vue | 13 +- .../components/cell/attachment/sort.ts | 7 +- .../components/cell/attachment/utils.ts | 3 + 6 files changed, 144 insertions(+), 10 deletions(-) create mode 100644 packages/nc-gui-v2/components/cell/attachment/Carousel.vue diff --git a/packages/nc-gui-v2/components.d.ts b/packages/nc-gui-v2/components.d.ts index d0e6800cef..9d7df38fcc 100644 --- a/packages/nc-gui-v2/components.d.ts +++ b/packages/nc-gui-v2/components.d.ts @@ -11,6 +11,7 @@ declare module '@vue/runtime-core' { AAutoComplete: typeof import('ant-design-vue/es')['AutoComplete'] AButton: typeof import('ant-design-vue/es')['Button'] ACard: typeof import('ant-design-vue/es')['Card'] + ACarousel: typeof import('ant-design-vue/es')['Carousel'] ACheckbox: typeof import('ant-design-vue/es')['Checkbox'] ACol: typeof import('ant-design-vue/es')['Col'] ACollapse: typeof import('ant-design-vue/es')['Collapse'] diff --git a/packages/nc-gui-v2/components/cell/attachment/Carousel.vue b/packages/nc-gui-v2/components/cell/attachment/Carousel.vue new file mode 100644 index 0000000000..2274b1e9e3 --- /dev/null +++ b/packages/nc-gui-v2/components/cell/attachment/Carousel.vue @@ -0,0 +1,128 @@ + + + + + + + + + + + + {{ selectedImage && selectedImage.title }} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/nc-gui-v2/components/cell/attachment/Modal.vue b/packages/nc-gui-v2/components/cell/attachment/Modal.vue index ae02af9b77..da5295b52f 100644 --- a/packages/nc-gui-v2/components/cell/attachment/Modal.vue +++ b/packages/nc-gui-v2/components/cell/attachment/Modal.vue @@ -25,7 +25,7 @@ const { onDrop, downloadFile, updateModelValue, -} = useAttachmentCell() +} = useAttachmentCell()! // todo: replace placeholder var const isLocked = ref(false) diff --git a/packages/nc-gui-v2/components/cell/attachment/index.vue b/packages/nc-gui-v2/components/cell/attachment/index.vue index 8aa198833f..3249a552a0 100644 --- a/packages/nc-gui-v2/components/cell/attachment/index.vue +++ b/packages/nc-gui-v2/components/cell/attachment/index.vue @@ -2,6 +2,7 @@ import { useProvideAttachmentCell } from './utils' import Modal from './Modal.vue' import { useSortable } from './sort' +import Carousel from './Carousel.vue' import { ref, useDropZone, watch } from '#imports' import { isImage, openLink } from '~/utils' import MaterialSymbolsAttachFile from '~icons/material-symbols/attach-file' @@ -26,7 +27,8 @@ const dropZoneRef = ref() const sortableRef = ref() -const { modalVisible, attachments, visibleItems, onDrop, isLoading, open, FileIcon } = useProvideAttachmentCell(updateModelValue) +const { modalVisible, attachments, visibleItems, onDrop, isLoading, open, FileIcon, selectedImage } = + useProvideAttachmentCell(updateModelValue) const { dragging } = useSortable(sortableRef, visibleItems, updateModelValue) @@ -43,17 +45,18 @@ watch( ) function updateModelValue(data: string | Record) { - console.log(data) emits('update:modelValue', typeof data !== 'string' ? JSON.stringify(data) : data) } -const selectImage = (file: any, i: unknown) => { - // todo: implement +const selectImage = (file: any) => { + selectedImage.value = file } + + { v-if="isImage(item.title, item.mimetype)" :alt="item.title || `#${i}`" :src="item.url || item.data" - @click="selectImage(item.url || item.data, i)" + @click="selectImage(item)" /> diff --git a/packages/nc-gui-v2/components/cell/attachment/sort.ts b/packages/nc-gui-v2/components/cell/attachment/sort.ts index c7985cc2bc..80cf19fb46 100644 --- a/packages/nc-gui-v2/components/cell/attachment/sort.ts +++ b/packages/nc-gui-v2/components/cell/attachment/sort.ts @@ -39,8 +39,6 @@ export function useSortable( // todo: replace with vuedraggable const initSortable = (el: HTMLElement) => { - if (sortable) sortable.destroy() - sortable = new Sortable(el, { handle: '.nc-attachment', ghostClass: 'ghost', @@ -50,11 +48,12 @@ export function useSortable( } watchPostEffect((onCleanup) => { + const _element = unref(element) + onCleanup(() => { - if (sortable) sortable.destroy() + if (_element && sortable) sortable.destroy() }) - const _element = unref(element) if (_element) initSortable(_element) }) diff --git a/packages/nc-gui-v2/components/cell/attachment/utils.ts b/packages/nc-gui-v2/components/cell/attachment/utils.ts index 1716d85969..c874b6e6d4 100644 --- a/packages/nc-gui-v2/components/cell/attachment/utils.ts +++ b/packages/nc-gui-v2/components/cell/attachment/utils.ts @@ -31,6 +31,8 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( const modalVisible = ref(false) + const selectedImage = ref() + const { project } = useProject() const { api, isLoading } = useApi() @@ -140,6 +142,7 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( removeFile, downloadFile, updateModelValue, + selectedImage, } }, 'attachmentCell',