Skip to content

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

TSN-171 geo smart tagging (#986)

Stanimir58e79ff4d466
diff --git a/app/components/VerticalNavigation.js b/app/components/VerticalNavigation.js
index 14416cd53..29367796c 100644
--- a/app/components/VerticalNavigation.js
+++ b/app/components/VerticalNavigation.js
@@ -43,9 +43,11 @@ import PerspectiveManager from '../components/PerspectiveManager';
import LocationManager from '../components/LocationManager';
import i18n from '../services/i18n';
import { Pro } from '../pro';
+import { type Tag } from '../reducers/taglibrary';
import {
actions as AppActions,
getDirectoryPath,
+ isEditTagDialogOpened,
isAboutDialogOpened,
isOnboardingDialogOpened,
isKeysDialogOpened,
@@ -60,6 +62,13 @@ import {
import { actions as SettingsActions, isFirstRun } from '../reducers/settings';
import LoadingLazy from './LoadingLazy';
+const EditEntryTagDialog = React.lazy(() => import(/* webpackChunkName: "EditEntryTagDialog" */ './dialogs/EditEntryTagDialog'));
+const EditEntryTagDialogAsync = props => (
+ <React.Suspense fallback={<LoadingLazy />}>
+ <EditEntryTagDialog {...props} />
+ </React.Suspense>
+);
+
const LicenseDialog = React.lazy(() => import(/* webpackChunkName: "LicenseDialog" */ './dialogs/LicenseDialog'));
const LicenseDialogAsync = props => (
<React.Suspense fallback={<LoadingLazy />}>
@@ -122,6 +131,10 @@ type Props = {
setFirstRun: (isFirstRun: boolean) => void,
isOnboardingDialogOpened: boolean,
toggleOnboardingDialog: () => void,
+ isEditTagDialogOpened: boolean,
+ toggleEditTagDialog: () => void,
+ currentEntryPath: string,
+ selectedTag: Tag,
isAboutDialogOpened: boolean,
toggleAboutDialog: () => void,
isCreateDirectoryOpened: boolean,
@@ -312,6 +325,15 @@ class VerticalNavigation extends React.Component<Props, State> {
onClose={this.props.toggleCreateDirectoryDialog}
selectedDirectoryPath={this.props.currentDirectory}
/>
+ {this.props.isEditTagDialogOpened && (
+ <EditEntryTagDialogAsync
+ key={uuidv1()}
+ open={this.props.isEditTagDialogOpened}
+ onClose={this.props.toggleEditTagDialog}
+ currentEntryPath={this.props.currentEntryPath}
+ selectedTag={this.props.selectedTag}
+ />
+ )}
{this.props.isAboutDialogOpened && (
<AboutDialogAsync
open={this.props.isAboutDialogOpened}
@@ -553,6 +575,7 @@ class VerticalNavigation extends React.Component<Props, State> {
function mapStateToProps(state) {
return {
isFirstRun: isFirstRun(state),
+ isEditTagDialogOpened: isEditTagDialogOpened(state),
isAboutDialogOpened: isAboutDialogOpened(state),
isKeysDialogOpened: isKeysDialogOpened(state),
isOnboardingDialogOpened: isOnboardingDialogOpened(state),
@@ -579,6 +602,7 @@ function mapActionCreatorsToProps(dispatch) {
toggleLicenseDialog: AppActions.toggleLicenseDialog,
toggleThirdPartyLibsDialog: AppActions.toggleThirdPartyLibsDialog,
toggleAboutDialog: AppActions.toggleAboutDialog,
+ toggleEditTagDialog: AppActions.toggleEditTagDialog,
switchTheme: SettingsActions.switchTheme,
setFirstRun: SettingsActions.setFirstRun,
},
diff --git a/app/components/dialogs/EditEntryTagDialog.js b/app/components/dialogs/EditEntryTagDialog.js
index 1b706645b..00c5af14d 100644
--- a/app/components/dialogs/EditEntryTagDialog.js
+++ b/app/components/dialogs/EditEntryTagDialog.js
@@ -18,6 +18,8 @@
*/
import React, { useState, useEffect } from 'react';
+import { connect } from 'react-redux';
+import { bindActionCreators } from 'redux';
import Button from '@material-ui/core/Button';
import TextField from '@material-ui/core/TextField';
import DialogActions from '@material-ui/core/DialogActions';
@@ -29,9 +31,10 @@ import FormHelperText from '@material-ui/core/FormHelperText';
import GenericDialog, { onEnterKeyHandler } from './GenericDialog';
import i18n from '../../services/i18n';
import { isPlusCode } from '../../utils/misc';
-import { isDateTimeTag } from '../../utils/dates';
import { type Tag } from '../../reducers/taglibrary';
import { Pro } from '../../pro';
+import { getSelectedTag } from '../../reducers/app';
+import TaggingActions, { defaultTagLocation } from '../../reducers/tagging-actions';
const styles = theme => ({
root: {
@@ -93,9 +96,10 @@ const EditEntryTagDialog = (props: Props) => {
function renderContent() {
const showGeoEditor = GeoTagEditor && isPlusCode(title);
const showDatePeriodEditor = false; // DatePeriodTagEditor && isDateTimeTag(title);
+
return (
<DialogContent data-tid="editEntryTagDialog" className={props.classes.root}>
- { showGeoEditor && <GeoTagEditor key={title} geoTag={title} onChange={setTitle} /> }
+ { showGeoEditor && <GeoTagEditor key={title} geoTag={title} onChange={setTitle} zoom={title === defaultTagLocation ? 2 : undefined} /> }
{ showDatePeriodEditor && <DatePeriodTagEditor key={title} datePeriodTag={title} onChange={setTitle} /> }
<FormControl
fullWidth={true}
@@ -154,4 +158,19 @@ const EditEntryTagDialog = (props: Props) => {
);
};
-export default withStyles(styles)(EditEntryTagDialog);
+function mapStateToProps(state) {
+ return {
+ selectedTag: getSelectedTag(state),
+ currentEntryPath: getSelectedTag(state) ? getSelectedTag(state).path : undefined
+ };
+}
+
+function mapDispatchToProps(dispatch) {
+ return bindActionCreators({
+ editTagForEntry: TaggingActions.editTagForEntry
+ }, dispatch);
+}
+
+export default withStyles(styles)(
+ connect(mapStateToProps, mapDispatchToProps)(EditEntryTagDialog)
+);
diff --git a/app/components/menus/EntryTagMenu.js b/app/components/menus/EntryTagMenu.js
index e157025a1..d0ed8fb19 100644
--- a/app/components/menus/EntryTagMenu.js
+++ b/app/components/menus/EntryTagMenu.js
@@ -18,7 +18,6 @@
*/
import React, { useState } from 'react';
-import uuidv1 from 'uuid';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import Divider from '@material-ui/core/Divider';
@@ -36,7 +35,8 @@ import { type Tag } from '../../reducers/taglibrary';
import { actions as LocationIndexActions } from '../../reducers/location-index';
import { type SearchQuery } from '../../services/search';
import { getMaxSearchResults } from '../../reducers/settings';
-import LoadingLazy from '../LoadingLazy';
+// import LoadingLazy from '../LoadingLazy';
+import { actions as AppActions } from '../../reducers/app';
type Props = {
classes: Object,
@@ -52,21 +52,24 @@ type Props = {
isReadOnlyMode: boolean
};
-const EditEntryTagDialog = React.lazy(() => import(/* webpackChunkName: "EditEntryTagDialog" */ '../dialogs/EditEntryTagDialog'));
+/* const EditEntryTagDialog = React.lazy(() => import(/!* webpackChunkName: "EditEntryTagDialog" *!/ '../dialogs/EditEntryTagDialog'));
const EditEntryTagDialogAsync = props => (
<React.Suspense fallback={<LoadingLazy />}>
<EditEntryTagDialog {...props} />
</React.Suspense>
-);
+); */
const EntryTagMenu = (props: Props) => {
- const [isEditTagDialogOpened, setIsEditTagDialogOpened] = useState(false);
+ // const [isEditTagDialogOpened, setIsEditTagDialogOpened] = useState(false);
const [isDateCalendarDialogOpened, setIsDateCalendarDialogOpened] = useState(false);
const [isDeleteTagDialogOpened, setIsDeleteTagDialogOpened] = useState(false);
function showEditTagDialog() {
props.onClose();
- setIsEditTagDialogOpened(true);
+ // setIsEditTagDialogOpened(true);
+ const tag = props.selectedTag;
+ tag.path = props.currentEntryPath;
+ props.toggleEditTagDialog(tag);
}
function showDeleteTagDialog() {
@@ -91,7 +94,7 @@ const EntryTagMenu = (props: Props) => {
}
function handleCloseDialogs() {
- setIsEditTagDialogOpened(false);
+ // setIsEditTagDialogOpened(false);
setIsDateCalendarDialogOpened(false);
setIsDeleteTagDialogOpened(false);
}
@@ -152,14 +155,14 @@ const EntryTagMenu = (props: Props) => {
confirmDialogTID={'confirmRemoveTagFromFile'}
confirmDialogContent={'confirmDialogContent'}
/>
- <EditEntryTagDialogAsync
+ {/* <EditEntryTagDialogAsync
key={uuidv1()}
open={isEditTagDialogOpened}
onClose={handleCloseDialogs}
editTagForEntry={props.editTagForEntry}
currentEntryPath={props.currentEntryPath}
selectedTag={props.selectedTag}
- />
+ /> */}
<DateCalendarDialog
open={isDateCalendarDialogOpened}
onClose={handleCloseDialogs}
@@ -180,6 +183,7 @@ function mapStateToProps(state) {
function mapDispatchToProps(dispatch) {
return bindActionCreators({
searchLocationIndex: LocationIndexActions.searchLocationIndex,
+ toggleEditTagDialog: AppActions.toggleEditTagDialog,
}, dispatch);
}
diff --git a/app/reducers/app.js b/app/reducers/app.js
index 9717bf0c8..bf16bb01e 100644
--- a/app/reducers/app.js
+++ b/app/reducers/app.js
@@ -71,6 +71,7 @@ export const types = {
SET_FILEDRAGGED: 'APP/SET_FILEDRAGGED',
SET_READONLYMODE: 'APP/SET_READONLYMODE',
RENAME_FILE: 'APP/RENAME_FILE',
+ TOGGLE_EDIT_TAG_DIALOG: 'APP/TOGGLE_EDIT_TAG_DIALOG',
TOGGLE_ABOUT_DIALOG: 'APP/TOGGLE_ABOUT_DIALOG',
TOGGLE_ONBOARDING_DIALOG: 'APP/TOGGLE_ONBOARDING_DIALOG',
TOGGLE_KEYBOARD_DIALOG: 'APP/TOGGLE_KEYBOARD_DIALOG',
@@ -129,6 +130,7 @@ export const initialState = {
autohide: false
},
openedFiles: [],
+ editTagDialogOpened: false,
aboutDialogOpened: false,
onboardingDialogOpened: false,
keysDialogOpened: false,
@@ -196,6 +198,12 @@ export default (state: Object = initialState, action: Object) => {
case types.SET_CURRENDIRECTORYCOLOR: {
return { ...state, currentDirectoryColor: action.color };
}
+ case types.TOGGLE_EDIT_TAG_DIALOG: {
+ return { ...state,
+ tag: action.tag,
+ editTagDialogOpened: !state.editTagDialogOpened
+ };
+ }
case types.TOGGLE_ABOUT_DIALOG: {
return { ...state, aboutDialogOpened: !state.aboutDialogOpened };
}
@@ -455,6 +463,7 @@ export const actions = {
) => {
dispatch(actions.toggleSelectDirectoryDialog());
},
+ toggleEditTagDialog: (tag: Tag) => ({ type: types.TOGGLE_EDIT_TAG_DIALOG, tag }),
toggleAboutDialog: () => ({ type: types.TOGGLE_ABOUT_DIALOG }),
toggleOnboardingDialog: () => ({ type: types.TOGGLE_ONBOARDING_DIALOG }),
toggleKeysDialog: () => ({ type: types.TOGGLE_KEYBOARD_DIALOG }),
@@ -1333,12 +1342,14 @@ export const isUpdateInProgress = (state: Object) =>
state.app.isUpdateInProgress;
export const isOnline = (state: Object) => state.app.isOnline;
export const getLastSelectedEntry = (state: Object) => state.app.lastSelectedEntry;
+export const getSelectedTag = (state: Object) => state.app.tag;
export const getSelectedEntries = (state: Object) => state.app.selectedEntries;
export const isFileOpened = (state: Object) => state.app.openedFiles.length > 0;
export const isGeneratingThumbs = (state: Object) => state.app.isGeneratingThumbs;
// export const isFileDragged = (state: Object) => state.app.isFileDragged;
export const isReadOnlyMode = (state: Object) => state.app.isReadOnlyMode;
export const isOnboardingDialogOpened = (state: Object) => state.app.onboardingDialogOpened;
+export const isEditTagDialogOpened = (state: Object) => state.app.editTagDialogOpened;
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/tagging-actions.js b/app/reducers/tagging-actions.js
index 01ceeddab..a6657c16c 100644
--- a/app/reducers/tagging-actions.js
+++ b/app/reducers/tagging-actions.js
@@ -37,6 +37,9 @@ import { formatDateTime4Tag, isPlusCode } from '../utils/misc';
import AppConfig from '../config';
import PlatformIO from '../services/platform-io';
import { Pro } from '../pro';
+import ocl from '../utils/openlocationcode';
+
+export const defaultTagLocation = ocl.encode(51.48, 0); // default tag coordinate Greenwich
const actions = {
addTags: (paths: Array<string>, tags: Array<Tag>, updateIndex?: boolean = true) => (
@@ -48,45 +51,57 @@ const actions = {
const processedTags = [];
tags.map((pTag) => {
const tag = { ...pTag };
+ tag.type = 'sidecar';
if (tag.functionality && tag.functionality.length > 0) {
- tag.title = generateTagValue(tag.functionality);
- tag.id = uuidv1();
+ if (tag.functionality === 'geoTagging' && Pro) {
+ // if (!isGeo(getState())) { // tag will be added later just open the Geo Dialog now
+ tag.path = paths[0]; // todo rethink this!
+ tag.title = defaultTagLocation;
+ dispatch(AppActions.toggleEditTagDialog(tag));
+ // }
+ } else {
+ tag.title = generateTagValue(tag);
+ tag.id = uuidv1();
+ processedTags.push(tag);
+ }
+ } else {
+ processedTags.push(tag);
}
- tag.type = 'sidecar';
- processedTags.push(tag);
return true;
});
- paths.map((path) => {
- dispatch(actions.addTagsToEntry(path, processedTags, updateIndex));
- return true;
- });
+ if (processedTags.length > 0) {
+ paths.map((path) => {
+ dispatch(actions.addTagsToEntry(path, processedTags, updateIndex));
+ return true;
+ });
- if (settings.addTagsToLibrary) { // collecting tags
+ if (settings.addTagsToLibrary) { // collecting tags
// filter existed in tagLibrary
- const uniqueTags = [];
- processedTags.map((tag) => {
- if (
- taglibrary.findIndex(tagGroup => tagGroup.children.findIndex(obj => obj.id === tag.id) !== -1) === -1 &&
+ const uniqueTags = [];
+ processedTags.map((tag) => {
+ if (
+ taglibrary.findIndex(tagGroup => tagGroup.children.findIndex(obj => obj.id === tag.id) !== -1) === -1 &&
!/^(?:\d+~\d+|\d+)$/.test(tag.title) && // skip adding of tag containing only digits
!isPlusCode(tag.title) // skip adding of tag containing geo information
- ) {
- uniqueTags.push(tag);
+ ) {
+ uniqueTags.push(tag);
+ }
+ return true;
+ });
+ if (uniqueTags.length > 0) {
+ const tagGroup = {
+ uuid: 'collected_tag_group_id', // uuid needs to be constant here (see mergeTagGroup)
+ title: i18n.t('core:collectedTags'),
+ expanded: true,
+ color: settings.tagBackgroundColor,
+ textcolor: settings.tagTextColor,
+ children: uniqueTags,
+ created_date: new Date(),
+ modified_date: new Date()
+ };
+ dispatch(TagLibraryActions.mergeTagGroup(tagGroup));
}
- return true;
- });
- if (uniqueTags.length > 0) {
- const tagGroup = {
- uuid: 'collected_tag_group_id', // uuid needs to be constant here (see mergeTagGroup)
- title: i18n.t('core:collectedTags'),
- expanded: true,
- color: settings.tagBackgroundColor,
- textcolor: settings.tagTextColor,
- children: uniqueTags,
- created_date: new Date(),
- modified_date: new Date()
- };
- dispatch(TagLibraryActions.mergeTagGroup(tagGroup));
}
}
},
@@ -220,9 +235,19 @@ const actions = {
dispatch(AppActions.showNotification(i18n.t('core:addingTagsFailed'), 'error', true));
});
return true;
- }).catch((error) => {
- console.warn('Error adding tags for ' + path + ' with ' + error);
- dispatch(AppActions.showNotification(i18n.t('core:addingTagsFailed'), 'error', true));
+ }).catch((error) => { // json metadata not exist -create the new one
+ console.warn('json metadata not exist create new ' + path + ' with ' + error);
+ // dispatch(AppActions.showNotification(i18n.t('core:addingTagsFailed'), 'error', true));
+ // eslint-disable-next-line no-param-reassign
+ tag.title = newTagTitle;
+ const fsEntryMeta = { tags: [tag] };
+ saveMetaDataPromise(path, fsEntryMeta).then(() => {
+ dispatch(AppActions.reflectUpdateSidecarTags(path, fsEntryMeta.tags));
+ return true;
+ }).catch((err) => {
+ console.warn('Error adding tags for ' + path + ' with ' + err);
+ dispatch(AppActions.showNotification(i18n.t('core:addingTagsFailed'), 'error', true));
+ });
});
}
@@ -231,7 +256,8 @@ const actions = {
const uniqueTags = [];
if (
taglibrary.findIndex(tagGroup => tagGroup.children.findIndex(obj => obj.title === newTagTitle) !== -1) === -1 &&
- !/^(?:\d+~\d+|\d+)$/.test(newTagTitle) // skip adding of tag containing only digits or geo tags
+ !/^(?:\d+~\d+|\d+)$/.test(newTagTitle) &&
+ !isPlusCode(newTagTitle)// skip adding of tag containing only digits or geo tags
) {
uniqueTags.push({
...tag,
@@ -478,19 +504,20 @@ function handleSmartTag(smarttagFunction: string) {
}
}
-function generateTagValue(smarttagFunction: string) {
- let tagTitle = smarttagFunction;
- switch (smarttagFunction) {
- /* case 'geoTagging': {
- $('#viewContainers').on('drop dragend', function(event) {
+function generateTagValue(tag) {
+ let tagTitle = tag.functionality;
+ switch (tag.functionality) {
+ case 'geoTagging': {
+ tagTitle = tag.title;
+ /* $('#viewContainers').on('drop dragend', function(event) {
if (TSCORE.PRO && TSCORE.selectedTag === 'geo-tag') {
TSCORE.UI.showTagEditDialog(true); // true start the dialog in add mode
} else if (!TSCORE.PRO && TSCORE.selectedTag === 'geo-tag') {
TSCORE.showAlertDialog($.i18n.t("ns.common:needProVersion"), $.i18n.t("ns.common:geoTaggingNotPossible"));
}
- });
- break;
- } */
+ }); */
+ break;
+ }
case 'today': {
tagTitle = formatDateTime4Tag(new Date(), false);
break;
diff --git a/app/reducers/taglibrary-default.js b/app/reducers/taglibrary-default.js
index 7d9719fcb..32f11ae62 100644
--- a/app/reducers/taglibrary-default.js
+++ b/app/reducers/taglibrary-default.js
@@ -182,7 +182,7 @@ export default [
textcolor: '#ffffff',
icon: '',
},
- /* {
+ {
id: 'e1f0760e-471c-4418-a404-6cb09e6f6c24',
type: 'plain',
title: 'geo-tag',
@@ -191,7 +191,7 @@ export default [
color: '#4986e7',
textcolor: '#ffffff',
icon: '',
- } */
+ }
]
},
{