aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFawn <fangrui_tong@brown.edu>2019-06-14 15:30:22 -0400
committerFawn <fangrui_tong@brown.edu>2019-06-14 15:30:22 -0400
commit05f0f145269fffc5dfada98a5f20bbc8e204bd28 (patch)
tree50031541e9361cc68b17f4c44f450f265fae5150 /src
parentf54496c7aa930e385e77aaf37df8d51db733e3a2 (diff)
cleaned up more link code
Diffstat (limited to 'src')
-rw-r--r--src/client/util/DocumentManager.ts42
-rw-r--r--src/client/util/DragManager.ts17
-rw-r--r--src/client/views/nodes/LinkMenu.tsx4
3 files changed, 12 insertions, 51 deletions
diff --git a/src/client/util/DocumentManager.ts b/src/client/util/DocumentManager.ts
index 2acbb3ad4..6271220e4 100644
--- a/src/client/util/DocumentManager.ts
+++ b/src/client/util/DocumentManager.ts
@@ -9,7 +9,7 @@ import { CollectionView } from '../views/collections/CollectionView';
import { CollectionPDFView } from '../views/collections/CollectionPDFView';
import { CollectionVideoView } from '../views/collections/CollectionVideoView';
import { Id } from '../../new_fields/FieldSymbols';
-import { LinkManager, LinkUtils } from './LinkManager';
+import { LinkManager } from './LinkManager';
export class DocumentManager {
@@ -86,53 +86,19 @@ export class DocumentManager {
public get LinkedDocumentViews() {
let linked = DocumentManager.Instance.DocumentViews.filter(dv => dv.isSelected() || BoolCast(dv.props.Document.libraryBrush, false)).reduce((pairs, dv) => {
-
let linksList = LinkManager.Instance.findAllRelatedLinks(dv.props.Document);
if (linksList && linksList.length) {
pairs.push(...linksList.reduce((pairs, link) => {
if (link) {
- // let destination = (link["linkedTo"] === dv.props.Document) ? link["linkedFrom"] : link["linkedTo"];
-
- let destination = LinkUtils.findOppositeAnchor(link, dv.props.Document);
- let linkToDoc = FieldValue(Cast(destination, Doc));
- // let linkToDoc = FieldValue(Cast(link.linkedTo, Doc));
- if (linkToDoc) {
- DocumentManager.Instance.getDocumentViews(linkToDoc).map(docView1 =>
+ let destination = LinkManager.Instance.findOppositeAnchor(link, dv.props.Document);
+ if (destination) {
+ DocumentManager.Instance.getDocumentViews(destination).map(docView1 =>
pairs.push({ a: dv, b: docView1, l: link }));
}
}
return pairs;
}, [] as { a: DocumentView, b: DocumentView, l: Doc }[]));
}
-
- // let linksList = DocListCast(dv.props.Document.linkedToDocs);
- // console.log("to links", linksList.length);
- // if (linksList && linksList.length) {
- // pairs.push(...linksList.reduce((pairs, link) => {
- // if (link) {
- // let linkToDoc = FieldValue(Cast(link.linkedTo, Doc));
- // if (linkToDoc) {
- // DocumentManager.Instance.getDocumentViews(linkToDoc).map(docView1 =>
- // pairs.push({ a: dv, b: docView1, l: link }));
- // }
- // }
- // return pairs;
- // }, [] as { a: DocumentView, b: DocumentView, l: Doc }[]));
- // }
- // linksList = DocListCast(dv.props.Document.linkedFromDocs);
- // console.log("from links", linksList.length);
- // if (linksList && linksList.length) {
- // pairs.push(...linksList.reduce((pairs, link) => {
- // if (link) {
- // let linkFromDoc = FieldValue(Cast(link.linkedFrom, Doc));
- // if (linkFromDoc) {
- // DocumentManager.Instance.getDocumentViews(linkFromDoc).map(docView1 =>
- // pairs.push({ a: dv, b: docView1, l: link }));
- // }
- // }
- // return pairs;
- // }, pairs));
- // }
return pairs;
}, [] as { a: DocumentView, b: DocumentView, l: Doc }[]);
return linked;
diff --git a/src/client/util/DragManager.ts b/src/client/util/DragManager.ts
index 9ac421fbf..b4acbcffa 100644
--- a/src/client/util/DragManager.ts
+++ b/src/client/util/DragManager.ts
@@ -4,7 +4,7 @@ import { Cast } from "../../new_fields/Types";
import { emptyFunction } from "../../Utils";
import { CollectionDockingView } from "../views/collections/CollectionDockingView";
import * as globalCssVariables from "../views/globalCssVariables.scss";
-import { LinkManager, LinkUtils } from "./LinkManager";
+import { LinkManager } from "./LinkManager";
export type dropActionType = "alias" | "copy" | undefined;
export function SetupDrag(_reference: React.RefObject<HTMLElement>, docFunc: () => Doc | Promise<Doc>, moveFunc?: DragManager.MoveFunction, dropAction?: dropActionType) {
@@ -42,18 +42,13 @@ export function SetupDrag(_reference: React.RefObject<HTMLElement>, docFunc: ()
export async function DragLinksAsDocuments(dragEle: HTMLElement, x: number, y: number, sourceDoc: Doc) {
let srcTarg = sourceDoc.proto;
let draggedDocs: Doc[] = [];
- // let draggedFromDocs: Doc[] = [];
if (srcTarg) {
- // let linkToDocs = await DocListCastAsync(srcTarg.linkedToDocs);
- // let linkFromDocs = await DocListCastAsync(srcTarg.linkedFromDocs);
let linkDocs = LinkManager.Instance.findAllRelatedLinks(srcTarg);
- if (linkDocs) draggedDocs = linkDocs.map(link => {
- return LinkUtils.findOppositeAnchor(link, sourceDoc);
- });
-
-
- // if (linkToDocs) draggedDocs = linkToDocs.map(linkDoc => Cast(linkDoc.linkedTo, Doc) as Doc);
- // if (linkFromDocs) draggedFromDocs = linkFromDocs.map(linkDoc => Cast(linkDoc.linkedFrom, Doc) as Doc);
+ if (linkDocs) {
+ draggedDocs = linkDocs.map(link => {
+ return LinkManager.Instance.findOppositeAnchor(link, sourceDoc);
+ });
+ }
}
// draggedDocs.push(...draggedFromDocs);
if (draggedDocs.length) {
diff --git a/src/client/views/nodes/LinkMenu.tsx b/src/client/views/nodes/LinkMenu.tsx
index ebca54c92..2fcbd25fa 100644
--- a/src/client/views/nodes/LinkMenu.tsx
+++ b/src/client/views/nodes/LinkMenu.tsx
@@ -7,7 +7,7 @@ import './LinkMenu.scss';
import React = require("react");
import { Doc, DocListCast } from "../../../new_fields/Doc";
import { Id } from "../../../new_fields/FieldSymbols";
-import { LinkManager, LinkUtils } from "../../util/LinkManager";
+import { LinkManager } from "../../util/LinkManager";
interface Props {
docView: DocumentView;
@@ -22,7 +22,7 @@ export class LinkMenu extends React.Component<Props> {
renderGroup = (group: Doc[]): Array<JSX.Element> => {
let source = this.props.docView.Document;
return group.map(linkDoc => {
- let destination = LinkUtils.findOppositeAnchor(linkDoc, source);
+ let destination = LinkManager.Instance.findOppositeAnchor(linkDoc, source);
return <LinkBox key={destination[Id] + source[Id]} linkDoc={linkDoc} sourceDoc={source} destinationDoc={destination} showEditor={action(() => this._editingLink = linkDoc)} />;
});
}