Skip to content

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

add prefixTagContainer in settingsDialog (#1906)

Stanimirab7a12851e70
diff --git a/app/components/dialogs/settings/SettingsAdvanced.tsx b/app/components/dialogs/settings/SettingsAdvanced.tsx
index 95305c437..0a0770b23 100644
--- a/app/components/dialogs/settings/SettingsAdvanced.tsx
+++ b/app/components/dialogs/settings/SettingsAdvanced.tsx
@@ -81,6 +81,7 @@ interface Props {
tileServers: Array<TS.MapTileServer>;
setGeoTaggingFormat: (geoTaggingFormat: string) => void;
setHistory: (key: string, value: number) => void;
+ setPrefixTagContainer: (prefix: string) => void;
}
const historyKeys = Pro && Pro.history ? Pro.history.historyKeys : {};
@@ -162,6 +163,15 @@ function SettingsAdvanced(props: Props) {
checked={props.settings.warningOpeningFilesExternally}
/>
</ListItem>
+ <ListItem className={classes.listItem}>
+ <ListItemText primary={i18n.t('core:prefixTagContainer')} />
+ <Input
+ style={{ maxWidth: '100px' }}
+ data-tid="prefixTagContainerTID"
+ value={props.settings.prefixTagContainer}
+ onChange={event => props.setPrefixTagContainer(event.target.value)}
+ />
+ </ListItem>
{Pro && (
<>
<ListItem className={classes.listItem}>
@@ -399,7 +409,8 @@ function mapActionCreatorsToProps(dispatch) {
setSaveTagInLocation: SettingsActions.setSaveTagInLocation,
setGeoTaggingFormat: SettingsActions.setGeoTaggingFormat,
setHistory: SettingsActions.setHistory,
- setRevisionsEnabled: SettingsActions.setRevisionsEnabled
+ setRevisionsEnabled: SettingsActions.setRevisionsEnabled,
+ setPrefixTagContainer: SettingsActions.setPrefixTagContainer
},
dispatch
);
diff --git a/app/components/menus/FileMenu.tsx b/app/components/menus/FileMenu.tsx
index e173bb716..bb1a0e8e3 100644
--- a/app/components/menus/FileMenu.tsx
+++ b/app/components/menus/FileMenu.tsx
@@ -59,6 +59,13 @@ import { bindActionCreators } from 'redux';
import { actions as AppActions } from '-/reducers/app';
import { connect } from 'react-redux';
import { supportedImgs } from '-/services/thumbsgenerator';
+import {
+ getEnableWS,
+ getMapTileServers,
+ getPrefixTagContainer,
+ getSettings,
+ isDevMode
+} from '-/reducers/settings';
// import AddIcon from '@mui/icons-material/Add';
interface Props {
@@ -93,6 +100,7 @@ interface Props {
reorderTop?: () => void;
reorderBottom?: () => void;
exitSearchMode: () => void;
+ prefixTagContainer: string;
}
function FileMenu(props: Props) {
@@ -224,7 +232,12 @@ function FileMenu(props: Props) {
const newFilePath =
(dirPath ? dirPath + PlatformIO.getDirSeparator() : '') +
- generateFileName(fileName, extractedTags, AppConfig.tagDelimiter);
+ generateFileName(
+ fileName,
+ extractedTags,
+ AppConfig.tagDelimiter,
+ props.prefixTagContainer
+ );
PlatformIO.copyFilePromise(selectedFilePath, newFilePath)
.then(() => {
@@ -503,6 +516,12 @@ function FileMenu(props: Props) {
);
}
+function mapStateToProps(state) {
+ return {
+ prefixTagContainer: getPrefixTagContainer(state)
+ };
+}
+
function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
@@ -513,4 +532,4 @@ function mapDispatchToProps(dispatch) {
);
}
-export default connect(undefined, mapDispatchToProps)(FileMenu);
+export default connect(mapStateToProps, mapDispatchToProps)(FileMenu);
diff --git a/app/reducers/settings-default.ts b/app/reducers/settings-default.ts
index 83eefc1d8..a672ce88c 100644
--- a/app/reducers/settings-default.ts
+++ b/app/reducers/settings-default.ts
@@ -104,6 +104,7 @@ export default {
typeof window.ExtRevisionsEnabled === 'undefined'
? true
: window.ExtRevisionsEnabled,
+ prefixTagContainer: AppConfig.prefixTagContainer,
isAutoSaveEnabled:
typeof window.ExtAutoSaveEnabled === 'undefined'
? false
diff --git a/app/reducers/settings.ts b/app/reducers/settings.ts
index 5fb7ca9d1..efb18dc52 100644
--- a/app/reducers/settings.ts
+++ b/app/reducers/settings.ts
@@ -64,6 +64,7 @@ export const types = {
SET_PERSISTTAGSINSIDECARFILE: 'SETTINGS/SET_PERSISTTAGSINSIDECARFILE',
SET_ADDTAGSTOLIBRARY: 'SETTINGS/SET_ADDTAGSTOLIBRARY',
SET_REVISIONS_ENABLED: 'SETTINGS/SET_REVISIONS_ENABLED',
+ SET_PREFIX_TAG_CONTAINER: 'SETTINGS/SET_PREFIX_TAG_CONTAINER',
SET_USEGENERATETHUMBNAILS: 'SETTINGS/SET_USEGENERATETHUMBNAILS',
SET_USETEXTEXTRACTION: 'SETTINGS/SET_USETEXTEXTRACTION',
SET_TAGCOLOR: 'SETTINGS/SET_TAGCOLOR',
@@ -224,6 +225,9 @@ export default (state: any = defaultSettings, action: any) => {
case types.SET_REVISIONS_ENABLED: {
return { ...state, isRevisionsEnabled: action.enabled };
}
+ case types.SET_PREFIX_TAG_CONTAINER: {
+ return { ...state, prefixTagContainer: action.prefixTagContainer };
+ }
case types.SET_USEGENERATETHUMBNAILS: {
return { ...state, useGenerateThumbnails: action.useGenerateThumbnails };
}
@@ -622,6 +626,10 @@ export const actions = {
type: types.SET_REVISIONS_ENABLED,
enabled
}),
+ setPrefixTagContainer: (prefixTagContainer: boolean) => ({
+ type: types.SET_PREFIX_TAG_CONTAINER,
+ prefixTagContainer
+ }),
setUseGenerateThumbnails: (useGenerateThumbnails: boolean) => ({
type: types.SET_USEGENERATETHUMBNAILS,
useGenerateThumbnails
@@ -830,6 +838,8 @@ export const isDevMode = (state: any) =>
window.ExtDevMode ? window.ExtDevMode : state.settings.devMode;
export const isRevisionsEnabled = (state: any) =>
state.settings.isRevisionsEnabled;
+export const getPrefixTagContainer = (state: any) =>
+ state.settings.prefixTagContainer;
export const getWarningOpeningFilesExternally = (state: any) =>
state.settings.warningOpeningFilesExternally;
export const getCheckForUpdateOnStartup = (state: any) =>
diff --git a/app/reducers/tagging-actions.ts b/app/reducers/tagging-actions.ts
index e8b168445..ff03d64e1 100644
--- a/app/reducers/tagging-actions.ts
+++ b/app/reducers/tagging-actions.ts
@@ -283,7 +283,12 @@ const actions = {
(containingDirectoryPath
? containingDirectoryPath + PlatformIO.getDirSeparator()
: '') +
- generateFileName(fileName, extractedTags, settings.tagDelimiter);
+ generateFileName(
+ fileName,
+ extractedTags,
+ settings.tagDelimiter,
+ settings.prefixTagContainer
+ );
return dispatch(AppActions.renameFile(path, newFilePath));
}
} else {
@@ -309,7 +314,12 @@ const actions = {
(containingDirectoryPath
? containingDirectoryPath + PlatformIO.getDirSeparator()
: '') +
- generateFileName(fileName, extractedTags, settings.tagDelimiter);
+ generateFileName(
+ fileName,
+ extractedTags,
+ settings.tagDelimiter,
+ settings.prefixTagContainer
+ );
if (path !== newFilePath) {
return dispatch(AppActions.renameFile(path, newFilePath));
}
@@ -404,7 +414,8 @@ const actions = {
const newFileName = generateFileName(
fileName,
extractedTags,
- settings.tagDelimiter
+ settings.tagDelimiter,
+ settings.prefixTagContainer
);
if (newFileName !== fileName) {
dispatch(
@@ -669,7 +680,12 @@ const actions = {
(containingDirectoryPath
? containingDirectoryPath + PlatformIO.getDirSeparator()
: '') +
- generateFileName(fileName, extractedTags, settings.tagDelimiter);
+ generateFileName(
+ fileName,
+ extractedTags,
+ settings.tagDelimiter,
+ settings.prefixTagContainer
+ );
if (path !== newFilePath) {
const success = await dispatch(
AppActions.renameFile(path, newFilePath)
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index f13eeaa53..bd5fe2d56 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -733,10 +733,10 @@ export async function loadSubFolders(path: string, loadHidden = false) {
export function generateFileName(
fileName: string,
tags: Array<string>,
- tagDelimiter: string
+ tagDelimiter: string,
+ prefixTagContainer = AppConfig.prefixTagContainer
) {
let tagsString = '';
- const { prefixTagContainer } = AppConfig;
// Creating the string will all the tags by more that 0 tags
if (tags && tags.length > 0) {
tagsString = AppConfig.beginTagContainer;
@@ -769,28 +769,41 @@ export function generateFileName(
} else {
// File has an extension
newFileName =
- fileName.substring(0, lastDotPosition).trim() +
- (tagsString ? ' ' + prefixTagContainer + tagsString : '') +
+ cleanFileName(
+ fileName.substring(0, lastDotPosition),
+ prefixTagContainer
+ ) +
+ (tagsString ? prefixTagContainer + tagsString : '') +
'.' +
fileExt;
}
} else {
// File does not have an extension
newFileName =
- fileName.substring(0, beginTagContainer).trim() +
- (tagsString ? ' ' + prefixTagContainer + tagsString : '') +
+ cleanFileName(
+ fileName.substring(0, beginTagContainer),
+ prefixTagContainer
+ ) +
+ (tagsString ? prefixTagContainer + tagsString : '') +
fileName.substring(endTagContainer + 1, fileName.length).trim();
}
if (newFileName.length < 1) {
throw new Error('Generated filename is invalid');
}
- // Removing double prefix
+ // Removing double prefix todo rethink this ?? there is no double prefix
newFileName = newFileName
.split(prefixTagContainer + '' + prefixTagContainer)
.join(prefixTagContainer);
return newFileName;
}
+function cleanFileName(fileName, prefixTagContainer) {
+ if (prefixTagContainer && fileName.endsWith(prefixTagContainer)) {
+ return fileName.slice(0, -prefixTagContainer.length);
+ }
+ return fileName.trim();
+}
+
export function parseNewTags(tagsInput: string, tagGroup: TS.TagGroup) {
if (tagGroup) {
let tags = tagsInput
diff --git a/tests/e2e/general.helpers.js b/tests/e2e/general.helpers.js
index 157789875..352cc5c4c 100644
--- a/tests/e2e/general.helpers.js
+++ b/tests/e2e/general.helpers.js
@@ -2,6 +2,7 @@
import path from 'path';
import { delay, clearLocalStorage } from './hook';
import { firstFile } from './test-utils';
+import AppConfig from '../../app/AppConfig';
export const defaultLocationPath =
'./testdata-tmp/file-structure/supported-filestypes';
@@ -643,9 +644,9 @@ export function getGridFileSelector(fileName) {
export function generateFileName(fileName, fileExt, tags, tagDelimiter = ' ') {
let tagsString = '';
- let beginTagContainer = '[';
- let endTagContainer = ']';
- const prefixTagContainer = '';
+ let beginTagContainer = AppConfig.beginTagContainer;
+ let endTagContainer = AppConfig.endTagContainer;
+ const prefixTagContainer = AppConfig.prefixTagContainer;
// Creating the string will all the tags by more that 0 tags
if (tags && tags.length > 0) {
tagsString = beginTagContainer;
@@ -669,13 +670,15 @@ export function generateFileName(fileName, fileExt, tags, tagDelimiter = ' ') {
) {
// File does not have an extension
newFileName =
- fileName.trim() + (tagsString ? ' ' + tagsString : '') + '.' + fileExt;
+ fileName.trim() +
+ (tagsString ? prefixTagContainer + tagsString : '') +
+ '.' +
+ fileExt;
} else {
// File does not have an extension
newFileName =
fileName.substring(0, beginTagContainer).trim() +
- prefixTagContainer +
- tagsString +
+ (tagsString ? prefixTagContainer + tagsString : '') +
fileName.substring(endTagContainer + 1, fileName.length).trim();
}
if (newFileName.length < 1) {