|
|
@ -1,17 +1,20 @@ |
|
|
|
import { SqlUiFactory } from 'nocodb-sdk' |
|
|
|
import { SqlUiFactory } from 'nocodb-sdk' |
|
|
|
import type { OracleUi, ProjectType, TableType } from 'nocodb-sdk' |
|
|
|
import type { OracleUi, ProjectType, TableType } from 'nocodb-sdk' |
|
|
|
import type { MaybeRef } from '@vueuse/core' |
|
|
|
import type { MaybeRef } from '@vueuse/core' |
|
|
|
import { useNuxtApp, useState } from '#app' |
|
|
|
import { useNuxtApp, useRoute, useState } from '#app' |
|
|
|
import { USER_PROJECT_ROLES } from '~/lib' |
|
|
|
import { USER_PROJECT_ROLES } from '~/lib' |
|
|
|
|
|
|
|
|
|
|
|
export function useProject(projectId?: MaybeRef<string>) { |
|
|
|
export function useProject(projectId?: MaybeRef<string>) { |
|
|
|
const projectRoles = useState<Record<string, boolean>>(USER_PROJECT_ROLES, () => ({})) |
|
|
|
const projectRoles = useState<Record<string, boolean>>(USER_PROJECT_ROLES, () => ({})) |
|
|
|
const { $api } = useNuxtApp() |
|
|
|
const { $api } = useNuxtApp() |
|
|
|
|
|
|
|
let _projectId = $ref('') |
|
|
|
const _projectId = $computed(() => unref(projectId)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const project = useState<ProjectType>('project') |
|
|
|
const project = useState<ProjectType>('project') |
|
|
|
const tables = useState<TableType[]>('tables', () => [] as TableType[]) |
|
|
|
const tables = useState<TableType[]>('tables', () => [] as TableType[]) |
|
|
|
|
|
|
|
const route = useRoute() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// todo: refactor path param name and variable name
|
|
|
|
|
|
|
|
const projectType = $computed(() => route.params.projectType as string) |
|
|
|
|
|
|
|
|
|
|
|
async function loadProjectRoles() { |
|
|
|
async function loadProjectRoles() { |
|
|
|
projectRoles.value = {} |
|
|
|
projectRoles.value = {} |
|
|
@ -29,17 +32,19 @@ export function useProject(projectId?: MaybeRef<string>) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function loadProject(id: string) { |
|
|
|
async function loadProject() { |
|
|
|
project.value = await $api.project.read(id) |
|
|
|
if (unref(projectId)) { |
|
|
|
await loadProjectRoles() |
|
|
|
_projectId = unref(projectId)! |
|
|
|
|
|
|
|
} else if (projectType === 'base') { |
|
|
|
|
|
|
|
const baseData = await $api.public.sharedBaseGet(route.params.projectId as string) |
|
|
|
|
|
|
|
_projectId = baseData.project_id! |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
_projectId = route.params.projectId as string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
project.value = await $api.project.read(_projectId!) |
|
|
|
watchEffect(async () => { |
|
|
|
await loadProjectRoles() |
|
|
|
if (_projectId) { |
|
|
|
|
|
|
|
await loadProject(_projectId) |
|
|
|
|
|
|
|
await loadTables() |
|
|
|
await loadTables() |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const projectBaseType = $computed(() => project.value?.bases?.[0]?.type || '') |
|
|
|
const projectBaseType = $computed(() => project.value?.bases?.[0]?.type || '') |
|
|
|
|
|
|
|
|
|
|
@ -48,6 +53,7 @@ export function useProject(projectId?: MaybeRef<string>) { |
|
|
|
const sqlUi = computed( |
|
|
|
const sqlUi = computed( |
|
|
|
() => SqlUiFactory.create({ client: projectBaseType }) as Exclude<ReturnType<typeof SqlUiFactory['create']>, typeof OracleUi>, |
|
|
|
() => SqlUiFactory.create({ client: projectBaseType }) as Exclude<ReturnType<typeof SqlUiFactory['create']>, typeof OracleUi>, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
const isSharedBase = computed(() => projectType === 'base') |
|
|
|
|
|
|
|
|
|
|
|
return { project, tables, loadProjectRoles, loadProject, loadTables, isMysql, isPg, sqlUi } |
|
|
|
return { project, tables, loadProjectRoles, loadProject, loadTables, isMysql, isPg, sqlUi, isSharedBase } |
|
|
|
} |
|
|
|
} |
|
|
|