aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/collections/collectionSchema/CollectionSchemaView.tsx')
-rw-r--r--src/client/views/collections/collectionSchema/CollectionSchemaView.tsx75
1 files changed, 39 insertions, 36 deletions
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
index 19d170c81..e493b2e5d 100644
--- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
+++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
@@ -6,7 +6,7 @@ import { observer } from 'mobx-react';
import * as React from 'react';
import { returnEmptyDoclist, returnEmptyString, returnFalse, returnIgnore, returnNever, returnTrue, setupMoveUpEvents, smoothScroll } from '../../../../ClientUtils';
import { emptyFunction } from '../../../../Utils';
-import { Doc, DocListCast, Field, FieldType, NumListCast, Opt, StrListCast } from '../../../../fields/Doc';
+import { Doc, DocListCast, Field, FieldType, IdToDoc, NumListCast, Opt, StrListCast } from '../../../../fields/Doc';
import { DocData } from '../../../../fields/DocSymbols';
import { Id } from '../../../../fields/FieldSymbols';
import { List } from '../../../../fields/List';
@@ -288,7 +288,6 @@ export class CollectionSchemaView extends CollectionSubView() {
this.addNewKey(key, defaultVal);
}
- this.modifyCellTags(true);
const newColWidth = this.tableWidth / (this.storedColumnWidths.length + 1);
const currWidths = this.storedColumnWidths.slice();
currWidths.splice(0, 0, newColWidth);
@@ -302,19 +301,24 @@ export class CollectionSchemaView extends CollectionSubView() {
@action
addNewKey = (key: string, defaultVal: any) => {
- if (this._newFieldType == ColumnType.Equation) {
- this.childDocs.forEach(doc => {
- const parsedEquation = this.parseEquation(defaultVal);
- const val = computed(() => { return this.parsedEquationResult(parsedEquation, doc);})
- doc[DocData][key] = val.get();
- // doc[DocData][key] = this.parsedEquationResult(eq, doc);
- // this.setupAutoUpdate(eq, doc);
- });
- } else {
- this.childDocs.forEach(doc => {
- doc[DocData][key] = defaultVal;
- });
+ this.childDocs.forEach(doc => {
+ doc[DocData][key] = defaultVal;
+ });
+ }
+
+ cleanupComputedField = (field: string) => {
+ const idPattern = /idToDoc\((.*?)\)/g;
+ let modField = field.slice();
+ let matches;
+ let results = new Map<string, string>();
+ while ((matches = idPattern.exec(field)) !== null) {
+ results.set(matches[0], matches[1].replace(/"/g, ''));
}
+ console.log(results);
+ results.forEach((id, funcId) => {
+ modField = modField.replace(funcId, 'd' + (this.rowIndex(IdToDoc(id)) + 1).toString());
+ })
+ return modField;
}
// @action
@@ -325,30 +329,30 @@ export class CollectionSchemaView extends CollectionSubView() {
// });
// }
- parseEquation = (eq: string): [string, Map<string, Doc>] => {
- const variablePattern = /[a-z]+/gi;
- const tagRefPattern = /{([^}]*)}/g;
- const docTagRefPairs = new Map<string, Doc>();
- let modifiedEq = eq;
- let match;
+ // parseEquation = (eq: string): [string, Map<string, Doc>] => {
+ // const variablePattern = /[a-z]+/gi;
+ // const tagRefPattern = /{([^}]*)}/g;
+ // const docTagRefPairs = new Map<string, Doc>();
+ // let modifiedEq = eq;
+ // let match;
- while (match = tagRefPattern.exec(eq)) {
- const ref = match[1];
- const [doc, key] = this.getCellInfoFromTag(ref);
- docTagRefPairs.set(ref, doc);
- const replacement = `docTagRefPairs.get('${ref}').${key}`;
- modifiedEq = modifiedEq.replace(new RegExp(`{${ref}}`, 'g'), replacement);
- }
+ // while (match = tagRefPattern.exec(eq)) {
+ // const ref = match[1];
+ // const [doc, key] = this.getCellInfoFromTag(ref);
+ // docTagRefPairs.set(ref, doc);
+ // const replacement = `docTagRefPairs.get('${ref}').${key}`;
+ // modifiedEq = modifiedEq.replace(new RegExp(`{${ref}}`, 'g'), replacement);
+ // }
- //modifiedEq = modifiedEq.replace(variablePattern, (match) => `doc.${match}`);
+ // modifiedEq = modifiedEq.replace(variablePattern, (match) => `doc.${match}`);
- return [modifiedEq, docTagRefPairs];
- }
+ // return [modifiedEq, docTagRefPairs];
+ // }
- parsedEquationResult = (eq: [string, Map<string, Doc>], doc: any): number => {
- const func = new Function('doc', 'docTagRefPairs', 'return ' + eq[0]);
- return func(doc, eq[1]);
- }
+ // parsedEquationResult = (eq: [string, Map<string, Doc>], doc: any): number => {
+ // const func = new Function('doc', 'docTagRefPairs', 'return ' + eq[0]);
+ // return func(doc, eq[1]);
+ // }
@undoBatch
removeColumn = (index: number) => {
@@ -547,7 +551,6 @@ export class CollectionSchemaView extends CollectionSubView() {
selectCell = (doc: Doc, col: number, shiftKey: boolean, ctrlKey: boolean) => {
this.populateCellTags();
console.log(this.getCellTag(doc, col));
- console.log(this.getCellInfoFromTag("C1"));
if (!shiftKey && !ctrlKey) this.clearSelection();
!this._selectedCells && (this._selectedCells = []);
!shiftKey && this._selectedCells && this._selectedCells.push(doc);
@@ -602,7 +605,7 @@ export class CollectionSchemaView extends CollectionSubView() {
const colTag = tag.replace(/[^A-Z]/g, '');
const col = lettersToNumber(colTag);
- const key: string = this.columnKeys[col];
+ const key: string = this.columnKeys[col - 1];
const rowNum = Number(tag.replace(/[^\d]/g, ''));
const doc = this.childDocs[rowNum - 1];