import { action, runInAction, observable, computed } from "mobx"; import { Document } from "../../../fields/Document"; import { ListField } from "../../../fields/ListField"; import React = require("react"); import { KeyStore } from "../../../fields/KeyStore"; import { FieldWaiting } from "../../../fields/Field"; import { undoBatch } from "../../util/UndoManager"; import { DragManager } from "../../util/DragManager"; import { DocumentView } from "../nodes/DocumentView"; import { Documents, DocumentOptions } from "../../documents/Documents"; import { Key } from "../../../fields/Key"; import { Transform } from "../../util/Transform"; import { CollectionView } from "./CollectionView"; import { RouteStore } from "../../../server/RouteStore"; import { TupleField } from "../../../fields/TupleField"; import { Server } from "mongodb"; import { DashUserModel } from "../../../server/authentication/models/user_model"; export interface CollectionViewProps { fieldKey: Key; Document: Document; ScreenToLocalTransform: () => Transform; isSelected: () => boolean; isTopMost: boolean; select: (ctrlPressed: boolean) => void; bindings: any; panelWidth: () => number; panelHeight: () => number; focus: (doc: Document) => void; } export interface SubCollectionViewProps extends CollectionViewProps { active: () => boolean; addDocument: (doc: Document) => void; removeDocument: (doc: Document) => boolean; CollectionView: CollectionView; currentUser?: DashUserModel; } export type CursorEntry = TupleField; export class CollectionViewBase extends React.Component { private dropDisposer?: DragManager.DragDropDisposer; protected createDropTarget = (ele: HTMLDivElement) => { if (this.dropDisposer) { this.dropDisposer(); } if (ele) { this.dropDisposer = DragManager.MakeDropTarget(ele, { handlers: { drop: this.drop.bind(this) } }); } } protected setCursorPosition(position: [number, number]) { let user = this.props.currentUser; if (user && user.id) { let ind; let doc = this.props.Document; let cursors = doc.GetOrCreate>(KeyStore.Cursors, ListField, false).Data; let entry = new TupleField([user.id, position]); // if ((ind = cursors.findIndex(entry => entry.Data[0] === user.id)) > -1) { // cursors[ind] = entry; // } else { // cursors.push(entry); // } } } protected getCursors(): CursorEntry[] { let user = this.props.currentUser; if (user && user.id) { let doc = this.props.Document; // return doc.GetList(KeyStore.Cursors, []).filter(entry => entry.Data[0] !== user.id); } return []; } @undoBatch @action protected drop(e: Event, de: DragManager.DropEvent) { const docView: DocumentView = de.data["documentView"]; const doc: Document = de.data["document"]; if (docView && (!docView.props.ContainingCollectionView || docView.props.ContainingCollectionView !== this.props.CollectionView)) { if (docView.props.RemoveDocument) { docView.props.RemoveDocument(docView.props.Document); } this.props.addDocument(docView.props.Document); } else if (doc) { this.props.removeDocument(doc); this.props.addDocument(doc); } e.stopPropagation(); } @action protected onDrop(e: React.DragEvent, options: DocumentOptions): void { let that = this; let html = e.dataTransfer.getData("text/html"); let text = e.dataTransfer.getData("text/plain"); if (text && text.startsWith(" this.props.addDocument(Documents.WebDocument(s, options)))) } let type = item.type console.log(type) if (item.kind == "file") { let fReader = new FileReader() let file = item.getAsFile(); let formData = new FormData() if (file) { formData.append('file', file) } 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: any; if (type.indexOf("image") !== -1) { doc = Documents.ImageDocument(path, { ...options, nativeWidth: 200, width: 200, }) } if (type.indexOf("video") !== -1) { doc = Documents.VideoDocument(path, { ...options, nativeWidth: 300, width: 300, }) } if (type.indexOf("audio") !== -1) { doc = Documents.AudioDocument(path, { ...options, nativeWidth: 300, width: 300, }) } if (type.indexOf("pdf") !== -1) { doc = Documents.PdfDocument(path, { ...options, nativeWidth: 300, width: 300, }) } let docs = that.props.Document.GetT(KeyStore.Data, ListField); if (docs != FieldWaiting) { if (!docs) { docs = new ListField(); that.props.Document.Set(KeyStore.Data, docs) } if (doc) { docs.Data.push(doc); } } }) }) }) } } } }