From 3dc46bdafb69c04a16cdf47934239e3aabeef5d5 Mon Sep 17 00:00:00 2001 From: mertmit Date: Tue, 5 Dec 2023 17:15:37 +0300 Subject: [PATCH 1/6] fix: filter mimetypes to preview in browser Signed-off-by: mertmit --- .../attachments-secure.controller.ts | 6 +++++- .../src/controllers/attachments.controller.ts | 18 +++++++++++++++--- .../nocodb/src/services/attachments.service.ts | 8 ++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/packages/nocodb/src/controllers/attachments-secure.controller.ts b/packages/nocodb/src/controllers/attachments-secure.controller.ts index e19b300077..5d7145307e 100644 --- a/packages/nocodb/src/controllers/attachments-secure.controller.ts +++ b/packages/nocodb/src/controllers/attachments-secure.controller.ts @@ -75,7 +75,11 @@ export class AttachmentsSecureController { path: path.join('nc', 'uploads', fpath), }); - res.sendFile(file.path); + if (this.attachmentsService.previewAvailable(file.type)) { + res.sendFile(file.path); + } else { + res.download(file.path); + } } catch (e) { res.status(404).send('Not found'); } diff --git a/packages/nocodb/src/controllers/attachments.controller.ts b/packages/nocodb/src/controllers/attachments.controller.ts index 00a471e1e5..353e840eb7 100644 --- a/packages/nocodb/src/controllers/attachments.controller.ts +++ b/packages/nocodb/src/controllers/attachments.controller.ts @@ -68,7 +68,11 @@ export class AttachmentsController { path: path.join('nc', 'uploads', filename), }); - res.sendFile(file.path); + if (this.attachmentsService.previewAvailable(file.type)) { + res.sendFile(file.path); + } else { + res.download(file.path); + } } catch (e) { res.status(404).send('Not found'); } @@ -94,7 +98,11 @@ export class AttachmentsController { ), }); - res.sendFile(file.path); + if (this.attachmentsService.previewAvailable(file.type)) { + res.sendFile(file.path); + } else { + res.download(file.path); + } } catch (e) { res.status(404).send('Not found'); } @@ -109,7 +117,11 @@ export class AttachmentsController { path: path.join('nc', 'uploads', fpath), }); - res.sendFile(file.path); + if (this.attachmentsService.previewAvailable(file.type)) { + res.sendFile(file.path); + } else { + res.download(file.path); + } } catch (e) { res.status(404).send('Not found'); } diff --git a/packages/nocodb/src/services/attachments.service.ts b/packages/nocodb/src/services/attachments.service.ts index ead5f4c4bb..ff6ba485ea 100644 --- a/packages/nocodb/src/services/attachments.service.ts +++ b/packages/nocodb/src/services/attachments.service.ts @@ -161,6 +161,14 @@ export class AttachmentsService { return { path: filePath, type }; } + previewAvailable(mimetype: string) { + const available = ['image', 'pdf', 'text/plain']; + if (available.some((type) => mimetype.includes(type))) { + return true; + } + return false; + } + sanitizeUrlPath(paths) { return paths.map((url) => url.replace(/[/.?#]+/g, '_')); } From c70ae51e98098ea14a83ae264fd347dae3e2d7ed Mon Sep 17 00:00:00 2001 From: mertmit Date: Fri, 1 Dec 2023 17:10:01 +0300 Subject: [PATCH 2/6] feat: display as progress Signed-off-by: mertmit --- packages/nc-gui/components.d.ts | 1 + packages/nc-gui/components/cell/Percent.vue | 12 +++++ .../smartsheet/column/EditOrAdd.vue | 1 + .../smartsheet/column/PercentOptions.vue | 51 ++++++++----------- .../column/PercentOptionsLegacy.vue | 47 +++++++++++++++++ 5 files changed, 81 insertions(+), 31 deletions(-) create mode 100644 packages/nc-gui/components/smartsheet/column/PercentOptionsLegacy.vue diff --git a/packages/nc-gui/components.d.ts b/packages/nc-gui/components.d.ts index 70144a9a06..5ae4fa0235 100644 --- a/packages/nc-gui/components.d.ts +++ b/packages/nc-gui/components.d.ts @@ -49,6 +49,7 @@ declare module '@vue/runtime-core' { AModal: typeof import('ant-design-vue/es')['Modal'] APagination: typeof import('ant-design-vue/es')['Pagination'] APopover: typeof import('ant-design-vue/es')['Popover'] + AProgress: typeof import('ant-design-vue/es')['Progress'] ARadio: typeof import('ant-design-vue/es')['Radio'] ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup'] ARate: typeof import('ant-design-vue/es')['Rate'] diff --git a/packages/nc-gui/components/cell/Percent.vue b/packages/nc-gui/components/cell/Percent.vue index 29c2efe3f9..cdf9993658 100644 --- a/packages/nc-gui/components/cell/Percent.vue +++ b/packages/nc-gui/components/cell/Percent.vue @@ -12,6 +12,8 @@ const emits = defineEmits(['update:modelValue']) const { showNull } = useGlobal() +const column = inject(ColumnInj)! + const editEnabled = inject(EditModeInj) const isEditColumn = inject(EditColumnInj, ref(false)) @@ -32,6 +34,13 @@ const vModel = computed({ const isExpandedFormOpen = inject(IsExpandedFormOpenInj, ref(false))! const focus: VNodeRef = (el) => !isExpandedFormOpen.value && !isEditColumn.value && (el as HTMLInputElement)?.focus() + +const percentMeta = computed(() => { + return { + is_progress: false, + ...parseProp(column.value?.meta), + } +}) diff --git a/packages/nc-gui/components/smartsheet/column/EditOrAdd.vue b/packages/nc-gui/components/smartsheet/column/EditOrAdd.vue index 67cf1abd6c..7f29e09e79 100644 --- a/packages/nc-gui/components/smartsheet/column/EditOrAdd.vue +++ b/packages/nc-gui/components/smartsheet/column/EditOrAdd.vue @@ -312,6 +312,7 @@ if (props.fromTableExplorer) { v-model:value="formState" /> + - diff --git a/packages/nc-gui/components/smartsheet/column/PercentOptionsLegacy.vue b/packages/nc-gui/components/smartsheet/column/PercentOptionsLegacy.vue new file mode 100644 index 0000000000..f296ba5bba --- /dev/null +++ b/packages/nc-gui/components/smartsheet/column/PercentOptionsLegacy.vue @@ -0,0 +1,47 @@ + + + + + From a7dc9bd1067a6fb97de2cd51336f417fafa43fd7 Mon Sep 17 00:00:00 2001 From: mertmit Date: Sat, 2 Dec 2023 12:12:08 +0300 Subject: [PATCH 3/6] fix: PR requested changes Signed-off-by: mertmit --- packages/nc-gui/components/cell/Percent.vue | 79 +++++++++++++++------ 1 file changed, 58 insertions(+), 21 deletions(-) diff --git a/packages/nc-gui/components/cell/Percent.vue b/packages/nc-gui/components/cell/Percent.vue index cdf9993658..0492fb5e32 100644 --- a/packages/nc-gui/components/cell/Percent.vue +++ b/packages/nc-gui/components/cell/Percent.vue @@ -35,35 +35,72 @@ const isExpandedFormOpen = inject(IsExpandedFormOpenInj, ref(false))! const focus: VNodeRef = (el) => !isExpandedFormOpen.value && !isEditColumn.value && (el as HTMLInputElement)?.focus() +const cellFocused = ref(false) + +const expandedEditEnabled = ref(false) + const percentMeta = computed(() => { return { is_progress: false, ...parseProp(column.value?.meta), } }) + +const onBlur = () => { + if (editEnabled) { + editEnabled.value = false + } + cellFocused.value = false + expandedEditEnabled.value = false +} + +const onFocus = () => { + cellFocused.value = true +} + +const onMouseover = () => { + expandedEditEnabled.value = true +} + +const onMouseleave = () => { + if (!cellFocused.value) { + expandedEditEnabled.value = false + } +} From 5a3f7f1138456656e8c5719225cef20258a7fec2 Mon Sep 17 00:00:00 2001 From: mertmit Date: Tue, 5 Dec 2023 18:49:30 +0300 Subject: [PATCH 4/6] fix: add test selector to wrapper Signed-off-by: mertmit --- packages/nc-gui/components/cell/Percent.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nc-gui/components/cell/Percent.vue b/packages/nc-gui/components/cell/Percent.vue index 0492fb5e32..516ddfe294 100644 --- a/packages/nc-gui/components/cell/Percent.vue +++ b/packages/nc-gui/components/cell/Percent.vue @@ -70,7 +70,7 @@ const onMouseleave = () => {