From 9ea0f409cfc2a6c11bb1cf6e00015eb97900507b Mon Sep 17 00:00:00 2001
From: bob <bcz@cs.brown.edu>
Date: Wed, 10 Apr 2019 10:45:59 -0400
Subject: fixed uploading of csv files.

---
 src/client/views/collections/CollectionSubView.tsx | 40 +++++++++++++---------
 1 file changed, 24 insertions(+), 16 deletions(-)

(limited to 'src/client/views/collections/CollectionSubView.tsx')

diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx
index 5cdea0568..588ff9483 100644
--- a/src/client/views/collections/CollectionSubView.tsx
+++ b/src/client/views/collections/CollectionSubView.tsx
@@ -87,8 +87,8 @@ export class CollectionSubView extends React.Component<SubCollectionViewProps> {
         return false;
     }
 
-    protected getDocumentFromType(type: string, path: string, options: DocumentOptions): Opt<Document> {
-        let ctor: ((path: string, options: DocumentOptions) => Document) | undefined;
+    protected async getDocumentFromType(type: string, path: string, options: DocumentOptions): Promise<Opt<Document>> {
+        let ctor: ((path: string, options: DocumentOptions) => (Document | Promise<Document | undefined>)) | undefined = undefined;
         if (type.indexOf("image") !== -1) {
             ctor = Documents.ImageDocument;
         }
@@ -102,6 +102,10 @@ export class CollectionSubView extends React.Component<SubCollectionViewProps> {
             ctor = Documents.PdfDocument;
             options.nativeWidth = 1200;
         }
+        if (type.indexOf("excel") !== -1) {
+            ctor = Documents.DBDocument;
+            options.copyDraggedItems = true;
+        }
         if (type.indexOf("html") !== -1) {
             if (path.includes('localhost')) {
                 let s = path.split('/');
@@ -159,10 +163,11 @@ export class CollectionSubView extends React.Component<SubCollectionViewProps> {
                     })).then(res => {
                         let type = res.headers["content-type"];
                         if (type) {
-                            let doc = this.getDocumentFromType(type, str, { ...options, width: 300, nativeWidth: 300 });
-                            if (doc) {
-                                this.props.addDocument(doc, false);
-                            }
+                            this.getDocumentFromType(type, str, { ...options, width: 300, nativeWidth: 300 }).then(doc => {
+                                if (doc) {
+                                    this.props.addDocument(doc, false);
+                                }
+                            });
                         }
                     });
                 promises.push(prom);
@@ -176,6 +181,7 @@ export class CollectionSubView extends React.Component<SubCollectionViewProps> {
                 if (file) {
                     formData.append('file', file);
                 }
+                let dropFileName = file ? file.name : "-empty-";
 
                 let prom = fetch(upload, {
                     method: 'POST',
@@ -185,18 +191,20 @@ export class CollectionSubView extends React.Component<SubCollectionViewProps> {
                     json.map((file: any) => {
                         let path = window.location.origin + file;
                         runInAction(() => {
-                            let doc = this.getDocumentFromType(type, path, { ...options, nativeWidth: 300, width: 300 });
+                            let docPromise = this.getDocumentFromType(type, path, { ...options, nativeWidth: 300, width: 300, title: dropFileName });
 
-                            let docs = this.props.Document.GetT(KeyStore.Data, ListField);
-                            if (docs !== FieldWaiting) {
-                                if (!docs) {
-                                    docs = new ListField<Document>();
-                                    this.props.Document.Set(KeyStore.Data, docs);
-                                }
-                                if (doc) {
-                                    docs.Data.push(doc);
+                            docPromise.then(doc => runInAction(() => {
+                                let docs = this.props.Document.GetT(KeyStore.Data, ListField);
+                                if (docs !== FieldWaiting) {
+                                    if (!docs) {
+                                        docs = new ListField<Document>();
+                                        this.props.Document.Set(KeyStore.Data, docs);
+                                    }
+                                    if (doc) {
+                                        docs.Data.push(doc);
+                                    }
                                 }
-                            }
+                            }));
                         });
                     });
                 });
-- 
cgit v1.2.3-70-g09d2

