diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | deploy/mobile/image.html | 15 | ||||
-rw-r--r-- | deploy/mobile/ink.html | 13 | ||||
-rw-r--r-- | package-lock.json | 5 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | src/client/Server.ts | 2 | ||||
-rw-r--r-- | src/client/views/Main.tsx | 18 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentView.tsx | 2 | ||||
-rw-r--r-- | src/fields/KeyStore.ts | 3 | ||||
-rw-r--r-- | src/mobile/ImageUpload.scss | 13 | ||||
-rw-r--r-- | src/mobile/ImageUpload.tsx | 72 | ||||
-rw-r--r-- | src/mobile/InkControls.tsx | 0 | ||||
-rw-r--r-- | src/server/index.ts | 22 | ||||
-rw-r--r-- | webpack.config.js | 2 |
14 files changed, 163 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore index 7b9483f69..2f9680a59 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ node_modules dist/ .DS_Store -src/server/public/files/* diff --git a/deploy/mobile/image.html b/deploy/mobile/image.html new file mode 100644 index 000000000..ae39a5217 --- /dev/null +++ b/deploy/mobile/image.html @@ -0,0 +1,15 @@ +<html> + +<head> + <title>Test view</title> + <link href="https://fonts.googleapis.com/css?family=Fjalla+One|Hind+Siliguri:300" rel="stylesheet"> +</head> + +<body> + <div id="root"> + <p>Capture Image: <input type="file" accept="image/*" id="capture" capture="camera"> + </div> + <script src="../imageUpload.js"></script> +</body> + +</html>
\ No newline at end of file diff --git a/deploy/mobile/ink.html b/deploy/mobile/ink.html new file mode 100644 index 000000000..938d85794 --- /dev/null +++ b/deploy/mobile/ink.html @@ -0,0 +1,13 @@ +<html> + +<head> + <title>Test view</title> + <link href="https://fonts.googleapis.com/css?family=Fjalla+One|Hind+Siliguri:300" rel="stylesheet"> +</head> + +<body> + <div id="root"></div> + <script src="../inkControls.js"></script> +</body> + +</html>
\ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 6280f52d9..093531ede 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5930,6 +5930,11 @@ } } }, + "mobile-detect": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/mobile-detect/-/mobile-detect-1.4.3.tgz", + "integrity": "sha512-UaahPNLllQsstHOEHAmVnTHCMQrAS9eL5Qgdi50QrYz6UgGk+Xziz2udz2GN6NYcyODcPLnasC7a7s6R2DjiaQ==" + }, "mobx": { "version": "5.9.0", "resolved": "https://registry.npmjs.org/mobx/-/mobx-5.9.0.tgz", diff --git a/package.json b/package.json index af45eabbb..f49b2e66e 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,7 @@ "jsonwebtoken": "^8.5.0", "jsx-to-string": "^1.4.0", "lodash": "^4.17.11", + "mobile-detect": "^1.4.3", "mobx": "^5.9.0", "mobx-react": "^5.3.5", "mobx-react-devtools": "^6.1.1", 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 345371884..437d025ef 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 b36d47b8b..1f803bd45 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -333,7 +333,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/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..935f5b5c1 --- /dev/null +++ b/src/mobile/ImageUpload.tsx @@ -0,0 +1,72 @@ +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'; + + + + +// 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 }) + 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/*" capture="camera" onChange={onFileLoad} className="input_file" id="input_image_file"></input> + <img id="img_preview" src=""></img> + </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) => { diff --git a/webpack.config.js b/webpack.config.js index 815e2b477..ff03181c9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -8,6 +8,8 @@ module.exports = { bundle: ["./src/client/views/Main.tsx", 'webpack-hot-middleware/client?reload=true'], viewer: ["./src/debug/Viewer.tsx", 'webpack-hot-middleware/client?reload=true'], test: ["./src/debug/Test.tsx", 'webpack-hot-middleware/client?reload=true'], + inkControls: ["./src/mobile/InkControls.tsx", 'webpack-hot-middleware/client?reload=true'], + imageUpload: ["./src/mobile/ImageUpload.tsx", 'webpack-hot-middleware/client?reload=true'], }, devtool: "source-map", node: { |