Browse Source

Merge branch 'geodata-prototyping-restart' of github.com:humannocode/nocodb into geodata-prototyping-restart

pull/4749/head
flisowna 2 years ago
parent
commit
7f143fa0f5
  1. 2
      packages/nc-gui/components/smartsheet/Map.vue
  2. 3
      packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue
  3. 3
      packages/nc-gui/components/smartsheet/toolbar/MappedBy.vue
  4. 4
      packages/nc-gui/composables/useMapViewDataStore.ts
  5. 14
      packages/nc-gui/composables/useViewColumns.ts
  6. 1
      packages/nc-gui/lib/enums.ts
  7. 1
      packages/nc-gui/lib/types.ts
  8. 8
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/getAst.ts
  9. 6
      packages/nocodb/src/lib/meta/api/publicApis/publicDataExportApis.ts
  10. 1
      packages/nocodb/src/lib/meta/api/viewApis.ts
  11. 32
      packages/nocodb/src/lib/models/MapView.ts
  12. 25
      packages/nocodb/src/lib/models/View.ts

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

@ -189,7 +189,6 @@ watch([formattedData, mapMetaData, markersClusterGroupRef], () => {
addMarker(lat, long, row) addMarker(lat, long, row)
}) })
// syncCount()
}) })
watch(view, async (nextView) => { watch(view, async (nextView) => {
@ -201,7 +200,6 @@ watch(view, async (nextView) => {
const count = computed(() => paginationData.value.totalRows) const count = computed(() => paginationData.value.totalRows)
// syncCount()
</script> </script>
<template> <template>

3
packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue

@ -55,6 +55,8 @@ const { eventBus } = useSmartsheetStoreOrThrow()
eventBus.on((event) => { eventBus.on((event) => {
if (event === SmartsheetStoreEvents.FIELD_RELOAD) { if (event === SmartsheetStoreEvents.FIELD_RELOAD) {
loadViewColumns() loadViewColumns()
} else if (event === SmartsheetStoreEvents.MAPPED_BY_COLUMN_CHANGE) {
loadViewColumns()
} }
}) })
@ -204,6 +206,7 @@ useMenuCloseOnEsc(open)
v-model:checked="field.show" v-model:checked="field.show"
v-e="['a:fields:show-hide']" v-e="['a:fields:show-hide']"
class="shrink" class="shrink"
:disabled="field.isViewEssentialField"
@change="saveOrUpdate(field, index)" @change="saveOrUpdate(field, index)"
> >
<div class="flex items-center"> <div class="flex items-center">

3
packages/nc-gui/components/smartsheet/toolbar/MappedBy.vue

@ -14,6 +14,8 @@ import {
watch, watch,
} from '#imports' } from '#imports'
const { eventBus } = useSmartsheetStoreOrThrow()
const meta = inject(MetaInj, ref()) const meta = inject(MetaInj, ref())
const activeView = inject(ActiveViewInj, ref()) const activeView = inject(ActiveViewInj, ref())
@ -48,6 +50,7 @@ const geoDataMappingFieldColumnId = computed({
await loadMapMeta() await loadMapMeta()
await loadMapData() await loadMapData()
;(activeView.value?.view as MapType).fk_geo_data_col_id = val ;(activeView.value?.view as MapType).fk_geo_data_col_id = val
eventBus.emit(SmartsheetStoreEvents.MAPPED_BY_COLUMN_CHANGE)
} }
}, },
}) })

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

@ -61,17 +61,13 @@ const [useProvideMapViewStore, useMapViewStore] = useInjectionState(
})) }))
async function syncCount() { async function syncCount() {
// const shouldUpdateRowsCounter = !isPublic.value
// if (shouldUpdateRowsCounter) {
const { count } = await $api.dbViewRow.count( const { count } = await $api.dbViewRow.count(
NOCO, NOCO,
project?.value?.title as string, project?.value?.title as string,
meta?.value?.id as string, meta?.value?.id as string,
viewMeta?.value?.id as string, viewMeta?.value?.id as string,
) )
console.log('in Sync')
paginationData.value.totalRows = count paginationData.value.totalRows = count
// }
} }
async function loadMapMeta() { async function loadMapMeta() {

14
packages/nc-gui/composables/useViewColumns.ts

@ -1,4 +1,4 @@
import { isSystemColumn } from 'nocodb-sdk' import { isSystemColumn, MapType, ViewTypes } from 'nocodb-sdk'
import type { ColumnType, TableType, ViewType } from 'nocodb-sdk' import type { ColumnType, TableType, ViewType } from 'nocodb-sdk'
import type { ComputedRef, Ref } from 'vue' import type { ComputedRef, Ref } from 'vue'
import { IsPublicInj, computed, inject, ref, useNuxtApp, useProject, useUIPermission, watch } from '#imports' import { IsPublicInj, computed, inject, ref, useNuxtApp, useProject, useUIPermission, watch } from '#imports'
@ -25,6 +25,13 @@ export function useViewColumns(
() => isPublic.value || !isUIAllowed('hideAllColumns') || !isUIAllowed('showAllColumns') || isSharedBase.value, () => isPublic.value || !isUIAllowed('hideAllColumns') || !isUIAllowed('showAllColumns') || isSharedBase.value,
) )
const isColumnViewEssential = (column: ColumnType) => {
// TODO: consider at some point ti delegate this via a cleaner design pattern to view specific check logic
// which could be inside of a view specific helper class (and generalized via an interface)
// (on the other hand, the logic complexity is still very low atm - might be overkill)
return view.value?.type === ViewTypes.MAP && (view.value?.view as MapType)?.fk_geo_data_col_id === column.id
}
const metaColumnById = computed<Record<string, ColumnType>>(() => { const metaColumnById = computed<Record<string, ColumnType>>(() => {
if (!meta.value?.columns) return {} if (!meta.value?.columns) return {}
@ -38,6 +45,7 @@ export function useViewColumns(
}) })
const loadViewColumns = async () => { const loadViewColumns = async () => {
if (!meta || !view) return if (!meta || !view) return
let order = 1 let order = 1
@ -62,8 +70,10 @@ export function useViewColumns(
title: column.title, title: column.title,
fk_column_id: column.id, fk_column_id: column.id,
...currentColumnField, ...currentColumnField,
show: currentColumnField.show || isColumnViewEssential(currentColumnField),
order: currentColumnField.order || order++, order: currentColumnField.order || order++,
system: isSystemColumn(metaColumnById?.value?.[currentColumnField.fk_column_id!]), system: isSystemColumn(metaColumnById?.value?.[currentColumnField.fk_column_id!]),
isViewEssentialField: isColumnViewEssential(column),
} }
}) })
.sort((a: Field, b: Field) => a.order - b.order) .sort((a: Field, b: Field) => a.order - b.order)
@ -98,7 +108,7 @@ export function useViewColumns(
if (isLocalMode.value) { if (isLocalMode.value) {
fields.value = fields.value?.map((field: Field) => ({ fields.value = fields.value?.map((field: Field) => ({
...field, ...field,
show: false, show: !!field.isViewEssentialField,
})) }))
reloadData?.() reloadData?.()
return return

1
packages/nc-gui/lib/enums.ts

@ -88,6 +88,7 @@ export enum SmartsheetStoreEvents {
DATA_RELOAD = 'data-reload', DATA_RELOAD = 'data-reload',
FIELD_RELOAD = 'field-reload', FIELD_RELOAD = 'field-reload',
FIELD_ADD = 'field-add', FIELD_ADD = 'field-add',
MAPPED_BY_COLUMN_CHANGE = 'mapped-by-column-change',
} }
export enum DataSourcesSubTab { export enum DataSourcesSubTab {

1
packages/nc-gui/lib/types.ts

@ -32,6 +32,7 @@ export interface Field {
title: string title: string
fk_column_id?: string fk_column_id?: string
system?: boolean system?: boolean
isViewEssentialField?: boolean
} }
export type Roles<T extends Role | ProjectRole = Role | ProjectRole> = Record<T | string, boolean> export type Roles<T extends Role | ProjectRole = Role | ProjectRole> = Record<T | string, boolean>

8
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/getAst.ts

@ -81,13 +81,13 @@ const getAst = async ({
...(await obj), ...(await obj),
[col.title]: [col.title]:
allowedCols && (!includePkByDefault || !col.pk) allowedCols && (!includePkByDefault || !col.pk)
? allowedCols[col.id] && ? (allowedCols[col.id] &&
(!isSystemColumn(col) || view.show_system_fields) && (!isSystemColumn(col) || view.show_system_fields) &&
(!fields?.length || fields.includes(col.title)) && (!fields?.length || fields.includes(col.title)) &&
value value)
: fields?.length : (fields?.length
? fields.includes(col.title) && value ? fields.includes(col.title) && value
: value, : value),
}; };
}, Promise.resolve({})); }, Promise.resolve({}));
}; };

6
packages/nocodb/src/lib/meta/api/publicApis/publicDataExportApis.ts

@ -19,7 +19,8 @@ async function exportExcel(req: Request, res: Response) {
if ( if (
view.type !== ViewTypes.GRID && view.type !== ViewTypes.GRID &&
view.type !== ViewTypes.KANBAN && view.type !== ViewTypes.KANBAN &&
view.type !== ViewTypes.GALLERY view.type !== ViewTypes.GALLERY &&
view.type !== ViewTypes.MAP
) )
NcError.notFound('Not found'); NcError.notFound('Not found');
@ -67,7 +68,8 @@ async function exportCsv(req: Request, res: Response) {
if ( if (
view.type !== ViewTypes.GRID && view.type !== ViewTypes.GRID &&
view.type !== ViewTypes.KANBAN && view.type !== ViewTypes.KANBAN &&
view.type !== ViewTypes.GALLERY view.type !== ViewTypes.GALLERY &&
view.type !== ViewTypes.MAP
) )
NcError.notFound('Not found'); NcError.notFound('Not found');

1
packages/nocodb/src/lib/meta/api/viewApis.ts

@ -89,6 +89,7 @@ async function showAllColumns(req: Request<any, any>, res) {
} }
async function hideAllColumns(req: Request<any, any>, res) { async function hideAllColumns(req: Request<any, any>, res) {
res.json( res.json(
await View.hideAllColumns( await View.hideAllColumns(
req.params.viewId, req.params.viewId,

32
packages/nocodb/src/lib/models/MapView.ts

@ -3,6 +3,7 @@ import { MapType } from 'nocodb-sdk';
import { CacheGetType, CacheScope, MetaTable } from '../utils/globals'; import { CacheGetType, CacheScope, MetaTable } from '../utils/globals';
import View from './View'; import View from './View';
import NocoCache from '../cache/NocoCache'; import NocoCache from '../cache/NocoCache';
import MapViewColumn from './MapViewColumn';
export default class MapView implements MapType { export default class MapView implements MapType {
fk_view_id: string; fk_view_id: string;
@ -41,21 +42,6 @@ export default class MapView implements MapType {
return view && new MapView(view); return view && new MapView(view);
} }
public static async IsColumnBeingUsedInMapView(
columnId: string,
ncMeta = Noco.ncMeta
) {
return (
(
await ncMeta.metaList2(null, null, MetaTable.MAP_VIEW, {
condition: {
fk_geo_data_col_id: columnId,
},
})
).length > 0
);
}
static async insert(view: Partial<MapView>, ncMeta = Noco.ncMeta) { static async insert(view: Partial<MapView>, ncMeta = Noco.ncMeta) {
const insertObj = { const insertObj = {
project_id: view.project_id, project_id: view.project_id,
@ -65,8 +51,9 @@ export default class MapView implements MapType {
meta: view.meta, meta: view.meta,
}; };
const viewRef = await View.get(view.fk_view_id);
if (!(view.project_id && view.base_id)) { if (!(view.project_id && view.base_id)) {
const viewRef = await View.get(view.fk_view_id);
insertObj.project_id = viewRef.project_id; insertObj.project_id = viewRef.project_id;
insertObj.base_id = viewRef.base_id; insertObj.base_id = viewRef.base_id;
} }
@ -96,6 +83,19 @@ export default class MapView implements MapType {
// set cache // set cache
await NocoCache.set(key, o); await NocoCache.set(key, o);
} }
if (body.fk_geo_data_col_id != null) {
const mapViewColumns = await MapViewColumn.list(mapId);
const mapViewMappedByColumn = mapViewColumns.find(
(mapViewColumn) =>
mapViewColumn.fk_column_id === body.fk_geo_data_col_id
);
await View.updateColumn(body.fk_view_id, mapViewMappedByColumn.id, {
show: true,
});
}
// update meta // update meta
return await ncMeta.metaUpdate(null, null, MetaTable.MAP_VIEW, updateObj, { return await ncMeta.metaUpdate(null, null, MetaTable.MAP_VIEW, updateObj, {
fk_view_id: mapId, fk_view_id: mapId,

25
packages/nocodb/src/lib/models/View.ts

@ -433,9 +433,7 @@ export default class View implements ViewType {
} else { } else {
show = false; show = false;
} }
} } else if (view.type === ViewTypes.KANBAN && !copyFromView) {
else if (view.type === ViewTypes.KANBAN && !copyFromView) {
const kanbanView = await KanbanView.get(view_id, ncMeta); const kanbanView = await KanbanView.get(view_id, ncMeta);
if (vCol.id === kanbanView?.fk_grp_col_id) { if (vCol.id === kanbanView?.fk_grp_col_id) {
// include grouping field if it exists // include grouping field if it exists
@ -452,14 +450,12 @@ export default class View implements ViewType {
// other columns will be hidden // other columns will be hidden
show = false; show = false;
} }
} } else if (view.type === ViewTypes.MAP && !copyFromView) {
else if (view.type === ViewTypes.MAP && !copyFromView) {
const mapView = await MapView.get(view_id, ncMeta); const mapView = await MapView.get(view_id, ncMeta);
if (vCol.id === mapView?.fk_geo_data_col_id) { if (vCol.id === mapView?.fk_geo_data_col_id) {
show = true; show = true;
}
} }
}
// if columns is list of virtual columns then get the parent column // if columns is list of virtual columns then get the parent column
const col = vCol.fk_column_id const col = vCol.fk_column_id
@ -1223,9 +1219,20 @@ export default class View implements ViewType {
// get existing cache // get existing cache
const dataList = await NocoCache.getList(scope, [viewId]); const dataList = await NocoCache.getList(scope, [viewId]);
const colsEssentialForView =
view.type === ViewTypes.MAP
? [(await MapView.get(viewId)).fk_geo_data_col_id]
: [];
const mergedIgnoreColdIds = [...ignoreColdIds, ...colsEssentialForView];
if (dataList?.length) { if (dataList?.length) {
for (const o of dataList) { for (const o of dataList) {
if (!ignoreColdIds?.length || !ignoreColdIds.includes(o.fk_column_id)) { if (
!mergedIgnoreColdIds?.length ||
!mergedIgnoreColdIds.includes(o.fk_column_id)
) {
// set data // set data
o.show = false; o.show = false;
// set cache // set cache
@ -1242,7 +1249,7 @@ export default class View implements ViewType {
{ {
fk_view_id: viewId, fk_view_id: viewId,
}, },
ignoreColdIds?.length mergedIgnoreColdIds?.length
? { ? {
_not: { _not: {
fk_column_id: { fk_column_id: {

Loading…
Cancel
Save