aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/CollectionView.tsx
diff options
context:
space:
mode:
authorSam Wilkins <abdullah_ahmed@brown.edu>2019-03-09 21:50:07 -0500
committerSam Wilkins <abdullah_ahmed@brown.edu>2019-03-09 21:50:07 -0500
commitf9f0fd90791562c295f8d9b237596cbabb086b79 (patch)
tree4c355c2175a3f8f8aacf0218cc6e62ec1e0ed712 /src/client/views/collections/CollectionView.tsx
parente673d4f70b8feb37dcd328440c019a49f8a22e88 (diff)
parent96eede5f7d1706a3f7ac6ee02a85bb3da217f467 (diff)
finalized workspace manipulation and merged with master
Diffstat (limited to 'src/client/views/collections/CollectionView.tsx')
-rw-r--r--src/client/views/collections/CollectionView.tsx80
1 files changed, 41 insertions, 39 deletions
diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx
index f938d2237..49df04163 100644
--- a/src/client/views/collections/CollectionView.tsx
+++ b/src/client/views/collections/CollectionView.tsx
@@ -1,4 +1,4 @@
-import { action, computed, observable } from "mobx";
+import { action, computed } from "mobx";
import { observer } from "mobx-react";
import { Document } from "../../../fields/Document";
import { ListField } from "../../../fields/ListField";
@@ -28,32 +28,39 @@ export const COLLECTION_BORDER_WIDTH = 2;
export class CollectionView extends React.Component<CollectionViewProps> {
public static LayoutString(fieldKey: string = "DataKey") {
- return `<CollectionView Document={Document}
+ return `<${CollectionView.name} Document={Document}
ScreenToLocalTransform={ScreenToLocalTransform} fieldKey={${fieldKey}} panelWidth={PanelWidth} panelHeight={PanelHeight} isSelected={isSelected} select={select} bindings={bindings}
- isTopMost={isTopMost} SelectOnLoad={selectOnLoad} BackgroundView={BackgroundView} />`;
+ isTopMost={isTopMost} SelectOnLoad={selectOnLoad} BackgroundView={BackgroundView} focus={focus}/>`;
}
- public active = () => {
- var isSelected = this.props.isSelected();
- var childSelected = SelectionManager.SelectedDocuments().some(view => view.props.ContainingCollectionView == this);
- var topMost = this.props.isTopMost;
+
+ public active: () => boolean = () => CollectionView.Active(this);
+ addDocument = (doc: Document): void => { CollectionView.AddDocument(this.props, doc); }
+ removeDocument = (doc: Document): boolean => { return CollectionView.RemoveDocument(this.props, doc); }
+ get subView() { return CollectionView.SubView(this); }
+
+ public static Active(self: CollectionView): boolean {
+ var isSelected = self.props.isSelected();
+ var childSelected = SelectionManager.SelectedDocuments().some(view => view.props.ContainingCollectionView == self);
+ var topMost = self.props.isTopMost;
return isSelected || childSelected || topMost;
}
+
@action
- addDocument = (doc: Document): void => {
- if (this.props.Document.Get(this.props.fieldKey) instanceof Field) {
+ public static AddDocument(props: CollectionViewProps, doc: Document) {
+ doc.SetNumber(KeyStore.Page, props.Document.GetNumber(KeyStore.CurPage, 0));
+ if (props.Document.Get(props.fieldKey) instanceof Field) {
//TODO This won't create the field if it doesn't already exist
- const value = this.props.Document.GetData(this.props.fieldKey, ListField, new Array<Document>())
+ const value = props.Document.GetData(props.fieldKey, ListField, new Array<Document>())
value.push(doc);
} else {
- this.props.Document.SetData(this.props.fieldKey, [doc], ListField);
+ props.Document.SetData(props.fieldKey, [doc], ListField);
}
}
-
@action
- removeDocument = (doc: Document): boolean => {
+ public static RemoveDocument(props: CollectionViewProps, doc: Document): boolean {
//TODO This won't create the field if it doesn't already exist
- const value = this.props.Document.GetData(this.props.fieldKey, ListField, new Array<Document>())
+ const value = props.Document.GetData(props.fieldKey, ListField, new Array<Document>())
let index = -1;
for (let i = 0; i < value.length; i++) {
if (value[i].Id == doc.Id) {
@@ -84,34 +91,29 @@ export class CollectionView extends React.Component<CollectionViewProps> {
}
}
- set collectionViewType(type: CollectionViewType) {
- let Document = this.props.Document;
- Document.SetData(KeyStore.ViewType, type, NumberField);
+ specificContextMenu = (e: React.MouseEvent): void => {
+ if (!e.isPropagationStopped() && this.props.Document.Id != "mainDoc") { // need to test this because GoldenLayout causes a parallel hierarchy in the React DOM for its children and the main document view7
+ ContextMenu.Instance.addItem({ description: "Freeform", event: () => this.props.Document.SetNumber(KeyStore.ViewType, CollectionViewType.Freeform) })
+ ContextMenu.Instance.addItem({ description: "Schema", event: () => this.props.Document.SetNumber(KeyStore.ViewType, CollectionViewType.Schema) })
+ ContextMenu.Instance.addItem({ description: "Treeview", event: () => this.props.Document.SetNumber(KeyStore.ViewType, CollectionViewType.Tree) })
+ ContextMenu.Instance.addItem({ description: "Docking", event: () => this.props.Document.SetNumber(KeyStore.ViewType, CollectionViewType.Docking) })
+ }
}
+ public static SubView(self: CollectionView) {
+ let subProps = { ...self.props, addDocument: self.addDocument, removeDocument: self.removeDocument, active: self.active, CollectionView: self }
+ switch (self.collectionViewType) {
+ case CollectionViewType.Freeform: return (<CollectionFreeFormView {...subProps} />)
+ case CollectionViewType.Schema: return (<CollectionSchemaView {...subProps} />)
+ case CollectionViewType.Docking: return (<CollectionDockingView {...subProps} />)
+ case CollectionViewType.Tree: return (<CollectionTreeView {...subProps} />)
+ }
+ return (null);
+ }
render() {
- let viewType = this.collectionViewType;
-
- switch (viewType) {
- case CollectionViewType.Freeform:
- return (<CollectionFreeFormView {...this.props}
- addDocument={this.addDocument} removeDocument={this.removeDocument} active={this.active}
- CollectionView={this} />);
- case CollectionViewType.Schema:
- return (<CollectionSchemaView {...this.props}
- addDocument={this.addDocument} removeDocument={this.removeDocument} active={this.active}
- CollectionView={this} />)
- case CollectionViewType.Docking:
- return (<CollectionDockingView {...this.props}
- addDocument={this.addDocument} removeDocument={this.removeDocument} active={this.active}
- CollectionView={this} />)
- case CollectionViewType.Tree:
- return (<CollectionTreeView {...this.props}
- addDocument={this.addDocument} removeDocument={this.removeDocument} active={this.active}
- CollectionView={this} />)
- default:
- return <div></div>
- }
+ return (<div className="collectionView-cont" onContextMenu={this.specificContextMenu}>
+ {this.subView}
+ </div>)
}
} \ No newline at end of file