|
|
|
@ -633,16 +633,26 @@ export default class View implements ViewType {
|
|
|
|
|
|
|
|
|
|
// keep primary_value_column always visible and first in grid view
|
|
|
|
|
if (view.type === ViewTypes.GRID) { |
|
|
|
|
const primary_value_column_meta = await ncMeta.metaGet2(null, null, MetaTable.COLUMNS, { |
|
|
|
|
fk_model_id: view.fk_model_id, |
|
|
|
|
pv: true, |
|
|
|
|
}); |
|
|
|
|
const primary_value_column_meta = await ncMeta.metaGet2( |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
MetaTable.COLUMNS, |
|
|
|
|
{ |
|
|
|
|
fk_model_id: view.fk_model_id, |
|
|
|
|
pv: true, |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const primary_value_column = await ncMeta.metaGet2( |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
MetaTable.GRID_VIEW_COLUMNS, |
|
|
|
|
{ |
|
|
|
|
fk_view_id: view.id, |
|
|
|
|
fk_column_id: primary_value_column_meta.id, |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const primary_value_column = await ncMeta.metaGet2(null, null, MetaTable.GRID_VIEW_COLUMNS, { |
|
|
|
|
fk_view_id: view.id, |
|
|
|
|
fk_column_id: primary_value_column_meta.id, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (primary_value_column && primary_value_column.id === colId) { |
|
|
|
|
updateObj.order = 1; |
|
|
|
|
updateObj.show = true; |
|
|
|
@ -1108,14 +1118,19 @@ export default class View implements ViewType {
|
|
|
|
|
const scope = this.extractViewColumnsTableNameScope(view); |
|
|
|
|
|
|
|
|
|
if (view.type === ViewTypes.GRID) { |
|
|
|
|
const primary_value_column = await ncMeta.metaGet2(null, null, MetaTable.COLUMNS, { |
|
|
|
|
fk_model_id: view.fk_model_id, |
|
|
|
|
pv: true, |
|
|
|
|
}) |
|
|
|
|
const primary_value_column = await ncMeta.metaGet2( |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
MetaTable.COLUMNS, |
|
|
|
|
{ |
|
|
|
|
fk_model_id: view.fk_model_id, |
|
|
|
|
pv: true, |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// keep primary_value_column always visible
|
|
|
|
|
if (primary_value_column) { |
|
|
|
|
ignoreColdIds.push(primary_value_column.id) |
|
|
|
|
ignoreColdIds.push(primary_value_column.id); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1179,27 +1194,41 @@ export default class View implements ViewType {
|
|
|
|
|
|
|
|
|
|
static async fixPVColumnForView(viewId, ncMeta = Noco.ncMeta) { |
|
|
|
|
// get a list of view columns sorted by order
|
|
|
|
|
const view_columns = await ncMeta.metaList2(null, null, MetaTable.GRID_VIEW_COLUMNS, { |
|
|
|
|
condition: { |
|
|
|
|
fk_view_id: viewId, |
|
|
|
|
}, |
|
|
|
|
orderBy: { |
|
|
|
|
order: 'asc', |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
const view_columns_meta = [] |
|
|
|
|
const view_columns = await ncMeta.metaList2( |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
MetaTable.GRID_VIEW_COLUMNS, |
|
|
|
|
{ |
|
|
|
|
condition: { |
|
|
|
|
fk_view_id: viewId, |
|
|
|
|
}, |
|
|
|
|
orderBy: { |
|
|
|
|
order: 'asc', |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
const view_columns_meta = []; |
|
|
|
|
|
|
|
|
|
// get column meta for each view column
|
|
|
|
|
for (const col of view_columns) { |
|
|
|
|
const col_meta = await ncMeta.metaGet2(null, null, MetaTable.COLUMNS, col.fk_column_id); |
|
|
|
|
const col_meta = await ncMeta.metaGet2( |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
MetaTable.COLUMNS, |
|
|
|
|
col.fk_column_id |
|
|
|
|
); |
|
|
|
|
view_columns_meta.push(col_meta); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const primary_value_column_meta = view_columns_meta.find((col) => col.pv); |
|
|
|
|
|
|
|
|
|
if (primary_value_column_meta) { |
|
|
|
|
const primary_value_column = view_columns.find((col) => col.fk_column_id === primary_value_column_meta.id); |
|
|
|
|
const primary_value_column_index = view_columns.findIndex((col) => col.fk_column_id === primary_value_column_meta.id); |
|
|
|
|
const primary_value_column = view_columns.find( |
|
|
|
|
(col) => col.fk_column_id === primary_value_column_meta.id |
|
|
|
|
); |
|
|
|
|
const primary_value_column_index = view_columns.findIndex( |
|
|
|
|
(col) => col.fk_column_id === primary_value_column_meta.id |
|
|
|
|
); |
|
|
|
|
const view_orders = view_columns.map((col) => col.order); |
|
|
|
|
const view_min_order = Math.min(...view_orders); |
|
|
|
|
|
|
|
|
@ -1210,7 +1239,7 @@ export default class View implements ViewType {
|
|
|
|
|
null, |
|
|
|
|
MetaTable.GRID_VIEW_COLUMNS, |
|
|
|
|
{ show: true }, |
|
|
|
|
primary_value_column.id, |
|
|
|
|
primary_value_column.id |
|
|
|
|
); |
|
|
|
|
await NocoCache.set( |
|
|
|
|
`${CacheScope.GRID_VIEW_COLUMN}:${primary_value_column.id}`, |
|
|
|
@ -1218,7 +1247,10 @@ export default class View implements ViewType {
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (primary_value_column.order === view_min_order && view_orders.filter((o) => o === view_min_order).length === 1) { |
|
|
|
|
if ( |
|
|
|
|
primary_value_column.order === view_min_order && |
|
|
|
|
view_orders.filter((o) => o === view_min_order).length === 1 |
|
|
|
|
) { |
|
|
|
|
// if primary_value_column is in first order do nothing
|
|
|
|
|
return; |
|
|
|
|
} else { |
|
|
|
@ -1245,14 +1277,19 @@ export default class View implements ViewType {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const views = await ncMeta.metaList2(null, null, MetaTable.GRID_VIEW_COLUMNS, { |
|
|
|
|
condition: { |
|
|
|
|
fk_view_id: viewId, |
|
|
|
|
}, |
|
|
|
|
orderBy: { |
|
|
|
|
order: 'asc', |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
const views = await ncMeta.metaList2( |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
MetaTable.GRID_VIEW_COLUMNS, |
|
|
|
|
{ |
|
|
|
|
condition: { |
|
|
|
|
fk_view_id: viewId, |
|
|
|
|
}, |
|
|
|
|
orderBy: { |
|
|
|
|
order: 'asc', |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
await NocoCache.setList(CacheScope.GRID_VIEW_COLUMN, [viewId], views); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|