aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Server.ts35
-rw-r--r--src/client/SocketStub.ts7
-rw-r--r--src/client/documents/Documents.ts8
-rw-r--r--src/client/views/Main.tsx122
4 files changed, 107 insertions, 65 deletions
diff --git a/src/client/Server.ts b/src/client/Server.ts
index a08fc2e87..fab51ca9c 100644
--- a/src/client/Server.ts
+++ b/src/client/Server.ts
@@ -20,7 +20,9 @@ export class Server {
this.ClientFieldsCached.set(fieldid, FieldWaiting);
//simulating a server call with a registered callback action
SocketStub.SEND_FIELD_REQUEST(fieldid,
- action((field: Field) => callback(Server.cacheField(field))));
+ action((field: Field) => {
+ callback(Server.cacheField(field))
+ }));
} else if (this.ClientFieldsCached.get(fieldid) != FieldWaiting) {
callback(this.ClientFieldsCached.get(fieldid) as Field);
}
@@ -29,14 +31,24 @@ export class Server {
static times = 0; // hack for testing
public static GetDocumentField(doc: Document, key: Key) {
- var hackTimeout: number = key == KeyStore.Data ? (this.times++ == 0 ? 5000 : 1000) : key == KeyStore.X ? 2500 : 500;
+ // let keyId: string = element[0]
+ // let valueId: string = element[1]
+ // Server.GetField(keyId, (key: Field) => {
+ // if (key instanceof Key) {
+ // Server.GetField(valueId, (field: Field) => {
+ // console.log(field)
+ // doc.Set(key as Key, field)
+ // })
+ // }
+ // else {
+ // console.log("how did you get a key that isnt a key wtf")
+ // }
+ // })
return this.GetField(doc._proxies.get(key.Id),
action((fieldfromserver: Field) => {
- doc._proxies.delete(key.Id);
doc.fields.set(key, fieldfromserver);
- })
- , hackTimeout);
+ }));
}
public static AddDocument(document: Document) {
@@ -48,8 +60,19 @@ export class Server {
public static DeleteDocumentField(doc: Document, key: Key) {
SocketStub.SEND_DELETE_DOCUMENT_FIELD(doc, key);
}
+
+ private static lock: boolean = false;
+
public static UpdateField(field: Field) {
- SocketStub.SEND_SET_FIELD(field);
+ if (this.lock) {
+ setTimeout(this.UpdateField, 1000, field)
+ }
+ this.lock = true
+ SocketStub.SEND_SET_FIELD(field, (args: any) => {
+ if (this.lock) {
+ this.lock = false
+ }
+ });
}
static connected(message: string) {
diff --git a/src/client/SocketStub.ts b/src/client/SocketStub.ts
index 03c0131ba..136c69668 100644
--- a/src/client/SocketStub.ts
+++ b/src/client/SocketStub.ts
@@ -34,8 +34,7 @@ export class SocketStub {
public static SEND_FIELD_REQUEST(fieldid: FIELD_ID, callback: (field: Field) => void) {
if (fieldid) {
- let args: GetFieldArgs = new GetFieldArgs(fieldid)
- Utils.EmitCallback(Server.Socket, MessageStore.GetField, args, (field: Field) => callback(field))
+ Utils.EmitCallback(Server.Socket, MessageStore.GetField, fieldid, (field: Field) => callback(field))
}
}
@@ -67,12 +66,12 @@ export class SocketStub {
document._proxies.delete(key.Id);
}
- public static SEND_SET_FIELD(field: Field) {
+ public static SEND_SET_FIELD(field: Field, fn: (args: any) => void) {
// Send a request to set the value of a field
// ...SOCKET(SET_FIELD, field id, serialized field value)
// Server updates the value of the field in its fieldstore
- Utils.Emit(Server.Socket, MessageStore.SetField, field.ToJson())
+ Utils.EmitCallback(Server.Socket, MessageStore.SetField, field.ToJson(), fn)
}
}
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 460bf9b23..f362af392 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -137,9 +137,9 @@ export namespace Documents {
}
let collectionProto: Document;
- function GetCollectionPrototype(): Document {
+ function GetCollectionPrototype(isMainDoc: boolean): Document {
if (!collectionProto) {
- collectionProto = new Document();
+ collectionProto = new Document(isMainDoc ? "dash" : undefined);
collectionProto.Set(KeyStore.X, new NumberField(0));
collectionProto.Set(KeyStore.Y, new NumberField(0));
collectionProto.Set(KeyStore.Scale, new NumberField(1));
@@ -153,8 +153,8 @@ export namespace Documents {
return collectionProto;
}
- export function CollectionDocument(documents: Array<Document>, options: DocumentOptions = {}): Document {
- let doc = GetCollectionPrototype().MakeDelegate();
+ export function CollectionDocument(documents: Array<Document>, options: DocumentOptions = {}, isMainDoc: boolean = false): Document {
+ let doc = GetCollectionPrototype(isMainDoc).MakeDelegate();
setupOptions(doc, options);
doc.Set(KeyStore.Data, new ListField(documents));
return doc;
diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx
index 197529c91..0f06f1278 100644
--- a/src/client/views/Main.tsx
+++ b/src/client/views/Main.tsx
@@ -14,16 +14,21 @@ import { ContextMenu } from './ContextMenu';
import { DocumentView } from './nodes/DocumentView';
import { ImageField } from '../../fields/ImageField';
import { CompileScript } from './../util/Scripting';
+import { Server } from '../Server';
+import { Utils } from '../../Utils';
+import { ServerUtils } from '../../server/ServerUtil';
+import { MessageStore, DocumentTransfer } from '../../server/Message';
+import { Database } from '../../server/database';
configure({
enforceActions: "observed"
});
-const mainNodeCollection = new Array<Document>();
-let mainContainer = Documents.DockDocument(mainNodeCollection, {
- x: 0, y: 0, title: "main container"
-})
+// const mainNodeCollection = new Array<Document>();
+// let mainContainer = Documents.DockDocument(mainNodeCollection, {
+// x: 0, y: 0, title: "main container"
+// })
window.addEventListener("drop", function (e) {
e.preventDefault();
@@ -54,11 +59,68 @@ document.addEventListener("pointerdown", action(function (e: PointerEvent) {
// schemaDocs[4].SetData(KS.Author, "Bob", TextField);
// schemaDocs.push(doc2);
// const doc7 = Documents.SchemaDocument(schemaDocs)
-const docset: Document[] = [];
-let doc4 = Documents.CollectionDocument(docset, {
- x: 0, y: 400, title: "mini collection"
-});
-mainContainer = doc4;
+
+Utils.EmitCallback(Server.Socket, MessageStore.GetField, "dash", (res: any) => {
+ console.log("HELLO WORLD")
+ console.log("RESPONSE: " + res)
+ let mainContainer: Document = new Document();
+ if (res) {
+ let obj = ServerUtils.FromJson(res) as Document
+ mainContainer = obj
+ console.log(mainContainer)
+ }
+ else {
+ const docset: Document[] = [];
+ let doc4 = Documents.CollectionDocument(docset, {
+ x: 0, y: 400, title: "mini collection"
+ }, true);
+ mainContainer = doc4;
+ let args = new DocumentTransfer(mainContainer.ToJson())
+ Utils.Emit(Server.Socket, MessageStore.AddDocument, args)
+ }
+
+ let addImageNode = action(() => {
+ mainContainer.GetList<Document>(KeyStore.Data, []).push(Documents.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", {
+ x: 0, y: 300, width: 200, height: 200, title: "added note"
+ }));
+ })
+ let addTextNode = action(() => {
+ mainContainer.GetList<Document>(KeyStore.Data, []).push(Documents.TextDocument({
+ x: 0, y: 300, width: 200, height: 200, title: "added note"
+ }));
+ })
+ let addColNode = action(() => {
+ mainContainer.GetList<Document>(KeyStore.Data, []).push(Documents.CollectionDocument([], {
+ x: 0, y: 300, width: 200, height: 200, title: "added note"
+ }));
+ })
+
+ ReactDOM.render((
+ <div style={{ position: "absolute", width: "100%", height: "100%" }}>
+ <DocumentView Document={mainContainer} ContainingCollectionView={undefined} DocumentView={undefined} />
+ <DocumentDecorations />
+ <ContextMenu />
+ <button style={{
+ position: 'absolute',
+ bottom: '0px',
+ left: '0px',
+ width: '150px'
+ }} onClick={addImageNode}>Add Image</button>
+ <button style={{
+ position: 'absolute',
+ bottom: '25px',
+ left: '0px',
+ width: '150px'
+ }} onClick={addTextNode}>Add Text</button>
+ <button style={{
+ position: 'absolute',
+ bottom: '50px',
+ left: '0px',
+ width: '150px'
+ }} onClick={addColNode}>Add Collection</button>
+ </div>),
+ document.getElementById('root'));
+})
// let doc5 = Documents.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", {
// x: 650, y: 500, width: 600, height: 600, title: "cat 2"
// });
@@ -78,45 +140,3 @@ mainContainer = doc4;
// mainContainer.Set(KeyStore.Data, mainNodes);
//}
//);
-
-let addImageNode = action(() => {
- doc4.GetList<Document>(KeyStore.Data, []).push(Documents.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", {
- x: 0, y: 300, width: 200, height: 200, title: "added note"
- }));
-})
-let addTextNode = action(() => {
- doc4.GetList<Document>(KeyStore.Data, []).push(Documents.TextDocument({
- x: 0, y: 300, width: 200, height: 200, title: "added note"
- }));
-})
-let addColNode = action(() => {
- doc4.GetList<Document>(KeyStore.Data, []).push(Documents.CollectionDocument([], {
- x: 0, y: 300, width: 200, height: 200, title: "added note"
- }));
-})
-
-ReactDOM.render((
- <div style={{ position: "absolute", width: "100%", height: "100%" }}>
- <DocumentView Document={mainContainer} ContainingCollectionView={undefined} DocumentView={undefined} />
- <DocumentDecorations />
- <ContextMenu />
- <button style={{
- position: 'absolute',
- bottom: '0px',
- left: '0px',
- width: '150px'
- }} onClick={addImageNode}>Add Image</button>
- <button style={{
- position: 'absolute',
- bottom: '25px',
- left: '0px',
- width: '150px'
- }} onClick={addTextNode}>Add Text</button>
- <button style={{
- position: 'absolute',
- bottom: '50px',
- left: '0px',
- width: '150px'
- }} onClick={addColNode}>Add Collection</button>
- </div>),
- document.getElementById('root')); \ No newline at end of file