From 48dbde117728e4b36bae11f0f16a796059ecf7ee Mon Sep 17 00:00:00 2001
From: dg314 <david_grossman@brown.edu>
Date: Sat, 17 Jul 2021 15:13:39 -0400
Subject: initial search panel

---
 src/client/views/search/SearchBox.tsx | 117 +++-------------------------------
 1 file changed, 8 insertions(+), 109 deletions(-)

(limited to 'src/client/views/search/SearchBox.tsx')

diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx
index b722868d6..740a28825 100644
--- a/src/client/views/search/SearchBox.tsx
+++ b/src/client/views/search/SearchBox.tsx
@@ -3,9 +3,9 @@ import { Tooltip } from '@material-ui/core';
 import { action, computed, IReactionDisposer, observable, reaction, runInAction } from 'mobx';
 import { observer } from 'mobx-react';
 import * as React from 'react';
-import { Doc, DocListCast, Field, Opt, DocListCastAsync } from '../../../fields/Doc';
+import { Doc, DocListCast, Field, Opt, DocListCastAsync, DataSym, HeightSym } from '../../../fields/Doc';
 import { documentSchema } from "../../../fields/documentSchemas";
-import { Copy, Id } from '../../../fields/FieldSymbols';
+import { Copy, Id, ToString } from '../../../fields/FieldSymbols';
 import { List } from '../../../fields/List';
 import { createSchema, listSpec, makeInterface } from '../../../fields/Schema';
 import { SchemaHeaderField } from '../../../fields/SchemaHeaderField';
@@ -52,8 +52,6 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
     private docsforfilter: Doc[] | undefined = [];
     private realTotalResults: number = 0;
     private newsearchstring = "";
-    private collectionRef = React.createRef<HTMLDivElement>();
-
 
     @observable _undoBackground: string | undefined = "";
     @observable _icons: string[] = this._allIcons;
@@ -116,62 +114,6 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
         }
     });
 
-    getFinalQuery(query: string): string {
-        //alters the query so it looks in the correct fields
-        //if this is true, th`en not all of the field boxes are checked
-        //TODO: data
-        const initialfilters = Cast(this.props.Document._docFilters, listSpec("string"), []);
-
-        const filters: string[] = [];
-
-        for (const initFilter of initialfilters) {
-            const fields = initFilter.split(":");
-            if (fields[2] !== undefined) {
-                filters.push(fields[0]);
-                filters.push(fields[1]);
-                filters.push(fields[2]);
-            }
-        }
-
-        const finalfilters: { [key: string]: string[] } = {};
-
-        for (let i = 0; i < filters.length; i = i++) {
-            const fields = filters[i].split(":");
-            if (finalfilters[fields[0]] !== undefined) {
-                finalfilters[fields[0]].push(fields[1]);
-            }
-            else {
-                finalfilters[fields[0]] = [fields[1]];
-            }
-        }
-
-        for (const key in finalfilters) {
-            const values = finalfilters[key];
-            if (values.length === 1) {
-                const mod = "_t:";
-                const newWords: string[] = [];
-                const oldWords = values[0].split(" ");
-                oldWords.forEach((word, i) => i === 0 ? newWords.push(key + mod + word) : newWords.push("AND " + key + mod + word));
-                query = `(${query}) AND (${newWords.join(" ")})`;
-            }
-            else {
-                for (let i = 0; i < values.length; i++) {
-                    const mod = "_t:";
-                    const newWords: string[] = [];
-                    const oldWords = values[i].split(" ");
-                    oldWords.forEach((word, i) => i === 0 ? newWords.push(key + mod + word) : newWords.push("AND " + key + mod + word));
-                    const v = "(" + newWords.join(" ") + ")";
-                    if (i === 0) {
-                        query = `(${query}) AND (${v}` + (values.length === 1 ? ")" : "");
-                    }
-                    else query = query + " OR " + v + (i === values.length - 1 ? ")" : "");
-                }
-            }
-        }
-
-        return query.replace(/-\s+/g, '');
-    }
-
     @action
     filterDocsByType(docs: Doc[]) {
         const finalDocs: Doc[] = [];
@@ -340,7 +282,6 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
                             this._results[index][1].push(...hlights);
                             this._results[index][2].push(...line);
                         }
-
                     }));
 
                     this._curRequest = undefined;
@@ -360,37 +301,6 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
         return this._lockPromise;
     }
 
-    startDragCollection = async () => {
-        const res = await this.getAllResults(this.getFinalQuery(StrCast(this.layoutDoc._searchString)));
-        const filtered = this.filterDocsByType(res.docs);
-        const docs = filtered.map(doc => Doc.GetT(doc, "isPrototype", "boolean", true) ? Doc.MakeDelegate(doc) : Doc.MakeAlias(doc));
-        let x = 0;
-        let y = 0;
-        for (const doc of docs.map(d => Doc.Layout(d))) {
-            doc.x = x;
-            doc.y = y;
-            const size = 200;
-            const aspect = Doc.NativeHeight(doc) / (Doc.NativeWidth(doc) || 1);
-            if (aspect > 1) {
-                doc._height = size;
-                doc._width = size / aspect;
-            } else if (aspect > 0) {
-                doc._width = size;
-                doc._height = size * aspect;
-            } else {
-                doc._width = size;
-                doc._height = size;
-            }
-            x += 250;
-            if (x > 1000) {
-                x = 0;
-                y += 300;
-            }
-        }
-        const headers = Cast(this.props.Document._schemaHeaders, listSpec(SchemaHeaderField), []).map(h => { const v = h[Copy](); v.color = "#f1efeb"; return v; });
-        return Docs.Create.SchemaDocument(headers, DocListCast(this.dataDoc[this.fieldKey]), { _autoHeight: true, _viewType: CollectionViewType.Schema, title: StrCast(this.layoutDoc._searchString) });
-    }
-
     @action.bound
     openSearch(e: React.SyntheticEvent) {
         e.stopPropagation();
@@ -479,6 +389,7 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
 
     render() {
         const myDashboards = DocListCast(CurrentUserUtils.MyDashboards.data);
+
         return (
             <div style={{ pointerEvents: "all" }} className="searchBox-container">
                 <div className="searchBox-bar" style={{ background: SearchBox.Instance._undoBackground }}>
@@ -487,7 +398,7 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
                             {`${Doc.CurrentUserEmail}`}
                             <div className="searchBox-logoff" onClick={() => window.location.assign(Utils.prepend("/logout"))}>
                                 Logoff
-                        </div>
+                            </div>
                         </div>
                         <div className="searchBox-lozenge" onClick={() => DocServer.UPDATE_SERVER_CACHE()}>
                             {`UI project`}
@@ -499,10 +410,10 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
                             </select>
                             <div className="searchBox-dashboards" onClick={undoBatch(() => CurrentUserUtils.createNewDashboard(Doc.UserDoc()))}>
                                 New
-                        </div>
+                            </div>
                             <div className="searchBox-dashboards" onClick={undoBatch(() => CurrentUserUtils.snapshotDashboard(Doc.UserDoc()))}>
                                 Snapshot
-                        </div>
+                            </div>
                         </div>
                     </div>
                     <div className="searchBox-query" >
@@ -511,24 +422,12 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
                             style={{ padding: 1, paddingLeft: 20, paddingRight: 60, color: "black", height: 20, width: 250 }} />
                         <div style={{ display: "flex", alignItems: "center" }}>
                             <div style={{ position: "absolute", left: 10 }}>
-                                <Tooltip title={<div className="dash-tooltip" >drag search results as collection</div>}>
-                                    <div ref={this.collectionRef}><FontAwesomeIcon onPointerDown={SetupDrag(this.collectionRef, () => StrCast(this.layoutDoc._searchString) ? this.startDragCollection() : undefined)} icon={"search"} size="lg"
-                                        style={{ cursor: "hand", color: "black", padding: 1, position: "relative" }} /></div>
-                                </Tooltip>
+                                <FontAwesomeIcon icon={"search"} size="lg"
+                                    style={{ color: "black", padding: 1, position: "relative" }} />
                             </div>
                             <div style={{ position: "absolute", left: Doc.UserDoc().noviceMode ? 220 : 200, width: 30, zIndex: 9000, color: "grey", background: "white", }}>
                                 {`${this._results.length}` + " of " + `${this.realTotalResults}`}
                             </div>
-                            {Doc.UserDoc().noviceMode ? (null) : <div style={{ cursor: "default", left: 235, position: "absolute", }}>
-                                <Tooltip title={<div className="dash-tooltip" >only display documents matching search</div>} >
-                                    <div>
-                                        <FontAwesomeIcon icon={"filter"} size="lg"
-                                            style={{ cursor: "hand", padding: 1, backgroundColor: this.filter ? "white" : "lightgray", color: this.filter ? "black" : "white" }}
-                                            onPointerDown={e => { e.stopPropagation(); SetupDrag(this.collectionRef, () => this.layoutDoc._searchString ? this.startDragCollection() : undefined); }}
-                                            onClick={action(() => this.setSearchFilter(this.currentSelectedCollection, this.filter ? undefined : this.docsforfilter))} />
-                                    </div>
-                                </Tooltip>
-                            </div>}
                         </div>
                     </div >
                 </div >
-- 
cgit v1.2.3-70-g09d2

