aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-02-19 05:19:50 -0500
committerTyler Schicke <tyler_schicke@brown.edu>2019-02-19 05:19:50 -0500
commitec2b0b56058fce137ff28ae3ec125f9e695f315c (patch)
treed29365b0969149dfc8f8bb2931482acc52f664db /src
parent70f0ba1275fa879e86d05c1aa3bb5b1567e3d04c (diff)
Changed some names, added some comments, and got rid of some unused stuff
Diffstat (limited to 'src')
-rw-r--r--src/client/views/Main.tsx2
-rw-r--r--src/client/views/collections/CollectionDockingView.tsx15
-rw-r--r--src/client/views/collections/CollectionFreeFormView.tsx42
-rw-r--r--src/client/views/collections/CollectionSchemaView.tsx4
-rw-r--r--src/client/views/collections/CollectionViewBase.tsx13
-rw-r--r--src/client/views/nodes/DocumentView.tsx8
6 files changed, 44 insertions, 40 deletions
diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx
index 1eeec7ff5..c3a9f1906 100644
--- a/src/client/views/Main.tsx
+++ b/src/client/views/Main.tsx
@@ -86,7 +86,7 @@ ReactDOM.render((
AddDocument={undefined} RemoveDocument={undefined} ScreenToLocalTransform={() => Transform.Identity}
Scaling={1}
isTopMost={true}
- ContainingCollectionView={undefined} DocumentView={undefined} />
+ ContainingCollectionView={undefined} />
<DocumentDecorations />
<ContextMenu />
</div>),
diff --git a/src/client/views/collections/CollectionDockingView.tsx b/src/client/views/collections/CollectionDockingView.tsx
index 1c1f6f8b4..05e1ea90a 100644
--- a/src/client/views/collections/CollectionDockingView.tsx
+++ b/src/client/views/collections/CollectionDockingView.tsx
@@ -25,7 +25,7 @@ export class CollectionDockingView extends CollectionViewBase {
private _containerRef = React.createRef<HTMLDivElement>();
@computed
private get modelForFlexLayout() {
- const { CollectionFieldKey: fieldKey, DocumentForCollection: Document } = this.props;
+ const { fieldKey: fieldKey, Document: Document } = this.props;
const value: Document[] = Document.GetData(fieldKey, ListField, []);
var docs = value.map(doc => {
return { type: 'tabset', weight: 50, selected: 0, children: [{ type: "tab", name: doc.Title, component: doc.Id }] };
@@ -40,8 +40,8 @@ export class CollectionDockingView extends CollectionViewBase {
});
}
@computed
- private get modelForGoldenLayout(): any {
- const { CollectionFieldKey: fieldKey, DocumentForCollection: Document } = this.props;
+ private get modelForGoldenLayout(): GoldenLayout {
+ const { fieldKey: fieldKey, Document: Document } = this.props;
const value: Document[] = Document.GetData(fieldKey, ListField, []);
var docs = value.map(doc => {
return { type: 'component', componentName: 'documentViewComponent', componentState: { doc: doc, scaling: 1 } };
@@ -92,7 +92,7 @@ export class CollectionDockingView extends CollectionViewBase {
if (component === "button") {
return <button>{node.getName()}</button>;
}
- const { CollectionFieldKey: fieldKey, DocumentForCollection: Document } = this.props;
+ const { fieldKey: fieldKey, Document: Document } = this.props;
const value: Document[] = Document.GetData(fieldKey, ListField, []);
for (var i: number = 0; i < value.length; i++) {
if (value[i].Id === component) {
@@ -101,7 +101,7 @@ export class CollectionDockingView extends CollectionViewBase {
ScreenToLocalTransform={() => Transform.Identity}
isTopMost={true}
Scaling={1}
- ContainingCollectionView={this} DocumentView={undefined} />);
+ ContainingCollectionView={this} />);
}
}
if (component === "text") {
@@ -262,9 +262,10 @@ export class CollectionDockingView extends CollectionViewBase {
render() {
- const { CollectionFieldKey: fieldKey, DocumentForCollection: Document } = this.props;
+ const { fieldKey: fieldKey, Document: Document } = this.props;
const value: Document[] = Document.GetData(fieldKey, ListField, []);
// bcz: not sure why, but I need these to force the flexlayout to update when the collection size changes.
+ // tfs: we should be able to use this.props.ScreenToLocalTransform to get s right?
var s = this.props.ContainingDocumentView != undefined ? this.props.ContainingDocumentView!.ScalingToScreenSpace : 1;
var w = Document.GetNumber(KeyStore.Width, 0) / s;
var h = Document.GetNumber(KeyStore.Height, 0) / s;
@@ -314,7 +315,7 @@ export class RenderClass extends React.Component<DockingProps> {
return this.props.CollectionDockingView.props.ScreenToLocalTransform().translate(-translateX, -translateY).scale(scale)
}}
isTopMost={true}
- ContainingCollectionView={this.props.CollectionDockingView} DocumentView={undefined} />
+ ContainingCollectionView={this.props.CollectionDockingView} />
if (nativeWidth > 0 && (layout.indexOf("CollectionFreeForm") == -1 || layout.indexOf("AnnotationsKey") != -1)) {
return <Measure onResize={
diff --git a/src/client/views/collections/CollectionFreeFormView.tsx b/src/client/views/collections/CollectionFreeFormView.tsx
index eca8a0adf..2c0a3f478 100644
--- a/src/client/views/collections/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/CollectionFreeFormView.tsx
@@ -31,18 +31,18 @@ export class CollectionFreeFormView extends CollectionViewBase {
}
@computed
- get isAnnotationOverlay() { return this.props.CollectionFieldKey == KeyStore.Annotations; }
+ get isAnnotationOverlay() { return this.props.fieldKey == KeyStore.Annotations; }
@computed
- get nativeWidth() { return this.props.DocumentForCollection.GetNumber(KeyStore.NativeWidth, 0); }
+ get nativeWidth() { return this.props.Document.GetNumber(KeyStore.NativeWidth, 0); }
@computed
- get nativeHeight() { return this.props.DocumentForCollection.GetNumber(KeyStore.NativeHeight, 0); }
+ get nativeHeight() { return this.props.Document.GetNumber(KeyStore.NativeHeight, 0); }
@computed
- get zoomScaling() { return this.props.DocumentForCollection.GetNumber(KeyStore.Scale, 1); }
+ get zoomScaling() { return this.props.Document.GetNumber(KeyStore.Scale, 1); }
@computed
- get resizeScaling() { return this.isAnnotationOverlay ? this.props.DocumentForCollection.GetNumber(KeyStore.Width, 0) / this.nativeWidth : 1; }
+ get resizeScaling() { return this.isAnnotationOverlay ? this.props.Document.GetNumber(KeyStore.Width, 0) / this.nativeWidth : 1; }
@action
drop = (e: Event, de: DragManager.DropEvent) => {
@@ -105,8 +105,8 @@ export class CollectionFreeFormView extends CollectionViewBase {
if (!e.cancelBubble && this.active) {
e.preventDefault();
e.stopPropagation();
- let x = this.props.DocumentForCollection.GetNumber(KeyStore.PanX, 0);
- let y = this.props.DocumentForCollection.GetNumber(KeyStore.PanY, 0);
+ let x = this.props.Document.GetNumber(KeyStore.PanX, 0);
+ let y = this.props.Document.GetNumber(KeyStore.PanY, 0);
let [dx, dy] = this.props.ScreenToLocalTransform().transformDirection(e.clientX - this._lastX, e.clientY - this._lastY);
this.SetPan(x + dx, y + dy);
@@ -131,7 +131,7 @@ export class CollectionFreeFormView extends CollectionViewBase {
let localTransform = this.getLocalTransform();
localTransform = localTransform.inverse().scaleAbout(deltaScale, x, y)
- this.props.DocumentForCollection.SetNumber(KeyStore.Scale, localTransform.Scale);
+ this.props.Document.SetNumber(KeyStore.Scale, localTransform.Scale);
this.SetPan(localTransform.TranslateX, localTransform.TranslateY);
}
@@ -139,8 +139,8 @@ export class CollectionFreeFormView extends CollectionViewBase {
private SetPan(panX: number, panY: number) {
const newPanX = Math.max((1 - this.zoomScaling) * this.nativeWidth, Math.min(0, panX));
const newPanY = Math.max((1 - this.zoomScaling) * this.nativeHeight, Math.min(0, panY));
- this.props.DocumentForCollection.SetNumber(KeyStore.PanX, this.isAnnotationOverlay ? newPanX : panX);
- this.props.DocumentForCollection.SetNumber(KeyStore.PanY, this.isAnnotationOverlay ? newPanY : panY);
+ this.props.Document.SetNumber(KeyStore.PanX, this.isAnnotationOverlay ? newPanX : panX);
+ this.props.Document.SetNumber(KeyStore.PanY, this.isAnnotationOverlay ? newPanY : panY);
}
@action
@@ -150,8 +150,8 @@ export class CollectionFreeFormView extends CollectionViewBase {
let fReader = new FileReader()
let file = e.dataTransfer.items[0].getAsFile();
let that = this;
- const panx: number = this.props.DocumentForCollection.GetNumber(KeyStore.PanX, 0);
- const pany: number = this.props.DocumentForCollection.GetNumber(KeyStore.PanY, 0);
+ const panx: number = this.props.Document.GetNumber(KeyStore.PanX, 0);
+ const pany: number = this.props.Document.GetNumber(KeyStore.PanY, 0);
let x = e.pageX - panx
let y = e.pageY - pany
@@ -161,11 +161,11 @@ export class CollectionFreeFormView extends CollectionViewBase {
let doc = Documents.ImageDocument(url, {
x: x, y: y
})
- let docs = that.props.DocumentForCollection.GetT(KeyStore.Data, ListField);
+ let docs = that.props.Document.GetT(KeyStore.Data, ListField);
if (docs != FieldWaiting) {
if (!docs) {
docs = new ListField<Document>();
- that.props.DocumentForCollection.Set(KeyStore.Data, docs)
+ that.props.Document.Set(KeyStore.Data, docs)
}
docs.Data.push(doc);
}
@@ -182,7 +182,7 @@ export class CollectionFreeFormView extends CollectionViewBase {
@action
bringToFront(doc: DocumentView) {
- const { CollectionFieldKey: fieldKey, DocumentForCollection: Document } = this.props;
+ const { fieldKey: fieldKey, Document: Document } = this.props;
const value: Document[] = Document.GetList<Document>(fieldKey, []);
var topmost = value.reduce((topmost, d) => Math.max(d.GetNumber(KeyStore.ZIndex, 0), topmost), -1000);
@@ -200,14 +200,14 @@ export class CollectionFreeFormView extends CollectionViewBase {
@computed
get translate(): [number, number] {
- const x = this.props.DocumentForCollection.GetNumber(KeyStore.PanX, 0);
- const y = this.props.DocumentForCollection.GetNumber(KeyStore.PanY, 0);
+ const x = this.props.Document.GetNumber(KeyStore.PanX, 0);
+ const y = this.props.Document.GetNumber(KeyStore.PanY, 0);
return [x, y];
}
@computed
get scale(): number {
- return this.props.DocumentForCollection.GetNumber(KeyStore.Scale, 1);
+ return this.props.Document.GetNumber(KeyStore.Scale, 1);
}
getTransform = (): Transform => {
@@ -220,8 +220,8 @@ export class CollectionFreeFormView extends CollectionViewBase {
}
render() {
- const Document: Document = this.props.DocumentForCollection;
- const value: Document[] = Document.GetList<Document>(this.props.CollectionFieldKey, []);
+ const Document: Document = this.props.Document;
+ const value: Document[] = Document.GetList<Document>(this.props.fieldKey, []);
const panx: number = Document.GetNumber(KeyStore.PanX, 0);
const pany: number = Document.GetNumber(KeyStore.PanY, 0);
var me = this;
@@ -249,7 +249,7 @@ export class CollectionFreeFormView extends CollectionViewBase {
ScreenToLocalTransform={this.getTransform}
isTopMost={false}
Scaling={1}
- ContainingCollectionView={this} DocumentView={this.props.ContainingDocumentView} />);
+ ContainingCollectionView={this} />);
})}
</div>
</div>
diff --git a/src/client/views/collections/CollectionSchemaView.tsx b/src/client/views/collections/CollectionSchemaView.tsx
index 9a0ce0782..5c95aca99 100644
--- a/src/client/views/collections/CollectionSchemaView.tsx
+++ b/src/client/views/collections/CollectionSchemaView.tsx
@@ -104,7 +104,7 @@ export class CollectionSchemaView extends CollectionViewBase {
@observable
private _parentScaling = 1; // used to transfer the dimensions of the content pane in the DOM to the ParentScaling prop of the DocumentView
render() {
- const { DocumentForCollection: Document, CollectionFieldKey: fieldKey } = this.props;
+ const { Document: Document, fieldKey: fieldKey } = this.props;
const children = Document.GetList<Document>(fieldKey, []);
const columns = Document.GetList(KS.ColumnsKey,
[KS.Title, KS.Data, KS.Author])
@@ -126,7 +126,7 @@ export class CollectionSchemaView extends CollectionViewBase {
ScreenToLocalTransform={() => Transform.Identity}//TODO This should probably be an actual transform
Scaling={this._parentScaling}
isTopMost={false}
- DocumentView={undefined} ContainingCollectionView={me} />
+ ContainingCollectionView={me} />
</div>
}
</Measure>
diff --git a/src/client/views/collections/CollectionViewBase.tsx b/src/client/views/collections/CollectionViewBase.tsx
index 4cbafe950..5dd10722d 100644
--- a/src/client/views/collections/CollectionViewBase.tsx
+++ b/src/client/views/collections/CollectionViewBase.tsx
@@ -14,15 +14,14 @@ import { Transform } from "../../util/Transform";
export interface CollectionViewProps {
- CollectionFieldKey: Key;
- DocumentForCollection: Document;
+ fieldKey: Key;
+ Document: Document;
ContainingDocumentView: Opt<DocumentView>;
ScreenToLocalTransform: () => Transform;
isSelected: () => boolean;
isTopMost: boolean;
select: (ctrlPressed: boolean) => void;
BackgroundView?: () => JSX.Element;
- ParentScaling: number;
}
export const COLLECTION_BORDER_WIDTH = 2;
@@ -31,8 +30,8 @@ export const COLLECTION_BORDER_WIDTH = 2;
export class CollectionViewBase extends React.Component<CollectionViewProps> {
public static LayoutString(collectionType: string, fieldKey: string = "DataKey") {
- return `<${collectionType} Scaling={Scaling} DocumentForCollection={Document}
- ScreenToLocalTransform={ScreenToLocalTransform} CollectionFieldKey={${fieldKey}} isSelected={isSelected} select={select}
+ return `<${collectionType} Document={Document}
+ ScreenToLocalTransform={ScreenToLocalTransform} fieldKey={${fieldKey}} isSelected={isSelected} select={select}
isTopMost={isTopMost}
ContainingDocumentView={DocumentView} BackgroundView={BackgroundView} />`;
}
@@ -46,14 +45,14 @@ export class CollectionViewBase extends React.Component<CollectionViewProps> {
@action
addDocument = (doc: Document): void => {
//TODO This won't create the field if it doesn't already exist
- const value = this.props.DocumentForCollection.GetData(this.props.CollectionFieldKey, ListField, new Array<Document>())
+ const value = this.props.Document.GetData(this.props.fieldKey, ListField, new Array<Document>())
value.push(doc);
}
@action
removeDocument = (doc: Document): boolean => {
//TODO This won't create the field if it doesn't already exist
- const value = this.props.DocumentForCollection.GetData(this.props.CollectionFieldKey, ListField, new Array<Document>())
+ const value = this.props.Document.GetData(this.props.fieldKey, ListField, new Array<Document>())
let index = value.indexOf(doc);
if (index !== -1) {
value.splice(index, 1)
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index f368fdeaf..14268c644 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -21,7 +21,6 @@ import { TextField } from "../../../fields/TextField";
const JsxParser = require('react-jsx-parser').default;//TODO Why does this need to be imported like this?
export interface DocumentViewProps {
- DocumentView: Opt<DocumentView> // needed only to set ContainingDocumentView on CollectionViewProps when invoked from JsxParser -- is there a better way?
ContainingCollectionView: Opt<CollectionViewBase>;
Document: Document;
@@ -29,6 +28,7 @@ export interface DocumentViewProps {
RemoveDocument?: (doc: Document) => boolean;
ScreenToLocalTransform: () => Transform;
isTopMost: boolean;
+ //tfs: This shouldn't be necessary I don't think
Scaling: number;
}
@@ -198,12 +198,13 @@ export class DocumentView extends React.Component<DocumentViewProps> {
//
// returns the cumulative scaling between the document and the screen
+ // tfs: I don't think this should be necessary
//
@computed
public get ScalingToScreenSpace(): number {
if (this.props.ContainingCollectionView != undefined &&
this.props.ContainingCollectionView.props.ContainingDocumentView != undefined) {
- let ss = this.props.ContainingCollectionView.props.DocumentForCollection.GetNumber(KeyStore.Scale, 1);
+ let ss = this.props.ContainingCollectionView.props.Document.GetNumber(KeyStore.Scale, 1);
return this.props.ContainingCollectionView.props.ContainingDocumentView.ScalingToScreenSpace * ss;
}
return 1;
@@ -229,6 +230,7 @@ export class DocumentView extends React.Component<DocumentViewProps> {
bindings[key.Name] = field && field != FieldWaiting ? field.GetValue() : field;
}
/*
+ tfs:
Should this be moved to CollectionFreeformView or another component that renders
Document backgrounds (or contents based on a layout key, which could be used here as well)
that CollectionFreeformView uses? It seems like a lot for it to be here considering only one view currently uses it...
@@ -245,6 +247,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);