Browse Source

geodata: work on mapViewStore

pull/4140/head
flisowna 2 years ago
parent
commit
6eeec60963
  1. 14
      packages/nc-gui/components/smartsheet/Map.vue
  2. 2
      packages/nc-gui/components/tabs/Smartsheet.vue
  3. 43
      packages/nc-gui/composables/useMapViewDataStore.ts

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

@ -14,11 +14,11 @@ provide(IsMapInj, ref(true))
provide(ReadonlyInj, !isUIAllowed('xcDatatableEditable')) provide(ReadonlyInj, !isUIAllowed('xcDatatableEditable'))
const reloadViewDataHook = inject(ReloadViewDataHookInj) const reloadViewDataHook = inject(ReloadViewDataHookInj)
// const meta = inject(MetaInj, ref())
const meta = inject(MetaInj, ref())
const view = inject(ActiveViewInj, ref()) const view = inject(ActiveViewInj, ref())
const { loadData, formattedData: data } = useViewData(meta, view) // const { loadData, formattedData: data } = useViewData(meta, view)
const { formattedData, loadMapData } = useMapViewStoreOrThrow()
watch(view, async (nextView) => { watch(view, async (nextView) => {
if (nextView?.type === ViewTypes.MAP) { if (nextView?.type === ViewTypes.MAP) {
@ -31,7 +31,7 @@ watch(view, async (nextView) => {
// const { isUIAllowed } = useUIPermission() // const { isUIAllowed } = useUIPermission()
onMounted(async () => { onMounted(async () => {
await loadData() await loadMapData()
// const geodata = data.value[0].row.geo.split(';') // const geodata = data.value[0].row.geo.split(';')
}) })
@ -41,10 +41,8 @@ const myMapRef = ref()
// const longitude = ref() // const longitude = ref()
const markersRef = ref() const markersRef = ref()
const { staticData } = useMapViewStoreOrThrow()
reloadViewDataHook?.on(async () => { reloadViewDataHook?.on(async () => {
alert('reloadViewDataHook for Map') loadMapData()
}) })
// function addMarker() { // function addMarker() {
@ -76,7 +74,7 @@ onMounted(async () => {
<template> <template>
<div class="flex flex-col h-full w-full"> <div class="flex flex-col h-full w-full">
{{ JSON.stringify(staticData) }} {{ JSON.stringify(formattedData) }}
<!-- <div class="flex m-4 gap-4"> <!-- <div class="flex m-4 gap-4">
<label :for="latitude">latitude</label> <label :for="latitude">latitude</label>
<input v-model="latitude" /> <input v-model="latitude" />

2
packages/nc-gui/components/tabs/Smartsheet.vue

@ -44,7 +44,7 @@ const reloadViewMetaEventHook = createEventHook<void | boolean>()
const openNewRecordFormHook = createEventHook<void>() const openNewRecordFormHook = createEventHook<void>()
useProvideKanbanViewStore(meta, activeView) useProvideKanbanViewStore(meta, activeView)
useProvideMapViewStore() useProvideMapViewStore(meta, activeView)
// todo: move to store // todo: move to store
provide(MetaInj, meta) provide(MetaInj, meta)

43
packages/nc-gui/composables/useMapViewDataStore.ts

@ -1,12 +1,41 @@
// const { project } = useProject() import type { ComputedRef, Ref } from 'vue'
import type { MapType, TableType, ViewType } from 'nocodb-sdk'
import { ref, useApi, useInjectionState } from '#imports'
const [useProvideMapViewStore, useMapViewStore] = useInjectionState(() => { const [useProvideMapViewStore, useMapViewStore] = useInjectionState(
const staticData = ['1', '2'] (
meta: Ref<TableType | MapType | undefined>,
viewMeta: Ref<ViewType | MapType | undefined> | ComputedRef<(ViewType & { id: string }) | undefined>,
) => {
const formattedData = ref<string[]>()
return { const { api } = useApi()
staticData, const { project } = useProject()
}
}) async function loadMapData() {
// if ((!project?.value?.id || !meta.value?.id || !viewMeta?.value?.id) && !isPublic.value) return
// reset formattedData & countByStack to avoid storing previous data after changing grouping field
formattedData.value = []
// alert('in loadMapData')
// debugger
const res = await api.dbViewRow.list('noco', project.value.id!, meta.value!.id!, viewMeta.value!.id!)
console.log('res in mapviewdatastore', res)
// for (const data of res.list) {
// formattedData.value = data.value
// }
formattedData.value = res.list
}
return {
formattedData,
loadMapData,
}
},
)
export { useProvideMapViewStore } export { useProvideMapViewStore }

Loading…
Cancel
Save