aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/CollectionSubView.tsx
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2020-02-14 15:36:56 -0500
committerSam Wilkins <samwilkins333@gmail.com>2020-02-14 15:36:56 -0500
commit3502cd93891030fa1c9ee21e55354127665acd0b (patch)
treede3ac80ff312904aaab31b75978aa7e9873f6131 /src/client/views/collections/CollectionSubView.tsx
parent3cce5982497564a0f5d69d0248ed07d76ec7bbe8 (diff)
parent5aecc6d75868dcafd0b1bb560ad5a4ad8ab976fa (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web
Diffstat (limited to 'src/client/views/collections/CollectionSubView.tsx')
-rw-r--r--src/client/views/collections/CollectionSubView.tsx114
1 files changed, 63 insertions, 51 deletions
diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx
index 32480ad4e..0963e1ea6 100644
--- a/src/client/views/collections/CollectionSubView.tsx
+++ b/src/client/views/collections/CollectionSubView.tsx
@@ -159,7 +159,7 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) {
const docDragData = de.complete.docDragData;
(this.props.Document.dropConverter instanceof ScriptField) &&
this.props.Document.dropConverter.script.run({ dragData: docDragData }); /// bcz: check this
- if (docDragData && !docDragData.applyAsTemplate) {
+ if (docDragData) {
if (de.altKey && docDragData.draggedDocuments.length) {
this.childDocs.map(doc => {
doc.layout_fromParent = docDragData.draggedDocuments[0];
@@ -253,7 +253,8 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) {
}
});
} else {
- const htmlDoc = Docs.Create.HtmlDocument(html, { ...options, title: "-web page-", _width: 300, _height: 300, documentText: text });
+ const htmlDoc = Docs.Create.HtmlDocument(html, { ...options, title: "-web page-", _width: 300, _height: 300 });
+ Doc.GetProto(htmlDoc)["data-text"] = text;
this.props.addDocument(htmlDoc);
}
return;
@@ -283,63 +284,74 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) {
const albumId = matches[3];
const mediaItems = await GooglePhotos.Query.AlbumSearch(albumId);
console.log(mediaItems);
+ return;
}
- const batch = UndoManager.StartBatch("collection view drop");
- const promises: Promise<void>[] = [];
- // tslint:disable-next-line:prefer-for-of
- for (let i = 0; i < e.dataTransfer.items.length; i++) {
- const item = e.dataTransfer.items[i];
- if (item.kind === "string" && item.type.indexOf("uri") !== -1) {
- let str: string;
- const prom = new Promise<string>(resolve => e.dataTransfer.items[i].getAsString(resolve))
- .then(action((s: string) => rp.head(Utils.CorsProxy(str = s))))
- .then(result => {
- const type = result["content-type"];
- if (type) {
- Docs.Get.DocumentFromType(type, str, options)
- .then(doc => doc && this.props.addDocument(doc));
- }
- });
- promises.push(prom);
- }
- const type = item.type;
- if (item.kind === "file") {
- const file = item.getAsFile();
- const formData = new FormData();
-
- if (!file || !file.type) {
- continue;
+ const { items } = e.dataTransfer;
+ const { length } = items;
+ if (length) {
+ const batch = UndoManager.StartBatch("collection view drop");
+ const promises: Promise<void>[] = [];
+ // tslint:disable-next-line:prefer-for-of
+ for (let i = 0; i < length; i++) {
+ const item = e.dataTransfer.items[i];
+ if (item.kind === "string" && item.type.indexOf("uri") !== -1) {
+ let str: string;
+ const prom = new Promise<string>(resolve => item.getAsString(resolve))
+ .then(action((s: string) => rp.head(Utils.CorsProxy(str = s))))
+ .then(result => {
+ const type = result["content-type"];
+ if (type) {
+ Docs.Get.DocumentFromType(type, str, options)
+ .then(doc => doc && this.props.addDocument(doc));
+ }
+ });
+ promises.push(prom);
}
+ const type = item.type;
+ if (item.kind === "file") {
+ const file = item.getAsFile();
+ const formData = new FormData();
+
+ if (!file || !file.type) {
+ continue;
+ }
- formData.append('file', file);
- const dropFileName = file ? file.name : "-empty-";
- promises.push(Networking.PostFormDataToServer("/uploadFormData", formData).then(results => {
- results.map(action((result: any) => {
- const { accessPaths, nativeWidth, nativeHeight, contentSize } = result;
- const full = { ...options, _width: 300, title: dropFileName };
- const pathname = Utils.prepend(accessPaths.agnostic.client);
- Docs.Get.DocumentFromType(type, pathname, full).then(doc => {
- if (doc) {
- const proto = Doc.GetProto(doc);
- proto.fileUpload = basename(pathname).replace("upload_", "").replace(/\.[a-z0-9]*$/, "");
- nativeWidth && (proto["data-nativeWidth"] = nativeWidth);
- nativeHeight && (proto["data-nativeHeight"] = nativeHeight);
- contentSize && (proto.contentSize = contentSize);
- this.props?.addDocument(doc);
+ formData.append('file', file);
+ const dropFileName = file ? file.name : "-empty-";
+ promises.push(Networking.PostFormDataToServer("/uploadFormData", formData).then(results => {
+ results.map(action((result: any) => {
+ const { accessPaths, nativeWidth, nativeHeight, contentSize } = result;
+ if (Object.keys(accessPaths).length) {
+ const full = { ...options, _width: 300, title: dropFileName };
+ const pathname = Utils.prepend(accessPaths.agnostic.client);
+ Docs.Get.DocumentFromType(type, pathname, full).then(doc => {
+ if (doc) {
+ const proto = Doc.GetProto(doc);
+ proto.fileUpload = basename(pathname).replace("upload_", "").replace(/\.[a-z0-9]*$/, "");
+ nativeWidth && (proto["data-nativeWidth"] = nativeWidth);
+ nativeHeight && (proto["data-nativeHeight"] = nativeHeight);
+ contentSize && (proto.contentSize = contentSize);
+ this.props?.addDocument(doc);
+ }
+ });
+ } else {
+ alert("Upload failed...");
}
- });
+ }));
}));
- }));
+ }
}
- }
- if (promises.length) {
- Promise.all(promises).finally(() => { completed && completed(); batch.end(); });
- } else {
- if (text && !text.includes("https://")) {
- this.props.addDocument(Docs.Create.TextDocument(text, { ...options, _width: 400, _height: 315 }));
+ if (promises.length) {
+ Promise.all(promises).finally(() => { completed && completed(); batch.end(); });
+ } else {
+ if (text && !text.includes("https://")) {
+ this.props.addDocument(Docs.Create.TextDocument(text, { ...options, _width: 400, _height: 315 }));
+ }
+ batch.end();
}
- batch.end();
+ } else {
+ alert("No uploadable content found.");
}
}
}