Skip to content

Commit

Permalink
Add metaType property
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Jun 3, 2024
1 parent dcdc1e5 commit 14deae0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/components/AutoForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
</template>
<script setup lang="ts">
import type { ApiRequest, ResponseStatus, ModalProvider, InputProp } from '@/types'
import type { MetadataType, ApiRequest, ResponseStatus, ModalProvider, InputProp } from '@/types'
import { computed, provide, ref, getCurrentInstance, watch, onMounted, onUnmounted, nextTick } from 'vue'
import { ApiResult, HttpMethods, humanize, map, omitEmpty } from '@servicestack/client'
import { useClient } from '@/use/client'
Expand All @@ -111,6 +111,7 @@ const props = withDefaults(defineProps<{
showLoading?: boolean
jsconfig?: string
formStyle?: "slideOver" | "card"
metaType?: MetadataType
configureField?: (field:InputProp) => void
configureFormLayout?: (field:InputProp[]) => void
Expand Down Expand Up @@ -190,11 +191,11 @@ const subHeadingClass = computed(() => props.subHeadingClass || form.subHeadingC
const buttonsClass = computed(() => typeof props.buttonsClass == 'string' ? props.buttonsClass : form.buttonsClass)
const typeName = computed(() => props.type ? getTypeName(props.type) : props.modelValue?.['getTypeName'] ? props.modelValue.getTypeName() : null)
const metaType = computed(() => typeOf(typeName.value))
const metaType = computed(() => props.metaType ?? typeOf(typeName.value))
const resolveModel = () => props.modelValue || newDto()
const model = ref(resolveModel())
const loading = computed(() => client.loading.value)
const title = computed(() => props.heading != null ? props.heading : (typeOf(typeName.value)?.description || humanize(typeName.value)))
const title = computed(() => props.heading != null ? props.heading : (metaType.value?.description || humanize(typeName.value)))
function newDto() {
return typeof props.type == 'string' ? createDto(props.type) : props.type ? new props.type() : props.modelValue
Expand Down
5 changes: 3 additions & 2 deletions src/components/AutoFormFields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</template>
<script setup lang="ts">
import type { InputInfo, ApiRequest, ResponseStatus, InputProp } from '@/types'
import type { MetadataType, InputInfo, ApiRequest, ResponseStatus, InputProp } from '@/types'
import { computed, getCurrentInstance } from 'vue'
import { typeForInput, typeProperties, useMetadata } from '@/use/metadata'
import { getTypeName } from '@/use/utils'
Expand All @@ -29,6 +29,7 @@ import { mapGet } from "@servicestack/client"
const props = withDefaults(defineProps<{
modelValue: ApiRequest
type?: string
metaType?: MetadataType
api: {error?:ResponseStatus}|null
formLayout?: InputInfo[]
configureField?: (field:InputProp) => void
Expand Down Expand Up @@ -68,7 +69,7 @@ const { metadataApi, apiOf, typeOf, typeOfRef, createFormLayout, Crud } = useMet
const typeName = computed(() => props.type || getTypeName(props.modelValue))
const type = computed(() => typeOf(typeName.value))
const type = computed(() => props.metaType ?? typeOf(typeName.value))
const dataModelType = computed(() =>
typeOfRef(metadataApi.value?.operations.find(x => x.request.name == typeName.value)?.dataModel) || type.value)
Expand Down

0 comments on commit 14deae0

Please sign in to comment.