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.
238 lines
6.7 KiB
238 lines
6.7 KiB
2 years ago
|
<script setup lang="ts">
|
||
2 years ago
|
import { message } from 'ant-design-vue'
|
||
2 years ago
|
import { useI18n } from 'vue-i18n'
|
||
2 years ago
|
import { onMounted, useClipboard, useNuxtApp, useProject } from '#imports'
|
||
2 years ago
|
import { extractSdkResponseErrorMsg } from '~/utils'
|
||
2 years ago
|
|
||
2 years ago
|
const { t } = useI18n()
|
||
|
|
||
2 years ago
|
interface ShareBase {
|
||
|
uuid?: string
|
||
|
url?: string
|
||
|
role?: string
|
||
|
}
|
||
|
|
||
2 years ago
|
enum ShareBaseRole {
|
||
2 years ago
|
Editor = 'editor',
|
||
|
Viewer = 'viewer',
|
||
|
}
|
||
|
|
||
2 years ago
|
const { dashboardUrl } = $(useDashboard())
|
||
|
|
||
2 years ago
|
const { $api, $e } = useNuxtApp()
|
||
2 years ago
|
|
||
2 years ago
|
let base = $ref<null | ShareBase>(null)
|
||
2 years ago
|
|
||
2 years ago
|
const showEditBaseDropdown = $ref(false)
|
||
2 years ago
|
|
||
2 years ago
|
const { project } = useProject()
|
||
2 years ago
|
|
||
2 years ago
|
const { copy } = useClipboard()
|
||
2 years ago
|
|
||
2 years ago
|
const url = $computed(() => (base && base.uuid ? `${dashboardUrl}#/base/${base.uuid}` : null))
|
||
2 years ago
|
|
||
|
const loadBase = async () => {
|
||
|
try {
|
||
|
if (!project.value.id) return
|
||
|
|
||
2 years ago
|
// todo: response is missing roles in type
|
||
|
const res = (await $api.project.sharedBaseGet(project.value.id)) as any
|
||
|
|
||
2 years ago
|
base = {
|
||
|
uuid: res.uuid,
|
||
|
url: res.url,
|
||
|
role: res.roles,
|
||
|
}
|
||
2 years ago
|
} catch (e: any) {
|
||
2 years ago
|
message.error(await extractSdkResponseErrorMsg(e))
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
const createShareBase = async (role = ShareBaseRole.Viewer) => {
|
||
2 years ago
|
try {
|
||
|
if (!project.value.id) return
|
||
|
|
||
2 years ago
|
// todo: return type void?
|
||
|
const res = (await $api.project.sharedBaseUpdate(project.value.id, {
|
||
2 years ago
|
roles: role,
|
||
2 years ago
|
})) as any
|
||
2 years ago
|
|
||
2 years ago
|
base = res ?? {}
|
||
|
base!.role = role
|
||
2 years ago
|
} catch (e: any) {
|
||
2 years ago
|
message.error(await extractSdkResponseErrorMsg(e))
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
$e('a:shared-base:enable', { role })
|
||
|
}
|
||
|
|
||
|
const disableSharedBase = async () => {
|
||
|
try {
|
||
|
if (!project.value.id) return
|
||
|
|
||
|
await $api.project.sharedBaseDisable(project.value.id)
|
||
2 years ago
|
base = null
|
||
2 years ago
|
} catch (e: any) {
|
||
2 years ago
|
message.error(await extractSdkResponseErrorMsg(e))
|
||
2 years ago
|
}
|
||
|
|
||
|
$e('a:shared-base:disable')
|
||
|
}
|
||
|
|
||
|
const recreate = async () => {
|
||
|
try {
|
||
|
if (!project.value.id) return
|
||
|
|
||
|
const sharedBase = await $api.project.sharedBaseCreate(project.value.id, {
|
||
2 years ago
|
roles: base?.role || ShareBaseRole.Viewer,
|
||
2 years ago
|
})
|
||
2 years ago
|
|
||
2 years ago
|
const newBase = sharedBase || {}
|
||
2 years ago
|
|
||
2 years ago
|
base = { ...newBase, role: base?.role }
|
||
2 years ago
|
} catch (e: any) {
|
||
2 years ago
|
message.error(await extractSdkResponseErrorMsg(e))
|
||
2 years ago
|
}
|
||
|
|
||
|
$e('a:shared-base:recreate')
|
||
|
}
|
||
|
|
||
|
const copyUrl = async () => {
|
||
|
if (!url) return
|
||
|
|
||
2 years ago
|
await copy(url)
|
||
|
|
||
2 years ago
|
// Copied shareable base url to clipboard!
|
||
|
message.success(t('msg.success.shareableURLCopied'))
|
||
2 years ago
|
|
||
|
$e('c:shared-base:copy-url')
|
||
|
}
|
||
|
|
||
|
const navigateToSharedBase = () => {
|
||
|
if (!url) return
|
||
|
|
||
|
window.open(url, '_blank')
|
||
|
|
||
|
$e('c:shared-base:open-url')
|
||
|
}
|
||
|
|
||
|
const generateEmbeddableIframe = () => {
|
||
|
if (!url) return
|
||
|
|
||
2 years ago
|
copy(`<iframe
|
||
2 years ago
|
class="nc-embed"
|
||
|
src="${url}?embed"
|
||
|
frameborder="0"
|
||
|
width="100%"
|
||
|
height="700"
|
||
|
style="background: transparent; border: 1px solid #ddd"></iframe>`)
|
||
2 years ago
|
|
||
2 years ago
|
// Copied embeddable html code!
|
||
|
message.success(t('msg.success.embeddableHTMLCodeCopied'))
|
||
2 years ago
|
|
||
|
$e('c:shared-base:copy-embed-frame')
|
||
|
}
|
||
|
|
||
|
onMounted(() => {
|
||
|
if (!base) {
|
||
|
loadBase()
|
||
|
}
|
||
|
})
|
||
|
</script>
|
||
|
|
||
|
<template>
|
||
2 years ago
|
<div class="flex flex-col w-full">
|
||
2 years ago
|
<div class="flex flex-row items-center space-x-0.5 pl-2 h-[0.8rem]">
|
||
2 years ago
|
<MdiOpenInNew />
|
||
|
|
||
2 years ago
|
<div class="text-xs">{{ $t('activity.shareBase.link') }}</div>
|
||
2 years ago
|
</div>
|
||
2 years ago
|
<div v-if="base?.uuid" class="flex flex-row mt-2 bg-red-50 py-4 mx-1 px-2 items-center rounded-sm w-full justify-between">
|
||
2 years ago
|
<span class="flex text-xs overflow-x-hidden overflow-ellipsis text-gray-700 pl-2 nc-url">{{ url }}</span>
|
||
2 years ago
|
<div class="flex border-l-1 pt-1 pl-1">
|
||
|
<a-tooltip placement="bottom">
|
||
|
<template #title>
|
||
2 years ago
|
<span>{{ $t('general.reload') }}</span>
|
||
2 years ago
|
</template>
|
||
2 years ago
|
<a-button type="text" class="!rounded-md mr-1 -mt-1.5 h-[1rem]" @click="recreate">
|
||
2 years ago
|
<template #icon>
|
||
2 years ago
|
<MdiReload class="flex mx-auto text-gray-600" />
|
||
2 years ago
|
</template>
|
||
|
</a-button>
|
||
|
</a-tooltip>
|
||
|
<a-tooltip placement="bottom">
|
||
|
<template #title>
|
||
2 years ago
|
<span>{{ $t('activity.copyUrl') }}</span>
|
||
2 years ago
|
</template>
|
||
2 years ago
|
<a-button type="text" class="!rounded-md mr-1 -mt-1.5 h-[1rem]" @click="copyUrl">
|
||
2 years ago
|
<template #icon>
|
||
2 years ago
|
<MdiContentCopy class="flex mx-auto text-gray-600" />
|
||
2 years ago
|
</template>
|
||
|
</a-button>
|
||
|
</a-tooltip>
|
||
|
<a-tooltip placement="bottom">
|
||
|
<template #title>
|
||
2 years ago
|
<span>{{ $t('activity.openTab') }}</span>
|
||
2 years ago
|
</template>
|
||
2 years ago
|
<a-button type="text" class="!rounded-md mr-1 -mt-1.5 h-[1rem]" @click="navigateToSharedBase">
|
||
2 years ago
|
<template #icon>
|
||
2 years ago
|
<MdiOpenInNew class="flex mx-auto text-gray-600" />
|
||
2 years ago
|
</template>
|
||
|
</a-button>
|
||
|
</a-tooltip>
|
||
|
<a-tooltip placement="bottom">
|
||
|
<template #title>
|
||
2 years ago
|
<span>{{ $t('activity.iFrame') }}</span>
|
||
2 years ago
|
</template>
|
||
2 years ago
|
<a-button type="text" class="!rounded-md mr-1 -mt-1.5 h-[1rem]" @click="generateEmbeddableIframe">
|
||
2 years ago
|
<template #icon>
|
||
2 years ago
|
<MdiXml class="flex mx-auto text-gray-600" />
|
||
2 years ago
|
</template>
|
||
|
</a-button>
|
||
|
</a-tooltip>
|
||
|
</div>
|
||
2 years ago
|
</div>
|
||
2 years ago
|
<!-- Generate publicly shareable readonly base -->
|
||
|
<div class="flex text-xs text-gray-500 mt-2 justify-start ml-2">{{ $t('msg.info.generatePublicShareableReadonlyBase') }}</div>
|
||
2 years ago
|
<div class="mt-4 flex flex-row justify-between mx-1">
|
||
|
<a-dropdown v-model="showEditBaseDropdown" class="flex">
|
||
|
<a-button>
|
||
2 years ago
|
<div class="flex flex-row items-center space-x-2 nc-disable-shared-base">
|
||
2 years ago
|
<div v-if="base?.uuid">{{ $t('activity.shareBase.enable') }}</div>
|
||
|
<div v-else>{{ $t('activity.shareBase.disable') }}</div>
|
||
2 years ago
|
<IcRoundKeyboardArrowDown class="h-[1rem]" />
|
||
2 years ago
|
</div>
|
||
|
</a-button>
|
||
|
|
||
|
<template #overlay>
|
||
|
<a-menu>
|
||
|
<a-menu-item>
|
||
2 years ago
|
<div v-if="base?.uuid" class="py-3" @click="disableSharedBase">{{ $t('activity.shareBase.disable') }}</div>
|
||
2 years ago
|
<div v-else class="py-3" @click="createShareBase(ShareBaseRole.Viewer)">{{ $t('activity.shareBase.enable') }}</div>
|
||
2 years ago
|
</a-menu-item>
|
||
|
</a-menu>
|
||
|
</template>
|
||
|
</a-dropdown>
|
||
|
|
||
2 years ago
|
<a-select v-if="base?.uuid" v-model:value="base.role" class="flex nc-shared-base-role">
|
||
2 years ago
|
<template #suffixIcon>
|
||
|
<div class="flex flex-row">
|
||
2 years ago
|
<IcRoundKeyboardArrowDown class="text-black -mt-0.5 h-[1rem]" />
|
||
2 years ago
|
</div>
|
||
|
</template>
|
||
2 years ago
|
<a-select-option
|
||
2 years ago
|
v-for="(role, index) in [ShareBaseRole.Editor, ShareBaseRole.Viewer]"
|
||
2 years ago
|
:key="index"
|
||
|
:value="role"
|
||
|
dropdown-class-name="capitalize"
|
||
|
@click="createShareBase(role)"
|
||
|
>
|
||
|
<div class="w-full px-2 capitalize">
|
||
|
{{ role }}
|
||
|
</div>
|
||
|
</a-select-option>
|
||
|
</a-select>
|
||
|
</div>
|
||
|
</div>
|
||
|
</template>
|