aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes
diff options
context:
space:
mode:
authorFawn <fangrui_tong@brown.edu>2019-06-19 22:27:21 -0400
committerFawn <fangrui_tong@brown.edu>2019-06-19 22:27:21 -0400
commitc5e401cb0a7fec2279ceecbc8d1429dcdd2f04b9 (patch)
treed7e3b77890c3c4f3be0dca1da9c4aae71ecaead7 /src/client/views/nodes
parentf362dbfc237536c6c4a8c6d088c3dc818080f7c2 (diff)
buttons on cut links functional except for when dragged from link menu
Diffstat (limited to 'src/client/views/nodes')
-rw-r--r--src/client/views/nodes/DocumentContentsView.tsx3
-rw-r--r--src/client/views/nodes/DocumentView.tsx14
-rw-r--r--src/client/views/nodes/FieldView.tsx6
-rw-r--r--src/client/views/nodes/LinkButtonBox.scss18
-rw-r--r--src/client/views/nodes/LinkButtonBox.tsx63
-rw-r--r--src/client/views/nodes/LinkMenu.tsx4
-rw-r--r--src/client/views/nodes/LinkMenuItem.scss (renamed from src/client/views/nodes/LinkBox.scss)0
-rw-r--r--src/client/views/nodes/LinkMenuItem.tsx (renamed from src/client/views/nodes/LinkBox.tsx)6
8 files changed, 107 insertions, 7 deletions
diff --git a/src/client/views/nodes/DocumentContentsView.tsx b/src/client/views/nodes/DocumentContentsView.tsx
index 02396c3af..940b00a90 100644
--- a/src/client/views/nodes/DocumentContentsView.tsx
+++ b/src/client/views/nodes/DocumentContentsView.tsx
@@ -12,6 +12,7 @@ import "./DocumentView.scss";
import { FormattedTextBox } from "./FormattedTextBox";
import { ImageBox } from "./ImageBox";
import { IconBox } from "./IconBox";
+import { LinkButtonBox } from "./LinkButtonBox";
import { KeyValueBox } from "./KeyValueBox";
import { PDFBox } from "./PDFBox";
import { VideoBox } from "./VideoBox";
@@ -103,7 +104,7 @@ export class DocumentContentsView extends React.Component<DocumentViewProps & {
render() {
if (!this.layout && (this.props.layoutKey !== "overlayLayout" || !this.templates.length)) return (null);
return <ObserverJsxParser
- components={{ FormattedTextBox, ImageBox, IconBox, FieldView, CollectionFreeFormView, CollectionDockingView, CollectionSchemaView, CollectionView, CollectionPDFView, CollectionVideoView, WebBox, KeyValueBox, PDFBox, VideoBox, AudioBox, HistogramBox }}
+ components={{ FormattedTextBox, ImageBox, IconBox, FieldView, CollectionFreeFormView, CollectionDockingView, CollectionSchemaView, CollectionView, CollectionPDFView, CollectionVideoView, WebBox, KeyValueBox, PDFBox, VideoBox, AudioBox, HistogramBox, LinkButtonBox }}
bindings={this.CreateBindings()}
jsx={this.finalLayout}
showWarnings={true}
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index e98392a18..c424384a4 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -462,6 +462,17 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
var scaling = this.props.ContentScaling();
var nativeHeight = this.nativeHeight > 0 ? `${this.nativeHeight}px` : "100%";
var nativeWidth = this.nativeWidth > 0 ? `${this.nativeWidth}px` : "100%";
+
+ // // for linkbutton docs
+ // let isLinkButton = BoolCast(this.props.Document.isLinkButton);
+ // let activeDvs = DocumentManager.Instance.DocumentViews.filter(dv => dv.isSelected() || BoolCast(dv.props.Document.libraryBrush, false));
+ // let display = isLinkButton ? activeDvs.reduce((found, dv) => {
+ // let matchSv = this.props.Document.sourceViewId === StrCast(dv.props.Document[Id]);
+ // let matchTv = this.props.Document.targetViewId === StrCast(dv.props.Document[Id]);
+ // let match = matchSv || matchTv;
+ // return match || found;
+ // }, false) : true;
+
return (
<div className={`documentView-node${this.props.isTopMost ? "-topmost" : ""}`}
ref={this._mainCont}
@@ -476,7 +487,8 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
background: this.Document.backgroundColor || "",
width: nativeWidth,
height: nativeHeight,
- transform: `scale(${scaling}, ${scaling})`
+ transform: `scale(${scaling}, ${scaling})`,
+ // display: display ? "block" : "none"
}}
onDrop={this.onDrop} onContextMenu={this.onContextMenu} onPointerDown={this.onPointerDown} onClick={this.onClick}
diff --git a/src/client/views/nodes/FieldView.tsx b/src/client/views/nodes/FieldView.tsx
index 5a83de8e3..6fecb34d7 100644
--- a/src/client/views/nodes/FieldView.tsx
+++ b/src/client/views/nodes/FieldView.tsx
@@ -18,6 +18,8 @@ import { FormattedTextBox } from "./FormattedTextBox";
import { IconBox } from "./IconBox";
import { ImageBox } from "./ImageBox";
import { VideoBox } from "./VideoBox";
+import { LinkButtonBox } from "./LinkButtonBox";
+import { LinkButtonField } from "../../../new_fields/LinkButtonField";
//
@@ -49,6 +51,7 @@ export interface FieldViewProps {
@observer
export class FieldView extends React.Component<FieldViewProps> {
public static LayoutString(fieldType: { name: string }, fieldStr: string = "data") {
+ console.log("LAYOUT STRING", fieldType.name, fieldStr);
return `<${fieldType.name} {...props} fieldKey={"${fieldStr}"} />`;
}
@@ -74,6 +77,9 @@ export class FieldView extends React.Component<FieldViewProps> {
else if (field instanceof IconField) {
return <IconBox {...this.props} />;
}
+ else if (field instanceof LinkButtonField) {
+ return <LinkButtonBox {...this.props} />;
+ }
else if (field instanceof VideoField) {
return <VideoBox {...this.props} />;
}
diff --git a/src/client/views/nodes/LinkButtonBox.scss b/src/client/views/nodes/LinkButtonBox.scss
new file mode 100644
index 000000000..24bfd2c9f
--- /dev/null
+++ b/src/client/views/nodes/LinkButtonBox.scss
@@ -0,0 +1,18 @@
+.linkBox-cont {
+ width: 200px;
+ height: 100px;
+ background-color: black;
+ text-align: center;
+ color: white;
+ padding: 10px;
+ border-radius: 5px;
+ position: relative;
+
+ .linkBox-cont-wrapper {
+ width: calc(100% - 20px);
+ position: absolute;
+ left: 50%;
+ top: 50%;
+ transform: translate(-50%, -50%);
+ }
+} \ No newline at end of file
diff --git a/src/client/views/nodes/LinkButtonBox.tsx b/src/client/views/nodes/LinkButtonBox.tsx
new file mode 100644
index 000000000..8a7c1ed8b
--- /dev/null
+++ b/src/client/views/nodes/LinkButtonBox.tsx
@@ -0,0 +1,63 @@
+import React = require("react");
+import { library } from '@fortawesome/fontawesome-svg-core';
+import { faCaretUp, faFilePdf, faFilm, faImage, faObjectGroup, faStickyNote } from '@fortawesome/free-solid-svg-icons';
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { computed, observable, runInAction } from "mobx";
+import { observer } from "mobx-react";
+import { FieldView, FieldViewProps } from './FieldView';
+import "./LinkButtonBox.scss";
+import { DocumentView } from "./DocumentView";
+import { Doc } from "../../../new_fields/Doc";
+import { LinkButtonField } from "../../../new_fields/LinkButtonField";
+import { Cast, StrCast, BoolCast } from "../../../new_fields/Types";
+import { CollectionDockingView } from "../collections/CollectionDockingView";
+import { DocumentManager } from "../../util/DocumentManager";
+import { Id } from "../../../new_fields/FieldSymbols";
+
+library.add(faCaretUp);
+library.add(faObjectGroup);
+library.add(faStickyNote);
+library.add(faFilePdf);
+library.add(faFilm);
+
+@observer
+export class LinkButtonBox extends React.Component<FieldViewProps> {
+ public static LayoutString() { return FieldView.LayoutString(LinkButtonBox); }
+
+ followLink = (): void => {
+ console.log("follow link???");
+ let field = Cast(this.props.Document[this.props.fieldKey], LinkButtonField, new LinkButtonField({ sourceViewId: "-1", targetViewId: "-1" }));
+ let targetView = DocumentManager.Instance.getDocumentViewById(field.data.targetViewId);
+ if (targetView && targetView.props.ContainingCollectionView) {
+ CollectionDockingView.Instance.AddRightSplit(targetView.props.ContainingCollectionView.props.Document);
+ }
+ }
+
+ render() {
+
+ let field = Cast(this.props.Document[this.props.fieldKey], LinkButtonField, new LinkButtonField({ sourceViewId: "-1", targetViewId: "-1" }));
+ let targetView = DocumentManager.Instance.getDocumentViewById(field.data.targetViewId);
+
+ let text = "Could not find link";
+ if (targetView) {
+ let context = targetView.props.ContainingCollectionView ? (" in the context of " + StrCast(targetView.props.ContainingCollectionView.props.Document.title)) : "";
+ text = "Link to " + StrCast(targetView.props.Document.title) + context;
+ }
+
+ let activeDvs = DocumentManager.Instance.DocumentViews.filter(dv => dv.isSelected() || BoolCast(dv.props.Document.libraryBrush, false));
+ let display = activeDvs.reduce((found, dv) => {
+ let matchSv = field.data.sourceViewId === StrCast(dv.props.Document[Id]);
+ let matchTv = field.data.targetViewId === StrCast(dv.props.Document[Id]);
+ let match = matchSv || matchTv;
+ return match || found;
+ }, false);
+
+ return (
+ <div className="linkBox-cont" style={{ display: display ? "block" : "none" }}>
+ <div className="linkBox-cont-wrapper">
+ <p>{text}</p>
+ </div>
+ </div >
+ );
+ }
+} \ No newline at end of file
diff --git a/src/client/views/nodes/LinkMenu.tsx b/src/client/views/nodes/LinkMenu.tsx
index aef56df67..7e4c15312 100644
--- a/src/client/views/nodes/LinkMenu.tsx
+++ b/src/client/views/nodes/LinkMenu.tsx
@@ -1,7 +1,7 @@
import { action, observable } from "mobx";
import { observer } from "mobx-react";
import { DocumentView } from "./DocumentView";
-import { LinkBox } from "./LinkBox";
+import { LinkMenuItem } from "./LinkMenuItem";
import { LinkEditor } from "./LinkEditor";
import './LinkMenu.scss';
import React = require("react");
@@ -23,7 +23,7 @@ export class LinkMenu extends React.Component<Props> {
let source = this.props.docView.Document;
return group.map(linkDoc => {
let destination = LinkManager.Instance.findOppositeAnchor(linkDoc, source);
- return <LinkBox key={destination[Id] + source[Id]} groupType={groupType} linkDoc={linkDoc} sourceDoc={source} destinationDoc={destination} showEditor={action(() => this._editingLink = linkDoc)} />;
+ return <LinkMenuItem key={destination[Id] + source[Id]} groupType={groupType} linkDoc={linkDoc} sourceDoc={source} destinationDoc={destination} showEditor={action(() => this._editingLink = linkDoc)} />;
});
}
diff --git a/src/client/views/nodes/LinkBox.scss b/src/client/views/nodes/LinkMenuItem.scss
index 77462f611..77462f611 100644
--- a/src/client/views/nodes/LinkBox.scss
+++ b/src/client/views/nodes/LinkMenuItem.scss
diff --git a/src/client/views/nodes/LinkBox.tsx b/src/client/views/nodes/LinkMenuItem.tsx
index 8d07547ed..c68365584 100644
--- a/src/client/views/nodes/LinkBox.tsx
+++ b/src/client/views/nodes/LinkMenuItem.tsx
@@ -4,7 +4,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { observer } from "mobx-react";
import { DocumentManager } from "../../util/DocumentManager";
import { undoBatch } from "../../util/UndoManager";
-import './LinkBox.scss';
+import './LinkMenuItem.scss';
import React = require("react");
import { Doc } from '../../../new_fields/Doc';
import { StrCast, Cast } from '../../../new_fields/Types';
@@ -15,7 +15,7 @@ import { SelectionManager } from '../../util/SelectionManager';
library.add(faEye, faEdit, faTimes, faArrowRight, faChevronDown, faChevronUp);
-interface Props {
+interface LinkMenuItemProps {
groupType: string;
linkDoc: Doc;
sourceDoc: Doc;
@@ -24,7 +24,7 @@ interface Props {
}
@observer
-export class LinkBox extends React.Component<Props> {
+export class LinkMenuItem extends React.Component<LinkMenuItemProps> {
private _drag = React.createRef<HTMLDivElement>();
@observable private _showMore: boolean = false;
@action toggleShowMore() { this._showMore = !this._showMore; }