Browse Source

geodata: extract out lat/long->joined string logic

pull/4749/head
Daniel Spaude 2 years ago
parent
commit
d5466bba84
No known key found for this signature in database
GPG Key ID: 654A3D1FA4F35FFE
  1. 4
      packages/nc-gui/components/cell/GeoData.vue
  2. 3
      packages/nc-gui/components/smartsheet/Map.vue
  3. 3
      packages/nc-gui/utils/geoDataUtils.ts

4
packages/nc-gui/components/cell/GeoData.vue

@ -1,6 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { GeoLocationType } from 'nocodb-sdk' import type { GeoLocationType } from 'nocodb-sdk'
import { useVModel } from '#imports' import { useVModel } from '#imports'
import { latLongToJoinedString } from '~~/utils/geoDataUtils'
interface Props { interface Props {
modelValue?: string | null modelValue?: string | null
@ -33,12 +34,11 @@ const formState = reactive({
}) })
const handleFinish = () => { const handleFinish = () => {
vModel.value = `${formState.latitude};${formState.longitude}` vModel.value = latLongToJoinedString(parseFloat(formState.latitude), parseFloat(formState.longitude))
isExpanded = false isExpanded = false
} }
const clear = () => { const clear = () => {
isExpanded = false isExpanded = false
formState.latitude = latitude formState.latitude = latitude

3
packages/nc-gui/components/smartsheet/Map.vue

@ -8,6 +8,7 @@ import { ViewTypes } from 'nocodb-sdk'
import { IsGalleryInj, IsGridInj, IsMapInj, OpenNewRecordFormHookInj, onMounted, provide, ref } from '#imports' import { IsGalleryInj, IsGridInj, IsMapInj, OpenNewRecordFormHookInj, onMounted, provide, ref } from '#imports'
import type { Row as RowType } from '~/lib' import type { Row as RowType } from '~/lib'
import { latLongToJoinedString } from '~~/utils/geoDataUtils'
provide(IsGalleryInj, ref(false)) provide(IsGalleryInj, ref(false))
provide(IsGridInj, ref(false)) provide(IsGridInj, ref(false))
@ -145,7 +146,7 @@ onMounted(async () => {
const lng = e.latlng.lng const lng = e.latlng.lng
const newRow = await addEmptyRow() const newRow = await addEmptyRow()
if (geoDataFieldColumn.value?.title) { if (geoDataFieldColumn.value?.title) {
newRow.row[geoDataFieldColumn.value.title] = `${lat.toFixed(7)};${lng.toFixed(7)}` newRow.row[geoDataFieldColumn.value.title] = latLongToJoinedString(lat, lng)
} }
expandForm(newRow, [lat, lng]) expandForm(newRow, [lat, lng])
}) })

3
packages/nc-gui/utils/geoDataUtils.ts

@ -0,0 +1,3 @@
const latLongToJoinedString = (lat: number, long: number) => `${lat.toFixed(7)};${long.toFixed(7)}`
export { latLongToJoinedString }
Loading…
Cancel
Save