aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Server.ts75
-rw-r--r--src/client/documents/Documents.ts10
-rw-r--r--src/client/views/Main.tsx2
-rw-r--r--src/client/views/nodes/CollectionFreeFormDocumentView.tsx11
4 files changed, 65 insertions, 33 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}>