TagSpaces is an offline, open source, document manager with tagging support
TST204 (#765)
Stanimireb9414cc6dd6
diff --git a/app/components/EntryContainer.js b/app/components/EntryContainer.jsindex 0957dfa53..c58725847 100644--- a/app/components/EntryContainer.js+++ b/app/components/EntryContainer.js@@ -249,8 +249,10 @@ class EntryContainer extends React.Component<Props, State> {this.setState({ editingSupported: false });}+ const { settings } = nextProps;+const currentEntry = nextProps.openedFiles[0];- const tags = extractTagsAsObjects(currentEntry.path);+ const tags = extractTagsAsObjects(currentEntry.path, settings.tagDelimiter);this.setState({selectedItem: {...currentEntry,@@ -258,9 +260,8 @@ class EntryContainer extends React.Component<Props, State> {}});- const { settings } = nextProps;this.setState({- entryPropertiesSplitSize: nextProps.settings.entryPropertiesSplitSize,+ entryPropertiesSplitSize: settings.entryPropertiesSplitSize,isPropertiesPanelVisible: settings.entryPropertiesSplitSize > defaultSplitSize});} else {@@ -938,7 +939,7 @@ class EntryContainer extends React.Component<Props, State> {shouldCopyFile={this.state.shouldCopyFile}normalizeShouldCopyFile={() => this.setState({ shouldCopyFile: false })}onEditTags={() => {- const tags = extractTagsAsObjects(currentEntry.path);+ const tags = extractTagsAsObjects(currentEntry.path, this.props.settings.tagDelimiter);this.setState({selectedItem: {...currentEntry,diff --git a/app/components/Search.js b/app/components/Search.jsindex 8eb2898df..2dfed0a1b 100644--- a/app/components/Search.js+++ b/app/components/Search.js@@ -45,6 +45,7 @@ import FormControl from '@material-ui/core/FormControl';import FormHelperText from '@material-ui/core/FormHelperText';// import Switch from '@material-ui/core/Switch';import { actions as AppActions, getIndexedEntriesCount, isIndexing, getDirectoryPath } from '../reducers/app';+import { getMaxSearchResults } from '../reducers/settings';import styles from './SidePanels.css';import i18n from '../services/i18n';import { FileTypeGroups, type SearchQuery } from '../services/search';@@ -57,6 +58,7 @@ type Props = {loadDirectoryContent: (path: string) => void,currentDirectory: string,indexedEntriesCount: number,+ maxSearchResults: number,indexing: boolean};@@ -119,7 +121,8 @@ class Search extends React.Component<Props, State> {textQuery: this.state.textQuery,fileTypes: this.state.fileTypes,tagConjunction: this.state.tagConjunction,- tags+ tags,+ maxSearchResults: this.props.maxSearchResults};console.log('Search object: ' + JSON.stringify(searchQuery));this.props.searchLocationIndex(searchQuery);@@ -370,7 +373,8 @@ function mapStateToProps(state) {return {indexing: isIndexing(state),currentDirectory: getDirectoryPath(state),- indexedEntriesCount: getIndexedEntriesCount(state)+ indexedEntriesCount: getIndexedEntriesCount(state),+ maxSearchResults: getMaxSearchResults(state)};}diff --git a/app/components/menus/TagMenu.js b/app/components/menus/TagMenu.jsindex 00fc92083..9b8822b3f 100644--- a/app/components/menus/TagMenu.js+++ b/app/components/menus/TagMenu.js@@ -34,6 +34,7 @@ import { type Tag, type TagGroup } from '../../reducers/taglibrary';import { actions as AppActions } from '../../reducers/app';import i18n from '../../services/i18n';import { type SearchQuery } from '../../services/search';+import { getMaxSearchResults } from '../../reducers/settings';type Props = {anchorEl?: Object,@@ -43,7 +44,8 @@ type Props = {selectedTagGroupEntry?: TagGroup,deleteTag: (uuid: string, tagGroupUuid: string) => void,searchLocationIndex: (searchQuery: SearchQuery) => void,- editTag: () => void+ editTag: () => void,+ maxSearchResults: number};type State = {@@ -64,7 +66,10 @@ class TagLibraryMenu extends React.Component<Props, State> {showFilesWithThisTag = () => {if (this.props.selectedTag) {- this.props.searchLocationIndex({ tags: [this.props.selectedTag.title] });+ this.props.searchLocationIndex({+ tags: [this.props.selectedTag.title],+ maxSearchResults: this.props.maxSearchResults+ });}this.props.onClose();};@@ -95,7 +100,7 @@ class TagLibraryMenu extends React.Component<Props, State> {}};-/*+ /*<MenuItem data-tid="tagSelectedFiles" onClick={this.tagSelectedFiles}><ListItemIcon><LocalOffer />@@ -162,10 +167,16 @@ class TagLibraryMenu extends React.Component<Props, State> {);}+function mapStateToProps(state) {+ return {+ maxSearchResults: getMaxSearchResults(state)+ };+}+function mapDispatchToProps(dispatch) {return bindActionCreators({searchLocationIndex: AppActions.searchLocationIndex,}, dispatch);}-export default connect(undefined, mapDispatchToProps)(TagLibraryMenu);+export default connect(mapStateToProps, mapDispatchToProps)(TagLibraryMenu);diff --git a/app/components/settings/SettingsGeneral.js b/app/components/settings/SettingsGeneral.jsindex 26b6d210e..6d9b65cdf 100644--- a/app/components/settings/SettingsGeneral.js+++ b/app/components/settings/SettingsGeneral.js@@ -73,7 +73,9 @@ type Props = {setUseTrashCan: () => void,setPersistTagsInSidecarFile: () => void,setAddTagsToLibrary: () => void,- setUseGenerateThumbnails: () => void+ setUseGenerateThumbnails: () => void,+ setTagDelimiter: () => void,+ setMaxSearchResult: () => void};type State = {@@ -109,7 +111,16 @@ class SettingsGeneral extends React.Component<Props, State> {this.setState({ currentTheme: event.target.value });};+ handleTagDelimiterChange = event => {+ this.props.setTagDelimiter(event.target.value);+ };++ handleMaxSearchResult = event => {+ this.props.setMaxSearchResult(event.target.value);+ };+render() {+ console.log('render settings');const classes = this.props.classes;return (@@ -256,7 +267,7 @@ class SettingsGeneral extends React.Component<Props, State> {</ListItemSecondaryAction></ListItem><ListItem>- <ListItemText primary={i18n.t('core:showUnixHiddenFiles')} />+ <ListItemText style={{ maxWidth: '350px' }} primary={i18n.t('core:showUnixHiddenFiles')} /><ListItemSecondaryAction><Switchdata-tid="settingsSetShowUnixHiddenEntries"@@ -269,6 +280,39 @@ class SettingsGeneral extends React.Component<Props, State> {/></ListItemSecondaryAction></ListItem>+ <ListItem>+ <ListItemText style={{ maxWidth: '300px' }} primary={i18n.t('core:tagDelimiterChoose')} />+ <ListItemSecondaryAction>+ <Select+ style={{ minWidth: '170px' }}+ data-tid="settingsTagDelimiterChoose"+ value={this.props.settings.tagDelimiter}+ onChange={this.handleTagDelimiterChange}+ inputProps={{+ name: 'tagDelimiter',+ id: 'tag-delimiter',+ }}+ >+ <MenuItem value=" ">{i18n.t('core:tagDelimiterSpace')}</MenuItem>+ <MenuItem value="_">{i18n.t('core:tagDelimiterUnderscore')}</MenuItem>+ <MenuItem value=",">{i18n.t('core:tagDelimiterComma')}</MenuItem>+ </Select>+ </ListItemSecondaryAction>+ </ListItem>+ <ListItem>+ <ListItemText primary={i18n.t('core:maxSearchResultChoose')} />+ <ListItemSecondaryAction>+ <Input+ style={{ maxWidth: '170px' }}+ type="number"+ data-tid="settingsMaxSearchResult"+ label={i18n.t('core:maxSearchResult')}+ value={this.props.settings.maxSearchResult}+ onChange={this.handleMaxSearchResult}+ // onBlur={this.handleMaxSearchResult}+ />+ </ListItemSecondaryAction>+ </ListItem>{ /* <ListItem><ListItemText primary={i18n.t('core:coloredFileExtensionsEnabled')} /><ListItemSecondaryAction>diff --git a/app/config.js b/app/config.jsindex a256bf8a3..81599c57d 100644--- a/app/config.js+++ b/app/config.js@@ -35,7 +35,7 @@ export default {prefixTagContainer: '',maxThumbSize: 400,indexerLimit: 200000,- maxSearchResult: 1000,+ // maxSearchResult: 1000,defaultFileColor: '#808080',defaultFolderColor: '#555', // transparent #FDEEBD #ff791b #2c001e #880e4fisElectron: (navigator.userAgent.toLowerCase().indexOf(' electron/') > -1),diff --git a/app/locales/en/core.json b/app/locales/en/core.jsonindex 863d7d06b..1448a9386 100644--- a/app/locales/en/core.json+++ b/app/locales/en/core.json@@ -344,5 +344,10 @@"invalidAccessKey": "Access Key is empty","invalidBucketName": "Bucket Name is empty","invalidRegion": "Region is empty",+ "tagDelimiterChoose": "Tag delimiter (e.g. Filename [TAG1_TAG2], _ is the delimiter)",+ "tagDelimiterSpace": "space ( ) -recommended",+ "tagDelimiterUnderscore": "underscore (_)",+ "tagDelimiterComma": "comma (,)",+ "maxSearchResultChoose": "Max Search Results","-": "-"}diff --git a/app/reducers/app.js b/app/reducers/app.jsindex 9c56537e4..99819f376 100644--- a/app/reducers/app.js+++ b/app/reducers/app.js@@ -43,6 +43,7 @@ import { sortByCriteria, formatDateTime4Tag } from '../utils/misc';import i18n from '../services/i18n';import { Pro } from '../pro';import { getThumbnailURLPromise } from '../services/thumbsgenerator';+import { getTagDelimiter } from './settings';export const types = {DEVICE_ONLINE: 'APP/DEVICE_ONLINE',@@ -449,7 +450,7 @@ export default (state: Object = initialState, action: Object) => {extension: extractFileExtension(action.newPath),tags: [...state.currentDirectoryEntries[indexForRenaming].tags.filter(tag => tag.type === 'sidecar'), // add only sidecar tags- ...extractTagsAsObjects(action.newPath)+ ...extractTagsAsObjects(action.newPath, getTagDelimiter(state))]};directoryEntries = [@@ -467,7 +468,7 @@ export default (state: Object = initialState, action: Object) => {extension: extractFileExtension(action.newPath),tags: [...state.currentDirectoryEntries[indexForRenaming].tags.filter(tag => tag.type === 'sidecar'), // add only sidecar tags- ...extractTagsAsObjects(action.newPath)+ ...extractTagsAsObjects(action.newPath, getTagDelimiter(state))]};directoryIndex = [diff --git a/app/reducers/settings-default.js b/app/reducers/settings-default.jsindex fe8427612..db2ea5d66 100644--- a/app/reducers/settings-default.js+++ b/app/reducers/settings-default.js@@ -30,6 +30,8 @@ export default {contentHash: '',isUpdateInProgress: false,isUpdateAvailable: false,+ tagDelimiter: ' ',+ maxSearchResult: 1000,desktopMode: true,newHTMLFileContent:'<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style type="text/css">body{overflow:auto;width:100%;height:100%;font:13.34px Ubuntu,arial,clean,sans-serif;color:#000;line-height:1.4em;background-color:#fff;padding:15px}p{margin:1em 0;line-height:1.5em}table{font:100%;margin:1em}table th{border-bottom:1px solid #bbb;padding:.2em 1em}table td{border-bottom:1px solid #ddd;padding:.2em 1em}input[type=image],input[type=password],input[type=text],textarea{font:99% helvetica,arial,freesans,sans-serif}option,select{padding:0 .25em}optgroup{margin-top:.5em}code,pre{font:12px Monaco, Courier ,monospace}pre{margin:1em 0;font-size:12px;background-color:#eee;border:1px solid #ddd;padding:5px;line-height:1.5em;color:#444;overflow:auto;-webkit-box-shadow:rgba(0,0,0,.07) 0 1px 2px inset;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}pre code{padding:0;font-size:12px;background-color:#eee;border:none}code{font-size:12px;background-color:#f8f8ff;color:#444;padding:0 .2em;border:1px solid #dedede}img{border:0;max-width:100%}abbr{border-bottom:none}a{color:#4183c4;text-decoration:none}a:hover{text-decoration:underline}a code,a:link code,a:visited code{color:#4183c4}h2,h3{margin:1em 0}h1,h2,h3,h4,h5,h6{border:0}h1{font-size:170%;border-top:4px solid #aaa;padding-top:.5em;margin-top:1.5em}h1:first-child{margin-top:0;padding-top:.25em;border-top:none}h2{font-size:150%;margin-top:1.5em;border-top:4px solid #e0e0e0;padding-top:.5em}h3{font-size:130%;margin-top:1em}h4{font-size:120%;margin-top:1em}h5{font-size:115%;margin-top:1em}h6{font-size:110%;margin-top:1em}hr{border:1px solid #ddd}ol,ul{margin:1em 0 1em 2em}ol li,ul li{margin-top:.5em;margin-bottom:.5em}ol ol,ol ul,ul ol,ul ul{margin-top:0;margin-bottom:0}blockquote{margin:1em 0;border-left:5px solid #ddd;padding-left:.6em;color:#555}dt{font-weight:700;margin-left:1em}dd{margin-left:2em;margin-bottom:1em}</style></head><body></body></html>',diff --git a/app/reducers/settings.js b/app/reducers/settings.jsindex f0667c505..df0a89953 100644--- a/app/reducers/settings.js+++ b/app/reducers/settings.js@@ -31,6 +31,8 @@ export const types = {SET_LANGUAGE: 'SETTINGS/SET_LANGUAGE',SET_SHOWUNIXHIDDENENTRIES: 'SETTINGS/SET_SHOWUNIXHIDDENENTRIES',SET_DESKTOPMODE: 'SETTINGS/SET_DESKTOPMODE',+ SET_TAG_DELIMITER: 'SETTINGS/SET_TAG_DELIMITER',+ SET_MAX_SEARCH_RESULT: 'SETTINGS/SET_MAX_SEARCH_RESULT',SET_CHECKFORUPDATES: 'SETTINGS/SET_CHECKFORUPDATES',SET_USEDEFAULTLOCATION: 'SETTINGS/SET_USEDEFAULTLOCATION',SET_COLOREDFILEEXTENSION: 'SETTINGS/SET_COLOREDFILEEXTENSION',@@ -87,6 +89,12 @@ export default (state = defaultSettings, action) => {case types.SET_SHOWUNIXHIDDENENTRIES: {return { ...state, showUnixHiddenEntries: action.showUnixHiddenEntries };}+ case types.SET_TAG_DELIMITER: {+ return { ...state, tagDelimiter: action.delimiter };+ }+ case types.SET_MAX_SEARCH_RESULT: {+ return { ...state, maxSearchResult: action.maxSearchResult };+ }case types.SET_DESKTOPMODE: {return { ...state, desktopMode: action.desktopMode };}@@ -254,6 +262,8 @@ export default (state = defaultSettings, action) => {};export const actions = {+ setTagDelimiter: (delimiter: string) => ({ type: types.SET_TAG_DELIMITER, delimiter }),+ setMaxSearchResult: (maxSearchResult: number) => ({ type: types.SET_MAX_SEARCH_RESULT, maxSearchResult }),setDesktopMode: (desktopMode: boolean) => ({ type: types.SET_DESKTOPMODE, desktopMode }),setShowUnixHiddenEntries: (showUnixHiddenEntries: boolean) => ({type: types.SET_SHOWUNIXHIDDENENTRIES,@@ -416,6 +426,8 @@ export const getCurrentTheme = (state: Object) => state.settings.currentTheme;export const isGlobalKeyBindingEnabled = (state: Object) => state.settings.enableGlobalKeyboardShortcuts;export const getLeftVerticalSplitSize = (state: Object) => state.settings.leftVerticalSplitSize;export const getMainVerticalSplitSize = (state: Object) => state.settings.mainVerticalSplitSize;+export const getTagDelimiter = (state: Object) => state.settings.tagDelimiter;+export const getMaxSearchResults = (state: Object) => state.settings.maxSearchResult;function generateKeyBindingObject(keyBindings: Array<Object>) {const kbObject = {};diff --git a/app/reducers/tagging-actions.js b/app/reducers/tagging-actions.jsindex d3d6083d8..b99db5817 100644--- a/app/reducers/tagging-actions.js+++ b/app/reducers/tagging-actions.js@@ -128,7 +128,7 @@ const actions = {} else {const fileName = extractFileName(path);const containingDirectoryPath = extractContainingDirectoryPath(path);- const extractedTags = extractTags(path);+ const extractedTags = extractTags(path, settings.tagDelimiter);for (let i = 0; i < tags.length; i += 1) {// check if tag is already in the tag arrayif (extractedTags.indexOf(tags[i].title) < 0) {@@ -136,26 +136,28 @@ const actions = {extractedTags.push(tags[i].title);}}- const newFilePath = containingDirectoryPath + AppConfig.dirSeparator + generateFileName(fileName, extractedTags);+ const newFilePath = containingDirectoryPath + AppConfig.dirSeparator + generateFileName(fileName, extractedTags, settings.tagDelimiter);dispatch(AppActions.renameFile(path, newFilePath));}// dispatch collectRecentTags(tags);},editTagForEntry: (path: string, tag: Tag, newTagTitle: string) => (- dispatch: (actions: Object) => void+ dispatch: (actions: Object) => void,+ getState: () => Object) => {+ const { settings } = getState();// TODO: Handle adding already added tagsif (tag.type === 'plain') {const fileName = extractFileName(path);const containingDirectoryPath = extractContainingDirectoryPath(path);- const extractedTags = extractTags(path);+ const extractedTags = extractTags(path, settings.tagDelimiter);for (let i = 0; i < extractedTags.length; i += 1) {// check if tag is already in the tag arrayif (extractedTags[i] === tag.title) {extractedTags[i] = newTagTitle.trim();}}- const newFileName = generateFileName(fileName, extractedTags);+ const newFileName = generateFileName(fileName, extractedTags, settings.tagDelimiter);if (newFileName !== fileName) {dispatch(AppActions.renameFile(path, containingDirectoryPath + AppConfig.dirSeparator + newFileName));}@@ -197,7 +199,9 @@ const actions = {},removeTagsFromEntry: (path: string, tags: Array<Tag>) => (dispatch: (actions: Object) => void,+ getState: () => Object) => {+ const { settings } = getState();const sidecarTags = [];let tagsInFilenameAvailable = false;tags.map(tag => {@@ -240,7 +244,7 @@ const actions = {if (!tagsInFilenameAvailable) {return;}- const extractedTags = extractTags(path);+ const extractedTags = extractTags(path, settings.tagDelimiter);if (extractedTags.length > 0) {const fileName = extractFileName(path);const containingDirectoryPath = extractContainingDirectoryPath(path);@@ -252,7 +256,7 @@ const actions = {extractedTags.splice(tagLoc, 1);}}- const newFilePath = containingDirectoryPath + AppConfig.dirSeparator + generateFileName(fileName, extractedTags);+ const newFilePath = containingDirectoryPath + AppConfig.dirSeparator + generateFileName(fileName, extractedTags, settings.tagDelimiter);dispatch(AppActions.renameFile(path, newFilePath));}}@@ -267,7 +271,9 @@ const actions = {},removeAllTagsFromEntry: (path: string) => (dispatch: (actions: Object) => void,+ getState: () => Object) => {+ const { settings } = getState();loadMetaDataPromise(path).then(fsEntryMeta => {const updatedFsEntryMeta = {...fsEntryMeta,@@ -291,7 +297,7 @@ const actions = {function removeAllTagsFromFilename() {// Tags in file name case, check is file- const extractedTags = extractTags(path);+ const extractedTags = extractTags(path, settings.tagDelimiter);if (extractedTags.length > 0) {const fileTitle = extractTitle(path);let fileExt = extractFileExtension(path);diff --git a/app/services/search.js b/app/services/search.jsindex 916446074..a9bf75dd8 100644--- a/app/services/search.js+++ b/app/services/search.js@@ -47,7 +47,8 @@ export type SearchQuery = {fileTypes?: Array<string>,tagConjunction?: 'AND' | 'OR',tags?: Array<string>,- lastChanged?: Date+ lastChanged?: Date,+ maxSearchResults?: number};@@ -176,8 +177,8 @@ export default class Search {if (results) {console.log('Results found: ' + results.length);- if (results.length >= AppConfig.maxSearchResult) {- results = results.slice(0, AppConfig.maxSearchResult);+ if (searchQuery.maxSearchResults && results.length >= searchQuery.maxSearchResults) {+ results = results.slice(0, searchQuery.maxSearchResults);}return results;}diff --git a/app/services/utils-io.js b/app/services/utils-io.jsindex 7ab5c3538..a8ebc3f64 100644--- a/app/services/utils-io.js+++ b/app/services/utils-io.js@@ -272,7 +272,7 @@ export async function loadSubFolders(path: string, loadHidden: boolean = false)return subfolders;}-export function generateFileName(fileName: string, tags: Array<string>) {+export function generateFileName(fileName: string, tags: Array<string>, tagDelimiter: string) {let tagsString = '';const prefixTagContainer = AppConfig.prefixTagContainer;// Creating the string will all the tags by more that 0 tags@@ -282,7 +282,7 @@ export function generateFileName(fileName: string, tags: Array<string>) {if (i === tags.length - 1) {tagsString += tags[i].trim();} else {- tagsString += tags[i].trim() + AppConfig.tagDelimiter;+ tagsString += tags[i].trim() + tagDelimiter;}}tagsString = tagsString.trim() + AppConfig.endTagContainer;diff --git a/app/utils/paths.js b/app/utils/paths.jsindex f37b7c46c..95e3344d2 100644--- a/app/utils/paths.js+++ b/app/utils/paths.js@@ -22,7 +22,7 @@ import { type Tag } from '../reducers/taglibrary';export function baseName(dirPath: string) {const fileName = dirPath.substring(dirPath.lastIndexOf(AppConfig.dirSeparator) + 1, dirPath.length);- return fileName ? fileName : dirPath;+ return fileName || dirPath;}export function extractFileExtension(filePath: string) {@@ -177,8 +177,8 @@ export function extractTitle(entryPath: string, isDirectory?: boolean = false) {return title;}-export function extractTagsAsObjects(filePath: string): Array<Tag> {- const tagsInFileName = extractTags(filePath);+export function extractTagsAsObjects(filePath: string, tagDelimiter: string): Array<Tag> {+ const tagsInFileName = extractTags(filePath, tagDelimiter);const tagArray = [];tagsInFileName.map((tag) => {tagArray.push({@@ -190,7 +190,11 @@ export function extractTagsAsObjects(filePath: string): Array<Tag> {return tagArray;}-export function extractTags(filePath: string) {+export function extractTags(filePath: string, tagDelimiter: string) {+ if (tagDelimiter === undefined) { // TODO get tagDelimiter from settings reducer only+ // eslint-disable-next-line no-param-reassign+ tagDelimiter = AppConfig.tagDelimiter;+ }// console.log('Extracting tags from: ' + filePath);const fileName = extractFileName(filePath);// WithoutExt@@ -203,7 +207,7 @@ export function extractTags(filePath: string) {}const cleanedTags = [];const tagContainer = fileName.slice(beginTagContainer + 1, endTagContainer).trim();- tags = tagContainer.split(AppConfig.tagDelimiter);+ tags = tagContainer.split(tagDelimiter);for (let i = 0; i < tags.length; i += 1) {// Min tag length set to 1 characterif (tags[i].trim().length > 0) {