mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
189 lines
5.2 KiB
189 lines
5.2 KiB
2 years ago
|
<script lang="ts" setup>
|
||
2 years ago
|
import { ViewTypes } from 'nocodb-sdk'
|
||
2 years ago
|
import { message } from 'ant-design-vue'
|
||
2 years ago
|
import {
|
||
|
computed,
|
||
|
extractSdkResponseErrorMsg,
|
||
2 years ago
|
useCopy,
|
||
2 years ago
|
useI18n,
|
||
|
useNuxtApp,
|
||
|
useProject,
|
||
|
useSmartsheetStoreOrThrow,
|
||
|
} from '#imports'
|
||
2 years ago
|
import MdiOpenInNewIcon from '~icons/mdi/open-in-new'
|
||
|
import MdiCopyIcon from '~icons/mdi/content-copy'
|
||
2 years ago
|
|
||
2 years ago
|
const { t } = useI18n()
|
||
|
|
||
2 years ago
|
const { view, $api } = useSmartsheetStoreOrThrow()
|
||
|
|
||
2 years ago
|
const { copy } = useCopy()
|
||
2 years ago
|
|
||
2 years ago
|
const { $e } = useNuxtApp()
|
||
2 years ago
|
|
||
2 years ago
|
const { dashboardUrl } = useDashboard()
|
||
2 years ago
|
|
||
2 years ago
|
const { isUIAllowed } = useUIPermission()
|
||
|
|
||
2 years ago
|
const { isSharedBase } = useProject()
|
||
|
|
||
2 years ago
|
let showShareModel = $ref(false)
|
||
2 years ago
|
|
||
2 years ago
|
const passwordProtected = ref(false)
|
||
2 years ago
|
|
||
2 years ago
|
const shared = ref()
|
||
|
|
||
2 years ago
|
const allowCSVDownload = computed({
|
||
|
get() {
|
||
|
return !!(shared.value?.meta && typeof shared.value.meta === 'string' ? JSON.parse(shared.value.meta) : shared.value.meta)
|
||
|
?.allowCSVDownload
|
||
|
},
|
||
|
set(allow) {
|
||
|
shared.value.meta = { allowCSVDownload: allow }
|
||
|
saveAllowCSVDownload()
|
||
|
},
|
||
|
})
|
||
2 years ago
|
|
||
|
const genShareLink = async () => {
|
||
2 years ago
|
shared.value = await $api.dbViewShare.create(view.value?.id as string)
|
||
2 years ago
|
shared.value.meta =
|
||
|
shared.value.meta && typeof shared.value.meta === 'string' ? JSON.parse(shared.value.meta) : shared.value.meta
|
||
|
passwordProtected.value = shared.value.password !== null && shared.value.password !== ''
|
||
2 years ago
|
showShareModel = true
|
||
|
}
|
||
|
|
||
|
const sharedViewUrl = computed(() => {
|
||
|
if (!shared.value) return
|
||
|
let viewType
|
||
|
|
||
|
switch (shared.value.type) {
|
||
|
case ViewTypes.FORM:
|
||
|
viewType = 'form'
|
||
|
break
|
||
|
case ViewTypes.KANBAN:
|
||
|
viewType = 'kanban'
|
||
|
break
|
||
|
default:
|
||
|
viewType = 'view'
|
||
|
}
|
||
|
|
||
2 years ago
|
return `${dashboardUrl?.value}#/nc/${viewType}/${shared.value.uuid}`
|
||
2 years ago
|
})
|
||
2 years ago
|
|
||
2 years ago
|
async function saveAllowCSVDownload() {
|
||
2 years ago
|
try {
|
||
|
const meta = shared.value.meta && typeof shared.value.meta === 'string' ? JSON.parse(shared.value.meta) : shared.value.meta
|
||
|
await $api.dbViewShare.update(shared.value.id, {
|
||
|
meta,
|
||
2 years ago
|
})
|
||
2 years ago
|
// Successfully updated
|
||
|
message.success(t('msg.success.updated'))
|
||
2 years ago
|
} catch (e: any) {
|
||
2 years ago
|
message.error(await extractSdkResponseErrorMsg(e))
|
||
2 years ago
|
}
|
||
|
if (allowCSVDownload?.value) {
|
||
|
$e('a:view:share:enable-csv-download')
|
||
|
} else {
|
||
|
$e('a:view:share:disable-csv-download')
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const saveShareLinkPassword = async () => {
|
||
|
try {
|
||
|
await $api.dbViewShare.update(shared.value.id, {
|
||
|
password: shared.value.password,
|
||
|
})
|
||
2 years ago
|
// Successfully updated
|
||
|
message.success(t('msg.success.updated'))
|
||
2 years ago
|
} catch (e: any) {
|
||
2 years ago
|
message.error(await extractSdkResponseErrorMsg(e))
|
||
2 years ago
|
}
|
||
|
|
||
|
$e('a:view:share:enable-pwd')
|
||
|
}
|
||
2 years ago
|
|
||
|
const copyLink = () => {
|
||
|
copy(sharedViewUrl?.value as string)
|
||
2 years ago
|
// Copied to clipboard
|
||
|
message.success(t('msg.info.copiedToClipboard'))
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
watch(passwordProtected, (value) => {
|
||
|
if (!value) {
|
||
|
shared.value.password = ''
|
||
|
saveShareLinkPassword()
|
||
|
}
|
||
2 years ago
|
})
|
||
2 years ago
|
</script>
|
||
|
|
||
|
<template>
|
||
2 years ago
|
<div>
|
||
2 years ago
|
<a-button
|
||
|
v-if="isUIAllowed('share-view') && !isSharedBase"
|
||
2 years ago
|
v-e="['c:view:share']"
|
||
2 years ago
|
outlined
|
||
|
class="nc-btn-share-view nc-toolbar-btn"
|
||
|
>
|
||
2 years ago
|
<div class="flex items-center gap-1" @click="genShareLink">
|
||
2 years ago
|
<MdiOpenInNewIcon />
|
||
2 years ago
|
<!-- Share View -->
|
||
2 years ago
|
<span class="!text-sm font-weight-normal"> {{ $t('activity.shareView') }}</span>
|
||
2 years ago
|
</div>
|
||
|
</a-button>
|
||
|
|
||
|
<!-- This view is shared via a private link -->
|
||
2 years ago
|
<a-modal
|
||
|
v-model:visible="showShareModel"
|
||
|
size="small"
|
||
|
:title="$t('msg.info.privateLink')"
|
||
|
:footer="null"
|
||
|
width="min(100vw,640px)"
|
||
2 years ago
|
wrap-class-name="nc-modal-share-view"
|
||
2 years ago
|
>
|
||
2 years ago
|
<div class="share-link-box nc-share-link-box bg-primary-50">
|
||
2 years ago
|
<div class="flex-1 h-min text-xs">{{ sharedViewUrl }}</div>
|
||
2 years ago
|
<a v-e="['c:view:share:open-url']" :href="sharedViewUrl" target="_blank">
|
||
2 years ago
|
<MdiOpenInNewIcon class="text-sm text-gray-500 mt-2" />
|
||
2 years ago
|
</a>
|
||
2 years ago
|
<MdiCopyIcon v-e="['c:view:share:copy-url']" class="text-gray-500 text-sm cursor-pointer" @click="copyLink" />
|
||
2 years ago
|
</div>
|
||
2 years ago
|
|
||
|
<a-collapse ghost>
|
||
2 years ago
|
<a-collapse-panel key="1" :header="$t('general.showOptions')">
|
||
2 years ago
|
<div class="mb-2">
|
||
2 years ago
|
<a-checkbox v-model:checked="passwordProtected" class="!text-xs">{{ $t('msg.info.beforeEnablePwd') }} </a-checkbox>
|
||
2 years ago
|
<div v-if="passwordProtected" class="flex gap-2 mt-2 mb-4">
|
||
|
<a-input
|
||
|
v-model:value="shared.password"
|
||
|
size="small"
|
||
2 years ago
|
class="!text-xs max-w-[250px]"
|
||
2 years ago
|
type="password"
|
||
2 years ago
|
:placeholder="$t('placeholder.password.enter')"
|
||
|
/>
|
||
2 years ago
|
<a-button size="small" class="!text-xs" @click="saveShareLinkPassword"
|
||
|
>{{ $t('placeholder.password.save') }}
|
||
|
</a-button>
|
||
2 years ago
|
</div>
|
||
|
</div>
|
||
|
<div>
|
||
2 years ago
|
<!-- Allow Download -->
|
||
2 years ago
|
<a-checkbox v-if="shared && shared.type === ViewTypes.GRID" v-model:checked="allowCSVDownload" class="!text-xs">
|
||
|
{{ $t('labels.downloadAllowed') }}
|
||
2 years ago
|
</a-checkbox>
|
||
|
</div>
|
||
|
</a-collapse-panel>
|
||
|
</a-collapse>
|
||
2 years ago
|
</a-modal>
|
||
2 years ago
|
</div>
|
||
|
</template>
|
||
2 years ago
|
|
||
|
<style scoped>
|
||
|
.share-link-box {
|
||
2 years ago
|
@apply flex p-2 w-full items-center items-center gap-1 bg-gray-100 rounded;
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
:deep(.ant-collapse-header) {
|
||
|
@apply !text-xs;
|
||
|
}
|
||
2 years ago
|
</style>
|