aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/CollectionView.tsx
diff options
context:
space:
mode:
authorlaurawilsonri <laura_wilson@brown.edu>2019-02-25 20:11:37 -0500
committerlaurawilsonri <laura_wilson@brown.edu>2019-02-25 20:11:37 -0500
commit3ef178ab23eae665a7323ae54e14114a2b6e656e (patch)
tree5f97a342f4e1e8d322035158e53eaf4bd4774305 /src/client/views/collections/CollectionView.tsx
parent171852260c04ba7aafd789b231d98cdaa2a7dc8d (diff)
parent292ff1a8d75f8b15f9388d2c577e09a13836d5dc (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into improveText
Diffstat (limited to 'src/client/views/collections/CollectionView.tsx')
-rw-r--r--src/client/views/collections/CollectionView.tsx32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx
index 57d876996..6ab0f15c0 100644
--- a/src/client/views/collections/CollectionView.tsx
+++ b/src/client/views/collections/CollectionView.tsx
@@ -12,14 +12,15 @@ import { CollectionDockingView } from "./CollectionDockingView";
import { CollectionSchemaView } from "./CollectionSchemaView";
import { CollectionViewProps } from "./CollectionViewBase";
var ReactDOM = require('react-dom');
-
-
+import { CollectionTreeView } from "./CollectionTreeView";
+import { Field } from "../../../fields/Field";
export enum CollectionViewType {
Invalid,
Freeform,
Schema,
Docking,
+ Tree
}
export const COLLECTION_BORDER_WIDTH = 2;
@@ -31,7 +32,7 @@ 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}
+ ScreenToLocalTransform={ScreenToLocalTransform} fieldKey={${fieldKey}} panelWidth={PanelWidth} panelHeight={PanelHeight} isSelected={isSelected} select={select} bindings={bindings}
isTopMost={isTopMost} BackgroundView={BackgroundView} />`;
}
public active = () => {
@@ -42,16 +43,26 @@ export class CollectionView 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.Document.GetData(this.props.fieldKey, ListField, new Array<Document>())
- value.push(doc);
+ if (this.props.Document.Get(this.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>())
+ value.push(doc);
+ } else {
+ this.props.Document.SetData(this.props.fieldKey, [doc], ListField);
+ }
}
@action
removeDocument = (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);
+ 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)
@@ -97,11 +108,12 @@ export class CollectionView extends React.Component<CollectionViewProps> {
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} />)
+ CollectionView={this} />);
case CollectionViewType.Schema:
return (<CollectionSchemaView {...this.props}
addDocument={this.addDocument} removeDocument={this.removeDocument} active={this.active}
@@ -110,6 +122,10 @@ export class CollectionView extends React.Component<CollectionViewProps> {
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>
}