diff options
| author | Stanley Yip <stanley_yip@brown.edu> | 2019-10-29 19:13:25 -0400 | 
|---|---|---|
| committer | Stanley Yip <stanley_yip@brown.edu> | 2019-10-29 19:13:25 -0400 | 
| commit | 525e18727edbdaba578e1ace748ddfd9573a65a4 (patch) | |
| tree | ff109c875a4d89708d8a9eaabff97971e08842e3 /src/client/util/DocumentManager.ts | |
| parent | b7353705ee06292e570c9847d72287190f3f42ed (diff) | |
| parent | 24031b32402f19932d293bdc3eb483235cff820a (diff) | |
Merge branch 'interaction_stanley' of https://github.com/browngraphicslab/Dash-Web into interaction_stanley
Diffstat (limited to 'src/client/util/DocumentManager.ts')
| -rw-r--r-- | src/client/util/DocumentManager.ts | 48 | 
1 files changed, 21 insertions, 27 deletions
| diff --git a/src/client/util/DocumentManager.ts b/src/client/util/DocumentManager.ts index 00de39671..346e88f40 100644 --- a/src/client/util/DocumentManager.ts +++ b/src/client/util/DocumentManager.ts @@ -1,5 +1,5 @@  import { action, computed, observable } from 'mobx'; -import { Doc, DocListCastAsync } from '../../new_fields/Doc'; +import { Doc, DocListCastAsync, DocListCast } from '../../new_fields/Doc';  import { Id } from '../../new_fields/FieldSymbols';  import { List } from '../../new_fields/List';  import { Cast, NumCast, StrCast } from '../../new_fields/Types'; @@ -9,6 +9,7 @@ import { DocumentView } from '../views/nodes/DocumentView';  import { LinkManager } from './LinkManager';  import { Scripting } from './Scripting';  import { SelectionManager } from './SelectionManager'; +import { DocumentType } from '../documents/DocumentTypes';  export class DocumentManager { @@ -41,8 +42,8 @@ export class DocumentManager {          if (toReturn.length === 0) {              DocumentManager.Instance.DocumentViews.map(view => {                  let doc = view.props.Document.proto; -                if (doc && doc[Id]) { -                    if (doc[Id] === id) { toReturn.push(view); } +                if (doc && doc[Id] && doc[Id] === id) { +                    toReturn.push(view);                  }              });          } @@ -72,6 +73,8 @@ export class DocumentManager {                          toReturn = view;                      }                  }); +            } else { +                break;              }          } @@ -87,49 +90,40 @@ export class DocumentManager {          return views.length ? views[0] : undefined;      }      public getDocumentViews(toFind: Doc): DocumentView[] { -          let toReturn: DocumentView[] = []; -        //gets document view that is in a freeform canvas collection -        DocumentManager.Instance.DocumentViews.map(view => { -            let doc = view.props.Document; - -            if (doc === toFind) { -                toReturn.push(view); -            } else { -                if (Doc.AreProtosEqual(doc, toFind)) { -                    toReturn.push(view); -                } -            } -        }); +        DocumentManager.Instance.DocumentViews.map(view => +            Doc.AreProtosEqual(view.props.Document, toFind) && toReturn.push(view));          return toReturn;      }      @computed      public get LinkedDocumentViews() { -        let pairs = DocumentManager.Instance.DocumentViews.filter(dv => dv.isSelected() || Doc.IsBrushed(dv.props.Document)).reduce((pairs, dv) => { +        let pairs = DocumentManager.Instance.DocumentViews.filter(dv => +            (dv.isSelected() || Doc.IsBrushed(dv.props.Document)) // draw links from DocumentViews that are selected or brushed OR +            || DocumentManager.Instance.DocumentViews.some(dv2 => {                                                  // Documentviews which +                let rest = DocListCast(dv2.props.Document.links).some(l => Doc.AreProtosEqual(l, dv.props.Document));// are link doc anchors  +                let init = (dv2.isSelected() || Doc.IsBrushed(dv2.props.Document)) && dv2.Document.type !== DocumentType.AUDIO;  // on a view that is selected or brushed +                return init && rest; +            }) +        ).reduce((pairs, dv) => {              let linksList = LinkManager.Instance.getAllRelatedLinks(dv.props.Document);              pairs.push(...linksList.reduce((pairs, link) => { -                if (link) { -                    let linkToDoc = LinkManager.Instance.getOppositeAnchor(link, dv.props.Document); -                    if (linkToDoc) { -                        DocumentManager.Instance.getDocumentViews(linkToDoc).map(docView1 => { -                            pairs.push({ a: dv, b: docView1, l: link }); -                        }); +                let linkToDoc = link && LinkManager.Instance.getOppositeAnchor(link, dv.props.Document); +                linkToDoc && DocumentManager.Instance.getDocumentViews(linkToDoc).map(docView1 => { +                    if (dv.props.Document.type !== DocumentType.LINK || dv.props.layoutKey !== docView1.props.layoutKey) { +                        pairs.push({ a: dv, b: docView1, l: link });                      } -                } +                });                  return pairs;              }, [] as { a: DocumentView, b: DocumentView, l: Doc }[])); -            // }              return pairs;          }, [] as { a: DocumentView, b: DocumentView, l: Doc }[]);          return pairs;      } - -      public jumpToDocument = async (targetDoc: Doc, willZoom: boolean, dockFunc?: (doc: Doc) => void, docContext?: Doc, linkId?: string, closeContextIfNotFound: boolean = false): Promise<void> => {          let highlight = () => {              const finalDocView = DocumentManager.Instance.getFirstDocumentView(targetDoc); | 
