Skip to content

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

added ui for location watching, improving location management

Ilian Sapundshievefbb884889cc
diff --git a/app/components/dialogs/CreateLocationDialog.js b/app/components/dialogs/CreateLocationDialog.js
index 7f45f2075..42375d911 100644
--- a/app/components/dialogs/CreateLocationDialog.js
+++ b/app/components/dialogs/CreateLocationDialog.js
@@ -61,6 +61,7 @@ type State = {
perspective?: string,
isDefault?: boolean,
isReadOnly?: boolean,
+ watchForChanges?: boolean,
persistIndex?: boolean
};
@@ -75,9 +76,25 @@ class CreateLocationDialog extends React.Component<Props, State> {
perspective: '',
isDefault: false,
isReadOnly: false,
+ watchForChanges: false,
persistIndex: false
};
+ componentWillReceiveProps = (nextProps: any) => {
+ if (nextProps.open === true) {
+ const dir = nextProps.selectedDirectoryPath;
+ this.setState({
+ name: dir ? extractDirectoryName(dir) : '',
+ path: dir || '',
+ perspective: '',
+ isDefault: false,
+ isReadOnly: false,
+ watchForChanges: Pro ? true : false,
+ persistIndex: false
+ });
+ }
+ };
+
handleInputChange = (event: Object) => {
const target = event.target;
const value = target.type === 'checkbox' ? target.checked : target.value;
@@ -92,13 +109,13 @@ class CreateLocationDialog extends React.Component<Props, State> {
// const pathRegex = this.state.path.match('^((\.\./|[a-zA-Z0-9_/\-\\])*\.[a-zA-Z0-9]+)$');
// const nameRegex = this.state.name.match('^[A-Z][-a-zA-Z]+$');
- if (this.state.path.length > 0) {
+ if (this.state.path && this.state.path.length > 0) {
this.setState({ errorTextPath: false, disableConfirmButton: false });
} else {
this.setState({ errorTextPath: true, disableConfirmButton: true });
}
- if (this.state.name.length > 0) {
+ if (this.state.name && this.state.name.length > 0) {
this.setState({ errorTextName: false, disableConfirmButton: false });
} else {
this.setState({ errorTextName: true, disableConfirmButton: true });
@@ -122,18 +139,6 @@ class CreateLocationDialog extends React.Component<Props, State> {
}
}
- componentWillReceiveProps = (nextProps: any) => {
- if (nextProps.open === true) {
- const dir = nextProps.selectedDirectoryPath;
- this.setState({
- name: dir ? extractDirectoryName(dir) : '',
- path: dir || '',
- perspective: '',
- isDefault: false
- });
- }
- };
-
onConfirm = () => {
if (!this.state.disableConfirmButton) {
this.props.addLocation({
@@ -143,7 +148,8 @@ class CreateLocationDialog extends React.Component<Props, State> {
perspective: this.state.perspective,
isDefault: this.state.isDefault,
isReadOnly: this.state.isReadOnly,
- persistIndex: this.state.persistIndex
+ persistIndex: this.state.persistIndex,
+ watchForChanges: this.state.watchForChanges
});
this.setState({
open: false,
@@ -241,6 +247,18 @@ class CreateLocationDialog extends React.Component<Props, State> {
}
label={i18n.t('core:persistIndexSwitch') + (Pro ? '' : ' - Available in Pro')}
/>
+ <FormControlLabel
+ control={
+ <Switch
+ disabled={!Pro}
+ data-tid="changeWatchForChanges"
+ name="watchForChanges"
+ checked={this.state.watchForChanges}
+ onChange={this.handleInputChange}
+ />
+ }
+ label={i18n.t('core:watchForChangesInLocation') + (Pro ? '' : ' - Available in Pro')}
+ />
</FormGroup>
</DialogContent>
);
diff --git a/app/components/dialogs/EditLocationDialog.js b/app/components/dialogs/EditLocationDialog.js
index 8f825c82a..114625489 100644
--- a/app/components/dialogs/EditLocationDialog.js
+++ b/app/components/dialogs/EditLocationDialog.js
@@ -58,9 +58,10 @@ type State = {
uuid?: string,
name?: string,
path?: string,
- perspectives?: Array<Object>,
+ perspective?: '',
isDefault?: boolean,
isReadOnly?: boolean,
+ watchForChanges?: boolean,
persistIndex?: boolean
};
@@ -72,9 +73,10 @@ class EditLocationDialog extends React.Component<Props, State> {
uuid: '',
name: '',
path: '',
- perspectives: '',
+ perspective: '',
isDefault: false,
isReadOnly: false,
+ watchForChanges: false,
persistIndex: false
};
@@ -88,6 +90,7 @@ class EditLocationDialog extends React.Component<Props, State> {
perspective: nextProps.location.perspective,
isDefault: nextProps.location.isDefault,
isReadOnly: nextProps.location.isReadOnly,
+ watchForChanges: nextProps.location.watchForChanges,
persistIndex: nextProps.location.persistIndex
});
}
@@ -149,6 +152,7 @@ class EditLocationDialog extends React.Component<Props, State> {
perspective: this.state.perspective,
isDefault: this.state.isDefault,
isReadOnly: this.state.isReadOnly,
+ watchForChanges: this.state.watchForChanges,
persistIndex: this.state.persistIndex
});
@@ -243,6 +247,18 @@ class EditLocationDialog extends React.Component<Props, State> {
}
label={i18n.t('core:persistIndexSwitch') + (Pro ? '' : ' - Available in Pro')}
/>
+ <FormControlLabel
+ control={
+ <Switch
+ disabled={!Pro}
+ data-tid="changeWatchForChanges"
+ name="watchForChanges"
+ checked={this.state.watchForChanges}
+ onChange={this.handleInputChange}
+ />
+ }
+ label={i18n.t('core:watchForChangesInLocation') + (Pro ? '' : ' - Available in Pro')}
+ />
</FormGroup>
</FormControl>
</DialogContent>
diff --git a/app/reducers/app.js b/app/reducers/app.js
index 07e5b8160..04b81dc6e 100644
--- a/app/reducers/app.js
+++ b/app/reducers/app.js
@@ -918,6 +918,9 @@ export const actions = {
) => {
const locations: Array<Location> = getState().locations;
const currentLocationId = getState().app;
+ if (Pro && Pro.Watcher) {
+ Pro.Watcher.stopWatching();
+ }
locations.map(location => {
if (location.uuid === locationId) {
dispatch(actions.setReadOnlyMode(location.isReadOnly || false));
@@ -926,7 +929,7 @@ export const actions = {
if (locationId !== currentLocationId) {
dispatch(actions.createDirectoryIndex(location.paths[0]));
}
- if (Pro && Pro.Watcher) {
+ if (Pro && Pro.Watcher && location.watchForChanges) {
Pro.Watcher.watchFolder(location.paths[0], dispatch);
}
}
@@ -938,18 +941,21 @@ export const actions = {
getState: () => Object
) => {
const locations: Array<Location> = getState().locations;
- locations.map(location => {
- if (location.uuid === locationId) {
- // location needed evtl. to unwatch many loc. root folders if available
- dispatch(actions.setCurrentLocationId(null));
- dispatch(actions.clearDirectoryContent());
- dispatch(actions.clearDirectoryIndex());
- if (Pro && Pro.Watcher) {
- Pro.Watcher.stopWatching();
+ const { currentLocationId } = getState().app;
+ if (currentLocationId === locationId) {
+ locations.map(location => {
+ if (location.uuid === locationId) {
+ // location needed evtl. to unwatch many loc. root folders if available
+ dispatch(actions.setCurrentLocationId(null));
+ dispatch(actions.clearDirectoryContent());
+ dispatch(actions.clearDirectoryIndex());
+ if (Pro && Pro.Watcher) {
+ Pro.Watcher.stopWatching();
+ }
}
- }
- return true;
- });
+ return true;
+ });
+ }
},
createDirectoryIndex: (directoryPath: string) => (
dispatch: (actions: Object) => void,
diff --git a/app/reducers/locations.js b/app/reducers/locations.js
index 048fe338f..bb9ef6b08 100644
--- a/app/reducers/locations.js
+++ b/app/reducers/locations.js
@@ -38,6 +38,7 @@ export type Location = {
creationDate?: string,
isDefault: boolean,
isReadOnly?: boolean,
+ watchForChanges?: boolean,
persistIndex?: boolean
};
@@ -75,6 +76,7 @@ export default (state: Array<Location> = initialState, action: Object) => {
isDefault: action.location.isDefault,
isReadOnly: action.location.isReadOnly,
persistIndex: action.location.persistIndex,
+ watchForChanges: action.location.watchForChanges,
}
];
}