diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/EditableView.tsx | 30 | ||||
-rw-r--r-- | src/client/views/collections/CollectionSchemaCells.tsx | 47 |
2 files changed, 61 insertions, 16 deletions
diff --git a/src/client/views/EditableView.tsx b/src/client/views/EditableView.tsx index fd687328c..f5a9716cd 100644 --- a/src/client/views/EditableView.tsx +++ b/src/client/views/EditableView.tsx @@ -6,6 +6,8 @@ import { ObjectField } from '../../fields/ObjectField'; import { SchemaHeaderField } from '../../fields/SchemaHeaderField'; import "./EditableView.scss"; import { DragManager } from '../util/DragManager'; +import { ComputedField } from '../../fields/ScriptField'; +import { FieldValue } from '../../fields/Types'; export interface EditableProps { /** @@ -54,6 +56,8 @@ export interface EditableProps { placeholder?: string; highlight?: boolean; positions?: number[]; + search?: string; + bing?: () => string; } /** @@ -183,8 +187,26 @@ export class EditableView extends React.Component<EditableProps> { />; } + returnHighlights() { + let results = []; + let length = this.props.search!.length + 1; + let contents = ""; + contents = this.props.bing!(); + console.log(contents); + // contents = String(this.props.contents.valueOf()); + results.push(<span style={{ fontStyle: this.props.fontStyle, fontSize: this.props.fontSize, color: this.props.contents ? "black" : "grey" }}>{contents ? contents.slice(0, this.props.positions![0]) : this.props.placeholder?.valueOf()}</span>); + this.props.positions?.forEach((num, cur) => { + results.push(<span style={{ backgroundColor: "#FFFF00", fontStyle: this.props.fontStyle, fontSize: this.props.fontSize, color: this.props.contents ? "black" : "grey" }}>{contents ? contents.slice(num, num + length) : this.props.placeholder?.valueOf()}</span>); + let end = 0; + cur === this.props.positions!.length - 1 ? end = contents.length - 1 : end = this.props.positions![cur + 1]; + results.push(<span style={{ fontStyle: this.props.fontStyle, fontSize: this.props.fontSize, color: this.props.contents ? "black" : "grey" }}>{contents ? contents.slice(num + length - 1, end) : this.props.placeholder?.valueOf()}</span>); + } + ) + + return results; + } + render() { - console.log(this.props.contents.valueOf()) if (this._editing && this.props.GetValue() !== undefined) { return this.props.sizeToContent ? <div style={{ display: "grid", minWidth: 100 }}> @@ -198,10 +220,8 @@ export class EditableView extends React.Component<EditableProps> { ref={this._ref} style={{ display: this.props.display, minHeight: "20px", height: `${this.props.height ? this.props.height : "auto"}`, maxHeight: `${this.props.maxHeight}` }} onClick={this.onClick} placeholder={this.props.placeholder}> - {this.props.highlight ? this.props.contents.forEach(el => { - console.log(el.valueOf()); - }) : undefined} - <span style={{ backgroundColor: "#FFFF00", fontStyle: this.props.fontStyle, fontSize: this.props.fontSize, color: this.props.contents ? "black" : "grey" }}>{this.props.contents ? this.props.contents?.valueOf() : this.props.placeholder?.valueOf()}</span> + {this.props.highlight === undefined ? <span style={{ fontStyle: this.props.fontStyle, fontSize: this.props.fontSize, color: this.props.contents ? "black" : "grey" }}>{this.props.contents ? this.props.contents?.valueOf() : this.props.placeholder?.valueOf()}</span> + : this.returnHighlights()} </div> ); } diff --git a/src/client/views/collections/CollectionSchemaCells.tsx b/src/client/views/collections/CollectionSchemaCells.tsx index 3fc29c46e..6fc0026e5 100644 --- a/src/client/views/collections/CollectionSchemaCells.tsx +++ b/src/client/views/collections/CollectionSchemaCells.tsx @@ -245,43 +245,67 @@ export class CollectionSchemaCell extends React.Component<CellProps> { // ); trace(); let positions = []; - if (type === "string") { - let term = contents + if (StrCast(this.props.Document._searchString) !== "") { + console.log(StrCast(this.props.Document._searchString)); + const cfield = ComputedField.WithoutComputed(() => FieldValue(props.Document[props.fieldKey])); + // if (cfield[Text]!==undefined){ + + // } + console.log(cfield?.valueOf()); + let term = StrCast(cfield); + console.log(term); let search = StrCast(this.props.Document._searchString) let start = term.indexOf(search) as number; let tally = 0; positions.push(start); while (start < contents.length && start !== -1) { - console.log(start, search.length + 1); - console.log(term.slice(start, start + search.length + 1)); term = term.slice(start + search.length + 1); tally += start + search.length + 1; - console.log(term); start = term.indexOf(search); positions.push(tally + start); - console.log(start); } - positions.pop(); console.log(positions); + if (positions.length > 1) { + positions.pop(); + } } - StrCast(this.props.Document._searchString) ? console.log(StrCast(this.props.Document._searchString)) : undefined; - return ( <div className="collectionSchemaView-cellContainer" style={{ cursor: fieldIsDoc ? "grab" : "auto" }} ref={dragRef} onPointerDown={this.onPointerDown} onPointerEnter={onPointerEnter} onPointerLeave={onPointerLeave}> <div className={className} ref={this._focusRef} onPointerDown={onItemDown} tabIndex={-1}> <div className="collectionSchemaView-cellContents" ref={type === undefined || type === "document" ? this.dropRef : null} key={props.Document[Id]}> <EditableView - positions={positions} + positions={positions.length > 0 ? positions : undefined} + search={StrCast(this.props.Document._searchString) ? StrCast(this.props.Document._searchString) : undefined} editing={this._isEditing} isEditingCallback={this.isEditingCallback} display={"inline"} contents={contents ? contents : type === "number" ? "0" : "undefined"} - highlight={true} + highlight={positions.length > 0 ? true : undefined} //contents={StrCast(contents)} height={"auto"} maxHeight={Number(MAX_ROW_HEIGHT)} placeholder={"enter value"} + bing={() => { + console.log("FLAMINGO"); + if (type === "number" && (contents === 0 || contents === "0")) { + return "0"; + } else { + const cfield = ComputedField.WithoutComputed(() => FieldValue(props.Document[props.fieldKey])); + console.log(cfield); + // if (type === "number") { + return StrCast(cfield); + // } + // return cfield; + // const cscript = cfield instanceof ComputedField ? cfield.script.originalScript : undefined; + // const cfinalScript = cscript?.split("return")[cscript.split("return").length - 1]; + // const val = cscript !== undefined ? (cfinalScript?.endsWith(";") ? `:=${cfinalScript?.substring(0, cfinalScript.length - 2)}` : cfinalScript) : + // Field.IsField(cfield) ? Field.toScriptString(cfield) : ""; + // return val; + + } + + }} GetValue={() => { if (type === "number" && (contents === 0 || contents === "0")) { return "0"; @@ -296,6 +320,7 @@ export class CollectionSchemaCell extends React.Component<CellProps> { const val = cscript !== undefined ? (cfinalScript?.endsWith(";") ? `:=${cfinalScript?.substring(0, cfinalScript.length - 2)}` : cfinalScript) : Field.IsField(cfield) ? Field.toScriptString(cfield) : ""; return val; + } }} |