From e6265a20f4c5d2619aa06cef6ee9442c0fd6bb41 Mon Sep 17 00:00:00 2001 From: Hannah Chow Date: Thu, 28 Feb 2019 01:09:26 -0500 Subject: first pass at linking drag and drop --- src/fields/KeyStore.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/fields') diff --git a/src/fields/KeyStore.ts b/src/fields/KeyStore.ts index a3b39735d..9c3dab6de 100644 --- a/src/fields/KeyStore.ts +++ b/src/fields/KeyStore.ts @@ -26,4 +26,6 @@ export namespace KeyStore { export const Caption = new Key("Caption"); export const ActiveFrame = new Key("ActiveFrame"); export const DocumentText = new Key("DocumentText"); + export const LinkedToDocs = new Key("LinkedToDocs"); + export const LinkedFromDocs = new Key("LinkedFromDocs"); } -- cgit v1.2.3-70-g09d2 From 406ffebb6f38a67f829df094465ecf3bd5c37f03 Mon Sep 17 00:00:00 2001 From: Hannah Chow Date: Tue, 5 Mar 2019 18:10:45 -0500 Subject: underlying link structure set up --- src/client/views/nodes/DocumentView.tsx | 8 +++++--- src/fields/KeyStore.ts | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/fields') diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index d31441399..e69485b9a 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -20,6 +20,7 @@ import { KeyValueBox } from "./KeyValueBox" import { WebBox } from "../nodes/WebBox"; import "./DocumentView.scss"; import React = require("react"); +import { TextField } from "../../../fields/TextField"; const JsxParser = require('react-jsx-parser').default; //TODO Why does this need to be imported like this? @@ -109,7 +110,6 @@ export class DocumentView extends React.Component { } } } -<<<<<<< HEAD private dropDisposer?: DragManager.DragDropDisposer; protected createDropTarget = (ele: HTMLDivElement) => { @@ -137,8 +137,6 @@ export class DocumentView extends React.Component { } } -======= ->>>>>>> bb1d3120f11a47e9d493202c1003dae52bf6667f onPointerMove = (e: PointerEvent): void => { if (e.cancelBubble) { return; @@ -208,6 +206,10 @@ export class DocumentView extends React.Component { let destDoc: Document = this.props.Document; let linkDoc: Document = new Document(); + linkDoc.Set(KeyStore.Title, new TextField("New Link")); + linkDoc.Set(KeyStore.LinkDescription, new TextField("")); + linkDoc.Set(KeyStore.LinkTags, new TextField("Default")); + sourceDoc.GetOrCreateAsync(KeyStore.LinkedToDocs, ListField, field => { (field as ListField).Data.push(linkDoc) }); linkDoc.GetOrCreateAsync(KeyStore.LinkedToDocs, ListField, field => { (field as ListField).Data.push(destDoc) }); destDoc.GetOrCreateAsync(KeyStore.LinkedFromDocs, ListField, field => { (field as ListField).Data.push(linkDoc) }); diff --git a/src/fields/KeyStore.ts b/src/fields/KeyStore.ts index 9c3dab6de..27f0c28f5 100644 --- a/src/fields/KeyStore.ts +++ b/src/fields/KeyStore.ts @@ -28,4 +28,6 @@ export namespace KeyStore { export const DocumentText = new Key("DocumentText"); export const LinkedToDocs = new Key("LinkedToDocs"); export const LinkedFromDocs = new Key("LinkedFromDocs"); + export const LinkDescription = new Key("LinkDescription"); + export const LinkTags = new Key("LinkTag"); } -- cgit v1.2.3-70-g09d2 From 2a7ecc8e179a8020c291da9ed84c877402dbd2f9 Mon Sep 17 00:00:00 2001 From: Hannah Chow Date: Thu, 7 Mar 2019 01:11:32 -0500 Subject: delete working --- src/client/views/nodes/DocumentView.tsx | 4 ++-- src/client/views/nodes/LinkBox.tsx | 23 ++++++++++++++++++----- src/client/views/nodes/LinkMenu.tsx | 1 + src/fields/Document.ts | 8 +++++++- 4 files changed, 28 insertions(+), 8 deletions(-) (limited to 'src/fields') diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index 220f7017e..c9afbb150 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -214,9 +214,9 @@ export class DocumentView extends React.Component { linkDoc.Set(KeyStore.LinkTags, new TextField("Default")); sourceDoc.GetOrCreateAsync(KeyStore.LinkedToDocs, ListField, field => { (field as ListField).Data.push(linkDoc) }); - linkDoc.GetOrCreateAsync(KeyStore.LinkedToDocs, ListField, field => { (field as ListField).Data.push(destDoc) }); + linkDoc.Set(KeyStore.LinkedToDocs, destDoc); destDoc.GetOrCreateAsync(KeyStore.LinkedFromDocs, ListField, field => { (field as ListField).Data.push(linkDoc) }); - linkDoc.GetOrCreateAsync(KeyStore.LinkedFromDocs, ListField, field => { (field as ListField).Data.push(sourceDoc) }); + linkDoc.Set(KeyStore.LinkedFromDocs, sourceDoc); diff --git a/src/client/views/nodes/LinkBox.tsx b/src/client/views/nodes/LinkBox.tsx index d6cb1f612..d493c55e7 100644 --- a/src/client/views/nodes/LinkBox.tsx +++ b/src/client/views/nodes/LinkBox.tsx @@ -31,11 +31,24 @@ export class LinkBox extends React.Component { onDeleteButtonPressed = (e: React.PointerEvent): void => { console.log("delete down"); e.stopPropagation(); - let linkToDoc: Document = this.props.linkDoc.GetData(KeyStore.LinkedToDocs, ListField, [])[0]; - let linkFromDoc: Document = this.props.linkDoc.GetData(KeyStore.LinkedFromDocs, ListField, [])[0]; - - // let linkToDocFromDocs: Document[] = linkToDoc.GetData(KeyStore.LinkedFromDocs, ListField, []); - // linkToDocFromDocs. + this.props.linkDoc.GetTAsync(KeyStore.LinkedFromDocs, Document, field => { + if (field) { + field.GetTAsync>(KeyStore.LinkedToDocs, ListField, field => { + if (field) { + field.Data.splice(field.Data.indexOf(this.props.linkDoc)); + } + }) + } + }); + this.props.linkDoc.GetTAsync(KeyStore.LinkedToDocs, Document, field => { + if (field) { + field.GetTAsync>(KeyStore.LinkedFromDocs, ListField, field => { + if (field) { + field.Data.splice(field.Data.indexOf(this.props.linkDoc)); + } + }) + } + }); } render() { diff --git a/src/client/views/nodes/LinkMenu.tsx b/src/client/views/nodes/LinkMenu.tsx index 4a1f49864..d0909e266 100644 --- a/src/client/views/nodes/LinkMenu.tsx +++ b/src/client/views/nodes/LinkMenu.tsx @@ -34,6 +34,7 @@ export class LinkMenu extends React.Component { })} {linkFrom.map(link => { + let name = link.GetData(KeyStore.Title, TextField, new String); return })} diff --git a/src/fields/Document.ts b/src/fields/Document.ts index 2e873439c..25e239417 100644 --- a/src/fields/Document.ts +++ b/src/fields/Document.ts @@ -1,6 +1,6 @@ import { Key } from "./Key" import { KeyStore } from "./KeyStore"; -import { Field, Cast, FieldWaiting, FieldValue, FieldId } from "./Field" +import { Field, Cast, FieldWaiting, FieldValue, FieldId, Opt } from "./Field" import { NumberField } from "./NumberField"; import { ObservableMap, computed, action } from "mobx"; import { TextField } from "./TextField"; @@ -128,6 +128,12 @@ export class Document extends Field { return false; } + GetTAsync(key: Key, ctor: { new(): T }, callback: (field: Opt) => void): boolean { + return this.GetAsync(key, (field) => { + callback(Cast(field, ctor)); + }) + } + /** * Same as {@link Document#GetAsync}, except a field of the given type * will be created if there is no field associated with the given key, -- cgit v1.2.3-70-g09d2