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