Browse Source

geodata: mapmetadata in mapview

pull/4140/head
flisowna 2 years ago
parent
commit
df11ad896c
  1. 3
      packages/nc-gui/components/smartsheet/Kanban.vue
  2. 24
      packages/nc-gui/components/smartsheet/Map.vue
  3. 64
      packages/nc-gui/composables/useMapViewDataStore.ts
  4. 20
      packages/nc-gui/composables/useViewData.ts
  5. 787
      packages/nocodb-sdk/src/lib/Api.ts

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

@ -12,6 +12,7 @@ import {
IsPublicInj,
MetaInj,
OpenNewRecordFormHookInj,
ReadonlyInj,
inject,
onBeforeMount,
onBeforeUnmount,
@ -84,6 +85,8 @@ provide(IsGridInj, ref(false))
provide(IsKanbanInj, ref(true))
provide(ReadonlyInj, !isUIAllowed('xcDatatableEditable'))
const hasEditPermission = $computed(() => isUIAllowed('xcDatatableEditable'))
const fields = inject(FieldsInj, ref([]))

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

@ -7,23 +7,28 @@ import { IsFormInj, IsGalleryInj, IsGridInj, IsMapInj, ReadonlyInj, onMounted, p
const { isUIAllowed } = useUIPermission()
provide(IsFormInj, ref(false))
// provide(IsFormInj, ref(false))
provide(IsGalleryInj, ref(false))
provide(IsGridInj, ref(false))
provide(IsMapInj, ref(true))
provide(ReadonlyInj, !isUIAllowed('xcDatatableEditable'))
const reloadViewDataHook = inject(ReloadViewDataHookInj)
// const meta = inject(MetaInj, ref())
// const view = inject(ActiveViewInj, ref())
const view = inject(ActiveViewInj, ref())
const meta = inject(MetaInj, ref())
const { formattedData, loadMapData, mapData } = useMapViewStoreOrThrow()
const reloadViewDataHook = inject(ReloadViewDataHookInj)
// const reloadViewMetaHook = inject(ReloadViewMetaHookInj)
const { formattedData, loadMapData, loadMapMeta, mapMetaData } = useMapViewStoreOrThrow()
// const { loadData, formattedData: data } = useViewData(meta, view)
// const { sharedView, sorts, nestedFilters } = useSharedView()
const {
showSystemFields,
// sortedAndFilteredFields,
@ -58,8 +63,10 @@ const markersRef = ref<L.MarkerClusterGroup | undefined>()
// const { isUIAllowed } = useUIPermission()
onMounted(async () => {
onBeforeMount(async () => {
await loadMapData()
await loadMapMeta()
console.log('on mapview mapMetaData', mapMetaData)
// const geodata = data.value[0].row.geo.split(';')
})
@ -71,10 +78,15 @@ onMounted(async () => {
// ),
// )
const { fk_geo_data_col_id } = mapMetaData.value
console.log('fk_geo_data_col_id', fk_geo_data_col_id)
watch(formattedData, () => {
markersRef.value?.clearLayers()
console.log('mapData', mapData?.value?.fk_geo_data_col_id)
console.log('mapMetaData', mapMetaData?.value?.fk_geo_data_col_id)
formattedData.value?.forEach((row) => {
console.log('fk_geo_data_col_id', fk_geo_data_col_id)
// const [lat, long] =
console.log('meta', meta?.value?.columns)
console.log('row', row)
@ -125,7 +137,7 @@ onMounted(async () => {
<template>
<div class="flex flex-col h-full w-full">
{{ JSON.stringify(mapData1) }}
{{ JSON.stringify(mapMetaData) }}
<!-- {{ JSON.stringify(selected) }} -->
<!-- {{ JSON.stringify(meta?.columns) }} -->
<!-- <div class="flex m-4 gap-4">

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

@ -1,6 +1,6 @@
import type { ComputedRef, Ref } from 'vue'
import type { ColumnType, MapType, TableType, ViewType } from 'nocodb-sdk'
import { ref, useApi, useInjectionState } from '#imports'
import type { MapType, TableType, ViewType } from 'nocodb-sdk'
import { ref, useInjectionState } from '#imports'
import type { Row } from '~/lib'
const [useProvideMapViewStore, useMapViewStore] = useInjectionState(
@ -10,58 +10,58 @@ const [useProvideMapViewStore, useMapViewStore] = useInjectionState(
) => {
const formattedData = ref<Row[]>()
const { api } = useApi()
const { project } = useProject()
// const { api } = useApi()
// const { project } = useProject()
// const { $e, $api } = useNuxtApp()
const { $api } = useNuxtApp()
const mapMetaData = ref<MapType>({})
const geoDataField = ref<string>('')
// const geoDataField = ref<string>('')
const geoDataFieldColumn = ref<ColumnType | undefined>()
// const geoDataFieldColumn = ref<ColumnType | undefined>()
async function loadMapData() {
async function loadMapMeta() {
if (!viewMeta?.value?.id || !meta?.value?.columns) return
mapMetaData.value = await $api.dbView.mapRead(viewMeta.value.id)
}
async function loadMapData() {
// if (!viewMeta?.value?.id || !meta?.value?.columns) return
formattedData.value = []
// formattedData.value = []
const res = await api.dbViewRow.list(
'noco',
project.value.id!,
meta.value!.id!,
viewMeta.value!.id!,
geoDataFieldColumn!.value!.id,
)
// const res = await api.dbViewRow.list('noco', project.value.id!, meta.value!.id!, viewMeta.value!.id!)
geoDataFieldColumn.value =
(meta.value.columns as ColumnType[]).filter((f) => f.id === mapMetaData.value.fk_geo_data_col_id)[0] || {}
// // geoDataFieldColumn.value =
// // (meta.value.columns as ColumnType[]).filter((f) => f.id === mapMetaData.value.fk_geo_data_col_id)[0] || {}
geoDataField.value = geoDataFieldColumn.value.title!
// geoDataField.value = geoDataFieldColumn!.value!.title!
const { fk_geo_data_col_id, meta: stack_meta } = mapMetaData.value
// // const { fk_geo_data_col_id, meta: geo_meta } = mapMetaData.value
const stackMetaObj: any.value = stack_meta ? JSON.parse(stack_meta as string) : {}
// // const geoMetaObj: any.value = geo_meta ? JSON.parse(geo_meta as string) : {}
console.log('column geodata', stackMetaObj.value[fk_geo_data_col_id])
// if ((!project?.value?.id || !meta.value?.id || !viewMeta?.value?.id) && !isPublic.value) return
// // console.log('column geodata', stackMetaObj.value[fk_geo_data_col_id])
// // 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
// // reset formattedData & countByStack to avoid storing previous data after changing grouping field
// alert('in loadMapData')
// debugger
// // alert('in loadMapData')
// // debugger
console.log('res in mapviewdatastore', res)
// console.log('res in mapviewdatastore', res)
// for (const data of res.list) {
// formattedData.value = data.value
// }
formattedData.value = res.list
// // for (const data of res.list) {
// // formattedData.value = data.value
// // }
// formattedData.value = res.list
}
return {
formattedData,
loadMapData,
loadMapMeta,
mapMetaData,
}
},

20
packages/nc-gui/composables/useViewData.ts

@ -1,5 +1,5 @@
import { ViewTypes } from 'nocodb-sdk'
import type { Api, ColumnType, FormType, GalleryType, MapType, PaginatedType, TableType, ViewType } from 'nocodb-sdk'
import type { Api, ColumnType, FormType, GalleryType, PaginatedType, TableType, ViewType } from 'nocodb-sdk'
import type { ComputedRef, Ref } from 'vue'
import {
IsPublicInj,
@ -202,6 +202,7 @@ export function useViewData(
async function insertRow(
currentRow: Row,
_rowIndex = formattedData.value?.length,
ltarState: Record<string, any> = {},
{ metaValue = meta.value, viewMetaValue = viewMeta.value }: { metaValue?: TableType; viewMetaValue?: ViewType } = {},
) {
@ -265,24 +266,15 @@ export function useViewData(
)
// audit
$api.utils.auditRowUpdate(id, {
fk_model_id: metaValue?.id as string,
fk_model_id: meta.value?.id as string,
column_name: property,
row_id: id,
value: getHTMLEncodedText(toUpdate.row[property]),
prev_value: getHTMLEncodedText(toUpdate.oldRow[property]),
})
/** update row data(to sync formula and other related columns)
* update only formula, rollup and auto updated datetime columns data to avoid overwriting any changes made by user
*/
Object.assign(
toUpdate.row,
metaValue!.columns!.reduce<Record<string, any>>((acc: Record<string, any>, col: ColumnType) => {
if (col.uidt === UITypes.Formula || col.uidt === UITypes.Rollup || col.au || col.cdf?.includes(' on update '))
acc[col.title!] = updatedRowData[col.title!]
return acc
}, {} as Record<string, any>),
)
/** update row data(to sync formula and other related columns) */
Object.assign(toUpdate.row, updatedRowData)
Object.assign(toUpdate.oldRow, updatedRowData)
} catch (e: any) {
message.error(`${t('msg.error.rowUpdateFailed')} ${await extractSdkResponseErrorMsg(e)}`)
@ -301,7 +293,7 @@ export function useViewData(
await until(() => !(row.rowMeta?.new && row.rowMeta?.saving)).toMatch((v) => v)
if (row.rowMeta.new) {
return await insertRow(row, ltarState, args)
return await insertRow(row, formattedData.value.indexOf(row), ltarState, args)
} else {
await updateRowProperty(row, property!, args)
}

787
packages/nocodb-sdk/src/lib/Api.ts

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save