aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-02-25 00:48:43 -0500
committerTyler Schicke <tyler_schicke@brown.edu>2019-02-25 00:48:43 -0500
commit3113bd7dfee404eea113633f97027a2370f8d817 (patch)
treeeee92237969c151bf8a9d203d23835e072634717 /src
parent7e106c6aa0bab72ae757453f88dd7616b4be0c5c (diff)
Got user workspaces working
Diffstat (limited to 'src')
-rw-r--r--src/client/views/Main.tsx178
-rw-r--r--src/server/authentication/models/User.ts2
-rw-r--r--src/server/index.ts15
3 files changed, 113 insertions, 82 deletions
diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx
index 2a3e2780b..97f68f4f5 100644
--- a/src/client/views/Main.tsx
+++ b/src/client/views/Main.tsx
@@ -19,6 +19,7 @@ import { Utils } from '../../Utils';
import { ServerUtils } from '../../server/ServerUtil';
import { MessageStore, DocumentTransfer } from '../../server/Message';
import { Database } from '../../server/database';
+import * as request from 'request'
configure({
@@ -42,6 +43,21 @@ document.addEventListener("pointerdown", action(function (e: PointerEvent) {
}
}), true)
+let mainDocId: string;
+request.get(window.location.origin + "/getUserDocId", (error, response, body) => {
+ if (body) {
+ mainDocId = body;
+ } else {
+ mainDocId = Utils.GenerateGuid();
+ request.post(window.location.origin + "/setUserDocId", {
+ body: {
+ userDocumentId: mainDocId
+ },
+ json: true
+ })
+ }
+ init();
+})
//runInAction(() =>
// let doc1 = Documents.TextDocument({ title: "hello" });
@@ -59,91 +75,91 @@ document.addEventListener("pointerdown", action(function (e: PointerEvent) {
// schemaDocs[4].SetData(KS.Author, "Bob", TextField);
// schemaDocs.push(doc2);
// const doc7 = Documents.SchemaDocument(schemaDocs)
+function init() {
+ Documents.initProtos(() => {
+ Utils.EmitCallback(Server.Socket, MessageStore.GetField, mainDocId, (res: any) => {
+ console.log("HELLO WORLD")
+ console.log("RESPONSE: " + res)
+ let mainContainer: Document;
+ if (res) {
+ var lid = KeyStore.Layout.Id;
+ let obj = ServerUtils.FromJson(res) as Document
+ mainContainer = obj
+ }
+ else {
+ const docset: Document[] = [];
+ mainContainer = Documents.CollectionDocument(docset, { x: 0, y: 400, title: "mini collection" }, mainDocId);
+ let args = new DocumentTransfer(mainContainer.ToJson())
+ Utils.Emit(Server.Socket, MessageStore.AddDocument, args)
+ }
-const mainDocId = "mainDoc";
-Documents.initProtos(() => {
- Utils.EmitCallback(Server.Socket, MessageStore.GetField, mainDocId, (res: any) => {
- console.log("HELLO WORLD")
- console.log("RESPONSE: " + res)
- let mainContainer: Document;
- if (res) {
- var lid = KeyStore.Layout.Id;
- let obj = ServerUtils.FromJson(res) as Document
- mainContainer = obj
- }
- else {
- const docset: Document[] = [];
- mainContainer = Documents.CollectionDocument(docset, { x: 0, y: 400, title: "mini collection" }, mainDocId);
- 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"
+ }));
+ })
- 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"
- }));
- })
+ let clearDatabase = action(() => {
+ Utils.Emit(Server.Socket, MessageStore.DeleteAll, {});
+ })
- let clearDatabase = action(() => {
- Utils.Emit(Server.Socket, MessageStore.DeleteAll, {});
+ ReactDOM.render((
+ <div style={{ position: "absolute", width: "100%", height: "100%" }}>
+ <a href="/logout">
+ <img
+ src="http://aux.iconspalace.com/uploads/logout-icon-256-510450847.png"
+ style={{
+ position: "absolute",
+ width: "20px",
+ height: "20px",
+ top: "20px",
+ zIndex: 15,
+ right: "20px",
+ }}
+ />
+ </a>
+ <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>
+ <button style={{
+ position: 'absolute',
+ bottom: '75px',
+ left: '0px',
+ width: '150px'
+ }} onClick={clearDatabase}>Clear Database</button>
+ </div>),
+ document.getElementById('root'));
})
-
- ReactDOM.render((
- <div style={{ position: "absolute", width: "100%", height: "100%" }}>
- <a href="/logout">
- <img
- src="http://aux.iconspalace.com/uploads/logout-icon-256-510450847.png"
- style={{
- position: "absolute",
- width: "20px",
- height: "20px",
- top: "20px",
- zIndex: 15,
- right: "20px",
- }}
- />
- </a>
- <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>
- <button style={{
- position: 'absolute',
- bottom: '75px',
- left: '0px',
- width: '150px'
- }} onClick={clearDatabase}>Clear Database</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"
// });
diff --git a/src/server/authentication/models/User.ts b/src/server/authentication/models/User.ts
index ed2952e48..bc838bb47 100644
--- a/src/server/authentication/models/User.ts
+++ b/src/server/authentication/models/User.ts
@@ -47,7 +47,7 @@ const userSchema = new mongoose.Schema({
passwordResetToken: String,
passwordResetExpires: Date,
- workspaces: Array,
+ userDocumentId: String,
facebook: String,
twitter: String,
diff --git a/src/server/index.ts b/src/server/index.ts
index 7189b32a0..87b6b0005 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -89,6 +89,21 @@ app.get("/home", (req, res) => {
res.sendFile(path.join(__dirname, '../../deploy/index.html'));
});
+app.get("/getUserDocId", (req, res) => {
+ console.log(req.user)
+ if (!req.user) {
+ return;
+ }
+ res.send(req.user.userDocumentId || "");
+})
+
+app.post("/setUserDocId", (req, res) => {
+ if (!req.user) {
+ return;
+ }
+ req.user.update({ $set: { userDocumentId: req.body.userDocumentId } }, () => { });
+})
+
// anyone attempting to navigate to localhost at this port will
// first have to login
app.get("/", getEntry);