From c469ece08b8df888395b6c1ab8205d3a027853fa Mon Sep 17 00:00:00 2001 From: yipstanley Date: Thu, 7 Mar 2019 22:18:47 -0500 Subject: changing branches --- src/client/documents/Documents.ts | 87 +++++++++++-------------- src/client/views/collections/CollectionView.tsx | 9 ++- src/client/views/nodes/FormattedTextBox.tsx | 4 +- src/client/views/nodes/ImageBox.tsx | 1 + src/fields/Document.ts | 4 +- 5 files changed, 52 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 4c5f26fbd..9f739a48c 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -11,6 +11,7 @@ import { CollectionView, CollectionViewType } from "../views/collections/Collect import { FieldView } from "../views/nodes/FieldView"; import { HtmlField } from "../../fields/HtmlField"; import { WebView } from "../views/nodes/WebView"; +import { Utils } from "../../Utils"; export interface DocumentOptions { x?: number; @@ -24,10 +25,10 @@ export interface DocumentOptions { export namespace Documents { export function initProtos(callback: () => void) { - Server.GetFields([collectionProtoId, textProtoId, imageProtoId], (fields) => { - collectionProto = fields[collectionProtoId] as Document; - imageProto = fields[imageProtoId] as Document; - textProto = fields[textProtoId] as Document; + Server.GetFields([], (fields) => { + // collectionProto = fields[collectionProtoId] as Document; + // imageProto = fields[imageProtoId] as Document; + // textProto = fields[textProtoId] as Document; callback() }); } @@ -59,18 +60,14 @@ export namespace Documents { doc.SetData(KeyStore.PanY, 0, NumberField); } - let textProto: Document; - const textProtoId = "textProto"; function GetTextPrototype(): Document { - if (!textProto) { - textProto = new Document(textProtoId); - textProto.Set(KeyStore.X, new NumberField(0)); - textProto.Set(KeyStore.Y, new NumberField(0)); - textProto.Set(KeyStore.Width, new NumberField(300)); - textProto.Set(KeyStore.Height, new NumberField(150)); - textProto.Set(KeyStore.Layout, new TextField(FormattedTextBox.LayoutString())); - textProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data])); - } + let textProto = new Document(); + textProto.Set(KeyStore.X, new NumberField(0)); + textProto.Set(KeyStore.Y, new NumberField(0)); + textProto.Set(KeyStore.Width, new NumberField(300)); + textProto.Set(KeyStore.Height, new NumberField(150)); + textProto.Set(KeyStore.Layout, new TextField(FormattedTextBox.LayoutString())); + textProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data])); return textProto; } @@ -103,27 +100,23 @@ export namespace Documents { return doc; } - let imageProto: Document; - const imageProtoId = "imageProto"; + // let imageProto: Document; + // const imageProtoId = "imageProto"; function GetImagePrototype(): Document { - if (!imageProto) { - imageProto = new Document(imageProtoId); - 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(CollectionView.LayoutString("AnnotationsKey"))); - imageProto.SetNumber(KeyStore.ViewType, CollectionViewType.Freeform) - imageProto.Set(KeyStore.BackgroundLayout, new TextField(ImageBox.LayoutString())); - // imageProto.SetField(KeyStore.Layout, new TextField('
')); - imageProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data, KeyStore.Annotations])); - return imageProto; - } + let imageProto = new Document(); + 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(CollectionView.LayoutString("AnnotationsKey"))); + imageProto.SetNumber(KeyStore.ViewType, CollectionViewType.Freeform) + imageProto.Set(KeyStore.BackgroundLayout, new TextField(ImageBox.LayoutString())); + // imageProto.SetField(KeyStore.Layout, new TextField('
')); + imageProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data, KeyStore.Annotations])); return imageProto; - } // example of custom display string for an image that shows a caption. @@ -146,28 +139,26 @@ export namespace Documents { 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.SetOnPrototype(KeyStore.Data, new ImageField(new URL(url))); + doc.SetOnPrototype(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])); + doc.SetOnPrototype(KeyStore.Annotations, new ListField([annotation])); return doc; } - let collectionProto: Document; + // let collectionProto: Document; const collectionProtoId = "collectionProto"; function GetCollectionPrototype(): Document { - if (!collectionProto) { - collectionProto = new Document(collectionProtoId); - collectionProto.Set(KeyStore.Scale, new NumberField(1)); - collectionProto.Set(KeyStore.PanX, new NumberField(0)); - collectionProto.Set(KeyStore.PanY, new NumberField(0)); - collectionProto.Set(KeyStore.Layout, new TextField(CollectionView.LayoutString("DataKey"))); - collectionProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data])); - } + let collectionProto = new Document(); + collectionProto.Set(KeyStore.Scale, new NumberField(1)); + collectionProto.Set(KeyStore.PanX, new NumberField(0)); + collectionProto.Set(KeyStore.PanY, new NumberField(0)); + collectionProto.Set(KeyStore.Layout, new TextField(CollectionView.LayoutString("DataKey"))); + collectionProto.Set(KeyStore.LayoutKeys, new ListField([KeyStore.Data])); return collectionProto; } @@ -175,9 +166,9 @@ export namespace Documents { let doc = GetCollectionPrototype().MakeDelegate(id); setupOptions(doc, options); if (typeof data === "string") { - doc.SetText(KeyStore.Data, data); + doc.SetOnPrototype(KeyStore.Data, new TextField(data)); } else { - doc.SetData(KeyStore.Data, data, ListField); + doc.SetOnPrototype(KeyStore.Data, new ListField(data)); } doc.SetNumber(KeyStore.ViewType, viewType); return doc; diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx index 90080ab43..18e290477 100644 --- a/src/client/views/collections/CollectionView.tsx +++ b/src/client/views/collections/CollectionView.tsx @@ -11,6 +11,7 @@ import { CollectionFreeFormView } from "./CollectionFreeFormView"; import { CollectionDockingView } from "./CollectionDockingView"; import { CollectionSchemaView } from "./CollectionSchemaView"; import { CollectionViewProps } from "./CollectionViewBase"; +import { Field } from "../../../fields/Field"; @@ -40,8 +41,12 @@ export class CollectionView extends React.Component { @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()) - value.push(doc); + let value = this.props.Document.GetData(this.props.fieldKey, ListField, new Array()) + value.push(doc) + // this.props.Document.GetAsync(this.props.fieldKey, (f: Field) => { + // (f as ListField).Data.push(doc); + // this.props.Document.SetOnPrototype(KeyStore.Data, (f as ListField)) + // }) } @action diff --git a/src/client/views/nodes/FormattedTextBox.tsx b/src/client/views/nodes/FormattedTextBox.tsx index 57ac880df..727645934 100644 --- a/src/client/views/nodes/FormattedTextBox.tsx +++ b/src/client/views/nodes/FormattedTextBox.tsx @@ -48,8 +48,8 @@ export class FormattedTextBox extends React.Component { const state = this._editorView.state.apply(tx); this._editorView.updateState(state); const { doc, fieldKey } = this.props; - // doc.SetOnPrototype(fieldKey, new RichTextField(JSON.stringify(state.toJSON()))) - doc.SetData(fieldKey, JSON.stringify(state.toJSON()), RichTextField); + doc.SetOnPrototype(fieldKey, new RichTextField(JSON.stringify(state.toJSON()))) + // doc.SetData(fieldKey, JSON.stringify(state.toJSON()), RichTextField); } } diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx index b5ce8b28c..f3c1d3f4e 100644 --- a/src/client/views/nodes/ImageBox.tsx +++ b/src/client/views/nodes/ImageBox.tsx @@ -81,6 +81,7 @@ export class ImageBox extends React.Component { render() { let field = this.props.doc.Get(this.props.fieldKey); + console.log(field) let path = field == FieldWaiting ? "https://image.flaticon.com/icons/svg/66/66163.svg" : field instanceof ImageField ? field.Data.href : "http://www.cs.brown.edu/~bcz/face.gif"; let nativeWidth = this.props.doc.GetNumber(KeyStore.NativeWidth, 1); diff --git a/src/fields/Document.ts b/src/fields/Document.ts index 39648a950..1b27c4a13 100644 --- a/src/fields/Document.ts +++ b/src/fields/Document.ts @@ -212,7 +212,9 @@ export class Document extends Field { CreateAlias(id?: string): Document { let alias = new Document(id) - alias.Set(KeyStore.Prototype, this) + this.GetAsync(KeyStore.Prototype, (f: Field) => { + alias.Set(KeyStore.Prototype, f) + }) return alias } -- cgit v1.2.3-70-g09d2