mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) move home server into core
Summary: This moves enough server material into core to run a home server. The data engine is not yet incorporated (though in manual testing it works when ported). Test Plan: existing tests pass Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2552
This commit is contained in:
41
app/server/lib/ServerColumnGetters.ts
Normal file
41
app/server/lib/ServerColumnGetters.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import {ColumnGetters} from 'app/common/ColumnGetters';
|
||||
import * as gristTypes from 'app/common/gristTypes';
|
||||
|
||||
/**
|
||||
*
|
||||
* An implementation of ColumnGetters for the server, currently
|
||||
* drawing on the data and metadata prepared for CSV export.
|
||||
*
|
||||
*/
|
||||
export class ServerColumnGetters implements ColumnGetters {
|
||||
private _rowIndices: Map<number, number>;
|
||||
private _colIndices: Map<number, string>;
|
||||
|
||||
constructor(rowIds: number[], private _dataByColId: {[colId: string]: any}, private _columns: any[]) {
|
||||
this._rowIndices = new Map<number, number>(rowIds.map((rowId, r) => [rowId, r] as [number, number]));
|
||||
this._colIndices = new Map<number, string>(_columns.map(col => [col.id, col.colId] as [number, string]));
|
||||
}
|
||||
|
||||
public getColGetter(colRef: number): ((rowId: number) => any) | null {
|
||||
const colId = this._colIndices.get(colRef);
|
||||
if (colId === undefined) {
|
||||
return null;
|
||||
}
|
||||
const col = this._dataByColId[colId];
|
||||
return rowId => {
|
||||
const idx = this._rowIndices.get(rowId);
|
||||
if (idx === undefined) {
|
||||
return null;
|
||||
}
|
||||
return col[idx];
|
||||
};
|
||||
}
|
||||
|
||||
public getManualSortGetter(): ((rowId: number) => any) | null {
|
||||
const manualSortCol = this._columns.find(c => c.colId === gristTypes.MANUALSORT);
|
||||
if (!manualSortCol) {
|
||||
return null;
|
||||
}
|
||||
return this.getColGetter(manualSortCol.id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user