diff options
author | Monika Hedman <monika_hedman@brown.edu> | 2019-02-19 19:01:28 -0500 |
---|---|---|
committer | Monika Hedman <monika_hedman@brown.edu> | 2019-02-19 19:01:28 -0500 |
commit | f2bdae28c9fcd5306b0d14e1bbfafc2bb232aed8 (patch) | |
tree | 8c4c3f21975329f9079aeb96b49a4db73fc40fa1 /src | |
parent | 0ac7f12d00273003b0d0ca87df7bf553fa2e93c0 (diff) |
got width and height!!!
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/DocumentManager.tsx | 57 | ||||
-rw-r--r-- | src/client/views/Main.tsx | 4 | ||||
-rw-r--r-- | src/client/views/TempTreeView.scss | 2 | ||||
-rw-r--r-- | src/client/views/TempTreeView.tsx | 26 | ||||
-rw-r--r-- | src/client/views/collections/CollectionViewBase.tsx | 1 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentView.tsx | 22 |
6 files changed, 45 insertions, 67 deletions
diff --git a/src/client/views/DocumentManager.tsx b/src/client/views/DocumentManager.tsx index 81231bf13..3aa185dd3 100644 --- a/src/client/views/DocumentManager.tsx +++ b/src/client/views/DocumentManager.tsx @@ -12,7 +12,7 @@ export class DocumentManager { //global holds all of the nodes (regardless of which collection they're in) @observable - public DocumentViews: DocumentView[]; + public DocumentViews: DocumentView[] = []; // singleton instance private static _instance: DocumentManager; @@ -24,7 +24,7 @@ export class DocumentManager { //private constructor so no other class can create a nodemanager private constructor() { - this.DocumentViews = new Array<DocumentView>(); + // this.DocumentViews = new Array<DocumentView>(); } public getDocumentView(toFind: Document): DocumentView | null { @@ -91,17 +91,12 @@ export class DocumentManager { let height: number; //if the view exists in a freeform collection - if (docView != null) { - //view.props.GetTransform().TranslateX - width = docView.props.Document.GetNumber(KeyStore.Width, 0) - height = docView.props.Document.GetNumber(KeyStore.Height, 0) + if (docView && docView.MainContent.current) { + width = docView.MainContent.current.clientWidth + height = docView.MainContent.current.clientHeight //base case: parent of parent does not exist if (docView.props.ContainingCollectionView == null) { - // scale = RootStore.Instance.MainNodeCollection.Scale; - // XView = (-node.X * scale) + (window.innerWidth / 2) - (node.Width * scale / 2); - // YView = (-node.Y * scale) + (window.innerHeight / 2) - (node.Height * scale / 2); - // RootStore.Instance.MainNodeCollection.SetViewportXY(XView, YView); scale = docView.props.ScreenToLocalTransform().Scale XView = (-docView.props.ScreenToLocalTransform().TranslateX * scale) + (window.innerWidth / 2) - (width * scale / 2) YView = (-docView.props.ScreenToLocalTransform().TranslateY * scale) + (window.innerHeight / 2) - (height * scale / 2) @@ -109,37 +104,17 @@ export class DocumentManager { } //parent is not main, parent is centered and calls itself else { - console.log("------------------------------------------") - console.log(docView.props.ContainingCollectionView.props.DocumentForCollection.Title) - console.log("------------------------------------------") - console.log("parent does exist") - if (docView.props.ContainingCollectionView.props.DocumentForCollection != null) { - console.log("view of parent exists") + if (docView.props.ContainingCollectionView.props.ContainingDocumentView && docView.props.ContainingCollectionView.props.ContainingDocumentView.MainContent.current) { + //view of parent + let tempCollectionView = docView.props.ContainingCollectionView.props.ContainingDocumentView - let tempView = this.getDocumentView(docView.props.ContainingCollectionView.props.DocumentForCollection) + let parentWidth = docView.props.ContainingCollectionView.props.ContainingDocumentView.MainContent.current.clientWidth + let parentHeight = docView.props.ContainingCollectionView.props.ContainingDocumentView.MainContent.current.clientHeight - //console.log(docView.props.ContainingCollectionView.props.DocumentForCollection.GetNumber(KeyStore.NativeWidth, 0)) - - // let parentWidth = docView.props.ContainingCollectionView.props.DocumentForCollection.GetNumber(KeyStore.Width, 0) - // let parentHeight = docView.props.ContainingCollectionView.props.DocumentForCollection.GetNumber(KeyStore.Height, 0) - - let parentWidth = docView.props.ContainingCollectionView.props.DocumentForCollection.GetNumber(KeyStore.Width, 0) - let parentHeight = docView.props.ContainingCollectionView.props.DocumentForCollection.GetNumber(KeyStore.Height, 0) - //_htmlElement!.clientWidth - - // console.log("window width: " + window.innerWidth + ", window height: " + window.innerHeight) - // console.log("parent width: " + parentWidth + ", parent height: " + parentHeight) - - - if (tempView != null) { - console.log("View is NOT null") - scale = tempView.props.ScreenToLocalTransform().Scale - - parentWidth *= scale - parentHeight *= scale - - console.log("window width: " + window.innerWidth + ", window height: " + window.innerHeight) - console.log("parent width: " + parentWidth + ", parent height: " + parentHeight) + //make sure to test if the parent view is a freeform view + if (tempCollectionView) { + //scale of parent + scale = tempCollectionView.props.ScreenToLocalTransform().Scale XView = (-docView.props.ScreenToLocalTransform().TranslateX * scale) + (parentWidth / 2) - (width * scale / 2); YView = (-docView.props.ScreenToLocalTransform().TranslateY * scale) + (parentHeight / 2) - (height * scale / 2); @@ -153,6 +128,10 @@ export class DocumentManager { } } + parentIsFreeform(node: any): boolean { + return node.props.ContainingCollectionView instanceof CollectionFreeFormView + } + private setViewportXY(collection: CollectionViewBase, x: number, y: number) { if (collection.props.BackgroundView != null) { collection.props.ScreenToLocalTransform().center(x, y) diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx index 0532cbc1f..5f7590f8d 100644 --- a/src/client/views/Main.tsx +++ b/src/client/views/Main.tsx @@ -72,11 +72,11 @@ let mainNodes = mainContainer.GetOrCreate<ListField<Document>>(KeyStore.Data, Li // mainNodes.Data.push(doc6); // mainNodes.Data.push(doc2); mainNodes.Data.push(doc4); -mainNodes.Data.push(doc3); +// mainNodes.Data.push(doc3); // mainNodes.Data.push(doc5); // mainNodes.Data.push(doc1); // mainNodes.Data.push(doc2); -mainNodes.Data.push(doc6); +// mainNodes.Data.push(doc6); //} //); diff --git a/src/client/views/TempTreeView.scss b/src/client/views/TempTreeView.scss index c50b5be2c..fe8cf4da8 100644 --- a/src/client/views/TempTreeView.scss +++ b/src/client/views/TempTreeView.scss @@ -1,7 +1,7 @@ .temptree { background: #ADD8E6; width: 300px; - height: 100px; + height: 200px; z-index: 100; position: fixed; bottom: 0px; diff --git a/src/client/views/TempTreeView.tsx b/src/client/views/TempTreeView.tsx index 2d02f3fde..4b1650ac5 100644 --- a/src/client/views/TempTreeView.tsx +++ b/src/client/views/TempTreeView.tsx @@ -1,4 +1,4 @@ -import { observable, computed } from "mobx"; +import { action, observable, computed } from "mobx"; import React = require("react"); import { observer } from "mobx-react"; import { Document } from "../../fields/Document"; @@ -13,23 +13,16 @@ export interface IProps { @observer export class TempTreeView extends React.Component<IProps>{ + @action onClick(doc: Document) { + let view = DocumentManager.Instance.getDocumentView(doc); if (view != null) { - //console.log(view.Id) - //console.log(view.props.GetTransform().TranslateX) - DocumentManager.Instance.centerNode(view); - console.log(view.props.Document.Title) - if (view.props.ContainingCollectionView != undefined) { - //console.log(view.props.ContainingCollectionView.Id) - // view.props.ContainingCollectionView - } - else { - console.log("containing collection is undefined") + if (DocumentManager.Instance.parentIsFreeform(view)) { + view.switchColor() } - - view.switchColor(); + DocumentManager.Instance.centerNode(view); } } @@ -37,10 +30,10 @@ export class TempTreeView extends React.Component<IProps>{ return ( <div className="tempTree"> <div className="list"> - {this.props.mainCollection.map(doc => { + {DocumentManager.Instance.DocumentViews.map(doc => { return ( - <div key={doc.Id} onClick={() => { this.onClick(doc) }}> - {doc.Title} + <div key={doc.Id} onClick={() => { this.onClick(doc.props.Document) }}> + {doc.props.Document.Title} </div> ) } @@ -49,5 +42,4 @@ export class TempTreeView extends React.Component<IProps>{ </div> ); } - }
\ No newline at end of file diff --git a/src/client/views/collections/CollectionViewBase.tsx b/src/client/views/collections/CollectionViewBase.tsx index 4cbafe950..35ba227e9 100644 --- a/src/client/views/collections/CollectionViewBase.tsx +++ b/src/client/views/collections/CollectionViewBase.tsx @@ -12,7 +12,6 @@ import { CollectionDockingView } from "./CollectionDockingView"; import { CollectionFreeFormDocumentView } from "../nodes/CollectionFreeFormDocumentView"; import { Transform } from "../../util/Transform"; - export interface CollectionViewProps { CollectionFieldKey: Key; DocumentForCollection: Document; diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index 9bd8c0288..8e2f1afe7 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -1,4 +1,4 @@ -import { action, computed } from "mobx"; +import { action, computed, runInAction } from "mobx"; import { observer } from "mobx-react"; import { observable } from "mobx"; import { Document } from "../../../fields/Document"; @@ -179,11 +179,11 @@ export class DocumentView extends React.Component<DocumentViewProps> { ContextMenu.Instance.displayMenu(e.pageX - 15, e.pageY - 15) } + //TODO Monika @action Center = (e: React.MouseEvent): void => { DocumentManager.Instance.centerNode(this.props.Document) DocumentManager.Instance.centerNode(this) - //console.log(this.props.ContainingCollectionView.props.) } @action @@ -230,17 +230,23 @@ export class DocumentView extends React.Component<DocumentViewProps> { } //adds doc to global list + @action componentDidMount: () => void = () => { - DocumentManager.Instance.DocumentViews.push(this); + runInAction(() => { + DocumentManager.Instance.DocumentViews.push(this); + }) } //removes doc from global list + @action componentWillUnmount: () => void = () => { - for (let node of DocumentManager.Instance.DocumentViews) { - if (Object.is(node, this)) { - DocumentManager.Instance.DocumentViews.splice(DocumentManager.Instance.DocumentViews.indexOf(this), 1); + runInAction(() => { + for (let node of DocumentManager.Instance.DocumentViews) { + if (Object.is(node, this)) { + DocumentManager.Instance.DocumentViews.splice(DocumentManager.Instance.DocumentViews.indexOf(this), 1); + } } - } + }) } isSelected = () => { return SelectionManager.IsSelected(this); @@ -278,6 +284,8 @@ export class DocumentView extends React.Component<DocumentViewProps> { bindings.BackgroundView = backgroundView; } + bindings.DocumentView = this; + var width = this.props.Document.GetNumber(KeyStore.NativeWidth, 0); var strwidth = width > 0 ? width.toString() + "px" : "100%"; var height = this.props.Document.GetNumber(KeyStore.NativeHeight, 0); |