Skip to content

TagSpaces is an offline, open source, document manager with tagging support

Perspective DnD

Stanimir Marinoveb2f95fb71f9
diff --git a/app/components/DragItemTypes.js b/app/components/DragItemTypes.js
index c80e4b265..cdc683de5 100644
--- a/app/components/DragItemTypes.js
+++ b/app/components/DragItemTypes.js
@@ -19,4 +19,5 @@
export default {
TAG: 'tag',
+ FILE: 'file_move'
};
diff --git a/app/components/FileSourceDnd.js b/app/components/FileSourceDnd.js
new file mode 100644
index 000000000..fb49c2555
--- /dev/null
+++ b/app/components/FileSourceDnd.js
@@ -0,0 +1,82 @@
+/**
+ * TagSpaces - universal file and folder organizer
+ * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License (version 3) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * @flow
+ */
+
+import React from 'react';
+import { DragSource } from 'react-dnd';
+import type { ConnectDragSource } from 'react-dnd';
+import DragItemTypes from './DragItemTypes';
+
+type Props = {
+
+ children: Array<Object>,
+ connectDragSource: ConnectDragSource
+};
+
+const boxSource = {
+ beginDrag(props) {
+ // console.log('beginDrag', props);
+ return {
+ path: props.children.props.entryPath
+ };
+ },
+
+ /* endDrag(props, monitor) {
+ const item = monitor.getItem();
+ const dropResult = monitor.getDropResult();
+
+ // console.log('DropRESULT: ', dropResult);
+ // console.log('item: ', item);
+ if (dropResult && dropResult.tagGroupId && dropResult.tagGroupId !== item.sourceTagGroupId) {
+ // console.log(`Dropped ${item.tagId} from ${item.sourceTagGroupId} into ${dropResult.tagGroupId}!`);
+ props.moveTag(item.tagId, item.sourceTagGroupId, dropResult.tagGroupId);
+ } else if (dropResult && dropResult.entryPath) {
+ // console.log(`Dropped item: ${item.tag.title} onto file: ${dropResult.entryPath}!`);
+ props.addTags([dropResult.entryPath], [item.tag]);
+ }
+ } */
+};
+
+class FileSourceDnd extends React.Component<Props> {
+ /* componentDidMount() {
+ const xml = '<svg version="1.1" height="25" width="100" xmlns="http://www.w3.org/2000/svg">' +
+ '<g>' +
+ '<rect x="0" y="0" rx="5" ry="5" width="100%" height="100%" style="fill:' + this.props.tag.color + ';opacity:0.5" />' +
+ '<text x="50%" y="55%" font-family="Roboto,Arial,Helvetica,Sans" font-size="13" dominant-baseline="middle" text-anchor="middle" fill="' + this.props.tag.textcolor + '">' + this.props.tag.title + '</text>' +
+ '</g>' +
+ '</svg>';
+ const img = new Image();
+ img.src = `data:image/svg+xml;charset=utf-8,${xml.replace(/(\r\n|\n|\r)/gm, '')}`;
+ img.onload = () => this.props.connectDragPreview(img, { anchorX: 1, anchorY: 0 });
+ // this.props.connectDragPreview(getEmptyImage(), { captureDraggingState: true });
+ } */
+
+ render() {
+ const { connectDragSource } = this.props;
+
+ return connectDragSource(
+ <span>
+ {this.props.children}
+ </span>);
+ }
+}
+
+export default DragSource(DragItemTypes.FILE, boxSource, (connect, monitor) => ({
+ connectDragSource: connect.dragSource(),
+ isDragging: monitor.isDragging()
+}))(FileSourceDnd);
diff --git a/app/components/TargetMoveFileBox.js b/app/components/TargetMoveFileBox.js
new file mode 100644
index 000000000..d4e017d76
--- /dev/null
+++ b/app/components/TargetMoveFileBox.js
@@ -0,0 +1,77 @@
+/**
+ * TagSpaces - universal file and folder organizer
+ * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License (version 3) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * @flow
+ */
+
+import React from 'react';
+import { DropTarget } from 'react-dnd';
+import { withStyles } from '@material-ui/core/styles/index';
+import i18n from '../services/i18n';
+
+const styles = theme => ({
+ dropzone: {
+ margin: 5,
+ position: 'absolute',
+ top: 0,
+ left: 0,
+ right: 0,
+ bottom: 0,
+ backgroundColor: '#1dd19f40',
+ zIndex: 1000,
+ border: '3px dashed white',
+ display: 'flex',
+ justifyContent: 'center',
+ alignItems: 'center',
+ textAlign: 'center',
+ fontSize: '40px',
+ fontWeight: 'bold',
+ color: 'white',
+ }
+});
+
+const boxTarget = {
+ drop(props, monitor, component) {
+ return component.props.onDrop(props, monitor);
+ },
+};
+
+type Props = {
+ classes: Object,
+ canDrop: boolean,
+ isOver: boolean,
+ connectDropTarget: Object,
+ children: Object
+};
+
+class TargetMoveFileBox extends React.Component<Props> {
+ render() {
+ const { classes, canDrop, isOver, connectDropTarget, children } = this.props;
+ const dragContent = canDrop && isOver ? (<div className={classes.dropzone}>{i18n.t('core:releaseToMoveDrop')}</div>) : undefined;
+ return connectDropTarget(
+ <div>
+ {dragContent}
+ {children}
+ </div>
+ );
+ }
+}
+
+export default withStyles(styles, { withTheme: true })(DropTarget(props => props.accepts, boxTarget, (connect, monitor) => ({
+ connectDropTarget: connect.dropTarget(),
+ isOver: monitor.isOver(),
+ canDrop: monitor.canDrop(),
+}))(TargetMoveFileBox));
diff --git a/app/locales/en/core.json b/app/locales/en/core.json
index 745d2b7c8..165b72972 100644
--- a/app/locales/en/core.json
+++ b/app/locales/en/core.json
@@ -350,5 +350,6 @@
"tagDelimiterComma": "comma (,)",
"maxSearchResultChoose": "Max Search Results",
"releaseToDrop": "Drop files to import them...",
+ "releaseToMoveDrop": "Move..",
"-": "-"
}
diff --git a/app/perspectives/grid-perspective/src/index.js b/app/perspectives/grid-perspective/src/index.js
index 0ca31be3d..52a104b68 100644
--- a/app/perspectives/grid-perspective/src/index.js
+++ b/app/perspectives/grid-perspective/src/index.js
@@ -19,6 +19,7 @@
import React from 'react';
import { connect } from 'react-redux';
+import { bindActionCreators } from 'redux';
import removeMd from 'remove-markdown';
import { withStyles } from '@material-ui/core/styles';
import classNames from 'classnames';
@@ -72,7 +73,11 @@ import AddRemoveTagsDialog from '../../../components/dialogs/AddRemoveTagsDialog
import MoveCopyFilesDialog from '../../../components/dialogs/MoveCopyFilesDialog';
import RenameFileDialog from '../../../components/dialogs/RenameFileDialog';
import TagDropContainer from '../../../components/TagDropContainer';
+import TargetMoveFileBox from '../../../components/TargetMoveFileBox';
+import FileSourceDnd from '../../../components/FileSourceDnd';
import AppConfig from '../../../config';
+import DragItemTypes from '../../../components/DragItemTypes';
+import IOActions from '../../../reducers/io-actions';
const maxDescriptionPreviewLength = 90;
@@ -229,7 +234,8 @@ type Props = {
removeAllTags: () => void,
editTagForEntry: () => void,
perspectiveCommand: Object,
- directoryContent: Array<FileSystemEntry>
+ directoryContent: Array<FileSystemEntry>,
+ moveFiles: (files: Array<string>, destination: string) => void
};
type State = {
@@ -427,114 +433,114 @@ class GridPerspective extends React.Component<Props, State> {
handleSortMenuIconClick = sort => {
switch (sort) {
- case 'byName':
- if (this.state.orderByName === null) {
- this.setState({
- orderBySize: null,
- orderByTags: null,
- orderByExt: null,
- orderByDate: null,
- orderByName: true
- });
- } else {
- this.setState({
- orderBySize: null,
- orderByTags: null,
- orderByExt: null,
- orderByDate: null,
- orderByName: false
- });
- }
- break;
- case 'byFileSize':
- if (this.state.orderBySize === null) {
- this.setState({
- orderByName: null,
- orderByTags: null,
- orderByExt: null,
- orderByDate: null,
- orderBySize: true
- });
- } else {
- this.setState({
- orderByName: null,
- orderByTags: null,
- orderByExt: null,
- orderByDate: null,
- orderBySize: false
- });
- }
- break;
- case 'byTags':
- if (this.state.orderByTags === null) {
- this.setState({
- orderByName: null,
- orderBySize: null,
- orderByExt: null,
- orderByDate: null,
- orderByTags: true
- });
- } else {
- this.setState({
- orderByName: null,
- orderBySize: null,
- orderByExt: null,
- orderByDate: null,
- orderByTags: false
- });
- }
- break;
- case 'byExtension':
- if (this.state.orderByExt === null) {
- this.setState({
- orderByName: null,
- orderBySize: null,
- orderByTags: null,
- orderByDate: null,
- orderByExt: true
- });
- } else {
- this.setState({
- orderByName: null,
- orderBySize: null,
- orderByTags: null,
- orderByDate: null,
- orderByExt: false
- });
- }
- break;
- case 'byDateModified':
- if (this.state.orderByDate === null) {
- this.setState({
- orderByName: null,
- orderBySize: null,
- orderByTags: null,
- orderByExt: null,
- orderByDate: true
- });
- } else {
- this.setState({
- orderByName: null,
- orderBySize: null,
- orderByTags: null,
- orderByExt: null,
- orderByDate: false
- });
- }
- break;
- default:
- break;
+ case 'byName':
+ if (this.state.orderByName === null) {
+ this.setState({
+ orderBySize: null,
+ orderByTags: null,
+ orderByExt: null,
+ orderByDate: null,
+ orderByName: true
+ });
+ } else {
+ this.setState({
+ orderBySize: null,
+ orderByTags: null,
+ orderByExt: null,
+ orderByDate: null,
+ orderByName: false
+ });
+ }
+ break;
+ case 'byFileSize':
+ if (this.state.orderBySize === null) {
+ this.setState({
+ orderByName: null,
+ orderByTags: null,
+ orderByExt: null,
+ orderByDate: null,
+ orderBySize: true
+ });
+ } else {
+ this.setState({
+ orderByName: null,
+ orderByTags: null,
+ orderByExt: null,
+ orderByDate: null,
+ orderBySize: false
+ });
+ }
+ break;
+ case 'byTags':
+ if (this.state.orderByTags === null) {
+ this.setState({
+ orderByName: null,
+ orderBySize: null,
+ orderByExt: null,
+ orderByDate: null,
+ orderByTags: true
+ });
+ } else {
+ this.setState({
+ orderByName: null,
+ orderBySize: null,
+ orderByExt: null,
+ orderByDate: null,
+ orderByTags: false
+ });
+ }
+ break;
+ case 'byExtension':
+ if (this.state.orderByExt === null) {
+ this.setState({
+ orderByName: null,
+ orderBySize: null,
+ orderByTags: null,
+ orderByDate: null,
+ orderByExt: true
+ });
+ } else {
+ this.setState({
+ orderByName: null,
+ orderBySize: null,
+ orderByTags: null,
+ orderByDate: null,
+ orderByExt: false
+ });
+ }
+ break;
+ case 'byDateModified':
+ if (this.state.orderByDate === null) {
+ this.setState({
+ orderByName: null,
+ orderBySize: null,
+ orderByTags: null,
+ orderByExt: null,
+ orderByDate: true
+ });
+ } else {
+ this.setState({
+ orderByName: null,
+ orderBySize: null,
+ orderByTags: null,
+ orderByExt: null,
+ orderByDate: false
+ });
+ }
+ break;
+ default:
+ break;
}
};
getLayoutClass = () => {
switch (this.state.layoutType) {
- case 'grid':
- return this.props.classes.gridContainer;
- case 'row':
- return this.props.classes.rowContainer;
- default:
- return this.props.classes.gridContainer;
+ case 'grid':
+ return this.props.classes.gridContainer;
+ case 'row':
+ return this.props.classes.rowContainer;
+ default:
+ return this.props.classes.gridContainer;
}
};
@@ -754,6 +760,14 @@ class GridPerspective extends React.Component<Props, State> {
return <ArrowDownIcon />;
};
+ handleFileMoveDrop = (item, monitor) => {
+ if (monitor) {
+ const { path } = monitor.getItem();
+ console.log('Dropped files: ' + path);
+ this.props.moveFiles([path], item.children.props.entryPath);
+ }
+ };
+
renderCell = (fsEntry: FileSystemEntry) => {
if (!fsEntry.isFile && !this.state.showDirectories) {
return;
@@ -768,7 +782,7 @@ class GridPerspective extends React.Component<Props, State> {
}
const { layoutType } = this.state;
// key={fsEntry.uuid}
- return (
+ const cellContent = (
<TagDropContainer entryPath={fsEntry.path}>
<Paper
data-entry-id={fsEntry.uuid}
@@ -786,21 +800,34 @@ class GridPerspective extends React.Component<Props, State> {
</Paper>
</TagDropContainer>
);
- };
+ if (fsEntry.isFile) {
+ return (
+ <FileSourceDnd>
+ {cellContent}
+ </FileSourceDnd>
+ );
+ }
- renderTag = (tag: Object, fsEntry) => {
return (
- <TagContainer
- defaultTextColor={this.props.tagTextColor}
- defaultBackgroundColor={this.props.tagBackgroundColor}
- tag={tag}
- key={tag.id}
- entryPath={fsEntry.path}
- handleTagMenu={this.handleTagMenu}
- />
+ <div style={{ position: 'relative' }}>
+ <TargetMoveFileBox accepts={[DragItemTypes.FILE]} onDrop={this.handleFileMoveDrop}>
+ {cellContent}
+ </TargetMoveFileBox>
+ </div>
);
};
+ renderTag = (tag: Object, fsEntry) => (
+ <TagContainer
+ defaultTextColor={this.props.tagTextColor}
+ defaultBackgroundColor={this.props.tagBackgroundColor}
+ tag={tag}
+ key={tag.id}
+ entryPath={fsEntry.path}
+ handleTagMenu={this.handleTagMenu}
+ />
+ );
+
renderCellContent = (fsEntry: FileSystemEntry) => {
const classes = this.props.classes;
let description = removeMd(fsEntry.description);
@@ -1230,6 +1257,12 @@ class GridPerspective extends React.Component<Props, State> {
}
}
+function mapActionCreatorsToProps(dispatch) {
+ return bindActionCreators({
+ moveFiles: IOActions.moveFiles
+ }, dispatch);
+}
+
function mapStateToProps(state) {
return {
tagTextColor: getTagTextColor(state),
@@ -1238,6 +1271,6 @@ function mapStateToProps(state) {
};
}
-export default connect(mapStateToProps)(
+export default connect(mapStateToProps, mapActionCreatorsToProps)(
withStyles(styles)(GridPerspective)
);