diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/Server.ts | 75 | ||||
-rw-r--r-- | src/client/documents/Documents.ts | 10 | ||||
-rw-r--r-- | src/client/views/Main.tsx | 2 | ||||
-rw-r--r-- | src/client/views/nodes/CollectionFreeFormDocumentView.tsx | 11 | ||||
-rw-r--r-- | src/fields/BasicField.ts | 5 | ||||
-rw-r--r-- | src/fields/Document.ts | 3 | ||||
-rw-r--r-- | src/fields/ListField.ts | 3 | ||||
-rw-r--r-- | src/fields/NumberField.ts | 2 |
8 files changed, 71 insertions, 40 deletions
diff --git a/src/client/Server.ts b/src/client/Server.ts index 3047f64b3..ed69e70b7 100644 --- a/src/client/Server.ts +++ b/src/client/Server.ts @@ -6,22 +6,13 @@ import { SocketStub } from "./SocketStub"; import * as OpenSocket from 'socket.io-client'; import { Utils } from "./../Utils"; import { MessageStore, Types } from "./../server/Message"; +import { ListField } from "../fields/ListField"; export class Server { - private static ClientFieldsCached: ObservableMap<FIELD_ID, Field | FIELD_WAITING> = new ObservableMap(); + public static ClientFieldsCached: ObservableMap<FIELD_ID, Field | FIELD_WAITING> = new ObservableMap(); static Socket: SocketIOClient.Socket = OpenSocket("http://localhost:1234"); static GUID: string = Utils.GenerateGuid() - private static Cache: { [id: string]: Field } = {}; - - @action - static updateField(field: { _id: string, data: any, type: Types }) { - if (field._id in Server.Cache) { - const f = Server.Cache[field._id]; - f.UpdateFromServer(field.data); - f.init(() => { }); - } - } // Retrieves the cached value of the field and sends a request to the server for the real value (if it's not cached). // Call this is from within a reaction and test whether the return value is FieldWaiting. @@ -29,18 +20,23 @@ export class Server { public static GetField(fieldid: FIELD_ID, callback: (field: Opt<Field>) => void = (f) => { }, doc: Document, key: Key, hackTimeout: number = -1) { if (!this.ClientFieldsCached.get(fieldid)) { var ft = this.times++; - var title = (doc._proxies.has(KeyStore.Title.Id) ? "???" : doc.Title) + "(" + doc.Id + ")"; - var mesg = "-----> field(" + ft + ") " + title + " " + key.Name; + var title = (!doc.fields.has(KeyStore.Title.Id) ? "???" : doc.Title) + "(" + doc.Id + ")"; + var mesg = " Query> field(" + ft + ") " + title + " " + key.Name; console.log(mesg); this.ClientFieldsCached.set(fieldid, FieldWaiting); //simulating a server call with a registered callback action - SocketStub.SEND_FIELD_REQUEST(fieldid, (field) => { - if (field) { - this.Cache[field.Id] = field; + SocketStub.SEND_FIELD_REQUEST(fieldid, action((field: Field | undefined) => { + console.log(" Reply> field(" + ft + ") " + title + " " + key.Name + " = " + (field ? field.GetValue() : "<undefined>")); + + if (this.ClientFieldsCached.has(fieldid) && this.ClientFieldsCached.get(fieldid) != FieldWaiting) + callback(this.ClientFieldsCached.get(fieldid) as Field); + else { + if (field) { + this.ClientFieldsCached.set(fieldid, field); + } + callback(field) } - console.log(" <=== field(" + ft + ") " + title + " " + key.Name); - callback(field) - }); + })); } else if (this.ClientFieldsCached.get(fieldid) != FieldWaiting) { callback(this.ClientFieldsCached.get(fieldid) as Field); } @@ -51,7 +47,6 @@ export class Server { SocketStub.SEND_FIELDS_REQUEST(fieldIds, (fields) => { for (let key in fields) { let field = fields[key]; - this.Cache[field.Id] = field; } callback(fields) }); @@ -93,13 +88,37 @@ export class Server { private static lock: boolean = false; + static printfield(field: Field) { + if (field instanceof Key) { + return field.Name; + } + else if (field instanceof Document) { + var title = (field._proxies.has(KeyStore.Title.Id) ? field.Title : "???") + return title; + } else if (field instanceof ListField) { + var str = "["; + (field as ListField<Field>).Data.map(d => str += this.printfield(d)); + str += "]"; + return str; + } + return field.GetValue() + } + public static UpdateField(field: Field) { if (this.lock) { // setTimeout(this.UpdateField, 1000, field) } this.lock = true - var title = field instanceof Document ? (((field as Document)._proxies.has(KeyStore.Title.Id) ? "doc:" : (field as Document).Title) + "(" + (field as Document).Id + ")") : field.GetValue(); - console.log("updating field " + title) + var type = "field" + if (field instanceof Key) { + type = "Key"; + } + else if (field instanceof Document) { + type = "Doc"; + } else if (field instanceof ListField) { + type = "List" + } + console.log("Set: " + type + "(" + field.Id + ") =" + this.printfield(field)); SocketStub.SEND_SET_FIELD(field, (args: any) => { if (this.lock) { this.lock = false @@ -121,6 +140,18 @@ export class Server { } return this.ClientFieldsCached.get(clientField.Id) as Field; } + + @action + static updateField(field: { _id: string, data: any, type: Types }) { + if (Server.ClientFieldsCached.has(field._id)) { + var f = Server.ClientFieldsCached.get(field._id); + if (f && f != FieldWaiting) { + console.log("Update from server:" + Server.printfield(f)); + f.UpdateFromServer(field.data); + f.init(() => { }); + } + } + } } Server.Socket.on(MessageStore.Foo.Message, Server.connected); diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 210e63cd3..118f0d83f 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -33,19 +33,19 @@ export namespace Documents { } function setupOptions(doc: Document, options: DocumentOptions): void { - if (options.x) { + if (options.x != undefined) { doc.SetData(KeyStore.X, options.x, NumberField); } - if (options.y) { + if (options.y != undefined) { doc.SetData(KeyStore.Y, options.y, NumberField); } - if (options.width) { + if (options.width != undefined) { doc.SetData(KeyStore.Width, options.width, NumberField); } - if (options.height) { + if (options.height != undefined) { doc.SetData(KeyStore.Height, options.height, NumberField); } - if (options.title) { + if (options.title != undefined) { doc.SetData(KeyStore.Title, options.title, TextField); } doc.SetData(KeyStore.Scale, 1, NumberField); diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx index 14e60409e..1ae691bf5 100644 --- a/src/client/views/Main.tsx +++ b/src/client/views/Main.tsx @@ -67,6 +67,7 @@ Documents.initProtos(() => { console.log("RESPONSE: " + res) let mainContainer: Document; if (res) { + var lid = KeyStore.Layout.Id; let obj = ServerUtils.FromJson(res) as Document mainContainer = obj } @@ -75,6 +76,7 @@ Documents.initProtos(() => { let doc4 = Documents.CollectionDocument(docset, { x: 0, y: 400, title: "mini collection" }, mainDocId); + var lid = KeyStore.Layout.Id; mainContainer = doc4; let args = new DocumentTransfer(mainContainer.ToJson()) Utils.Emit(Server.Socket, MessageStore.AddDocument, args) diff --git a/src/client/views/nodes/CollectionFreeFormDocumentView.tsx b/src/client/views/nodes/CollectionFreeFormDocumentView.tsx index 1d53cedc4..616ccea65 100644 --- a/src/client/views/nodes/CollectionFreeFormDocumentView.tsx +++ b/src/client/views/nodes/CollectionFreeFormDocumentView.tsx @@ -204,14 +204,13 @@ export class CollectionFreeFormDocumentView extends DocumentView { } render() { - var freestyling = this.props.ContainingCollectionView instanceof CollectionFreeFormView; return ( <div className="node" ref={this._mainCont} style={{ - transform: freestyling ? this.transform : "", - width: freestyling ? this.width : "100%", - height: freestyling ? this.height : "100%", - position: freestyling ? "absolute" : "relative", - zIndex: freestyling ? this.zIndex : 0, + transform: this.transform, + width: this.width, + height: this.height, + position: "absolute", + zIndex: this.zIndex, }} onContextMenu={this.onContextMenu} onPointerDown={this.onPointerDown}> diff --git a/src/fields/BasicField.ts b/src/fields/BasicField.ts index 95f737dea..6326a90ad 100644 --- a/src/fields/BasicField.ts +++ b/src/fields/BasicField.ts @@ -27,10 +27,9 @@ export abstract class BasicField<T> extends Field { } set Data(value: T) { - if (this.data === value) { - return; + if (this.data != value) { + this.data = value; } - this.data = value; Server.UpdateField(this); } diff --git a/src/fields/Document.ts b/src/fields/Document.ts index 4b159b4eb..0d233c295 100644 --- a/src/fields/Document.ts +++ b/src/fields/Document.ts @@ -58,6 +58,8 @@ export class Document extends Field { break; } } + if (doc == FieldWaiting) + field = FieldWaiting; } return field; @@ -101,6 +103,7 @@ export class Document extends Field { @action Set(key: Key, field: Field | undefined): void { + console.log("Assign: " + key.Name + " = " + (field ? field.GetValue() : "<undefined>") + " (" + (field ? field.Id : "<undefined>") + ")"); if (field) { this.fields.set(key.Id, { key, field }); this._proxies.set(key.Id, field.Id) diff --git a/src/fields/ListField.ts b/src/fields/ListField.ts index d3d8fc71b..a46ce813d 100644 --- a/src/fields/ListField.ts +++ b/src/fields/ListField.ts @@ -43,17 +43,14 @@ export class ListField<T extends Field> extends BasicField<T[]> { } init(callback: (field: Field) => any) { - console.log("requesting list fields " + this._proxies.length) Server.GetFields(this._proxies, action((fields: { [index: string]: Field }) => { if (!this.arraysEqual(this._proxies, this.Data.map(field => field.Id))) { - console.log("Got new fields " + this.Data.length) this.Data = this._proxies.map(id => fields[id] as T) observe(this.Data, () => { this.updateProxies() Server.UpdateField(this); }) } - console.log("received fields " + this.Data) callback(this); })) } diff --git a/src/fields/NumberField.ts b/src/fields/NumberField.ts index 29e285201..6571695de 100644 --- a/src/fields/NumberField.ts +++ b/src/fields/NumberField.ts @@ -4,7 +4,7 @@ import { FIELD_ID } from "./Field"; export class NumberField extends BasicField<number> { constructor(data: number = 0, id: FIELD_ID = undefined, save: boolean = true) { - super(data, save, id); + super(data, false, id); } ToScriptString(): string { |