diff --git a/packages/nc-gui-v2/components/dlg/ViewCreate.vue b/packages/nc-gui-v2/components/dlg/ViewCreate.vue new file mode 100644 index 0000000000..a287ab02e0 --- /dev/null +++ b/packages/nc-gui-v2/components/dlg/ViewCreate.vue @@ -0,0 +1,116 @@ + + + + + + + + + {{ $t('general.create') }} {{ type }} {{ $t('objects.view') }} + + + + + + + + + + {{ $t('general.cancel') }} + + + {{ $t('general.submit') }} + + + + + + + diff --git a/packages/nc-gui-v2/components/dlg/VueCreate.vue b/packages/nc-gui-v2/components/dlg/VueCreate.vue deleted file mode 100644 index 102f034131..0000000000 --- a/packages/nc-gui-v2/components/dlg/VueCreate.vue +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - - {{ $t('general.create') }} {{ typeAlias }} {{ $t('objects.view') }} - - - - - - - - - - {{ $t('general.cancel') }} - - - {{ $t('general.submit') }} - - - - - - - diff --git a/packages/nc-gui-v2/components/index.ts b/packages/nc-gui-v2/components/index.ts index ef87664295..751984d570 100644 --- a/packages/nc-gui-v2/components/index.ts +++ b/packages/nc-gui-v2/components/index.ts @@ -3,6 +3,8 @@ import type { InjectionKey, Ref } from 'vue' import type { EventHook } from '@vueuse/core' import type useViewData from '~/composables/useViewData' +export type ViewType = (GridType | GalleryType | FormType | KanbanType) & { id?: string } + export const ColumnInj: InjectionKey = Symbol('column-injection') export const MetaInj: InjectionKey> = Symbol('meta-injection') export const TabMetaInj: InjectionKey = Symbol('tab-meta-injection') @@ -13,9 +15,8 @@ export const IsFormInj: InjectionKey = Symbol('is-form-injection') export const IsGridInj: InjectionKey = Symbol('is-grid-injection') export const IsLockedInj: InjectionKey = Symbol('is-locked-injection') export const ValueInj: InjectionKey = Symbol('value-injection') -export const ActiveViewInj: InjectionKey> = - Symbol('active-view-injection') +export const ActiveViewInj: InjectionKey> = Symbol('active-view-injection') export const ReadonlyInj: InjectionKey = Symbol('readonly-injection') export const ReloadViewDataHookInj: InjectionKey> = Symbol('reload-view-data-injection') export const FieldsInj: InjectionKey> = Symbol('fields-injection') -export const ViewListInj: InjectionKey> = Symbol('view-list-injection') +export const ViewListInj: InjectionKey> = Symbol('view-list-injection') diff --git a/packages/nc-gui-v2/components/smartsheet/Sidebar.vue b/packages/nc-gui-v2/components/smartsheet/Sidebar.vue index dae39ebebe..ac0f39c748 100644 --- a/packages/nc-gui-v2/components/smartsheet/Sidebar.vue +++ b/packages/nc-gui-v2/components/smartsheet/Sidebar.vue @@ -3,7 +3,7 @@ import { ViewTypes } from 'nocodb-sdk' import type { TableType } from 'nocodb-sdk' import type { Ref } from 'vue' import { inject, ref } from '#imports' -import { ActiveViewInj, MetaInj } from '~/components' +import { ActiveViewInj, MetaInj, ViewListInj } from '~/components' import useViews from '~/composables/useViews' import { viewIcons } from '~/utils/viewUtils' import MdiPlusIcon from '~icons/mdi/plus' @@ -17,6 +17,7 @@ provide(ViewListInj, views) const _isUIAllowed = (view: string) => {} +// todo decide based on route param loadViews().then(() => { activeView.value = views.value?.[0] }) @@ -25,12 +26,19 @@ const toggleDrawer = ref(false) // todo: identify based on meta const isView = ref(false) const viewCreateType = ref() -const viewCreateDlg = ref() +const viewCreateDlg = ref(false) const openCreateViewDlg = (type: ViewTypes) => { viewCreateDlg.value = true viewCreateType.value = type } + +const onViewCreate = (view)=>{ + views.value?.push(view) + activeView.value = view + viewCreateDlg.value = false +} + @@ -188,7 +196,7 @@ const openCreateViewDlg = (type: ViewTypes) => { - + @@ -208,7 +216,7 @@ const openCreateViewDlg = (type: ViewTypes) => { - + @@ -236,7 +244,7 @@ const openCreateViewDlg = (type: ViewTypes) => { dense class="body-2 nc-create-form-view" v-on="on" - @click="openCreateViewDlg(viewTypes.FORM)" + @click="openCreateViewDlg(ViewTypes.FORM)" > @@ -262,7 +270,7 @@ const openCreateViewDlg = (type: ViewTypes) => { - + diff --git a/packages/nc-gui-v2/composables/useViewCreate.ts b/packages/nc-gui-v2/composables/useViewCreate.ts index bfa9771a45..a52b8823da 100644 --- a/packages/nc-gui-v2/composables/useViewCreate.ts +++ b/packages/nc-gui-v2/composables/useViewCreate.ts @@ -1,32 +1,63 @@ -import type { ViewTypes } from 'nocodb-sdk' -import { UITypes } from 'nocodb-sdk' +import type { TableType } from 'nocodb-sdk' +import { ViewTypes } from 'nocodb-sdk' +import type { Ref } from 'vue' +import { useToast } from 'vue-toastification' import { useNuxtApp } from '#app' +import useMetas from '~/composables/useMetas' -export default (onViewCreate?: (viewMeta: any) => void) => { +export default (meta: Ref, onViewCreate?: (viewMeta: any) => void) => { const view = reactive<{ title: string; type?: ViewTypes }>({ title: '', }) + const loading = ref(false) + const { $api } = useNuxtApp() + const toast = useToast() + const { metas } = useMetas() - const createView = async () => { - if (!sqlUi?.value) return - const columns = sqlUi?.value?.getNewTableColumns().filter((col) => { - if (col.column_name === 'id' && table.columns.includes('id_ag')) { - Object.assign(col, sqlUi?.value?.getDataTypeForUiType({ uidt: UITypes.ID }, 'AG')) - col.dtxp = sqlUi?.value?.getDefaultLengthForDatatype(col.dt) - col.dtxs = sqlUi?.value?.getDefaultScaleForDatatype(col.dt) - return true - } - return table.columns.includes(col.column_name) - }) + const createView = async (viewType: ViewTypes, selectedViewId = null) => { + loading.value = true - const tableMeta = await $api.dbTable.create(project?.value?.id as string, { - ...table, - columns, - }) + try { + let data + switch (viewType) { + case ViewTypes.GRID: + // todo: update swagger + data = await $api.dbView.gridCreate( + meta?.value?.id as string, + { + title: view?.title, + copy_from_id: selectedViewId, + } as any, + ) + break + case ViewTypes.GALLERY: + data = await $api.dbView.galleryCreate( + meta?.value?.id as string, + { + title: view?.title, + copy_from_id: selectedViewId, + } as any, + ) + break + case ViewTypes.FORM: + data = await $api.dbView.formCreate( + meta?.value?.id as string, + { + title: view?.title, + copy_from_id: selectedViewId, + } as any, + ) + break + } + toast.success('View created successfully') + onViewCreate?.(data) + } catch (e) { + toast.error(e.message) + } - onViewCreate?.(tableMeta) + loading.value = false } const generateUniqueTitle = () => { @@ -37,5 +68,5 @@ export default (onViewCreate?: (viewMeta: any) => void) => { // table.title = `Sheet${c}` } - return { view, createView, generateUniqueTitle } + return { view, createView, generateUniqueTitle, loading } }
+ {{ $t('general.create') }} {{ type }} {{ $t('objects.view') }} +
- {{ $t('general.create') }} {{ typeAlias }} {{ $t('objects.view') }} -