aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/CollectionView.tsx
diff options
context:
space:
mode:
authoryipstanley <stanley_yip@brown.edu>2019-03-09 18:37:47 -0500
committeryipstanley <stanley_yip@brown.edu>2019-03-09 18:37:47 -0500
commitc739d5ae0f7d78bbd65134606c727df5a71defec (patch)
tree27c05f13a244a04717eeaa8aeb537b60b0ca985c /src/client/views/collections/CollectionView.tsx
parent1135a989b154aae084e07e09195e2d1c59e06180 (diff)
parent96eede5f7d1706a3f7ac6ee02a85bb3da217f467 (diff)
finally merged
Diffstat (limited to 'src/client/views/collections/CollectionView.tsx')
-rw-r--r--src/client/views/collections/CollectionView.tsx96
1 files changed, 56 insertions, 40 deletions
diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx
index 18e290477..47807116b 100644
--- a/src/client/views/collections/CollectionView.tsx
+++ b/src/client/views/collections/CollectionView.tsx
@@ -11,15 +11,15 @@ import { CollectionFreeFormView } from "./CollectionFreeFormView";
import { CollectionDockingView } from "./CollectionDockingView";
import { CollectionSchemaView } from "./CollectionSchemaView";
import { CollectionViewProps } from "./CollectionViewBase";
+import { CollectionTreeView } from "./CollectionTreeView";
import { Field } from "../../../fields/Field";
-
-
export enum CollectionViewType {
Invalid,
Freeform,
Schema,
Docking,
+ Tree
}
export const COLLECTION_BORDER_WIDTH = 2;
@@ -28,32 +28,47 @@ export const COLLECTION_BORDER_WIDTH = 2;
export class CollectionView extends React.Component<CollectionViewProps> {
public static LayoutString(fieldKey: string = "DataKey") {
- return `<CollectionView Document={Document}
- ScreenToLocalTransform={ScreenToLocalTransform} fieldKey={${fieldKey}} isSelected={isSelected} select={select} bindings={bindings}
- isTopMost={isTopMost} BackgroundView={BackgroundView} />`;
+ 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} 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 => {
- //TODO This won't create the field if it doesn't already exist
- let value = this.props.Document.GetData(this.props.fieldKey, ListField, new Array<Document>())
- value.push(doc)
- // this.props.Document.GetAsync(this.props.fieldKey, (f: Field) => {
- // (f as ListField<Document>).Data.push(doc);
- // this.props.Document.SetOnPrototype(KeyStore.Data, (f as ListField<Document>))
- // })
+ 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 = props.Document.GetData(props.fieldKey, ListField, new Array<Document>())
+ value.push(doc);
+ } else {
+ props.Document.SetOnPrototype(props.fieldKey, new ListField([doc]));
+ }
}
@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>())
- let index = value.indexOf(doc);
+ 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) {
+ index = i;
+ break;
+ }
+ }
+
if (index !== -1) {
value.splice(index, 1)
@@ -76,28 +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) })
+ }
}
- 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} />)
- default:
- return <div></div>
+ 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() {
+ return (<div className="collectionView-cont" onContextMenu={this.specificContextMenu}>
+ {this.subView}
+ </div>)
}
} \ No newline at end of file