mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 04:16:00 +00:00
removed free table (data sheet) concept
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
import _ from 'lodash';
|
||||
import type { EngineDriver, ViewInfo, ColumnInfo } from 'dbgate-types';
|
||||
import { GridDisplay, ChangeCacheFunc, ChangeConfigFunc } from './GridDisplay';
|
||||
import { GridConfig, GridCache } from './GridConfig';
|
||||
import { FreeTableModel } from './FreeTableModel';
|
||||
import { analyseCollectionDisplayColumns } from '.';
|
||||
|
||||
export class FreeTableGridDisplay extends GridDisplay {
|
||||
constructor(
|
||||
public model: FreeTableModel,
|
||||
config: GridConfig,
|
||||
setConfig: ChangeConfigFunc,
|
||||
cache: GridCache,
|
||||
setCache: ChangeCacheFunc
|
||||
) {
|
||||
super(config, setConfig, cache, setCache);
|
||||
this.columns = model?.structure?.__isDynamicStructure
|
||||
? analyseCollectionDisplayColumns(model?.rows, this)
|
||||
: this.getDisplayColumns(model);
|
||||
this.filterable = false;
|
||||
this.sortable = false;
|
||||
}
|
||||
|
||||
getDisplayColumns(model: FreeTableModel) {
|
||||
return _.uniqBy(
|
||||
model?.structure?.columns
|
||||
?.map(col => this.getDisplayColumn(col))
|
||||
?.map(col => ({
|
||||
...col,
|
||||
isChecked: this.isColumnChecked(col),
|
||||
})) || [],
|
||||
col => col.uniqueName
|
||||
);
|
||||
}
|
||||
|
||||
getDisplayColumn(col: ColumnInfo) {
|
||||
const uniquePath = [col.columnName];
|
||||
const uniqueName = uniquePath.join('.');
|
||||
return {
|
||||
...col,
|
||||
pureName: 'data',
|
||||
schemaName: '',
|
||||
headerText: col.columnName,
|
||||
uniqueName,
|
||||
uniquePath,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
import type { TableInfo } from 'dbgate-types';
|
||||
|
||||
export interface FreeTableModel {
|
||||
structure: TableInfo;
|
||||
rows: any[];
|
||||
}
|
||||
|
||||
export function createFreeTableModel() {
|
||||
return {
|
||||
structure: {
|
||||
columns: [
|
||||
{
|
||||
columnName: 'col1',
|
||||
},
|
||||
],
|
||||
foreignKeys: [],
|
||||
},
|
||||
rows: [
|
||||
{
|
||||
col1: 'val1',
|
||||
},
|
||||
{
|
||||
col1: 'val2',
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import { FreeTableModel } from './FreeTableModel';
|
||||
import _ from 'lodash';
|
||||
import uuidv1 from 'uuid/v1';
|
||||
import uuidv4 from 'uuid/v4';
|
||||
@@ -27,160 +26,6 @@ const modules = {
|
||||
moment,
|
||||
};
|
||||
|
||||
// function runTramsformValue(
|
||||
// func,
|
||||
// macroArgs: {},
|
||||
// data: FreeTableModel,
|
||||
// preview: boolean,
|
||||
// selectedCells: MacroSelectedCell[],
|
||||
// errors: string[] = []
|
||||
// ) {
|
||||
// const selectedRows = _.groupBy(selectedCells, 'row');
|
||||
// const rows = data.rows.map((row, rowIndex) => {
|
||||
// const selectedRow = selectedRows[rowIndex];
|
||||
// if (selectedRow) {
|
||||
// const modifiedFields = [];
|
||||
// let res = null;
|
||||
// for (const cell of selectedRow) {
|
||||
// const { column } = cell;
|
||||
// const oldValue = row[column];
|
||||
// let newValue = oldValue;
|
||||
// try {
|
||||
// newValue = func(oldValue, macroArgs, modules, rowIndex, row, column);
|
||||
// } catch (err) {
|
||||
// errors.push(`Error processing column ${column} on row ${rowIndex}: ${err.message}`);
|
||||
// }
|
||||
// if (newValue != oldValue) {
|
||||
// if (res == null) {
|
||||
// res = { ...row };
|
||||
// }
|
||||
// res[column] = newValue;
|
||||
// if (preview) modifiedFields.push(column);
|
||||
// }
|
||||
// }
|
||||
// if (res) {
|
||||
// if (modifiedFields.length > 0) {
|
||||
// return {
|
||||
// ...res,
|
||||
// __modifiedFields: new Set(modifiedFields),
|
||||
// };
|
||||
// }
|
||||
// return res;
|
||||
// }
|
||||
// return row;
|
||||
// } else {
|
||||
// return row;
|
||||
// }
|
||||
// });
|
||||
|
||||
// return {
|
||||
// structure: data.structure,
|
||||
// rows,
|
||||
// };
|
||||
// }
|
||||
|
||||
// function removePreviewRowFlags(rows) {
|
||||
// rows = rows.filter(row => row.__rowStatus != 'deleted');
|
||||
// rows = rows.map(row => {
|
||||
// if (row.__rowStatus || row.__modifiedFields || row.__insertedFields || row.__deletedFields)
|
||||
// return _.omit(row, ['__rowStatus', '__modifiedFields', '__insertedFields', '__deletedFields']);
|
||||
// return row;
|
||||
// });
|
||||
// return rows;
|
||||
// }
|
||||
|
||||
// function runTramsformRows(
|
||||
// func,
|
||||
// macroArgs: {},
|
||||
// data: FreeTableModel,
|
||||
// preview: boolean,
|
||||
// selectedCells: MacroSelectedCell[],
|
||||
// errors: string[] = []
|
||||
// ) {
|
||||
// let rows = data.rows;
|
||||
// try {
|
||||
// rows = func(
|
||||
// data.rows,
|
||||
// macroArgs,
|
||||
// modules,
|
||||
// selectedCells,
|
||||
// data.structure.columns.map(x => x.columnName),
|
||||
// data.structure.columns
|
||||
// );
|
||||
// if (!preview) {
|
||||
// rows = removePreviewRowFlags(rows);
|
||||
// }
|
||||
// } catch (err) {
|
||||
// errors.push(`Error processing rows: ${err.message}`);
|
||||
// }
|
||||
// return {
|
||||
// structure: data.structure,
|
||||
// rows,
|
||||
// };
|
||||
// }
|
||||
|
||||
// function runTramsformData(
|
||||
// func,
|
||||
// macroArgs: {},
|
||||
// data: FreeTableModel,
|
||||
// preview: boolean,
|
||||
// selectedCells: MacroSelectedCell[],
|
||||
// errors: string[] = []
|
||||
// ) {
|
||||
// try {
|
||||
// let { rows, columns, cols } = func(
|
||||
// data.rows,
|
||||
// macroArgs,
|
||||
// modules,
|
||||
// selectedCells,
|
||||
// data.structure.columns.map(x => x.columnName),
|
||||
// data.structure.columns
|
||||
// );
|
||||
// if (cols && !columns) {
|
||||
// columns = cols.map(columnName => ({ columnName }));
|
||||
// }
|
||||
// columns = _.uniqBy(columns, 'columnName');
|
||||
// if (!preview) {
|
||||
// rows = removePreviewRowFlags(rows);
|
||||
// }
|
||||
// return {
|
||||
// structure: { columns },
|
||||
// rows,
|
||||
// };
|
||||
// } catch (err) {
|
||||
// errors.push(`Error processing data: ${err.message}`);
|
||||
// }
|
||||
// return data;
|
||||
// }
|
||||
|
||||
// export function runMacro(
|
||||
// macro: MacroDefinition,
|
||||
// macroArgs: {},
|
||||
// data: FreeTableModel,
|
||||
// preview: boolean,
|
||||
// selectedCells: MacroSelectedCell[],
|
||||
// errors: string[] = []
|
||||
// ): FreeTableModel {
|
||||
// let func;
|
||||
// try {
|
||||
// func = eval(getMacroFunction[macro.type](macro.code));
|
||||
// } catch (err) {
|
||||
// errors.push(`Error compiling macro ${macro.name}: ${err.message}`);
|
||||
// return data;
|
||||
// }
|
||||
// if (macro.type == 'transformValue') {
|
||||
// return runTramsformValue(func, macroArgs, data, preview, selectedCells, errors);
|
||||
// }
|
||||
// if (macro.type == 'transformRows') {
|
||||
// return runTramsformRows(func, macroArgs, data, preview, selectedCells, errors);
|
||||
// }
|
||||
// if (macro.type == 'transformData') {
|
||||
// // @ts-ignore
|
||||
// return runTramsformData(func, macroArgs, data, preview, selectedCells, errors);
|
||||
// }
|
||||
// return data;
|
||||
// }
|
||||
|
||||
export function compileMacroFunction(macro: MacroDefinition, errors = []) {
|
||||
if (!macro) return null;
|
||||
let func;
|
||||
|
||||
Reference in New Issue
Block a user