aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/Server.ts2
-rw-r--r--src/client/views/Main.tsx18
-rw-r--r--src/client/views/nodes/DocumentView.tsx2
-rw-r--r--src/debug/Viewer.tsx4
-rw-r--r--src/fields/KeyStore.ts3
-rw-r--r--src/mobile/ImageUpload.scss13
-rw-r--r--src/mobile/ImageUpload.tsx79
-rw-r--r--src/mobile/InkControls.tsx0
-rw-r--r--src/server/index.ts22
9 files changed, 137 insertions, 6 deletions
diff --git a/src/client/Server.ts b/src/client/Server.ts
index f2d7de75c..5e42c8285 100644
--- a/src/client/Server.ts
+++ b/src/client/Server.ts
@@ -145,4 +145,4 @@ export class Server {
}
Server.Socket.on(MessageStore.Foo.Message, Server.connected);
-Server.Socket.on(MessageStore.SetField.Message, Server.updateField); \ No newline at end of file
+Server.Socket.on(MessageStore.SetField.Message, Server.updateField);
diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx
index f6e19f6c9..2b5efa07d 100644
--- a/src/client/views/Main.tsx
+++ b/src/client/views/Main.tsx
@@ -32,6 +32,8 @@ import { faPenNib } from '@fortawesome/free-solid-svg-icons';
import { faFilm } from '@fortawesome/free-solid-svg-icons';
import { faMusic } from '@fortawesome/free-solid-svg-icons';
import Measure from 'react-measure';
+import { Field, Opt } from '../../fields/Field';
+import { ListField } from '../../fields/ListField';
configure({ enforceActions: "observed" }); // causes errors to be generated when modifying an observable outside of an action
@@ -44,6 +46,7 @@ document.addEventListener("pointerdown", action(function (e: PointerEvent) {
}), true)
const pathname = window.location.pathname.split("/");
const mainDocId = pathname[pathname.length - 1];
+const pendingDocId = "pending-doc"
var mainContainer: Document;
let mainfreeform: Document;
@@ -79,9 +82,24 @@ Documents.initProtos(mainDocId, (res?: Document) => {
var dockingLayout = { content: [{ type: 'row', content: [CollectionDockingView.makeDocumentConfig(mainfreeform)] }] };
mainContainer.SetText(KeyStore.Data, JSON.stringify(dockingLayout));
mainContainer.Set(KeyStore.ActiveFrame, mainfreeform);
+ let pendingDocument = Documents.SchemaDocument([], { title: "New Mobile Uploads" }, pendingDocId)
+ mainContainer.Set(KeyStore.OptionalRightCollection, pendingDocument)
}, 0);
}
+ // if there is a pending doc, and it has new data, show it (syip: we use a timeout to prevent collection docking view from being uninitialized)
+ setTimeout(() => {
+ Server.GetField(pendingDocId, (res?: Field) => {
+ if (res instanceof Document) {
+ res.GetTAsync<ListField<Document>>(KeyStore.Data, ListField, (f: Opt<ListField<Document>>) => {
+ if (f && f.Data.length > 0) {
+ CollectionDockingView.Instance.AddRightSplit(res)
+ }
+ })
+ }
+ })
+ }, 100)
+
let imgurl = "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg";
let pdfurl = "http://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611_sample_explain.pdf"
let weburl = "https://cs.brown.edu/courses/cs166/";
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index 5d2f6293d..6a3967b3b 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -334,7 +334,7 @@ export class DocumentView extends React.Component<DocumentViewProps> {
onContextMenu={this.onContextMenu}
onPointerDown={this.onPointerDown} >
<DocumentContentsView {...this.props} isSelected={this.isSelected} select={this.select} layoutKey={KeyStore.Layout} />
- </div>
+ </div >
)
}
} \ No newline at end of file
diff --git a/src/debug/Viewer.tsx b/src/debug/Viewer.tsx
index 780e9f8f2..7fdd77bf3 100644
--- a/src/debug/Viewer.tsx
+++ b/src/debug/Viewer.tsx
@@ -137,11 +137,13 @@ class DebugViewer extends React.Component<{ fieldId: string }> {
content = (<FieldViewer field={this.field} />)
} else if (this.field instanceof Key) {
content = (<KeyViewer field={this.field} />)
+ } else {
+ content = (<span>Unrecognized field type</span>)
}
} else if (this.error) {
content = <span>Field <b>{this.props.fieldId}</b> not found <button onClick={() => this.update()}>Refresh</button></span>
} else {
- content = <>Field loading</>
+ content = <span>Field loading: {this.props.fieldId}</span>
}
return content;
}
diff --git a/src/fields/KeyStore.ts b/src/fields/KeyStore.ts
index 06cdc8fc8..9c7a45af4 100644
--- a/src/fields/KeyStore.ts
+++ b/src/fields/KeyStore.ts
@@ -37,4 +37,7 @@ export namespace KeyStore {
export const CurPage = new Key("CurPage");
export const NumPages = new Key("NumPages");
export const Ink = new Key("Ink");
+ export const OptionalRightCollection = new Key("OptionalRightCollection");
+ export const Archives = new Key("Archives");
+ export const Updated = new Key("Updated");
}
diff --git a/src/mobile/ImageUpload.scss b/src/mobile/ImageUpload.scss
new file mode 100644
index 000000000..d0b7d4e41
--- /dev/null
+++ b/src/mobile/ImageUpload.scss
@@ -0,0 +1,13 @@
+.imgupload_cont {
+ height: 100vh;
+ width: 100vw;
+ align-content: center;
+ .button_file {
+ text-align: center;
+ height: 50%;
+ width: 50%;
+ background-color: paleturquoise;
+ color: grey;
+ font-size: 3em;
+ }
+} \ No newline at end of file
diff --git a/src/mobile/ImageUpload.tsx b/src/mobile/ImageUpload.tsx
new file mode 100644
index 000000000..292a3a035
--- /dev/null
+++ b/src/mobile/ImageUpload.tsx
@@ -0,0 +1,79 @@
+import * as ReactDOM from 'react-dom';
+import React = require('react');
+import "./ImageUpload.scss"
+import { action, runInAction } from "mobx";
+import { type } from 'os';
+import { Documents } from '../client/documents/Documents';
+import { Document } from '../fields/Document';
+import { Server } from '../client/Server';
+import { Opt, Field } from '../fields/Field';
+import { ListField } from '../fields/ListField';
+import { KeyStore } from '../fields/KeyStore';
+import { ImageField } from '../fields/ImageField';
+
+
+
+
+// const onPointerDown = (e: React.TouchEvent) => {
+// let imgInput = document.getElementById("input_image_file");
+// if (imgInput) {
+// imgInput.click();
+// }
+// }
+const pendingDocId = "pending-doc"
+
+const onFileLoad = (file: any) => {
+ let imgPrev = document.getElementById("img_preview")
+ if (imgPrev) {
+ let files: File[] = file.target.files;
+ if (files.length != 0) {
+ console.log(files[0]);
+ let formData = new FormData();
+ formData.append("file", files[0]);
+
+ const upload = window.location.origin + "/upload"
+ fetch(upload, {
+ method: 'POST',
+ body: formData
+ }).then((res: Response) => {
+ return res.json()
+ }).then(json => {
+ json.map((file: any) => {
+ let path = window.location.origin + file
+ runInAction(() => {
+ var doc: Document = Documents.ImageDocument(path, { nativeWidth: 200, width: 200 })
+ doc.GetTAsync(KeyStore.Data, ImageField, (i) => {
+ if (i) {
+ document.getElementById("message")!.innerText = i.Data.href;
+ }
+ })
+ Server.GetField(pendingDocId, (res: Opt<Field>) => {
+ if (res) {
+ if (res instanceof Document) {
+ res.GetOrCreateAsync(KeyStore.Data, ListField, (f: ListField<Document>) => {
+ f.Data.push(doc)
+ })
+ }
+ }
+ })
+ })
+ })
+ })
+ // console.log(window.location.origin + file[0])
+
+ //imgPrev.setAttribute("src", window.location.origin + files[0].name)
+ }
+ }
+
+
+}
+
+ReactDOM.render((
+ <div className="imgupload_cont">
+ {/* <button className = "button_file" = {onPointerDown}> Open Image </button> */}
+ <input type="file" accept="image/*" onChange={onFileLoad} className="input_file" id="input_image_file"></input>
+ <img id="img_preview" src=""></img>
+ <div id="message" />
+ </div>),
+ document.getElementById('root')
+); \ No newline at end of file
diff --git a/src/mobile/InkControls.tsx b/src/mobile/InkControls.tsx
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/mobile/InkControls.tsx
diff --git a/src/server/index.ts b/src/server/index.ts
index 7f1e95964..4be35b7b7 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -27,6 +27,7 @@ import * as expressValidator from 'express-validator';
import expressFlash = require('express-flash');
import * as bodyParser from 'body-parser';
import * as session from 'express-session';
+import * as mobileDetect from 'mobile-detect';
import c = require("crypto");
const MongoStore = require('connect-mongo')(session);
const mongoose = require('mongoose');
@@ -34,6 +35,7 @@ const bluebird = require('bluebird');
import { performance } from 'perf_hooks'
import * as fs from 'fs';
import * as request from 'request'
+import { exec } from 'child_process'
const download = (url: string, dest: fs.PathLike) => {
request.get(url).pipe(fs.createWriteStream(dest));
@@ -99,9 +101,23 @@ app.use('/images', express.static(__dirname + '/public'))
let FieldStore: ObservableMap<FieldId, Field> = new ObservableMap();
// define a route handler for the default home page
-app.get("/", (req, res) => {
- res.redirect("/doc/mainDoc");
- // res.sendFile(path.join(__dirname, '../../deploy/index.html'));
+app.get("/", (req: express.Request, res: express.Response) => {
+ let detector = new mobileDetect(req.headers['user-agent'] || "");
+ if (detector.mobile() != null) {
+ res.sendFile(path.join(__dirname, '../../deploy/mobile/image.html'));
+ } else {
+ res.redirect("/doc/mainDoc");
+ }
+});
+
+app.get("/pull", (req, res) => {
+ exec('"C:\\Program Files\\Git\\git-bash.exe" -c "git pull"', (err, stdout, stderr) => {
+ if (err) {
+ res.send(err.message);
+ return;
+ }
+ res.redirect("/");
+ })
});
app.get("/doc/:docId", (req, res) => {