Skip to content

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

tree Impl

Stanimir Marinov7a87bd3dd690
diff --git a/app/components/LocationManager.js b/app/components/LocationManager.js
index dea97848c..df0b1f3b1 100644
--- a/app/components/LocationManager.js
+++ b/app/components/LocationManager.js
@@ -18,6 +18,8 @@
*/
import React from 'react';
+import Table from 'rc-table';
+import 'rc-table/assets/index.css';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { withStyles } from '@material-ui/core/styles';
@@ -60,13 +62,15 @@ import { actions as AppActions, getCurrentLocationId } from '../reducers/app';
import { getPerspectives } from '../reducers/settings';
import i18n from '../services/i18n';
import { isObj } from '../utils/misc';
-// import AppConfig from '../config';
+import AppConfig from '../config';
+import PlatformIO from '../services/platform-io';
type Props = {
classes: Object,
locations: Array<Location>,
perspectives: Array<Object>,
currentLocationId: string,
+ // getDirectoriesTree: (path: string, deepLevel: number) => void,
loadDirectoryContent: (path: string) => void,
openLocation: (path: string) => void,
openFileNatively: (path: string) => void,
@@ -100,7 +104,15 @@ type State = {
isEditLocationDialogOpened?: boolean,
isDeleteLocationDialogOpened?: boolean,
isSelectDirectoryDialogOpened?: boolean,
- isCreateDirectoryDialogOpened?: boolean
+ isCreateDirectoryDialogOpened?: boolean,
+ dirs?: Array<Object>
+};
+
+type SubFolder = {
+ uuid: string,
+ name: string,
+ path: string,
+ children?: Array<SubFolder>
};
class LocationManager extends React.Component<Props, State> {
@@ -117,9 +129,79 @@ class LocationManager extends React.Component<Props, State> {
isEditLocationDialogOpened: false,
isDeleteLocationDialogOpened: false,
isCreateDirectoryDialogOpened: false,
- isSelectDirectoryDialogOpened: false
+ isSelectDirectoryDialogOpened: false,
+ dirs: []
};
+ getDirectoriesTree = (subFolder: SubFolder, deepLevel: number) =>
+ // const { settings } = getState();
+ PlatformIO.listDirectoryPromise(subFolder.path, false)
+ .then(dirEntries => {
+ const directoryContent = [];
+ dirEntries.map(entry => {
+ /* if (!settings.showUnixHiddenEntries && entry.name === AppConfig.metaFolder) {
+ return true;
+ } TODO */
+ // const enhancedEntry = enhanceEntry(entry);
+ if (!entry.isFile) {
+ directoryContent.push(entry);
+ }
+ return true;
+ });
+ if (directoryContent.length > 0) {
+ // eslint-disable-next-line no-param-reassign
+ subFolder.children = directoryContent;
+ if (deepLevel > 0) {
+ const promisesArr = [];
+ directoryContent.map(directory => promisesArr.push(this.getDirectoriesTree(directory, deepLevel - 1)));
+ return Promise.all(promisesArr);
+ }
+ }
+ return subFolder;
+ })
+ .catch(error => {
+ console.log('getDirectoriesTree', error);
+ })
+ ;
+
+ loadSubDirectories = (location: Location, deepLevel: number) => {
+ const subFolder = {
+ uuid: location.uuid,
+ name: location.name,
+ path: location.paths[0],
+ };
+ this.getDirectoriesTree(subFolder, deepLevel).then(children => {
+ /* if (folder.uuid !== children.uuid) {
+ // eslint-disable-next-line no-param-reassign
+ folder.children = children;
+ }
+ this.mergeDirs(folder); */
+ const dirsTree = this.state.dirs;
+ dirsTree[location.uuid] = children;
+ this.setState({
+ dirs: dirsTree
+ });
+ /* [
+ ...this.state.dirs,
+ { [location.uuid]: children }
+ ] */
+ return true;
+ })
+ .catch(error => {
+ console.log('loadSubDirectories', error);
+ });
+ };
+ /* componentWillReceiveProps(nextProps) {
+ if (this.props.locations !== nextProps.locations) {
+ nextProps.locations.map(entry => {
+ if (this.state.locationRootPath === entry.path || this.state.locationRootPath === entry.paths[0]) {
+ console.log('componentWillReceiveProps');
+ this.props.loadSubDirectories(entry);
+ }
+ });
+ }
+ } */
+
handleCloseDialogs = () => {
this.setState({
isCreateLocationDialogOpened: false,
@@ -249,8 +331,16 @@ class LocationManager extends React.Component<Props, State> {
handleLocationClick = (location: Location) => {
if (location.uuid === this.props.currentLocationId) {
+ if (this.state.dirs[location.uuid] !== undefined) {
+ const dirsTree = this.state.dirs;
+ dirsTree[location.uuid] = undefined;
+ this.setState({
+ dirs: dirsTree
+ });
+ }
this.props.loadDirectoryContent(location.paths[0]);
} else {
+ this.loadSubDirectories(location, 1);
this.props.openLocation(location.uuid);
this.state.locationRootPath = location.paths[0];
}
@@ -269,41 +359,99 @@ class LocationManager extends React.Component<Props, State> {
}
};
+ renderNameColumnAction = (field, location, key) => {
+ const children = (
+ <span>
+ <FolderIcon style={{ marginTop: 0, marginBottom: -8 }} className={this.props.classes.icon} />
+ <span style={{ fontSize: 15 }}>{field}</span>
+ <IconButton
+ style={{ float: 'right', paddingTop: 0, paddingBottom: 0, paddingLeft: 0, paddingRight: 0 }}
+ aria-label={i18n.t('core:options')}
+ aria-haspopup="true"
+ data-tid={'locationMoreButton_' + field.name}
+ onClick={event => this.handleLocationContextMenuClick(event, location)}
+ >
+ <MoreVertIcon />
+ </IconButton>
+ </span>
+ );
+ return {
+ children,
+ props: {},
+ }; // (<span>{ name }</span>);
+ };
// <Tooltip id="tooltip-icon" title={i18n.t('core:moreOperations')} placement="bottom"></Tooltip>
- renderLocation = (location: Location) => (
- <ListItem
- data-tid={'location_' + location.name.replace(/ /g,'_')}
- className={
- this.props.currentLocationId === location.uuid
- ? this.props.classes.listItemSelected
- : this.props.classes.listItem
- }
- key={location.uuid}
- title={location.paths[0]}
- button
- onClick={() => this.handleLocationClick(location)}
- >
- <ListItemIcon>
- <FolderIcon className={this.props.classes.icon} />
- </ListItemIcon>
- <ListItemText style={{ paddingLeft: 5, paddingRight: 5 }} data-tid="locationTitleElement" primary={location.name} />
- {location.isDefault && (
- <DefaultLocationIcon
- title={i18n.t('core: thisIsStartupLocation')}
- data-tid="startupIndication"
- className={this.props.classes.icon}
- />
- )}
- <IconButton
- aria-label={i18n.t('core:options')}
- aria-haspopup="true"
- data-tid={'locationMoreButton_' + location.name}
- onClick={event => this.handleLocationContextMenuClick(event, location)}
- >
- <MoreVertIcon />
- </IconButton>
- </ListItem>
- );
+ renderLocation = (location: Location) => {
+ let table;
+ if (this.state.dirs[location.uuid] !== undefined) {
+ const columns = [
+ {
+ title: undefined,
+ dataIndex: 'name',
+ key: 'name',
+ width: '80%',
+ render: this.renderNameColumnAction,
+ onCell: this.handleCellClick,
+ }
+ ];
+ table = (<Table
+ // defaultExpandAllRows
+ // className={classes.locationListArea}
+ className="table"
+ rowKey="uuid"
+ data={this.state.dirs[location.uuid]}
+ columns={columns}
+ // expandedRowRender={this.expandedRowRender}
+ onExpand={this.onExpand}
+ // expandIcon={CustomExpandIcon}
+ // expandIconAsCell
+ /* onRow={(record, index) => ({
+ onClick: this.onRowClick.bind(null, record, index),
+ })} */
+ />);
+ }
+ return (
+ <div>
+ <ListItem
+ data-tid={'location_' + location.name.replace(/ /g, '_')}
+ className={
+ this.props.currentLocationId === location.uuid
+ ? this.props.classes.listItemSelected
+ : this.props.classes.listItem
+ }
+ key={location.uuid}
+ title={location.paths[0]}
+ button
+ onClick={() => this.handleLocationClick(location)}
+ >
+ <ListItemIcon>
+ <FolderIcon className={this.props.classes.icon} />
+ </ListItemIcon>
+ <ListItemText
+ style={{ paddingLeft: 5, paddingRight: 5 }}
+ data-tid="locationTitleElement"
+ primary={location.name}
+ />
+ {location.isDefault && (
+ <DefaultLocationIcon
+ title={i18n.t('core: thisIsStartupLocation')}
+ data-tid="startupIndication"
+ className={this.props.classes.icon}
+ />
+ )}
+ <IconButton
+ aria-label={i18n.t('core:options')}
+ aria-haspopup="true"
+ data-tid={'locationMoreButton_' + location.name}
+ onClick={event => this.handleLocationContextMenuClick(event, location)}
+ >
+ <MoreVertIcon />
+ </IconButton>
+ </ListItem>
+ {table}
+ </div>
+ );
+ };
render() {
const classes = this.props.classes;