TagSpaces is an offline, open source, document manager with tagging support
TSN626 set tagging method per location (#1439)
Stanimir5e814a02e8cb
diff --git a/app/components/LocationManager.tsx b/app/components/LocationManager.tsxindex e065cd97e..44511af3f 100644--- a/app/components/LocationManager.tsx+++ b/app/components/LocationManager.tsx@@ -32,7 +32,10 @@ import {getLocations} from '../reducers/locations';import { actions as AppActions } from '../reducers/app';-import { isDesktopMode } from '-/reducers/settings';+import {+ getPersistTagsInSidecarFile,+ isDesktopMode+} from '-/reducers/settings';import i18n from '../services/i18n';import AppConfig from '../config';import LoadingLazy from '-/components/LoadingLazy';@@ -55,7 +58,6 @@ interface Props {classes: any;style: any;locations: Array<TS.Location>;- // perspectives: Array<Object>;hideDrawer: () => void;openURLExternally: (path: string) => void;toggleOpenLinkDialog: () => void;@@ -66,6 +68,7 @@ interface Props {removeLocation: (location: TS.Location) => void;moveLocation: (uuid: string, position: number) => void;isDesktop: boolean;+ isPersistTagsInSidecar: boolean;}type SubFolder = {@@ -185,6 +188,7 @@ const LocationManager = (props: Props) => {open={isCreateLocationDialogOpened}onClose={() => setCreateLocationDialogOpened(false)}addLocation={props.addLocation}+ isPersistTagsInSidecar={props.isPersistTagsInSidecar}/>)}{isEditLocationDialogOpened && (@@ -193,6 +197,7 @@ const LocationManager = (props: Props) => {onClose={() => setEditLocationDialogOpened(false)}location={selectedLocation}editLocation={props.editLocation}+ isPersistTagsInSidecar={props.isPersistTagsInSidecar}/>)}{isDeleteLocationDialogOpened && (@@ -304,8 +309,8 @@ const LocationManager = (props: Props) => {function mapStateToProps(state) {return {locations: getLocations(state),- // perspectives: getPerspectives(state),- isDesktop: isDesktopMode(state)+ isDesktop: isDesktopMode(state),+ isPersistTagsInSidecar: getPersistTagsInSidecarFile(state)};}diff --git a/app/components/dialogs/AddRemoveTagsDialog.tsx b/app/components/dialogs/AddRemoveTagsDialog.tsxindex 21d6df4a4..fd2761336 100644--- a/app/components/dialogs/AddRemoveTagsDialog.tsx+++ b/app/components/dialogs/AddRemoveTagsDialog.tsx@@ -22,8 +22,8 @@ import Button from '@material-ui/core/Button';import DialogActions from '@material-ui/core/DialogActions';import DialogContent from '@material-ui/core/DialogContent';import DialogTitle from '@material-ui/core/DialogTitle';-// import IconButton from '@material-ui/core/IconButton';-// import CloseIcon from '@material-ui/icons/Close';+import IconButton from '@material-ui/core/IconButton';+import CloseIcon from '@material-ui/icons/Close';import List from '@material-ui/core/List';import ListItem from '@material-ui/core/ListItem';import ListItemIcon from '@material-ui/core/ListItemIcon';@@ -61,6 +61,10 @@ const AddRemoveTagsDialog = (props: Props) => {}};+ const onClose = (event: React.MouseEvent<HTMLElement>) => {+ onCloseDialog();+ };+const onCloseDialog = (clearSelection?: boolean) => {setNewlyAddedTags([]);props.onClose(clearSelection);@@ -95,7 +99,7 @@ const AddRemoveTagsDialog = (props: Props) => {onCloseDialog(true);};- const { open, selectedEntries = [], fullScreen, onClose } = props;+ const { open, selectedEntries = [], fullScreen } = props;const disabledButtons =!newlyAddedTags || newlyAddedTags.length < 1 || selectedEntries.length < 1;@@ -109,17 +113,17 @@ const AddRemoveTagsDialog = (props: Props) => {><DialogTitle>{i18n.t('core:tagOperationTitle')}- {/* <IconButton+ <IconButtonaria-label="close"style={{position: 'absolute',right: 5,top: 5}}- onClick={onCloseDialog}+ onClick={onClose}><CloseIcon />- </IconButton> */}+ </IconButton></DialogTitle><DialogContent style={{ minHeight: 330 }}><TagsSelectdiff --git a/app/components/dialogs/CreateEditLocationDialog.tsx b/app/components/dialogs/CreateEditLocationDialog.tsxindex b323ddbb0..3de1c0348 100644--- a/app/components/dialogs/CreateEditLocationDialog.tsx+++ b/app/components/dialogs/CreateEditLocationDialog.tsx@@ -28,12 +28,19 @@ import Switch from '@material-ui/core/Switch';import FormControl from '@material-ui/core/FormControl';import FormControlLabel from '@material-ui/core/FormControlLabel';import FormGroup from '@material-ui/core/FormGroup';+import Typography from '@material-ui/core/Typography';import Grid from '@material-ui/core/Grid';import Radio from '@material-ui/core/Radio';import RadioGroup from '@material-ui/core/RadioGroup';-import { Tooltip, Typography } from '@material-ui/core';+import Tooltip from '@material-ui/core/Tooltip';import Dialog from '@material-ui/core/Dialog';import Input from '@material-ui/core/Input';+import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup';+import ToggleButton from '@material-ui/lab/ToggleButton';+import IconButton from '@material-ui/core/IconButton';+import CloseIcon from '@material-ui/icons/Close';+import CheckIcon from '@material-ui/icons/Check';+import InfoIcon from '@material-ui/icons/InfoOutlined';import i18n from '-/services/i18n';import { Pro } from '-/pro';import ObjectStoreForm from './ObjectStoreForm';@@ -44,16 +51,8 @@ import { TS } from '-/tagspaces.namespace';import { locationType } from '-/utils/misc';const styles: any = theme => ({- root: {- display: 'flex'- },formControl: {- margin: theme.spacing(3)- },- group: {- margin: theme.spacing(1, 0),- display: 'flex',- flexDirection: 'row'+ marginLeft: theme.spacing(0)}});@@ -61,9 +60,11 @@ interface Props {location?: TS.Location;open: boolean;onClose: () => void;+ classes: any;fullScreen: boolean;addLocation?: (location: TS.Location) => void;editLocation?: (location: TS.Location) => void;+ isPersistTagsInSidecar: boolean;}const CreateEditLocationDialog = (props: Props) => {@@ -126,14 +127,23 @@ const CreateEditLocationDialog = (props: Props) => {const [bucketName, setBucketName] = useState<string>(location ? location.bucketName : '');- const [region, setRegion] = useState<string>(location ? location.region : '');- const [type, setType] = useState<string>(- location- ? location.type- : AppConfig.isWeb- ? locationType.TYPE_CLOUD- : locationType.TYPE_LOCAL+ const [persistTagsInSidecarFile, setPersistTagsInSidecarFile] = useState<+ boolean | null+ >(+ location && location.persistTagsInSidecarFile !== undefined+ ? location.persistTagsInSidecarFile+ : null // props.isPersistTagsInSidecar);+ const [region, setRegion] = useState<string>(location ? location.region : '');+ let defaultType;+ if (location) {+ defaultType = location.type;+ } else if (AppConfig.isWeb) {+ defaultType = locationType.TYPE_CLOUD;+ } else {+ defaultType = locationType.TYPE_LOCAL;+ }+ const [type, setType] = useState<string>(defaultType);const [newuuid, setNewUuid] = useState<string>(location ? location.uuid : uuidv1());@@ -226,7 +236,7 @@ const CreateEditLocationDialog = (props: Props) => {);};- const { fullScreen, open, onClose } = props;+ const { fullScreen, open, onClose, classes } = props;const onConfirm = () => {if (!disableConfirmButton()) {@@ -266,6 +276,10 @@ const CreateEditLocationDialog = (props: Props) => {maxIndexAge};}+ if (persistTagsInSidecarFile !== null) {+ // props.isPersistTagsInSidecar !== persistTagsInSidecarFile) {+ loc = { ...loc, persistTagsInSidecarFile };+ }if (props.addLocation) {props.addLocation(loc);@@ -331,6 +345,14 @@ const CreateEditLocationDialog = (props: Props) => {);}+ const currentTagsSetting =+ props.location && props.location.persistTagsInSidecarFile !== null+ ? location.persistTagsInSidecarFile+ : props.isPersistTagsInSidecar;++ const disableLocationTypeSwitch: boolean =+ !Pro || AppConfig.isWeb || props.location !== undefined;+return (<Dialogopen={open}@@ -351,7 +373,18 @@ const CreateEditLocationDialog = (props: Props) => {<DialogTitle>{props.location? i18n.t('core:editLocationTitle')- : i18n.t('core:createLocationTitle')}+ : i18n.t('core:createLocationTitle')}{' '}+ <IconButton+ aria-label="close"+ style={{+ position: 'absolute',+ right: 5,+ top: 5+ }}+ onClick={onClose}+ >+ <CloseIcon />+ </IconButton></DialogTitle><DialogContent><Grid container spacing={2}>@@ -359,7 +392,7 @@ const CreateEditLocationDialog = (props: Props) => {<Typography>{i18n.t('core:locationType')}</Typography></Grid><Grid item xs={10}>- <FormControl disabled={!Pro || AppConfig.isWeb}>+ <FormControl disabled={disableLocationTypeSwitch}><RadioGrouptitle={Pro ? '' : i18n.t('core:thisFunctionalityIsAvailableInPro')@@ -390,8 +423,11 @@ const CreateEditLocationDialog = (props: Props) => {</Grid></Grid>{content}- <FormGroup>+ <FormGroup style={{ marginTop: 10 }}><FormControlLabel+ className={classes.formControl}+ labelPlacement="start"+ style={{ justifyContent: 'space-between' }}control={<Switchdata-tid="locationIsDefault"@@ -405,6 +441,9 @@ const CreateEditLocationDialog = (props: Props) => {label={i18n.t('core:startupLocation')}/><FormControlLabel+ className={classes.formControl}+ labelPlacement="start"+ style={{ justifyContent: 'space-between' }}control={<Switchdisabled={!Pro}@@ -422,6 +461,9 @@ const CreateEditLocationDialog = (props: Props) => {}/><FormControlLabel+ className={classes.formControl}+ labelPlacement="start"+ style={{ justifyContent: 'space-between' }}control={<Switchdisabled={!Pro || type === locationType.TYPE_CLOUD}@@ -440,6 +482,9 @@ const CreateEditLocationDialog = (props: Props) => {/>{showAdvancedMode && (<FormControlLabel+ className={classes.formControl}+ labelPlacement="start"+ style={{ justifyContent: 'space-between' }}control={<Switchdisabled={!Pro}@@ -459,6 +504,9 @@ const CreateEditLocationDialog = (props: Props) => {)}{showAdvancedMode && (<FormControlLabel+ className={classes.formControl}+ labelPlacement="start"+ style={{ justifyContent: 'space-between' }}control={<Switchdisabled={!Pro}@@ -478,6 +526,9 @@ const CreateEditLocationDialog = (props: Props) => {)}{showAdvancedMode && (<FormControlLabel+ className={classes.formControl}+ labelPlacement="start"+ style={{ justifyContent: 'space-between' }}control={<Tooltip title={i18n.t('core:maxIndexAgeHelp')}><Input@@ -485,7 +536,8 @@ const CreateEditLocationDialog = (props: Props) => {style={{maxWidth: 70,marginLeft: 15,- marginRight: 15+ marginRight: 15,+ marginBottom: 15}}type="number"data-tid="maxIndexAgeTID"@@ -498,12 +550,123 @@ const CreateEditLocationDialog = (props: Props) => {label={i18n.t('core:maxIndexAge')}/>)}+ {showAdvancedMode &&+ (AppConfig.useSidecarsForFileTaggingDisableSetting ? (+ <FormControlLabel+ className={classes.formControl}+ labelPlacement="start"+ style={{ justifyContent: 'space-between' }}+ control={+ <Button size="small" variant="outlined" disabled>+ {currentTagsSetting ? 'Use Sidecar Files' : 'Rename Files'}+ </Button>+ }+ label={+ <Typography variant="caption" display="block" gutterBottom>+ {i18n.t('core:fileTaggingSetting')}+ </Typography>+ }+ />+ ) : (+ <FormControlLabel+ labelPlacement="top"+ className={classes.formControl}+ style={{ alignItems: 'start' }}+ control={+ <ToggleButtonGroup+ value={persistTagsInSidecarFile}+ size="small"+ exclusive+ >+ <ToggleButton+ value={null}+ data-tid="settingsSetPersistTagsDefault"+ onClick={() => setPersistTagsInSidecarFile(null)}+ >+ <Tooltip+ arrow+ title={+ <Typography color="inherit">+ Use the default settings for saving the tags:{' '}+ <b>+ {currentTagsSetting+ ? 'Use Sidecar Files'+ : 'Rename Files'}+ </b>+ </Typography>+ }+ >+ <div style={{ display: 'flex' }}>+ {persistTagsInSidecarFile === null && <CheckIcon />}+ {i18n.t('core:default')} + <InfoIcon />+ </div>+ </Tooltip>+ </ToggleButton>+ <ToggleButton+ value={false}+ data-tid="settingsSetPersistTagsInFileName"+ onClick={() => setPersistTagsInSidecarFile(false)}+ >+ <Tooltip+ arrow+ title={+ <Typography color="inherit">+ Use the name of file for saving the tags - Tagging+ the file <b>image.jpg</b> with a tag <b>sunset</b>{' '}+ will rename it to <b>image[sunset].jpg</b>+ </Typography>+ }+ >+ <div style={{ display: 'flex' }}>+ {persistTagsInSidecarFile !== null &&+ !persistTagsInSidecarFile && <CheckIcon />}+ Rename Files + <InfoIcon />+ </div>+ </Tooltip>+ </ToggleButton>+ <ToggleButton+ value={true}+ data-tid="settingsSetPersistTagsInSidecarFile"+ onClick={() => setPersistTagsInSidecarFile(true)}+ >+ <Tooltip+ arrow+ title={+ <Typography color="inherit">+ Use sidecar file for saving the tags - Tagging the+ file <b>image.jpg</b> with a tag <b>sunset</b> will+ save this tag in an additional sidecar file called{' '}+ <b>image.jpg.json</b> located in a sub folder with+ the name <b>.ts</b>+ </Typography>+ }+ >+ <div style={{ display: 'flex' }}>+ {persistTagsInSidecarFile !== null &&+ persistTagsInSidecarFile && <CheckIcon />}+ Use Sidecar Files + <InfoIcon />+ </div>+ </Tooltip>+ </ToggleButton>+ </ToggleButtonGroup>+ }+ label={+ <Typography variant="caption" display="block" gutterBottom>+ {i18n.t('core:fileTaggingSetting')}+ </Typography>+ }+ />+ ))}</FormGroup></DialogContent><DialogActions style={{ justifyContent: 'space-between' }}><Buttondata-tid="switchAdvancedModeTID"onClick={() => setShowAdvancedMode(!showAdvancedMode)}+ style={{ marginLeft: 10 }}>{showAdvancedMode? i18n.t('core:switchSimpleMode')diff --git a/app/components/dialogs/LocalForm.tsx b/app/components/dialogs/LocalForm.tsxindex 943781f18..31952458b 100644--- a/app/components/dialogs/LocalForm.tsx+++ b/app/components/dialogs/LocalForm.tsx@@ -20,7 +20,6 @@ import React from 'react';import InputAdornment from '@material-ui/core/InputAdornment';import FormControl from '@material-ui/core/FormControl';-// import FormHelperText from '@material-ui/core/FormHelperText';import Input from '@material-ui/core/Input';import InputLabel from '@material-ui/core/InputLabel';import IconButton from '@material-ui/core/IconButton';@@ -102,9 +101,6 @@ const LocalForm = (props: Props) => {</InputAdornment>}/>- {/* {state.errorTextPath && (- <FormHelperText>{i18n.t('core:invalidPath')}</FormHelperText>- )} */}</FormControl></Grid><Grid item xs={12}>@@ -122,9 +118,6 @@ const LocalForm = (props: Props) => {data-tid="locationName"fullWidth={true}/>- {/* {state.errorTextName && (- <FormHelperText>{i18n.t('core:invalidName')}</FormHelperText>- )} */}</FormControl></Grid>{showAdvancedMode && (@@ -143,9 +136,6 @@ const LocalForm = (props: Props) => {onChange={event => setNewUuid(event.target.value)}value={newuuid}/>- {/* {state.errorTextId && (- <FormHelperText>{i18n.t('core:invalidId')}</FormHelperText>- )} */}</FormControl></Grid>)}diff --git a/app/components/dialogs/ObjectStoreForm.tsx b/app/components/dialogs/ObjectStoreForm.tsxindex 751a62f53..045a58301 100644--- a/app/components/dialogs/ObjectStoreForm.tsx+++ b/app/components/dialogs/ObjectStoreForm.tsx@@ -79,47 +79,6 @@ export const regions = ['sa-east-1'];-const styles: any = (theme: any) => ({- root: {- flexGrow: 1,- height: 250- },- input: {- display: 'flex',- padding: 0,- height: 36,- marginTop: 10- },- valueContainer: {- display: 'flex',- flexWrap: 'wrap',- flex: 1,- alignItems: 'center',- overflow: 'hidden'- },- noOptionsMessage: {- padding: theme.spacing(1, 2)- },- singleValue: {- fontSize: 16- },- placeholder: {- position: 'absolute',- left: 2,- fontSize: 16- },- paper: {- // position: 'absolute',- zIndex: 1,- marginTop: theme.spacing(1),- left: 0,- right: 0- },- divider: {- height: theme.spacing(2)- }-});-interface Props {classes: any;theme: any;@@ -392,4 +351,4 @@ const ObjectStoreForm = (props: Props) => {);};-export default withStyles(styles, { withTheme: true })(ObjectStoreForm);+export default withStyles(undefined, { withTheme: true })(ObjectStoreForm);diff --git a/app/components/dialogs/settings/SettingsGeneral.tsx b/app/components/dialogs/settings/SettingsGeneral.tsxindex 5916fe6b5..3e1e9059e 100644--- a/app/components/dialogs/settings/SettingsGeneral.tsx+++ b/app/components/dialogs/settings/SettingsGeneral.tsx@@ -156,7 +156,7 @@ const SettingsGeneral = (props: Props) => {: ''}>- <ListItemText primary="File tagging method" />+ <ListItemText primary={i18n.t('core:fileTaggingSetting')} />{AppConfig.useSidecarsForFileTaggingDisableSetting ? (<Button size="small" variant="outlined" disabled>{persistTagsInSidecarFile ? 'Use Sidecar Files' : 'Rename Files'}diff --git a/app/locales/en/core.json b/app/locales/en/core.jsonindex e122a0f29..e2d1cdf92 100644--- a/app/locales/en/core.json+++ b/app/locales/en/core.json@@ -571,5 +571,7 @@"addTileServersSettings": "In order to see the map, add at least one map tile server in the settings of the app","showFolderMapControl": "Show folders on the map","noSubFoldersFound": "No sub folders in the current folder",+ "fileTaggingSetting": "File tagging method",+ "default": "Default","-": "-"}diff --git a/app/perspectives/grid-perspective/components/CellContent.tsx b/app/perspectives/grid-perspective/components/CellContent.tsxindex 9a49d7076..d802f276b 100644--- a/app/perspectives/grid-perspective/components/CellContent.tsx+++ b/app/perspectives/grid-perspective/components/CellContent.tsx@@ -277,8 +277,8 @@ const CellContent = (props: Props) => {}}style={{backgroundColor: fsEntry.isFile- ? fsEntryColor- : fsEntryBackgroundColor || fsEntryColor+ ? 'transparent'+ : fsEntryBackgroundColor}}>{fsEntry.isFile ? fsEntry.extension : <FolderIcon />}diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex 753911660..66f7b61b2 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -2112,6 +2112,20 @@ export const getCurrentLocationPath = (state: any) => {}return undefined;};+export const getLocationPersistTagsInSidecarFile = (state: any) => {+ if (state.locations) {+ for (let i = 0; i < state.locations.length; i += 1) {+ const location = state.locations[i];+ if (+ state.app.currentLocationId &&+ location.uuid === state.app.currentLocationId+ ) {+ return location.persistTagsInSidecarFile;+ }+ }+ }+ return undefined;+};export const isUpdateAvailable = (state: any) => state.app.isUpdateAvailable;export const isUpdateInProgress = (state: any) => state.app.isUpdateInProgress;export const isOnline = (state: any) => state.app.isOnline;diff --git a/app/reducers/locations.ts b/app/reducers/locations.tsindex 64bbb18cb..1a9907d23 100644--- a/app/reducers/locations.ts+++ b/app/reducers/locations.ts@@ -73,7 +73,8 @@ export default (state: Array<TS.Location> = initialState, action: any) => {uuid:action.location.newuuid !== undefined? action.location.newuuid- : action.location.uuid+ : action.location.uuid,+ persistTagsInSidecarFile: action.location.persistTagsInSidecarFile},...state.slice(indexForEditing + 1)];diff --git a/app/reducers/tagging-actions.ts b/app/reducers/tagging-actions.tsindex 4f568917f..d7da36578 100644--- a/app/reducers/tagging-actions.ts+++ b/app/reducers/tagging-actions.ts@@ -17,7 +17,10 @@*/import OpenLocationCode from 'open-location-code-typescript';import i18n from '../services/i18n';-import { actions as AppActions } from './app';+import {+ actions as AppActions,+ getLocationPersistTagsInSidecarFile+} from './app';import { actions as TagLibraryActions } from './taglibrary';import {extractFileExtension,@@ -40,6 +43,16 @@ import { TS } from '-/tagspaces.namespace';export const defaultTagLocation = OpenLocationCode.encode(51.48, 0, undefined); // default tag coordinate Greenwich+const persistTagsInSidecarFile = state => {+ const locationPersistTagsInSidecarFile = getLocationPersistTagsInSidecarFile(+ state+ );+ if (locationPersistTagsInSidecarFile !== undefined) {+ return locationPersistTagsInSidecarFile;+ }+ return getPersistTagsInSidecarFile(state);+};+const actions = {addTags: (paths: Array<string>,@@ -150,7 +163,7 @@ const actions = {console.log('No sidecar found ' + error);}- if (!entryProperties.isFile || getPersistTagsInSidecarFile(getState())) {+ if (!entryProperties.isFile || persistTagsInSidecarFile(getState())) {// Handling adding tags in sidecarif (fsEntryMeta) {const uniqueTags = getNonExistingTags(@@ -322,7 +335,7 @@ const actions = {// Work around solutiondelete tag.functionality;const entryProperties = await PlatformIO.getPropertiesPromise(path);- if (entryProperties.isFile && !getPersistTagsInSidecarFile(getState())) {+ if (entryProperties.isFile && !persistTagsInSidecarFile(getState())) {tag.type = 'plain';}}diff --git a/app/tagspaces.namespace.d.ts b/app/tagspaces.namespace.d.tsindex 09708ddb4..6a82e1188 100644--- a/app/tagspaces.namespace.d.ts+++ b/app/tagspaces.namespace.d.ts@@ -40,6 +40,7 @@ export namespace TS {persistIndex?: boolean;fullTextIndex?: boolean;maxIndexAge?: number;+ persistTagsInSidecarFile?: boolean;}interface SearchQuery {