aboutsummaryrefslogtreecommitdiff
path: root/src/client/documents/Documents.ts
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-02-25 01:22:40 -0500
committerTyler Schicke <tyler_schicke@brown.edu>2019-02-25 01:22:40 -0500
commit80a2f5540af2aae49685de09a2b94f216f10f0d7 (patch)
treeb9ed70d2d176e31e9d69312dd2587ed13165832f /src/client/documents/Documents.ts
parent62e06a2c9ce5054777a7a790e5b03b96d3cd6425 (diff)
parent41ff4813ddd9e6094d7d609c5960e1a614e00d7f (diff)
Merge branch 'master' of github-tsch-brown:browngraphicslab/Dash-Web into authentication
Diffstat (limited to 'src/client/documents/Documents.ts')
-rw-r--r--src/client/documents/Documents.ts146
1 files changed, 85 insertions, 61 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index f779dcd03..4c5f26fbd 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -5,47 +5,53 @@ import { TextField } from "../../fields/TextField";
import { NumberField } from "../../fields/NumberField";
import { ListField } from "../../fields/ListField";
import { FormattedTextBox } from "../views/nodes/FormattedTextBox";
-import { CollectionDockingView } from "../views/collections/CollectionDockingView";
-import { CollectionSchemaView } from "../views/collections/CollectionSchemaView";
import { ImageField } from "../../fields/ImageField";
import { ImageBox } from "../views/nodes/ImageBox";
-import { CollectionFreeFormView } from "../views/collections/CollectionFreeFormView";
-import { FIELD_ID } from "../../fields/Field";
+import { CollectionView, CollectionViewType } from "../views/collections/CollectionView";
+import { FieldView } from "../views/nodes/FieldView";
+import { HtmlField } from "../../fields/HtmlField";
+import { WebView } from "../views/nodes/WebView";
-interface DocumentOptions {
+export interface DocumentOptions {
x?: number;
y?: number;
width?: number;
height?: number;
+ nativeWidth?: number;
+ nativeHeight?: number;
title?: string;
}
export namespace Documents {
export function initProtos(callback: () => void) {
- Server.GetFields([collectionProtoId, textProtoId, imageProtoId, schemaProtoId, dockProtoId], (fields) => {
+ Server.GetFields([collectionProtoId, textProtoId, imageProtoId], (fields) => {
collectionProto = fields[collectionProtoId] as Document;
imageProto = fields[imageProtoId] as Document;
textProto = fields[textProtoId] as Document;
- dockProto = fields[dockProtoId] as Document;
- schemaProto = fields[schemaProtoId] as Document;
callback()
});
}
function setupOptions(doc: Document, options: DocumentOptions): void {
- if (options.x != undefined) {
+ if (options.x !== undefined) {
doc.SetData(KeyStore.X, options.x, NumberField);
}
- if (options.y != undefined) {
+ if (options.y !== undefined) {
doc.SetData(KeyStore.Y, options.y, NumberField);
}
- if (options.width != undefined) {
+ if (options.width !== undefined) {
doc.SetData(KeyStore.Width, options.width, NumberField);
}
- if (options.height != undefined) {
+ if (options.height !== undefined) {
doc.SetData(KeyStore.Height, options.height, NumberField);
}
- if (options.title != undefined) {
+ if (options.nativeWidth !== undefined) {
+ doc.SetData(KeyStore.NativeWidth, options.nativeWidth, NumberField);
+ }
+ if (options.nativeHeight !== undefined) {
+ doc.SetData(KeyStore.NativeHeight, options.nativeHeight, NumberField);
+ }
+ if (options.title !== undefined) {
doc.SetData(KeyStore.Title, options.title, TextField);
}
doc.SetData(KeyStore.Scale, 1, NumberField);
@@ -75,52 +81,28 @@ export namespace Documents {
return doc;
}
- let schemaProto: Document;
- const schemaProtoId = "schemaProto";
- function GetSchemaPrototype(): Document {
- if (!schemaProto) {
- schemaProto = new Document(schemaProtoId);
- schemaProto.Set(KeyStore.X, new NumberField(0));
- schemaProto.Set(KeyStore.Y, new NumberField(0));
- schemaProto.Set(KeyStore.Width, new NumberField(300));
- schemaProto.Set(KeyStore.Height, new NumberField(150));
- schemaProto.Set(KeyStore.Layout, new TextField(CollectionSchemaView.LayoutString()));
- schemaProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data]));
+ let htmlProto: Document;
+ const htmlProtoId = "htmlProto";
+ function GetHtmlPrototype(): Document {
+ if (!htmlProto) {
+ htmlProto = new Document(htmlProtoId);
+ htmlProto.Set(KeyStore.X, new NumberField(0));
+ htmlProto.Set(KeyStore.Y, new NumberField(0));
+ htmlProto.Set(KeyStore.Width, new NumberField(300));
+ htmlProto.Set(KeyStore.Height, new NumberField(150));
+ htmlProto.Set(KeyStore.Layout, new TextField(WebView.LayoutString()));
+ htmlProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data]));
}
- return schemaProto;
+ return htmlProto;
}
- export function SchemaDocument(documents: Array<Document>, options: DocumentOptions = {}): Document {
- let doc = GetSchemaPrototype().MakeDelegate();
+ export function HtmlDocument(html: string, options: DocumentOptions = {}): Document {
+ let doc = GetHtmlPrototype().MakeDelegate();
setupOptions(doc, options);
- doc.Set(KeyStore.Data, new ListField(documents));
+ doc.Set(KeyStore.Data, new HtmlField(html));
return doc;
}
-
- let dockProto: Document;
- const dockProtoId = "dockProto";
- function GetDockPrototype(): Document {
- if (!dockProto) {
- dockProto = new Document();
- dockProto.Set(KeyStore.X, new NumberField(0));
- dockProto.Set(KeyStore.Y, new NumberField(0));
- dockProto.Set(KeyStore.Width, new NumberField(300));
- dockProto.Set(KeyStore.Height, new NumberField(150));
- dockProto.Set(KeyStore.Layout, new TextField(CollectionDockingView.LayoutString()));
- dockProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data]));
- }
- return dockProto;
- }
-
- export function DockDocument(documents: Array<Document>, options: DocumentOptions = {}): Document {
- let doc = GetDockPrototype().MakeDelegate();
- setupOptions(doc, options);
- doc.Set(KeyStore.Data, new ListField(documents));
- return doc;
- }
-
-
let imageProto: Document;
const imageProtoId = "imageProto";
function GetImagePrototype(): Document {
@@ -129,20 +111,49 @@ export namespace Documents {
imageProto.Set(KeyStore.Title, new TextField("IMAGE PROTO"));
imageProto.Set(KeyStore.X, new NumberField(0));
imageProto.Set(KeyStore.Y, new NumberField(0));
+ imageProto.Set(KeyStore.NativeWidth, new NumberField(300));
+ imageProto.Set(KeyStore.NativeHeight, new NumberField(300));
imageProto.Set(KeyStore.Width, new NumberField(300));
imageProto.Set(KeyStore.Height, new NumberField(300));
- imageProto.Set(KeyStore.Layout, new TextField(ImageBox.LayoutString()));
+ imageProto.Set(KeyStore.Layout, new TextField(CollectionView.LayoutString("AnnotationsKey")));
+ imageProto.SetNumber(KeyStore.ViewType, CollectionViewType.Freeform)
+ imageProto.Set(KeyStore.BackgroundLayout, new TextField(ImageBox.LayoutString()));
// imageProto.SetField(KeyStore.Layout, new TextField('<div style={"background-image: " + {Data}} />'));
- imageProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data]));
+ imageProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data, KeyStore.Annotations]));
return imageProto;
}
return imageProto;
+
}
+ // example of custom display string for an image that shows a caption.
+ function EmbeddedCaption() {
+ return `<div style="position:absolute; height:100%">
+ <div style="position:relative; margin:auto; width:85%; margin:auto" >`
+ + ImageBox.LayoutString() +
+ `</div>
+ <div style="position:relative; overflow:auto; height:15%; text-align:center; ">`
+ + FormattedTextBox.LayoutString("CaptionKey") +
+ `</div>
+ </div>` };
+ function FixedCaption() {
+ return `<div style="position:absolute; height:30px; bottom:0; width:100%">
+ <div style="position:absolute; width:100%; height:100%; overflow:auto;text-align:center;bottom:0;">`
+ + FormattedTextBox.LayoutString("CaptionKey") +
+ `</div>
+ </div>` };
+
export function ImageDocument(url: string, options: DocumentOptions = {}): Document {
let doc = GetImagePrototype().MakeDelegate();
setupOptions(doc, options);
doc.Set(KeyStore.Data, new ImageField(new URL(url)));
+ doc.Set(KeyStore.Caption, new TextField("my caption..."));
+ doc.Set(KeyStore.BackgroundLayout, new TextField(EmbeddedCaption()));
+ doc.Set(KeyStore.OverlayLayout, new TextField(FixedCaption()));
+ doc.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data, KeyStore.Annotations, KeyStore.Caption]));
+
+ let annotation = Documents.TextDocument({ title: "hello" });
+ doc.Set(KeyStore.Annotations, new ListField([annotation]));
return doc;
}
@@ -151,23 +162,36 @@ export namespace Documents {
function GetCollectionPrototype(): Document {
if (!collectionProto) {
collectionProto = new Document(collectionProtoId);
- collectionProto.Set(KeyStore.X, new NumberField(0));
- collectionProto.Set(KeyStore.Y, new NumberField(0));
collectionProto.Set(KeyStore.Scale, new NumberField(1));
collectionProto.Set(KeyStore.PanX, new NumberField(0));
collectionProto.Set(KeyStore.PanY, new NumberField(0));
- collectionProto.Set(KeyStore.Width, new NumberField(300));
- collectionProto.Set(KeyStore.Height, new NumberField(300));
- collectionProto.Set(KeyStore.Layout, new TextField(CollectionFreeFormView.LayoutString()));
+ collectionProto.Set(KeyStore.Layout, new TextField(CollectionView.LayoutString("DataKey")));
collectionProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data]));
}
return collectionProto;
}
- export function CollectionDocument(documents: Array<Document>, options: DocumentOptions = {}, id?: string): Document {
+ export function CollectionDocument(data: Array<Document> | string, viewType: CollectionViewType, options: DocumentOptions = {}, id?: string): Document {
let doc = GetCollectionPrototype().MakeDelegate(id);
setupOptions(doc, options);
- doc.Set(KeyStore.Data, new ListField(documents));
+ if (typeof data === "string") {
+ doc.SetText(KeyStore.Data, data);
+ } else {
+ doc.SetData(KeyStore.Data, data, ListField);
+ }
+ doc.SetNumber(KeyStore.ViewType, viewType);
return doc;
}
+
+ export function FreeformDocument(documents: Array<Document>, options: DocumentOptions, id?: string) {
+ return CollectionDocument(documents, CollectionViewType.Freeform, options, id)
+ }
+
+ export function SchemaDocument(documents: Array<Document>, options: DocumentOptions, id?: string) {
+ return CollectionDocument(documents, CollectionViewType.Schema, options, id)
+ }
+
+ export function DockDocument(config: string, options: DocumentOptions, id?: string) {
+ return CollectionDocument(config, CollectionViewType.Docking, options, id)
+ }
} \ No newline at end of file