Browse Source

feat(nc-gui): allow prefill shared form setup

pull/7786/head
Ramesh Mane 10 months ago
parent
commit
2973185708
  1. 70
      packages/nc-gui/composables/useSharedFormViewStore.ts
  2. 3
      packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue
  3. 3
      packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue

70
packages/nc-gui/composables/useSharedFormViewStore.ts

@ -49,8 +49,15 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share
const sharedFormView = ref<FormType>()
const meta = ref<TableType>()
const columns =
ref<(ColumnType & { required?: BoolType; show?: BoolType; label?: StringOrNullType; enable_scanner?: BoolType })[]>()
const columns = ref<
(ColumnType & {
required?: BoolType
show?: BoolType
label?: StringOrNullType
enable_scanner?: BoolType
read_only?: boolean
})[]
>()
const sharedViewMeta = ref<SharedViewMeta>({})
const formResetHook = createEventHook<void>()
@ -82,14 +89,9 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share
const fieldRequired = (fieldName = 'This field') =>
helpers.withMessage(t('msg.error.fieldRequired', { value: fieldName }), required)
const formColumns = computed(() => {
const filterdFormColumns = columns.value?.filter((c) => c.show).filter((col) => !isVirtualCol(col) || isLinksOrLTAR(col.uidt))
// if (Object.keys(route.query).length && sharedViewMeta.value.preFilledMode !== PreFilledMode.Disabled) {
// }
return filterdFormColumns
})
const formColumns = computed(() =>
columns.value?.filter((c) => c.show).filter((col) => !isVirtualCol(col) || isLinksOrLTAR(col.uidt)),
)
const loadSharedView = async () => {
passwordError.value = null
@ -126,6 +128,8 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share
await setMeta(viewMeta.model)
handlePreFillForm()
// if base is not defined then set it with an object containing source
if (!base.value?.sources)
baseStore.setProject({
@ -245,6 +249,52 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share
v$.value?.$reset()
}
function handlePreFillForm() {
// http://localhost:3000/#/nc/form/070dbc84-f3ca-43a3-808a-3547a873933f?Multiselect=a,b
if (Object.keys(route.query).length && sharedViewMeta.value.preFilledMode !== PreFilledMode.Disabled) {
console.log('router', route.query)
columns.value = columns.value?.map((c) => {
if ((c.label || c.title) && route.query?.[c.label!] === undefined && route.query?.[c.title!] === undefined) {
return c
}
switch (sharedViewMeta.value.preFilledMode) {
case PreFilledMode.Hidden: {
c.show = false
}
case PreFilledMode.Locked: {
c.read_only = true
}
}
switch (c.uidt) {
case UITypes.SingleSelect:
case UITypes.MultiSelect: {
const allValues = (c.dtxp as string)?.split(',').map((o) => o?.replace(/^['"]|['"]$/g, ''))
let options = ((route.query?.[c.label!] || route.query?.[c.title!]) as string)?.split(',').filter((op) => {
console.log('options', op, allValues, allValues.includes(op))
if (allValues.includes(op)) return true
})
console.log('c', options, c)
if (options.length) {
formState.value[c.title!] = c.uidt === UITypes.SingleSelect ? options[0] : options.join(',')
}
break
}
case UITypes.User: {
break
}
default: {
formState.value[c.title!] = route.query?.[c.label!] || route.query?.[c.title!]
}
}
return c
})
console.log('column', columns.value)
}
}
/** reset form if show_blank_form is true */
watch(submitted, (nextVal) => {
if (nextVal && sharedFormView.value?.show_blank_form) {

3
packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue

@ -200,7 +200,8 @@ const onDecode = async (scannedCodeValue: string) => {
{ 'layout-list': parseProp(field?.meta)?.isList },
]"
:column="field"
edit-enabled
:edit-enabled="!field?.read_only"
:read-only="field?.read_only"
/>
<a-button
v-if="field.enable_scanner"

3
packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue

@ -297,7 +297,8 @@ onMounted(() => {
:class="parseProp(field?.meta)?.isList ? 'layout-list' : ''"
:data-testid="`nc-survey-form__input-${field.title.replaceAll(' ', '')}`"
:column="field"
edit-enabled
:edit-enabled="!field?.read_only"
:read-only="field?.read_only"
/>
<div class="flex flex-col gap-2 text-slate-500 dark:text-slate-300 text-[0.75rem] my-2 px-1">

Loading…
Cancel
Save