aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2019-03-28 12:59:35 -0400
committerBob Zeleznik <zzzman@gmail.com>2019-03-28 12:59:35 -0400
commitfddd13da196a26affe61b30d93a3fe1b24f391a6 (patch)
treea28175619afaf14b83c98fc6282419f1d1a2c82d
parentcbf88ae3466e17fef57c7d63cc72ee42b75ccce6 (diff)
works better with prototypes and links
-rw-r--r--src/client/util/DocumentManager.ts5
-rw-r--r--src/client/views/collections/CollectionFreeFormView.tsx53
-rw-r--r--src/client/views/collections/CollectionView.tsx4
-rw-r--r--src/client/views/nodes/LinkBox.tsx2
4 files changed, 50 insertions, 14 deletions
diff --git a/src/client/util/DocumentManager.ts b/src/client/util/DocumentManager.ts
index 5bc16343e..28624dba8 100644
--- a/src/client/util/DocumentManager.ts
+++ b/src/client/util/DocumentManager.ts
@@ -26,6 +26,11 @@ export class DocumentManager {
// this.DocumentViews = new Array<DocumentView>();
}
+ public getAllDocumentViews(collection: Document) {
+ return this.DocumentViews.filter(dv =>
+ dv.props.ContainingCollectionView && dv.props.ContainingCollectionView.props.Document == collection);
+ }
+
public getDocumentView(toFind: Document): DocumentView | null {
let toReturn: DocumentView | null;
diff --git a/src/client/views/collections/CollectionFreeFormView.tsx b/src/client/views/collections/CollectionFreeFormView.tsx
index cba1110a1..0843d3670 100644
--- a/src/client/views/collections/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/CollectionFreeFormView.tsx
@@ -1,7 +1,7 @@
import { action, computed, observable, reaction, runInAction } from "mobx";
import { observer } from "mobx-react";
import { Document } from "../../../fields/Document";
-import { FieldWaiting, Field } from "../../../fields/Field";
+import { FieldWaiting, Field, Opt } from "../../../fields/Field";
import { KeyStore } from "../../../fields/KeyStore";
import { ListField } from "../../../fields/ListField";
import { TextField } from "../../../fields/TextField";
@@ -21,6 +21,8 @@ import React = require("react");
import v5 = require("uuid/v5");
import { DocumentManager } from "../../util/DocumentManager";
import { Utils } from "../../../Utils";
+import { Server } from "../../Server";
+import { AverageAggregateParameters } from "../../northstar/model/idea/idea";
@observer
export class CollectionFreeFormView extends CollectionViewBase {
@@ -424,42 +426,71 @@ export class LinksView extends React.Component<CollectionViewProps> {
super(props);
}
- @observable _pairs: { a: Document, b: Document }[] = [];
+ @observable _triples: { a: Document, b: Document, l: Document }[] = [];
findPairs() {
return DocumentManager.Instance.DocumentViews.filter(dv => dv.props.ContainingCollectionView && dv.props.ContainingCollectionView.props.Document === this.props.Document).reduce((pairs, dv) => {
+
+ return DocumentManager.Instance.DocumentViews.reduce((pairs, dv) => {
+ let srcViews = [dv];
+ let srcAnnot = dv.props.Document.GetT(KeyStore.AnnotationOn, Document);
+ if (srcAnnot && srcAnnot != FieldWaiting && srcAnnot instanceof Document) {
+ srcViews = DocumentManager.Instance.getDocumentViews(srcAnnot.GetPrototype() as Document)
+ }
+ srcViews = srcViews.filter(sv =>
+ sv.props.ContainingCollectionView && sv.props.ContainingCollectionView.props.Document == self
+ );
let linksList = dv.props.Document.GetT(KeyStore.LinkedToDocs, ListField);
if (linksList && linksList != FieldWaiting && linksList.Data.length) {
pairs.push(...linksList.Data.reduce((pairs, link) => {
if (link instanceof Document) {
let linkToDoc = link.GetT(KeyStore.LinkedToDocs, Document);
if (linkToDoc && linkToDoc != FieldWaiting) {
- DocumentManager.Instance.getDocumentViews(linkToDoc).map(docView1 =>
- pairs.push({ a: dv.props.Document, b: docView1.props.Document })
- )
+ DocumentManager.Instance.getDocumentViews(linkToDoc).map(docView1 => {
+
+ let targetViews = [docView1];
+ let docAnnot = docView1.props.Document.GetT(KeyStore.AnnotationOn, Document);
+ if (docAnnot && docAnnot != FieldWaiting && docAnnot instanceof Document) {
+ targetViews = DocumentManager.Instance.getDocumentViews(docAnnot.GetPrototype() as Document)
+ }
+ targetViews.filter(tv =>
+ tv.props.ContainingCollectionView && tv.props.ContainingCollectionView.props.Document == self
+ ).map(tv => srcViews.map(sv =>
+ pairs.push({ a: sv.props.Document, b: tv.props.Document, l: link })))
+ })
}
}
return pairs;
- }, [] as { a: Document, b: Document }[]));
+ }, [] as { a: Document, b: Document, l: Document }[]));
}
return pairs;
- }, [] as { a: Document, b: Document }[]);
+ }, [] as { a: Document, b: Document, l: Document }[]);
}
componentDidMount() {
- reaction(() => this.findPairs(), (pairs) => runInAction(() => this._pairs = pairs));
+ reaction(() => this.findPairs(), (pairs) => runInAction(() => this._triples = pairs));
+ }
+
+ onPointerDown(e: React.PointerEvent) {
+ let line = (e.nativeEvent as any).path[0];
+ line.style.stroke = "red";
+ Server.GetField(line.id, action((f: Opt<Field>) => {
+ if (f instanceof Document) {
+ console.log(f.Title);
+ }
+ }));
}
render() {
- if (!this._pairs.length)
+ if (!this._triples.length)
return (null);
return <svg className="collectionfreeformview-svgCanvas">
- {this._pairs.map(pair => {
+ {this._triples.map(pair => {
let x1 = pair.a.GetNumber(KeyStore.X, 0) + pair.a.GetNumber(KeyStore.Width, 0) / 2;
let y1 = pair.a.GetNumber(KeyStore.Y, 0) + pair.a.GetNumber(KeyStore.Height, 0) / 2;
let x2 = pair.b.GetNumber(KeyStore.X, 0) + pair.b.GetNumber(KeyStore.Width, 0) / 2;
let y2 = pair.b.GetNumber(KeyStore.Y, 0) + pair.b.GetNumber(KeyStore.Height, 0) / 2;
return (
- <line key={Utils.GenerateGuid()} className="collectionfreeformview-linkLine"
+ <line key={Utils.GenerateGuid()} id={pair.l.Id} className="collectionfreeformview-linkLine" onPointerDown={this.onPointerDown}
x1={`${x1}`} y1={`${y1}`}
x2={`${x2}`} y2={`${y2}`} />
)
diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx
index 2fa2c9086..789f07e8c 100644
--- a/src/client/views/collections/CollectionView.tsx
+++ b/src/client/views/collections/CollectionView.tsx
@@ -69,9 +69,9 @@ export class CollectionView extends React.Component<CollectionViewProps> {
@action
public static AddDocument(props: CollectionViewProps, doc: Document, allowDuplicates: boolean): boolean {
var curPage = props.Document.GetNumber(KeyStore.CurPage, -1);
- doc.SetNumber(KeyStore.Page, curPage);
+ doc.SetOnPrototype(KeyStore.Page, new NumberField(curPage));
if (curPage > 0) {
- doc.Set(KeyStore.AnnotationOn, props.Document);
+ doc.SetOnPrototype(KeyStore.AnnotationOn, props.Document);
}
if (props.Document.Get(props.fieldKey) instanceof Field) {
//TODO This won't create the field if it doesn't already exist
diff --git a/src/client/views/nodes/LinkBox.tsx b/src/client/views/nodes/LinkBox.tsx
index 457fecee3..e81f8fec7 100644
--- a/src/client/views/nodes/LinkBox.tsx
+++ b/src/client/views/nodes/LinkBox.tsx
@@ -45,7 +45,7 @@ export class LinkBox extends React.Component<Props> {
} else {
this.props.pairedDoc.GetAsync(KeyStore.AnnotationOn, (contextDoc: any) => {
if (!contextDoc) {
- CollectionDockingView.Instance.AddRightSplit(this.props.pairedDoc);
+ CollectionDockingView.Instance.AddRightSplit(this.props.pairedDoc.MakeDelegate());
} else if (contextDoc instanceof Document) {
this.props.pairedDoc.GetTAsync(KeyStore.Page, NumberField).then((pfield: any) => {
contextDoc.GetTAsync(KeyStore.CurPage, NumberField).then((cfield: any) => {