diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/documents/Documents.ts | 12 | ||||
-rw-r--r-- | src/client/util/Import & Export/DirectoryImportBox.scss | 0 | ||||
-rw-r--r-- | src/client/util/Import & Export/DirectoryImportBox.tsx (renamed from src/client/util/Import & Export/ImportBox.tsx) | 71 | ||||
-rw-r--r-- | src/client/util/Import & Export/ImageImporter.tsx | 67 | ||||
-rw-r--r-- | src/client/util/request-image-size.js | 6 | ||||
-rw-r--r-- | src/client/views/MainView.tsx | 1 | ||||
-rw-r--r-- | src/client/views/collections/CollectionSubView.tsx | 4 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentContentsView.tsx | 4 | ||||
-rw-r--r-- | src/client/views/nodes/ImageBox.tsx | 4 |
9 files changed, 76 insertions, 93 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 5d637dd3a..26b5498a2 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -36,7 +36,7 @@ import { UndoManager } from "../util/UndoManager"; import { RouteStore } from "../../server/RouteStore"; import { LinkManager } from "../util/LinkManager"; import { DocumentManager } from "../util/DocumentManager"; -import ImportBox from "../util/Import & Export/ImportBox"; +import DirectoryImportBox from "../util/Import & Export/DirectoryImportBox"; var requestImageSize = require('../util/request-image-size'); var path = require('path'); @@ -180,7 +180,7 @@ export namespace Docs { } function CreateImportPrototype(): Doc { - let importProto = setupPrototypeOptions(importProtoId, "IMPORT_PROTO", ImportBox.LayoutString(), { x: 0, y: 0, width: 600, height: 600, type: DocTypes.IMPORT }); + let importProto = setupPrototypeOptions(importProtoId, "IMPORT_PROTO", DirectoryImportBox.LayoutString(), { x: 0, y: 0, width: 600, height: 600, type: DocTypes.IMPORT }); return importProto; } @@ -347,7 +347,7 @@ export namespace Docs { return CreateInstance(collProto, new List(documents), { ...options, viewType: CollectionViewType.Docking, dockingConfig: config }, id); } - export async function getDocumentFromType(type: string, path: string, options: DocumentOptions, addDocument?: (document: Doc, allowDuplicates?: boolean) => boolean): Promise<Opt<Doc>> { + export async function getDocumentFromType(type: string, path: string, options: DocumentOptions): Promise<Opt<Doc>> { let ctor: ((path: string, options: DocumentOptions) => (Doc | Promise<Doc | undefined>)) | undefined = undefined; if (type.indexOf("image") !== -1) { ctor = Docs.ImageDocument; @@ -370,17 +370,17 @@ export namespace Docs { if (path.includes(window.location.hostname)) { let s = path.split('/'); let id = s[s.length - 1]; - DocServer.GetRefField(id).then(field => { + return DocServer.GetRefField(id).then(field => { if (field instanceof Doc) { let alias = Doc.MakeAlias(field); alias.x = options.x || 0; alias.y = options.y || 0; alias.width = options.width || 300; alias.height = options.height || options.width || 300; - addDocument && addDocument(alias, false); + return alias; } + return undefined; }); - return undefined; } ctor = Docs.WebDocument; options = { height: options.width, ...options, title: path, nativeWidth: undefined }; diff --git a/src/client/util/Import & Export/DirectoryImportBox.scss b/src/client/util/Import & Export/DirectoryImportBox.scss new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/client/util/Import & Export/DirectoryImportBox.scss diff --git a/src/client/util/Import & Export/ImportBox.tsx b/src/client/util/Import & Export/DirectoryImportBox.tsx index 630911710..2d77f6ae6 100644 --- a/src/client/util/Import & Export/ImportBox.tsx +++ b/src/client/util/Import & Export/DirectoryImportBox.tsx @@ -3,31 +3,42 @@ import React = require("react"); import { Doc } from "../../../new_fields/Doc"; import { DocServer } from "../../DocServer"; import { RouteStore } from "../../../server/RouteStore"; -import { action, observable } from "mobx"; +import { action, observable, runInAction } from "mobx"; import { FieldViewProps, FieldView } from "../../views/nodes/FieldView"; import Measure, { ContentRect } from "react-measure"; import { library } from '@fortawesome/fontawesome-svg-core'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { faArrowUp } from '@fortawesome/free-solid-svg-icons'; +import { faArrowUp, faTag, faFileExcel } from '@fortawesome/free-solid-svg-icons'; import { Docs, DocumentOptions } from "../../documents/Documents"; +import { EditableView } from "../../views/EditableView"; -interface ImageImporterProps { - addSchema: (imageDocs: Doc[]) => void; -} - -export default class ImportBox extends React.Component<FieldViewProps> { +export default class DirectoryImportBox extends React.Component<FieldViewProps> { + private selector = React.createRef<HTMLInputElement>(); @observable private top = 0; @observable private left = 0; private dimensions = 50; + @observable private key = "Key"; + @observable private value = "Value"; + + public static LayoutString() { return FieldView.LayoutString(DirectoryImportBox); } + constructor(props: FieldViewProps) { super(props); - library.add(faArrowUp); + library.add(faArrowUp, faTag); } - public static LayoutString() { return FieldView.LayoutString(ImportBox); } + updateKey = (newKey: string) => { + runInAction(() => this.key = newKey); + console.log("KEY ", this.key); + return true; + } - private selector = React.createRef<HTMLInputElement>(); + updateValue = (newValue: string) => { + runInAction(() => this.value = newValue); + console.log("VALUE ", this.value); + return true; + } handleSelection = async (e: React.ChangeEvent<HTMLInputElement>) => { let promises: Promise<void>[] = []; @@ -56,6 +67,7 @@ export default class ImportBox extends React.Component<FieldViewProps> { }).then(async (res: Response) => { (await res.json()).map(action((file: any) => { let path = DocServer.prepend(file); + console.log(path); let docPromise = Docs.getDocumentFromType(type, path, { nativeWidth: 300, width: 300, title: dropFileName }); docPromise.then(doc => doc && docs.push(doc)); })); @@ -76,8 +88,8 @@ export default class ImportBox extends React.Component<FieldViewProps> { } componentDidMount() { - this.selector.current!.setAttribute("directory", "true"); - this.selector.current!.setAttribute("webkitdirectory", "true"); + this.selector.current!.setAttribute("directory", ""); + this.selector.current!.setAttribute("webkitdirectory", ""); } @action @@ -93,6 +105,7 @@ export default class ImportBox extends React.Component<FieldViewProps> { render() { let dimensions = 50; + let keyValueStyle = { paddingLeft: 5, width: "50%" }; return ( <Measure offset onResize={this.preserveCentering}> {({ measureRef }) => @@ -125,6 +138,40 @@ export default class ImportBox extends React.Component<FieldViewProps> { <FontAwesomeIcon icon={faArrowUp} color="#FFFFFF" size={"2x"} /> </div> </label> + <div style={{ + position: "absolute", + top: 5, + right: 5, + borderRadius: "50%", + width: 25, + height: 25, + background: "black" + }} /> + <div style={{ + position: "absolute", + right: 9.5, + top: 11 + }}> + <FontAwesomeIcon icon={faTag} color="#FFFFFF" size={"1x"} /> + </div> + <div style={{ display: "flex", flexDirection: "row", borderBottom: "1px solid black", paddingBottom: 5 }} > + <div className={"key_container"} style={keyValueStyle}> + <EditableView + contents={this.key} + SetValue={this.updateKey} + GetValue={() => this.key} + oneLine={true} + /> + </div> + <div className={"value_container"} style={keyValueStyle}> + <EditableView + contents={this.value} + SetValue={this.updateValue} + GetValue={() => this.value} + oneLine={true} + /> + </div> + </div> </div> } </Measure> diff --git a/src/client/util/Import & Export/ImageImporter.tsx b/src/client/util/Import & Export/ImageImporter.tsx deleted file mode 100644 index d664f6487..000000000 --- a/src/client/util/Import & Export/ImageImporter.tsx +++ /dev/null @@ -1,67 +0,0 @@ -import "fs"; -import React = require("react"); -import { Doc } from "../../../new_fields/Doc"; -import { DocServer } from "../../DocServer"; -import { RouteStore } from "../../../server/RouteStore"; -import { action } from "mobx"; -import { Docs } from "../../documents/Documents"; -import { FieldViewProps } from "../../views/nodes/FieldView"; - -interface ImageImporterProps { - addSchema: (imageDocs: Doc[]) => void; -} - -export default class BulkImporter extends React.Component<FieldViewProps> { - private selector = React.createRef<HTMLInputElement>(); - - handleSelection = async (e: React.ChangeEvent<HTMLInputElement>) => { - let promises: Promise<void>[] = []; - let docs: Doc[] = []; - - let files = e.target.files; - if (!files) return; - - for (let i = 0; i < files.length; i++) { - let target = files.item(i); - - if (target === null) { - continue; - } - - let type = target.type; - let formData = new FormData(); - formData.append('file', target); - let dropFileName = target ? target.name : "-empty-"; - - let prom = fetch(DocServer.prepend(RouteStore.upload), { - method: 'POST', - body: formData - }).then(async (res: Response) => { - (await res.json()).map(action((file: any) => { - let path = window.location.origin + file; - let docPromise = Docs.getDocumentFromType(type, path, { nativeWidth: 300, width: 300, title: dropFileName }); - docPromise.then(doc => doc && docs.push(doc)); - })); - }); - promises.push(prom); - } - - await Promise.all(promises); - - let parent = Docs.SchemaDocument(["title", "data"], docs, { width: 300, height: 300, title: "Bulk Import from Directory" }); - } - - componentDidMount() { - this.selector.current!.setAttribute("directory", "true"); - this.selector.current!.setAttribute("webkitdirectory", "true"); - } - - render() { - return ( - <div> - <input ref={this.selector} name={"selector"} onChange={this.handleSelection} type="file" style={{ position: "absolute" }} /> - </div> - ); - } - -}
\ No newline at end of file diff --git a/src/client/util/request-image-size.js b/src/client/util/request-image-size.js index 0f9328872..27605d167 100644 --- a/src/client/util/request-image-size.js +++ b/src/client/util/request-image-size.js @@ -21,7 +21,9 @@ module.exports = function requestImageSize(options) { if (options && typeof options === 'object') { opts = Object.assign(options, opts); } else if (options && typeof options === 'string') { - opts = Object.assign({ uri: options }, opts); + opts = Object.assign({ + uri: options + }, opts); } else { return Promise.reject(new Error('You should provide an URI string or a "request" options object.')); } @@ -70,4 +72,4 @@ module.exports = function requestImageSize(options) { req.on('error', err => reject(err)); }); -}; +};
\ No newline at end of file diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx index e38fd3c8b..3d059b2f3 100644 --- a/src/client/views/MainView.tsx +++ b/src/client/views/MainView.tsx @@ -38,7 +38,6 @@ import PDFMenu from './pdf/PDFMenu'; import { InkTool } from '../../new_fields/InkField'; import _ from "lodash"; import KeyManager from './GlobalKeyHandler'; -import BulkImporter from '../util/Import & Export/ImageImporter'; @observer export class MainView extends React.Component { diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx index e886ad84a..8cb2e1beb 100644 --- a/src/client/views/collections/CollectionSubView.tsx +++ b/src/client/views/collections/CollectionSubView.tsx @@ -182,7 +182,7 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) { .then(result => { let type = result["content-type"]; if (type) { - Docs.getDocumentFromType(type, str, { ...options, width: 300, nativeWidth: 300 }, this.props.addDocument) + Docs.getDocumentFromType(type, str, { ...options, width: 300, nativeWidth: 300 }) .then(doc => doc && this.props.addDocument(doc, false)); } }); @@ -204,7 +204,7 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) { }).then(async (res: Response) => { (await res.json()).map(action((file: any) => { let path = window.location.origin + file; - let docPromise = Docs.getDocumentFromType(type, path, { ...options, nativeWidth: 300, width: 300, title: dropFileName }, this.props.addDocument); + let docPromise = Docs.getDocumentFromType(type, path, { ...options, nativeWidth: 300, width: 300, title: dropFileName }); docPromise.then(doc => doc && this.props.addDocument(doc)); })); }); diff --git a/src/client/views/nodes/DocumentContentsView.tsx b/src/client/views/nodes/DocumentContentsView.tsx index e9fec1588..0bfb2954f 100644 --- a/src/client/views/nodes/DocumentContentsView.tsx +++ b/src/client/views/nodes/DocumentContentsView.tsx @@ -24,7 +24,7 @@ import { Without, OmitKeys } from "../../../Utils"; import { Cast, StrCast, NumCast } from "../../../new_fields/Types"; import { List } from "../../../new_fields/List"; import { Doc } from "../../../new_fields/Doc"; -import ImportBox from "../../util/Import & Export/ImportBox"; +import DirectoryImportBox from "../../util/Import & Export/DirectoryImportBox"; const JsxParser = require('react-jsx-parser').default; //TODO Why does this need to be imported like this? type BindingProps = Without<FieldViewProps, 'fieldKey'>; @@ -107,7 +107,7 @@ export class DocumentContentsView extends React.Component<DocumentViewProps & { if (this.props.renderDepth > 7) return (null); if (!this.layout && (this.props.layoutKey !== "overlayLayout" || !this.templates.length)) return (null); return <ObserverJsxParser - components={{ FormattedTextBox, ImageBox, IconBox, ImportBox, FieldView, CollectionFreeFormView, CollectionDockingView, CollectionSchemaView, CollectionView, CollectionPDFView, CollectionVideoView, WebBox, KeyValueBox, PDFBox, VideoBox, AudioBox, HistogramBox }} + components={{ FormattedTextBox, ImageBox, IconBox, DirectoryImportBox, FieldView, CollectionFreeFormView, CollectionDockingView, CollectionSchemaView, CollectionView, CollectionPDFView, CollectionVideoView, WebBox, KeyValueBox, PDFBox, VideoBox, AudioBox, HistogramBox }} bindings={this.CreateBindings(this.props.Document.layout instanceof Doc ? this.props.Document.layout : this.props.Document)} jsx={this.finalLayout} showWarnings={true} diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx index 06bf65f73..88c122b61 100644 --- a/src/client/views/nodes/ImageBox.tsx +++ b/src/client/views/nodes/ImageBox.tsx @@ -213,7 +213,9 @@ export class ImageBox extends DocComponent<FieldViewProps, ImageDocument>(ImageD }), 0); } }) - .catch((err: any) => console.log(err)); + .catch((err: any) => { + console.log(err); + }); } render() { |