TagSpaces is an offline, open source, document manager with tagging support
readonly mode and persistent search index, refactoring location dialogs
Ilian Sapundshiev90213df149af
diff --git a/app/components/EntryContainer.js b/app/components/EntryContainer.jsindex 31d602b53..5e2edffe9 100644--- a/app/components/EntryContainer.js+++ b/app/components/EntryContainer.js@@ -65,6 +65,7 @@ import {type OpenedEntry,NotificationTypes,getOpenedFiles,+ isReadOnlyMode,actions as AppActions} from '../reducers/app';import { getAllTags } from '../reducers/taglibrary';@@ -168,6 +169,7 @@ type Props = {selectedEntries?: Array,deleteFile: (path: string) => void,toggleEntryFullWidth: () => void,+ isReadOnlyMode: boolean,setEntryPropertiesSplitSize: (size: number) => void};@@ -957,6 +959,7 @@ function mapStateToProps(state) {return {openedFiles: getOpenedFiles(state),settings: state.settings,+ isReadOnlyMode: isReadOnlyMode(state),allTags: getAllTags(state)};}diff --git a/app/components/FolderContainer.js b/app/components/FolderContainer.jsindex 9618fa297..fc7e93bb3 100644--- a/app/components/FolderContainer.js+++ b/app/components/FolderContainer.js@@ -42,7 +42,8 @@ import {getDirectoryPath,getCurrentLocationId,getLastSelectedEntry,- getSearchResultCount+ getSearchResultCount,+ isReadOnlyMode} from '../reducers/app';import TaggingActions from '../reducers/tagging-actions';import { getAllTags, type Tag } from '../reducers/taglibrary';@@ -152,6 +153,7 @@ type Props = {loadDirectoryContent: (path: string) => void,loadParentDirectoryContent: () => void,setLastSelectedEntry: (entryPath: string | null) => void,+ isReadOnlyMode: boolean,showNotification: () => void};@@ -411,6 +413,7 @@ class FolderContainer extends React.Component<Props, State> {toggleCreateFileDialog={this.props.toggleCreateFileDialog}deleteDirectory={this.props.deleteDirectory}showNotification={this.props.showNotification}+ isReadOnlyMode={this.props.isReadOnlyMode}/></div>)}@@ -435,6 +438,7 @@ function mapStateToProps(state) {directoryContent: getDirectoryContent(state),allTags: getAllTags(state),searchResultCount: getSearchResultCount(state),+ isReadOnlyMode: isReadOnlyMode(state),settings: state.settings};}diff --git a/app/components/LocationManager.js b/app/components/LocationManager.jsindex 80ae638f7..504aa3f36 100644--- a/app/components/LocationManager.js+++ b/app/components/LocationManager.js@@ -66,6 +66,7 @@ type Props = {openLocation: (path: string) => void,openFileNatively: (path: string) => void,openDirectory: (path: string) => void,+ createDirectoryIndex: (path: string) => void,addLocation: () => void,editLocation: () => void,moveLocationUp: (locationId: string) => void,@@ -318,7 +319,6 @@ class LocationManager extends React.Component<Props, State> {onClose={this.handleCloseDialogs}addLocation={this.props.addLocation}perspectives={this.props.perspectives}- showNotification={this.props.showNotification}showSelectDirectoryDialog={this.showSelectDirectoryDialog}selectedDirectoryPath={this.state.selectedDirectoryPath}/>@@ -327,9 +327,8 @@ class LocationManager extends React.Component<Props, State> {onClose={this.handleCloseDialogs}location={this.state.selectedLocation}editLocation={this.props.editLocation}- locations={this.props.locations}+ createDirectoryIndex={this.props.createDirectoryIndex}perspectives={this.props.perspectives}- showNotification={this.props.showNotification}showSelectDirectoryDialog={this.showSelectDirectoryDialog}selectedDirectoryPath={this.state.selectedDirectoryPath}/>@@ -452,6 +451,7 @@ function mapDispatchToProps(dispatch) {return bindActionCreators({...LocationActions,openLocation: AppActions.openLocation,+ createDirectoryIndex: AppActions.createDirectoryIndex,closeLocation: AppActions.closeLocation,loadDirectoryContent: AppActions.loadDirectoryContent,reflectCreateEntry: AppActions.reflectCreateEntry,diff --git a/app/components/dialogs/CreateLocationDialog.js b/app/components/dialogs/CreateLocationDialog.jsindex 942f6aa5b..45ca3e3c1 100644--- a/app/components/dialogs/CreateLocationDialog.js+++ b/app/components/dialogs/CreateLocationDialog.js@@ -29,7 +29,7 @@ import {import IconButton from 'material-ui/IconButton';import FolderIcon from 'material-ui-icons/Folder';import Switch from 'material-ui/Switch';-import { FormControl, FormControlLabel, FormHelperText } from 'material-ui/Form';+import { FormControl, FormControlLabel, FormHelperText, FormGroup } from 'material-ui/Form';import Input, { InputLabel, InputAdornment } from 'material-ui/Input';import GenericDialog, { onEnterKeyHandler } from './GenericDialog';import i18n from '../../services/i18n';@@ -37,11 +37,15 @@ import PlatformIO from '../../services/platform-io';import { extractDirectoryName } from '../../utils/paths';import { type Location } from '../../reducers/locations';import AppConfig from '../../config';+import { Pro } from '../../pro';type Props = {- open: boolean,+ open?: boolean,onClose: () => void,- addLocation: (location: Location) => void+ addLocation: (location: Location) => void,+ perspectives: Array<Object>,+ showSelectDirectoryDialog: () => void,+ selectedDirectoryPath?: string | null};type State = {@@ -52,7 +56,9 @@ type State = {name?: string,path?: string,perspective?: string,- isDefault?: boolean+ isDefault?: boolean,+ isReadOnly?: boolean,+ persistIndex?: boolean};class CreateLocationDialog extends React.Component<Props, State> {@@ -64,7 +70,9 @@ class CreateLocationDialog extends React.Component<Props, State> {name: '',path: '',perspective: '',- isDefault: false+ isDefault: false,+ isReadOnly: false,+ persistIndex: false};handleInputChange = (event: Object) => {@@ -96,16 +104,16 @@ class CreateLocationDialog extends React.Component<Props, State> {openDirectory() {if (AppConfig.isElectron) {- PlatformIO.selectDirectoryDialog().then((selectedPaths) => {- this.setState({- name: extractDirectoryName(selectedPaths[0]),- path: selectedPaths[0]+ PlatformIO.selectDirectoryDialog().then((selectedPaths) => {+ this.setState({+ name: extractDirectoryName(selectedPaths[0]),+ path: selectedPaths[0]+ });+ this.handleValidation();+ return true;+ }).catch((err) => {+ console.log('selectDirectoryDialog failed with: ' + err);});- this.handleValidation();- return true;- }).catch((err) => {- console.log('selectDirectoryDialog failed with: ' + err);- });} else {this.props.showSelectDirectoryDialog();}@@ -130,7 +138,9 @@ class CreateLocationDialog extends React.Component<Props, State> {name: this.state.name,paths: [this.state.path],perspective: this.state.perspective,- isDefault: this.state.isDefault+ isDefault: this.state.isDefault,+ isReadOnly: this.state.isReadOnly,+ persistIndex: this.state.persistIndex});this.setState({open: false,@@ -192,17 +202,43 @@ class CreateLocationDialog extends React.Component<Props, State> {/>{this.state.errorTextName && <FormHelperText>Invalid Name</FormHelperText>}</FormControl>- <FormControlLabel- control={- <Switch- data-tid="locationIsDefault"- name="isDefault"- checked={this.state.isDefault}- onChange={this.handleInputChange}- />- }- label={i18n.t('core:startupLocation')}- />+ <FormGroup>+ <FormControlLabel+ control={+ <Switch+ data-tid="locationIsDefault"+ name="isDefault"+ checked={this.state.isDefault}+ onChange={this.handleInputChange}+ />+ }+ label={i18n.t('core:startupLocation')}+ />+ <FormControlLabel+ control={+ <Switch+ disabled={!Pro}+ data-tid="changeReadOnlyMode"+ name="isReadOnly"+ checked={this.state.isReadOnly}+ onChange={this.handleInputChange}+ />+ }+ label={i18n.t('core:readonlyModeSwitch') + (Pro ? '' : ' - Available in Pro')}+ />+ <FormControlLabel+ control={+ <Switch+ disabled={!Pro}+ data-tid="changePersistIndex"+ name="persistIndex"+ checked={this.state.persistIndex}+ onChange={this.handleInputChange}+ />+ }+ label={i18n.t('core:persistIndexSwitch') + (Pro ? '' : ' - Available in Pro')}+ />+ </FormGroup></DialogContent>);};diff --git a/app/components/dialogs/EditLocationDialog.js b/app/components/dialogs/EditLocationDialog.jsindex 28b667f78..533b1e0bb 100644--- a/app/components/dialogs/EditLocationDialog.js+++ b/app/components/dialogs/EditLocationDialog.js@@ -28,15 +28,41 @@ import {import IconButton from 'material-ui/IconButton';import FolderIcon from 'material-ui-icons/Folder';import Switch from 'material-ui/Switch';-import { FormControl, FormControlLabel, FormHelperText } from 'material-ui/Form';+import { FormControl, FormControlLabel, FormHelperText, FormGroup } from 'material-ui/Form';import Input, { InputLabel, InputAdornment } from 'material-ui/Input';-import GenericDialog from './GenericDialog';+import GenericDialog, { onEnterKeyHandler } from './GenericDialog';import i18n from '../../services/i18n';import PlatformIO from '../../services/platform-io';import { extractDirectoryName } from '../../utils/paths';+import { type Location } from '../../reducers/locations';import AppConfig from '../../config';+import { Pro } from '../../pro';-class EditLocationDialog extends GenericDialog {+type Props = {+ open?: boolean,+ onClose: () => void,+ location?: Location | null,+ editLocation: (location: Location) => void,+ createDirectoryIndex: (path: string) => void,+ perspectives: Array<string>,+ showSelectDirectoryDialog: () => void,+ selectedDirectoryPath?: string | null+};++type State = {+ errorTextPath?: boolean,+ errorTextName?: boolean,+ openDirectoryButtonDisabled?: boolean,+ uuid?: string,+ name?: string,+ path?: string,+ perspectives?: Array<Object>,+ isDefault?: boolean,+ isReadOnly?: boolean,+ persistIndex?: boolean+};++class EditLocationDialog extends React.Component<Props, State> {state = {errorTextPath: false,errorTextName: false,@@ -45,7 +71,9 @@ class EditLocationDialog extends GenericDialog {name: '',path: '',perspectives: '',- isDefault: false+ isDefault: false,+ isReadOnly: false,+ persistIndex: false};componentWillReceiveProps = (nextProps: any) => {@@ -56,7 +84,9 @@ class EditLocationDialog extends GenericDialog {name: dir ? extractDirectoryName(dir) : nextProps.location.name,path: dir || nextProps.location.paths[0],perspective: nextProps.location.perspective,- isDefault: nextProps.location.isDefault+ isDefault: nextProps.location.isDefault,+ isReadOnly: nextProps.location.isReadOnly,+ persistIndex: nextProps.location.persistIndex});}};@@ -74,13 +104,13 @@ class EditLocationDialog extends GenericDialog {handleValidation() {// const pathRegex = '^((\.\./|[a-zA-Z0-9_/\-\\])*\.[a-zA-Z0-9]+)$';// const nameRegex = '^[A-Z][-a-zA-Z]+$';- if (this.state.path.length > 0) {+ if (this.state.path && this.state.path.length > 0) {this.setState({ errorTextPath: false });} else {this.setState({ errorTextPath: true });}- if (this.state.name.length > 0) {+ if (this.state.name && this.state.name.length > 0) {this.setState({ errorTextName: false });} else {this.setState({ errorTextName: true });@@ -109,19 +139,29 @@ class EditLocationDialog extends GenericDialog {onConfirm = () => {this.handleValidation();- if (this.state.path.length > 0 && this.state.name.length > 0) {+ if (this.state.path && this.state.path.length > 0 && this.state.name && this.state.name.length > 0) {this.props.editLocation({uuid: this.state.uuid,name: this.state.name,paths: [this.state.path],perspective: this.state.perspective,- isDefault: this.state.isDefault+ isDefault: this.state.isDefault,+ isReadOnly: this.state.isReadOnly,+ persistIndex: this.state.persistIndex});this.props.onClose();}};+ onIndexLocation = () => {+ this.handleValidation();+ if (this.state.path && this.state.path.length > 0 && this.state.name && this.state.name.length > 0) {+ this.props.createDirectoryIndex(this.state.path);+ this.props.onClose();+ }+ };+renderTitle = () => (<DialogTitle>{i18n.t('core:editLocationTitle')}</DialogTitle>);@@ -172,17 +212,45 @@ class EditLocationDialog extends GenericDialog {/>{this.state.errorTextName && <FormHelperText>Invalid Name</FormHelperText>}</FormControl>- <FormControlLabel- control={- <Switch- data-tid="editStartupLocation"- name="isDefault"- checked={this.state.isDefault}- onChange={this.handleInputChange}+ <FormControl>+ <FormGroup>+ <FormControlLabel+ control={+ <Switch+ data-tid="editStartupLocation"+ name="isDefault"+ checked={this.state.isDefault}+ onChange={this.handleInputChange}+ />+ }+ label={i18n.t('core:startupLocation')}/>- }- label={i18n.t('core:startupLocation')}- />+ <FormControlLabel+ control={+ <Switch+ disabled={!Pro}+ data-tid="changeReadOnlyMode"+ name="isReadOnly"+ checked={this.state.isReadOnly}+ onChange={this.handleInputChange}+ />+ }+ label={i18n.t('core:readonlyModeSwitch') + (Pro ? '' : ' - Available in Pro')}+ />+ <FormControlLabel+ control={+ <Switch+ disabled={!Pro}+ data-tid="changePersistIndex"+ name="persistIndex"+ checked={this.state.persistIndex}+ onChange={this.handleInputChange}+ />+ }+ label={i18n.t('core:persistIndexSwitch') + (Pro ? '' : ' - Available in Pro')}+ />+ </FormGroup>+ </FormControl></DialogContent>);@@ -208,6 +276,12 @@ class EditLocationDialog extends GenericDialog {renderActions = () => (<DialogActions>+ <Button+ data-tid="closeEditLocationDialog"+ onClick={this.onIndexLocation}+ >+ {i18n.t('core:indexLocation')}+ </Button><Buttondata-tid="closeEditLocationDialog"color="primary"@@ -224,6 +298,19 @@ class EditLocationDialog extends GenericDialog {</Button></DialogActions>);++ render() {+ return (+ <GenericDialog+ open={this.props.open}+ onClose={this.props.onClose}+ onEnterKey={(event) => onEnterKeyHandler(event, this.onConfirm)}+ renderTitle={this.renderTitle}+ renderContent={this.renderContent}+ renderActions={this.renderActions}+ />+ );+ }}export default EditLocationDialog;diff --git a/app/components/menus/DirectoryMenu.js b/app/components/menus/DirectoryMenu.jsindex c312d030b..88fb2f8bc 100644--- a/app/components/menus/DirectoryMenu.js+++ b/app/components/menus/DirectoryMenu.js@@ -58,7 +58,8 @@ type Props = {text: string,notificationType: string,autohide: boolean- ) => void+ ) => void,+ isReadOnlyMode: boolean};type State = {@@ -261,24 +262,28 @@ class DirectoryMenu extends React.Component<Props, State> {<ListItemText inset primary={i18n.t('core:reloadDirectory')} /></MenuItem>)}- <MenuItem- data-tid="renameDirectory"- onClick={this.showRenameDirectoryDialog}- >- <ListItemIcon>- <RenameFolderIcon />- </ListItemIcon>- <ListItemText inset primary={i18n.t('core:renameDirectory')} />- </MenuItem>- <MenuItem- data-tid="deleteDirectory"- onClick={this.showDeleteDirectoryDialog}- >- <ListItemIcon>- <DeleteForeverIcon />- </ListItemIcon>- <ListItemText inset primary={i18n.t('core:deleteDirectory')} />- </MenuItem>+ {!this.props.isReadOnlyMode && (+ <MenuItem+ data-tid="renameDirectory"+ onClick={this.showRenameDirectoryDialog}+ >+ <ListItemIcon>+ <RenameFolderIcon />+ </ListItemIcon>+ <ListItemText inset primary={i18n.t('core:renameDirectory')} />+ </MenuItem>+ )}+ {!this.props.isReadOnlyMode && (+ <MenuItem+ data-tid="deleteDirectory"+ onClick={this.showDeleteDirectoryDialog}+ >+ <ListItemIcon>+ <DeleteForeverIcon />+ </ListItemIcon>+ <ListItemText inset primary={i18n.t('core:deleteDirectory')} />+ </MenuItem>+ )}{!this.props.perspectiveMode && (<MenuItemdata-tid="openDirectoryNatively"@@ -296,7 +301,7 @@ class DirectoryMenu extends React.Component<Props, State> {{!this.props.perspectiveMode && (<Divider />)}- {!this.props.perspectiveMode && (+ {!this.props.isReadOnlyMode && !this.props.perspectiveMode && (<MenuItemdata-tid="newSubDirectory"onClick={this.showCreateDirectoryDialog}@@ -307,8 +312,7 @@ class DirectoryMenu extends React.Component<Props, State> {<ListItemText inset primary={i18n.t('core:newSubdirectory')} /></MenuItem>)}-- {!this.props.perspectiveMode && (+ {!this.props.isReadOnlyMode && !this.props.perspectiveMode && (<MenuItem data-tid="createNewFile" onClick={this.createNewFile}><ListItemIcon><NewFileIcon />@@ -316,7 +320,7 @@ class DirectoryMenu extends React.Component<Props, State> {<ListItemText inset primary={i18n.t('core:newFileNote')} /></MenuItem>)}- {!this.props.perspectiveMode && (+ {!this.props.isReadOnlyMode && !this.props.perspectiveMode && (<MenuItem data-tid="addExistingFile" onClick={this.addExistingFile}><ListItemIcon><AddExistingFileIcon />diff --git a/app/config.js b/app/config.jsindex f5c46e4de..095813d14 100644--- a/app/config.js+++ b/app/config.js@@ -24,6 +24,7 @@ export default {tagspacesAppPath: '/tagspaces/',metaFolder: '.ts',metaFolderFile: 'tsm.json',+ folderIndexFile: 'tsi.json',metaFileExt: '.json',thumbFileExt: '.jpg',thumbType: 'image/jpeg',diff --git a/app/locales/en/core.json b/app/locales/en/core.jsonindex 3f6d77fdd..718c4a108 100644--- a/app/locales/en/core.json+++ b/app/locales/en/core.json@@ -316,5 +316,7 @@"showHideDirectories": "Show / hide directories","sort": "Sort","thirdPartyLibs": "Third Party Libraries",+ "readonlyModeSwitch": "Open location in readonly mode",+ "persistIndexSwitch": "Switch to manual index creation with persisted search index","-": "-"}diff --git a/app/reducers/app.js b/app/reducers/app.jsindex b2c0c5d53..07e5b8160 100644--- a/app/reducers/app.js+++ b/app/reducers/app.js@@ -17,7 +17,7 @@* @flow*/-import { type Location } from './locations';+import { type Location, getLocation } from './locations';import PlatformIO from '../services/platform-io';import Search, { type SearchQuery } from '../services/search';import uuidv1 from 'uuid';@@ -71,6 +71,7 @@ export const types = {SET_CURRENLOCATIONID: 'APP/SET_CURRENLOCATIONID',SET_LAST_SELECTED_ENTRY: 'APP/SET_LAST_SELECTED_ENTRY',SET_FILEDRAGGED: 'APP/SET_FILEDRAGGED',+ SET_READONLYMODE: 'APP/SET_READONLYMODE',RENAME_FILE: 'APP/RENAME_FILE',SORT_BY: 'APP/SORT_BY',TOGGLE_ABOUT_DIALOG: 'APP/TOGGLE_ABOUT_DIALOG',@@ -120,6 +121,7 @@ export const initialState = {currentDirectoryEntries: [],currentDirectoryIndex: [],isIndexing: false,+ isReadOnlyMode: false,searchResults: [],notificationStatus: {visible: false,@@ -150,6 +152,9 @@ export default (state: Object = initialState, action: Object) => {case types.DEVICE_OFFLINE: {return { ...state, isOnline: false, error: null };}+ case types.SET_READONLYMODE: {+ return { ...state, isReadOnlyMode: action.isReadOnlyMode };+ }case types.SET_NEW_VERSION_AVAILABLE: {return {...state,@@ -915,6 +920,7 @@ export const actions = {const currentLocationId = getState().app;locations.map(location => {if (location.uuid === locationId) {+ dispatch(actions.setReadOnlyMode(location.isReadOnly || false));dispatch(actions.setCurrentLocationId(location.uuid));dispatch(actions.loadDirectoryContent(location.paths[0]));if (locationId !== currentLocationId) {@@ -946,12 +952,18 @@ export const actions = {});},createDirectoryIndex: (directoryPath: string) => (- dispatch: (actions: Object) => void+ dispatch: (actions: Object) => void,+ getState: () => Object) => {+ const state = getState();+ const currentLocation: Location = getLocation(state, state.app.currentLocationId);dispatch(actions.startDirectoryIndexing());createDirectoryIndex(directoryPath).then(directoryIndex => {dispatch(actions.indexDirectorySuccess(directoryIndex));+ if (Pro && currentLocation.persistIndex) {+ Pro.Indexer.persistIndex(directoryPath, directoryIndex);+ }return true;}).catch(err => {@@ -999,6 +1011,10 @@ export const actions = {type: types.SET_FILEDRAGGED,isFileDragged}),+ setReadOnlyMode: (isReadOnlyMode: boolean) => ({+ type: types.SET_READONLYMODE,+ isReadOnlyMode+ }),openFile: (entryPath: string, isFile?: boolean = true) => (dispatch: (actions: Object) => void,getState: () => Object@@ -1350,6 +1366,7 @@ export const isOnline = (state: Object) => state.app.isOnline;export const getLastSelectedEntry = (state: Object) => state.app.lastSelectedEntry;export const isFileOpened = (state: Object) => state.app.openedFiles.length > 0;export const isFileDragged = (state: Object) => state.app.isFileDragged;+export const isReadOnlyMode = (state: Object) => state.app.isReadOnlyMode;export const isAboutDialogOpened = (state: Object) => state.app.aboutDialogOpened;export const isKeysDialogOpened = (state: Object) => state.app.keysDialogOpened;export const isLicenseDialogOpened = (state: Object) => state.app.licenseDialogOpened;diff --git a/app/reducers/locations.js b/app/reducers/locations.jsindex 480a0aa01..048fe338f 100644--- a/app/reducers/locations.js+++ b/app/reducers/locations.js@@ -36,7 +36,9 @@ export type Location = {paths: Array<string>,perspective?: string, // id of the perspectivecreationDate?: string,- isDefault: boolean+ isDefault: boolean,+ isReadOnly?: boolean,+ persistIndex?: boolean};export const initialState = [];@@ -48,7 +50,9 @@ Object.keys(devicePaths).forEach(key => {uuid: uuidv1(),name: key, // TODO use i18npaths: [devicePaths[key]],- isDefault: false+ isDefault: false,+ isReadOnly: false,+ persistIndex: false});});@@ -68,7 +72,9 @@ export default (state: Array<Location> = initialState, action: Object) => {paths: action.location.paths,perspective: action.location.perspective,creationDate: new Date().toJSON(),- isDefault: action.location.isDefault+ isDefault: action.location.isDefault,+ isReadOnly: action.location.isReadOnly,+ persistIndex: action.location.persistIndex,}];}@@ -149,7 +155,13 @@ export const actions = {createLocation: (location: Location) => ({ type: types.ADD_LOCATION, location }),moveLocationUp: (uuid: string) => ({ type: types.MOVE_UP_LOCATION, uuid }),moveLocationDown: (uuid: string) => ({ type: types.MOVE_DOWN_LOCATION, uuid }),- editLocation: (location: Location) => ({+ editLocation: (location: Location) => (+ dispatch: (actions: Object) => void+ ) => {+ dispatch(actions.changeLocation(location));+ dispatch(AppActions.setReadOnlyMode(location.isReadOnly || false));+ },+ changeLocation: (location: Location) => ({type: types.EDIT_LOCATION,location}),@@ -167,6 +179,16 @@ export const actions = {// Selectorsexport const getLocations = (state: Object): Array<Location> => state.locations;+export const getLocation = (state: Object, locationId: string): Location | null => {+ let foundLocation = null;+ state.locations.map((location) => {+ if (location.uuid === locationId) {+ foundLocation = location;+ }+ return true;+ });+ return foundLocation;+};export const getDefaultLocationId = (state: Object): ?string => {let defaultLocationID;state.locations.map((location) => {