aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-05-02 01:31:18 -0400
committerTyler Schicke <tyler_schicke@brown.edu>2019-05-02 01:31:18 -0400
commit2c1cf7fd3e1d71813f23f60acb9264a4f8bf33b0 (patch)
tree2e38e5a51758dc54d6be586a3f53ca96eec3a020 /src/client/views/nodes
parenteebe58b47acfe3b13c22407b98763cdbd6e1eb58 (diff)
parent407c104f0ad0957d71f73c14f5b835fab387ecd2 (diff)
Merge branch 'newDocs' of github-tsch-brown:browngraphicslab/Dash-Web into newDocs
Diffstat (limited to 'src/client/views/nodes')
-rw-r--r--src/client/views/nodes/DocumentContentsView.tsx25
-rw-r--r--src/client/views/nodes/DocumentView.tsx46
2 files changed, 36 insertions, 35 deletions
diff --git a/src/client/views/nodes/DocumentContentsView.tsx b/src/client/views/nodes/DocumentContentsView.tsx
index 794442469..24e8a36ae 100644
--- a/src/client/views/nodes/DocumentContentsView.tsx
+++ b/src/client/views/nodes/DocumentContentsView.tsx
@@ -20,7 +20,8 @@ import { HistogramBox } from "../../northstar/dash-nodes/HistogramBox";
import React = require("react");
import { FieldViewProps } from "./FieldView";
import { Without, OmitKeys } from "../../../Utils";
-import { Cast } from "../../../new_fields/Types";
+import { Cast, StrCast } from "../../../new_fields/Types";
+import { List } from "../../../new_fields/List";
const JsxParser = require('react-jsx-parser').default; //TODO Why does this need to be imported like this?
type BindingProps = Without<FieldViewProps, 'fieldKey'>;
@@ -40,11 +41,31 @@ export class DocumentContentsView extends React.Component<DocumentViewProps & {
return { props: OmitKeys(this.props, ['parentActive'], (obj: any) => obj.active = this.props.parentActive).omit };
}
+ @computed get templates(): List<string> {
+ let field = this.props.Document.templates;
+ if (field && field instanceof List) {
+ return field;
+ }
+ return new List<string>();
+ }
+ set templates(templates: List<string>) { this.props.Document.templates = templates; }
+ get finalLayout() {
+ const baseLayout = this.layout;
+ let base = baseLayout;
+ let layout = baseLayout;
+
+ this.templates.forEach(template => {
+ layout = template.replace("{layout}", base);
+ base = layout;
+ });
+ return layout;
+ }
+
render() {
return <JsxParser
components={{ FormattedTextBox, ImageBox, IconBox, CollectionFreeFormView, CollectionDockingView, CollectionSchemaView, CollectionView, CollectionPDFView, CollectionVideoView, WebBox, KeyValueBox, PDFBox, VideoBox, AudioBox, HistogramBox }}
bindings={this.CreateBindings()}
- jsx={this.layout}
+ jsx={this.finalLayout}
showWarnings={true}
onError={(test: any) => { console.log(test); }}
/>;
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index f58dc4a02..5588fa1ac 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -87,12 +87,14 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
public get ContentDiv() { return this._mainCont.current; }
@computed get active(): boolean { return SelectionManager.IsSelected(this) || this.props.parentActive(); }
@computed get topMost(): boolean { return this.props.isTopMost; }
- @computed get templates(): Array<Template> {
- return new Array<Template>();
- // let field = this.props.Document[KeyStore.Templates];
- // return !field || field === FieldWaiting ? [] : field.Data;
+ @computed get templates(): List<string> {
+ let field = this.props.Document.templates;
+ if (field && field instanceof List) {
+ return field;
+ }
+ return new List<string>();
}
- set templates(templates: Array<Template>) { /* this.props.Document.templates = templates;*/ }
+ set templates(templates: List<string>) { this.props.Document.templates = templates; }
screenRect = (): ClientRect | DOMRect => this._mainCont.current ? this._mainCont.current.getBoundingClientRect() : new DOMRect();
@action
@@ -239,44 +241,22 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
}
}
- updateLayout = async () => {
- const baseLayout = await StrCast(this.props.Document.baseLayout);
- if (baseLayout) {
- let base = baseLayout;
- let layout = baseLayout;
-
- this.templates.forEach(template => {
- let temp = template.Layout;
- layout = temp.replace("{layout}", base);
- base = layout;
- });
-
- this.props.Document.layout = layout;
- }
- }
@action
addTemplate = (template: Template) => {
- let templates = this.templates;
- templates.push(template);
- templates = templates.splice(0, templates.length).sort(Templates.sortTemplates);
- this.templates = templates;
- this.updateLayout();
+ this.templates.push(template.Layout);
+ this.templates = this.templates;
}
@action
removeTemplate = (template: Template) => {
- let templates = this.templates;
- for (let i = 0; i < templates.length; i++) {
- let temp = templates[i];
- if (temp.Name === template.Name) {
- templates.splice(i, 1);
+ for (let i = 0; i < this.templates.length; i++) {
+ if (this.templates[i] === template.Layout) {
+ this.templates.splice(i, 1);
break;
}
}
- templates = templates.splice(0, templates.length).sort(Templates.sortTemplates);
- this.templates = templates;
- this.updateLayout();
+ this.templates = this.templates;
}
@action