Skip to content

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

fix TSN163 Collect all new tags

Stanimir Marinov4e34170243a6
diff --git a/app/components/settings/SettingsGeneral.js b/app/components/settings/SettingsGeneral.js
index de2c679e0..d32d70fcd 100644
--- a/app/components/settings/SettingsGeneral.js
+++ b/app/components/settings/SettingsGeneral.js
@@ -72,6 +72,7 @@ type Props = {
setCalculateTags: () => void,
setUseTrashCan: () => void,
setPersistTagsInSidecarFile: () => void,
+ setAddTagsToLibrary: () => void,
setUseGenerateThumbnails: () => void
};
@@ -268,6 +269,20 @@ class SettingsGeneral extends React.Component<Props, State> {
/>
</ListItemSecondaryAction>
</ListItem>
+ <ListItem>
+ <ListItemText primary={i18n.t('core:addTagsToLibrary')} />
+ <ListItemSecondaryAction>
+ <Switch
+ data-tid="settingsSetAddTagsToLibrary"
+ onClick={() =>
+ this.props.setAddTagsToLibrary(
+ !this.props.settings.addTagsToLibrary
+ )
+ }
+ checked={this.props.settings.addTagsToLibrary}
+ />
+ </ListItemSecondaryAction>
+ </ListItem>
<ListItem>
<ListItemText primary={i18n.t('core:useGenerateThumbnails')} />
<ListItemSecondaryAction>
diff --git a/app/reducers/settings.js b/app/reducers/settings.js
index 7a51a7b4b..76f3ba773 100644
--- a/app/reducers/settings.js
+++ b/app/reducers/settings.js
@@ -46,6 +46,7 @@ export const types = {
SET_CALCULATETAGS: 'SETTINGS/SET_CALCULATETAGS',
SET_USETRASHCAN: 'SETTINGS/SET_USETRASHCAN',
SET_PERSISTTAGSINSIDECARFILE: 'SETTINGS/SET_PERSISTTAGSINSIDECARFILE',
+ SET_ADDTAGSTOLIBRARY: 'SETTINGS/SET_ADDTAGSTOLIBRARY',
SET_USEGENERATETHUMBNAILS: 'SETTINGS/SET_USEGENERATETHUMBNAILS',
SET_USETEXTEXTRACTION: 'SETTINGS/SET_USETEXTEXTRACTION',
SET_TAGCOLOR: 'SETTINGS/SET_TAGCOLOR',
@@ -134,6 +135,9 @@ export default (state = defaultSettings, action) => {
case types.SET_PERSISTTAGSINSIDECARFILE: {
return { ...state, persistTagsInSidecarFile: action.persistTagsInSidecarFile };
}
+ case types.SET_ADDTAGSTOLIBRARY: {
+ return { ...state, addTagsToLibrary: action.addTagsToLibrary };
+ }
case types.SET_USEGENERATETHUMBNAILS: {
return { ...state, useGenerateThumbnails: action.useGenerateThumbnails };
}
@@ -273,6 +277,10 @@ export const actions = {
type: types.SET_PERSISTTAGSINSIDECARFILE,
persistTagsInSidecarFile
}),
+ setAddTagsToLibrary: (addTagsToLibrary: boolean) => ({
+ type: types.SET_ADDTAGSTOLIBRARY,
+ addTagsToLibrary
+ }),
setUseGenerateThumbnails: (useGenerateThumbnails: boolean) => ({
type: types.SET_USEGENERATETHUMBNAILS,
useGenerateThumbnails
diff --git a/app/reducers/tagging-actions.js b/app/reducers/tagging-actions.js
index b09317e81..dcff1ec97 100644
--- a/app/reducers/tagging-actions.js
+++ b/app/reducers/tagging-actions.js
@@ -18,7 +18,7 @@
*/
import { actions as AppActions } from './app';
-import { type Tag } from './taglibrary';
+import { actions as TagLibraryActions, type Tag } from './taglibrary';
import {
extractFileExtension,
extractFileName,
@@ -41,7 +41,7 @@ const actions = {
paths.map((path) => {
dispatch(actions.addTagsToEntry(path, tags));
return true;
- });
+ });
},
addTagsToEntry: (path: string, tags: Array<Tag>) => (
dispatch: (actions: Object) => void,
@@ -58,6 +58,21 @@ const actions = {
processedTags.push(tag);
return true;
});
+
+ if (settings.addTagsToLibrary) {
+ const tagGroup = {
+ uuid: 'custom_tag_group_id', // uuid needs to be constant here (see mergeTagGroup)
+ title: 'Custom',
+ expanded: true,
+ color: '#00ff00',
+ textcolor: '#000',
+ children: processedTags,
+ created_date: new Date(),
+ modified_date: new Date()
+ };
+ dispatch(TagLibraryActions.mergeTagGroup(tagGroup));
+ }
+
// TODO: Handle adding already added tags
if (settings.persistTagsInSidecarFile) {
// Handling adding tags in sidecar
@@ -331,23 +346,23 @@ const actions = {
function handleSmartTag(smarttagFunction: string) {
switch (smarttagFunction) {
- case 'today':
- message = data.title ? data.title : '';
- if (data.message) {
- message = message + ': ' + data.message;
- }
- this.props.showNotification(message, NotificationTypes.default);
- break;
- default:
- console.log('Not recognized messaging command: ' + msg);
- break;
+ case 'today':
+ message = data.title ? data.title : '';
+ if (data.message) {
+ message = message + ': ' + data.message;
+ }
+ this.props.showNotification(message, NotificationTypes.default);
+ break;
+ default:
+ console.log('Not recognized messaging command: ' + msg);
+ break;
}
}
function generateTagValue(smarttagFunction: string) {
let tagTitle = smarttagFunction;
switch (smarttagFunction) {
- /* case 'geoTagging': {
+ /* case 'geoTagging': {
$('#viewContainers').on('drop dragend', function(event) {
if (TSCORE.PRO && TSCORE.selectedTag === 'geo-tag') {
TSCORE.UI.showTagEditDialog(true); // true start the dialog in add mode
@@ -357,41 +372,41 @@ function generateTagValue(smarttagFunction: string) {
});
break;
} */
- case 'today': {
- tagTitle = formatDateTime4Tag(new Date(), false);
- break;
- }
- case 'tomorrow': {
- const d = new Date();
- d.setDate(d.getDate() + 1);
- tagTitle = formatDateTime4Tag(d, false);
- break;
- }
- case 'yesterday': {
- const d = new Date();
- d.setDate(d.getDate() - 1);
- tagTitle = formatDateTime4Tag(d, false);
- break;
- }
- case 'currentMonth': {
- let cMonth = '' + (new Date().getMonth() + 1);
- if (cMonth.length === 1) {
- cMonth = '0' + cMonth;
- }
- tagTitle = '' + new Date().getFullYear() + cMonth;
- break;
- }
- case 'currentYear': {
- tagTitle = '' + new Date().getFullYear();
- break;
- }
- case 'now': {
- tagTitle = formatDateTime4Tag(new Date(), true);
- break;
- }
- default: {
- break;
+ case 'today': {
+ tagTitle = formatDateTime4Tag(new Date(), false);
+ break;
+ }
+ case 'tomorrow': {
+ const d = new Date();
+ d.setDate(d.getDate() + 1);
+ tagTitle = formatDateTime4Tag(d, false);
+ break;
+ }
+ case 'yesterday': {
+ const d = new Date();
+ d.setDate(d.getDate() - 1);
+ tagTitle = formatDateTime4Tag(d, false);
+ break;
+ }
+ case 'currentMonth': {
+ let cMonth = '' + (new Date().getMonth() + 1);
+ if (cMonth.length === 1) {
+ cMonth = '0' + cMonth;
}
+ tagTitle = '' + new Date().getFullYear() + cMonth;
+ break;
+ }
+ case 'currentYear': {
+ tagTitle = '' + new Date().getFullYear();
+ break;
+ }
+ case 'now': {
+ tagTitle = formatDateTime4Tag(new Date(), true);
+ break;
+ }
+ default: {
+ break;
+ }
}
return tagTitle;
}
diff --git a/app/reducers/taglibrary.js b/app/reducers/taglibrary.js
index ac092e946..0cb541f0f 100644
--- a/app/reducers/taglibrary.js
+++ b/app/reducers/taglibrary.js
@@ -30,6 +30,7 @@ export const types = {
IMPORT_TAGGROUP: 'IMPORT_TAGGROUP',
IMPORT_OLD_TAGGROUP: 'IMPORT_OLD_TAGGROUP',
ADD_TAGGROUP: 'ADD_TAGGROUP',
+ MERGE_TAGGROUP: 'MERGE_TAGGROUP',
REMOVE_TAGGROUP: 'REMOVE_TAGGROUP',
UPDATE_TAGGROUP: 'UPDATE_TAGGROUP',
TOGGLE_TAGGROUP: 'TOGGLE_TAGGROUP',
@@ -107,6 +108,34 @@ export default (state: Array<TagGroup> = defaultTagLibrary, action: Object) => {
}
return state;
}
+ case types.MERGE_TAGGROUP: {
+ const indexForEditing = state.findIndex(obj => obj.uuid === action.entry.uuid);
+ if (indexForEditing >= 0) {
+ return [
+ ...state.slice(0, indexForEditing),
+ {
+ uuid: action.entry.uuid,
+ title: action.entry.title,
+ expanded: action.entry.expanded,
+ children: [...state[indexForEditing].children, ...action.entry.children],
+ created_date: new Date(),
+ modified_date: new Date()
+ },
+ ...state.slice(indexForEditing + 1)
+ ];
+ }
+ return [...state, {
+ uuid: action.entry.uuid || uuidv1(),
+ title: action.entry.title,
+ expanded: action.entry.expanded,
+ color: action.entry.color,
+ textcolor: action.entry.textcolor,
+ children: action.entry.children,
+ created_date: new Date(),
+ modified_date: new Date()
+ }
+ ];
+ }
case types.UPDATE_TAGGROUP: {
let indexForEditing = -1;
state.forEach((tagGroup, index) => {
@@ -367,7 +396,7 @@ export default (state: Array<TagGroup> = defaultTagLibrary, action: Object) => {
if (tagGroup.uuid === state.uuid) {
tagGroup.children.forEach((tag) => {
if (tag.id !== action.id) {
- arr.push(tagGroup[index].children.push(tag))
+ arr.push(tagGroup[index].children.push(tag));
}
});
} else {
@@ -393,6 +422,7 @@ export const actions = {
removeTagGroup: (parentTagGroupUuid: Uuid) => ({ type: types.REMOVE_TAGGROUP, uuid: parentTagGroupUuid }),
toggleTagGroup: (expanded: boolean, parentTagGroupUuid: Uuid) => ({ type: types.TOGGLE_TAGGROUP, expanded, uuid: parentTagGroupUuid }),
addTagGroup: (entry: TagGroup) => ({ type: types.ADD_TAGGROUP, entry }),
+ mergeTagGroup: (entry: TagGroup) => ({ type: types.MERGE_TAGGROUP, entry }),
addTag: (tag: string, parentTagGroupUuid: Uuid) => {
console.log('INSIDE ADD TAG');
console.log(tag, parentTagGroupUuid);