Browse Source

WIP geodata: add marker by tap holding in a map view - passing and saving in expanded form works

pull/4723/head
flisowna 2 years ago
parent
commit
1c5139f101
  1. 21
      packages/nc-gui/components/cell/GeoData.vue
  2. 18
      packages/nc-gui/components/smartsheet/Cell.vue
  3. 23
      packages/nc-gui/components/smartsheet/Map.vue
  4. 5
      packages/nc-gui/components/smartsheet/expanded-form/index.vue

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

@ -1,15 +1,9 @@
<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 { InitialGeoPositionData } from '../smartsheet/expanded-form/index.vue';
interface Props { interface Props {
modelValue?: string | null modelValue?: string | null
defaultValues?: {
lat?: number | null
long?: number | null
} | null
// defaultGeoPosition?: InitialGeoPositionData
} }
interface Emits { interface Emits {
@ -22,24 +16,14 @@ const emits = defineEmits<Emits>()
const vModel = useVModel(props, 'modelValue', emits) const vModel = useVModel(props, 'modelValue', emits)
// const defaultGeoPosition = useVModel(props, 'defaultGeoPosition')
// let error = $ref<string | undefined>()
let isExpanded = $ref(false) let isExpanded = $ref(false)
let isLoading = $ref(false) let isLoading = $ref(false)
// const shouldSetDefaultGeoPosition = defaultGeoPosition.value?.geoColId === const [latitude, longitude] = (vModel.value || '').split(';')
const [latitude, longitude] = vModel.value
? (vModel.value || '').split(';')
: [props?.defaultValues?.lat || '', props?.defaultValues?.long || '']
const latLongStr = computed(() => { const latLongStr = computed(() => {
const [latitude, longitude] = vModel.value const [latitude, longitude] = (vModel.value || '').split(';')
? (vModel.value || '').split(';')
: [props?.defaultValues?.lat || '', props?.defaultValues?.long || '']
return latitude && longitude ? `${latitude}; ${longitude}` : 'Set location' return latitude && longitude ? `${latitude}; ${longitude}` : 'Set location'
}) })
@ -54,7 +38,6 @@ const handleFinish = () => {
} }
const clear = () => { const clear = () => {
// error = undefined
isExpanded = false isExpanded = false

18
packages/nc-gui/components/smartsheet/Cell.vue

@ -104,7 +104,9 @@ const syncValue = useDebounceFn(
) )
const vModel = computed({ const vModel = computed({
get: () => props.modelValue, get: () => {
return props.modelValue
},
set: (val) => { set: (val) => {
if (val !== props.modelValue) { if (val !== props.modelValue) {
currentRow.value.rowMeta.changed = true currentRow.value.rowMeta.changed = true
@ -130,18 +132,6 @@ const syncAndNavigate = (dir: NavigateDir, e: KeyboardEvent) => {
if (!isForm.value) e.stopImmediatePropagation() if (!isForm.value) e.stopImmediatePropagation()
} }
// TODO: probably wanna do this more generic / not column-type specific
const defaultValues = computed(() =>
column.value.id === props.defaultGeoPosition?.geoColId
? {
lat: props.defaultGeoPosition?.lat,
long: props.defaultGeoPosition?.long,
}
: null,
)
console.log('column.value in cell', column.value)
</script> </script>
<template> <template>
@ -156,7 +146,7 @@ console.log('column.value in cell', column.value)
> >
<template v-if="column"> <template v-if="column">
<LazyCellTextArea v-if="isTextArea(column)" v-model="vModel" /> <LazyCellTextArea v-if="isTextArea(column)" v-model="vModel" />
<LazyCellGeoData v-else-if="isGeoData(column)" v-model="vModel" :default-values="defaultValues" /> <LazyCellGeoData v-else-if="isGeoData(column)" v-model="vModel" />
<LazyCellCheckbox v-else-if="isBoolean(column, abstractType)" v-model="vModel" /> <LazyCellCheckbox v-else-if="isBoolean(column, abstractType)" v-model="vModel" />
<LazyCellAttachment v-else-if="isAttachment(column)" v-model="vModel" :row-index="props.rowIndex" /> <LazyCellAttachment v-else-if="isAttachment(column)" v-model="vModel" :row-index="props.rowIndex" />
<LazyCellSingleSelect v-else-if="isSingleSelect(column)" v-model="vModel" :row-index="props.rowIndex" /> <LazyCellSingleSelect v-else-if="isSingleSelect(column)" v-model="vModel" :row-index="props.rowIndex" />

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

@ -44,9 +44,6 @@ const getMapCenterLocalStorageKey = (viewId: string) => `mapView.center.${viewId
const expandForm = (row: RowType, state?: Record<string, any>, clickedLatLongForNewRow?: [number, number]) => { const expandForm = (row: RowType, state?: Record<string, any>, clickedLatLongForNewRow?: [number, number]) => {
const rowId = extractPkFromRow(row.row, meta.value!.columns!) const rowId = extractPkFromRow(row.row, meta.value!.columns!)
console.log('state in expandForm', state)
console.log('row in expandForm', row)
console.log('clickedLatLongForNewRow', clickedLatLongForNewRow)
if (rowId) { if (rowId) {
router.push({ router.push({
query: { query: {
@ -90,17 +87,13 @@ const addMarker = (lat: number, long: number, row: RowType) => {
throw new Error('Map is null') throw new Error('Map is null')
} }
const newMarker = L.marker([lat, long]).on('click', () => { const newMarker = L.marker([lat, long]).on('click', () => {
console.log('OnNewMarker')
expandForm(row) expandForm(row)
}) })
console.log('onaddMarker', lat, long)
markersClusterGroupRef.value?.addLayer(newMarker) markersClusterGroupRef.value?.addLayer(newMarker)
} }
const resetZoomAndCenterBasedOnLocalStorage = () => { const resetZoomAndCenterBasedOnLocalStorage = () => {
if (mapMetaData?.value?.fk_view_id == null) { if (mapMetaData?.value?.fk_view_id == null) {
console.error('Early leaving of resetZoomAndCenterBasedOnLocalStorage because "mapMetaData?.value?.fk_view_id == null"')
console.log('mapMetaData?.value', mapMetaData?.value)
return return
} }
const initialZoomLevel = parseInt(localStorage.getItem(getMapZoomLocalStorageKey(mapMetaData.value.fk_view_id)) || '10') const initialZoomLevel = parseInt(localStorage.getItem(getMapZoomLocalStorageKey(mapMetaData.value.fk_view_id)) || '10')
@ -147,22 +140,14 @@ onMounted(async () => {
} }
}) })
// myMap.on('contextmenu', async function (e) {
// console.log('onContext')
// const newRow = await addEmptyRow()
// const lat = e.latlng.lat
// const lng = e.latlng.lng
// addMarker(lat, lng, newRow)
// expandForm(newRow)
// submitForm()
// })
myMap.on('contextmenu', async function (e) { myMap.on('contextmenu', async function (e) {
const newRow = await addEmptyRow()
const lat = e.latlng.lat const lat = e.latlng.lat
const lng = e.latlng.lng const lng = e.latlng.lng
const newRow = await addEmptyRow()
if (geoDataFieldColumn.value?.title) {
newRow.row[geoDataFieldColumn.value.title] = `${lat.toFixed(7)};${lng.toFixed(7)}`
}
addMarker(lat, lng, newRow) addMarker(lat, lng, newRow)
console.log('oncontextClick', lat, lng, newRow)
expandForm(newRow, undefined, [lat, lng]) expandForm(newRow, undefined, [lat, lng])
}) })
}) })

5
packages/nc-gui/components/smartsheet/expanded-form/index.vue

@ -6,7 +6,6 @@ import {
FieldsInj, FieldsInj,
IsFormInj, IsFormInj,
IsKanbanInj, IsKanbanInj,
IsMapInj,
MetaInj, MetaInj,
ReloadRowDataHookInj, ReloadRowDataHookInj,
computedInject, computedInject,
@ -52,8 +51,6 @@ const state = toRef(props, 'state')
const meta = toRef(props, 'meta') const meta = toRef(props, 'meta')
const newRow = row.value.row.geoColId
// const initialGeoPositionData = toRef(props, 'initialGeoPositionData') // const initialGeoPositionData = toRef(props, 'initialGeoPositionData')
const initialGeoPositionData = ref(props.initialGeoPositionData) const initialGeoPositionData = ref(props.initialGeoPositionData)
@ -68,8 +65,6 @@ const fields = computedInject(FieldsInj, (_fields) => {
const isKanban = inject(IsKanbanInj, ref(false)) const isKanban = inject(IsKanbanInj, ref(false))
const isMap = inject(IsMapInj, ref(false))
provide(MetaInj, meta) provide(MetaInj, meta)
const { commentsDrawer, changedColumns, state: rowState, isNew, loadRow } = useProvideExpandedFormStore(meta, row) const { commentsDrawer, changedColumns, state: rowState, isNew, loadRow } = useProvideExpandedFormStore(meta, row)

Loading…
Cancel
Save