TagSpaces is an offline, open source, document manager with tagging support
TSN678 - Tags from location (#1450)
Stanimirbc25d6d87fc0
diff --git a/app/components/TagLibrary.tsx b/app/components/TagLibrary.tsxindex 8069ebf26..ebe2e68c0 100644--- a/app/components/TagLibrary.tsx+++ b/app/components/TagLibrary.tsx@@ -16,7 +16,7 @@**/-import React, { useCallback, useState } from 'react';+import React, { useCallback, useEffect, useState } from 'react';import { bindActionCreators } from 'redux';import { connect } from 'react-redux';import classNames from 'classnames';@@ -64,6 +64,8 @@ import SmartTags from '../reducers/smart-tags';import { AppConfig } from '-/config';import EditTagDialog from '-/components/dialogs/EditTagDialog';import { TS } from '-/tagspaces.namespace';+import { getLocations } from '-/reducers/locations';+import { Pro } from '-/pro';interface Props {classes: any;@@ -81,7 +83,7 @@ interface Props {sortTagGroup: (uuid: string) => void;collectTagsFromLocation: (tagGroup: TS.TagGroup) => void;addTags: () => void;- importTagGroups: () => void;+ importTagGroups: (entries: Array<TS.TagGroup>, replace?: boolean) => void;exportTagGroups: () => void;createTagGroup: () => void;addTag: () => void;@@ -96,6 +98,8 @@ interface Props {) => void;selectedEntries: Array<TS.FileSystemEntry>;tagGroupCollapsed: Array<string>;+ locations: Array<TS.Location>;+ saveTagInLocation: boolean;}const TagLibrary = (props: Props) => {@@ -136,6 +140,31 @@ const TagLibrary = (props: Props) => {boolean>(false);+ useEffect(() => {+ if (props.saveTagInLocation) {+ refreshTagsFromLocation();+ }+ }, []);++ const refreshTagsFromLocation = () => {+ props.locations.map(location =>+ Pro.MetaOperations.getTagGroups(location.path)+ .then((tagGroups: Array<TS.TagGroup>) => {+ if (tagGroups && tagGroups.length > 0) {+ const newGroups = tagGroups.map(group => ({+ ...group,+ locationId: location.uuid+ }));+ props.importTagGroups(newGroups, false);+ }+ return true;+ })+ .catch(err => {+ console.error(err);+ })+ );+ };+const isTagLibraryReadOnly =window.ExtTagLibrary && window.ExtTagLibrary.length > 0;@@ -207,6 +236,18 @@ const TagLibrary = (props: Props) => {setTagGroupMenuAnchorEl(null);};+ function getLocationName(locationId: string) {+ if (locationId) {+ const location: TS.Location = props.locations.find(+ l => l.uuid === locationId+ );+ if (location) {+ return ' (' + location.name + ')';+ }+ }+ return '';+ }+const renderTagGroup = tagGroup => {// eslint-disable-next-line no-param-reassigntagGroup.expanded = !(@@ -236,7 +277,7 @@ const TagLibrary = (props: Props) => {data-tid="locationTitleElement"noWrap>- {tagGroup.title + ' '}+ {tagGroup.title + getLocationName(tagGroup.locationId)}{!tagGroup.expanded && (<span className={props.classes.badge}>{tagGroup.children.length}@@ -401,6 +442,8 @@ const TagLibrary = (props: Props) => {showCreateTagGroupDialog={showCreateTagGroupDialog}showNotification={showNotification}openURLExternally={props.openURLExternally}+ saveTagInLocation={props.saveTagInLocation}+ refreshTagsFromLocation={refreshTagsFromLocation}/>{Boolean(tagMenuAnchorEl) && (<TagMenu@@ -459,7 +502,9 @@ function mapStateToProps(state) {selectedEntries: getSelectedEntries(state),allTags: getAllTags(state),isReadOnlyMode: isReadOnlyMode(state),- tagGroupCollapsed: state.settings.tagGroupCollapsed+ tagGroupCollapsed: state.settings.tagGroupCollapsed,+ locations: getLocations(state),+ saveTagInLocation: state.settings.saveTagInLocation};}diff --git a/app/components/dialogs/CreateTagGroupDialog.tsx b/app/components/dialogs/CreateTagGroupDialog.tsxindex 7670f01ec..0bcb13f9c 100644--- a/app/components/dialogs/CreateTagGroupDialog.tsx+++ b/app/components/dialogs/CreateTagGroupDialog.tsx@@ -16,7 +16,7 @@**/-import React, { useReducer, useRef, useState } from 'react';+import React, { ChangeEvent, useReducer, useRef, useState } from 'react';import uuidv1 from 'uuid';import Button from '@material-ui/core/Button';import TextField from '@material-ui/core/TextField';@@ -26,12 +26,17 @@ import DialogTitle from '@material-ui/core/DialogTitle';import FormControl from '@material-ui/core/FormControl';import FormHelperText from '@material-ui/core/FormHelperText';import Dialog from '@material-ui/core/Dialog';+import MenuItem from '@material-ui/core/MenuItem';+import Select from '@material-ui/core/Select';+import { connect } from 'react-redux';import IconButton from '@material-ui/core/IconButton';import CloseIcon from '@material-ui/icons/Close';import ColorPickerDialog from './ColorPickerDialog';import i18n from '-/services/i18n';import TransparentBackground from '../TransparentBackground';import { TS } from '-/tagspaces.namespace';+import { getLocations } from '-/reducers/locations';+import { getCurrentLocationId } from '-/reducers/app';interface Props {open: boolean;@@ -40,6 +45,9 @@ interface Props {fullScreen?: boolean;color: string;textcolor: string;+ currentLocationId: string | null;+ locations: Array<TS.Location>;+ saveTagInLocation: boolean;}const CreateTagGroupDialog = (props: Props) => {@@ -53,6 +61,7 @@ const CreateTagGroupDialog = (props: Props) => {const disableConfirmButton = useRef<boolean>(true);const color = useRef<string>(props.color);const textcolor = useRef<string>(props.textcolor);+ const locationId = useRef<string>(props.currentLocationId);// eslint-disable-next-line no-unused-varsconst [ignored, forceUpdate] = useReducer(x => x + 1, 0);@@ -95,6 +104,7 @@ const CreateTagGroupDialog = (props: Props) => {title: title.current,color: color.current,textcolor: textcolor.current,+ locationId: locationId.current,children: []});props.onClose();@@ -183,6 +193,27 @@ const CreateTagGroupDialog = (props: Props) => {</IconButton></DialogTitle><DialogContent>+ {props.saveTagInLocation && (+ <FormControl fullWidth={true} error={inputError}>+ <Select+ defaultValue={locationId.current}+ onChange={(event: ChangeEvent<HTMLInputElement>) => {+ locationId.current = event.target.value;+ // rerender+ forceUpdate();+ }}+ >+ {props.locations.map(location => (+ <MenuItem key={location.uuid} value={location.uuid}>+ {location.name}+ </MenuItem>+ ))}+ </Select>+ <FormHelperText>+ {i18n.t('core:tagGroupLocationHelper')}+ </FormHelperText>+ </FormControl>+ )}<FormControl fullWidth={true} error={inputError}><TextFieldfullWidth={true}@@ -268,4 +299,12 @@ const CreateTagGroupDialog = (props: Props) => {);};-export default CreateTagGroupDialog;+function mapStateToProps(state) {+ return {+ locations: getLocations(state),+ currentLocationId: getCurrentLocationId(state),+ saveTagInLocation: state.settings.saveTagInLocation+ };+}++export default connect(mapStateToProps)(CreateTagGroupDialog);diff --git a/app/components/dialogs/EditTagDialog.tsx b/app/components/dialogs/EditTagDialog.tsxindex cb14455a9..8c7858c55 100644--- a/app/components/dialogs/EditTagDialog.tsx+++ b/app/components/dialogs/EditTagDialog.tsx@@ -16,7 +16,7 @@**/-import React, { useEffect, useState } from 'react';+import React, { useEffect, useRef, useState } from 'react';import Button from '@material-ui/core/Button';import TextField from '@material-ui/core/TextField';import format from 'date-fns/format';@@ -53,7 +53,6 @@ const EditTagDialog = (props: Props) => {const [textcolor, setTextcolor] = useState<string>(props.selectedTag.textcolor);- const [modifiedDate] = useState<string>(props.selectedTag.modified_date);useEffect(() => {handleValidation();@@ -165,7 +164,7 @@ const EditTagDialog = (props: Props) => {error={inputError}style={{ overflow: 'visible' }}>- {modifiedDate && (+ {props.selectedTag.modified_date && (<divclassName="tag-date"style={{@@ -178,7 +177,12 @@ const EditTagDialog = (props: Props) => {<span className="text" style={{ fontWeight: 600 }}>{`${i18n.t('core:modifiedDate')}: `}</span>- <time>{format(new Date(modifiedDate), 'yyyy-mm-dd')}</time>+ <time>+ {format(+ new Date(props.selectedTag.modified_date),+ 'yyyy-mm-dd'+ )}+ </time></div>)}<TextFielddiff --git a/app/components/dialogs/EditTagGroupDialog.tsx b/app/components/dialogs/EditTagGroupDialog.tsxindex 5bdcb54c4..5e5517653 100644--- a/app/components/dialogs/EditTagGroupDialog.tsx+++ b/app/components/dialogs/EditTagGroupDialog.tsx@@ -16,7 +16,7 @@**/-import React, { useEffect, useState } from 'react';+import React, { ChangeEvent, useEffect, useState } from 'react';import Button from '@material-ui/core/Button';import TextField from '@material-ui/core/TextField';import DialogActions from '@material-ui/core/DialogActions';@@ -28,10 +28,15 @@ import Switch from '@material-ui/core/Switch';import Dialog from '@material-ui/core/Dialog';import IconButton from '@material-ui/core/IconButton';import CloseIcon from '@material-ui/icons/Close';+import Select from '@material-ui/core/Select';+import MenuItem from '@material-ui/core/MenuItem';+import { connect } from 'react-redux';import ColorPickerDialog from './ColorPickerDialog';import i18n from '-/services/i18n';import TransparentBackground from '../TransparentBackground';import { TS } from '-/tagspaces.namespace';+import { getLocations } from '-/reducers/locations';+import { Pro } from '-/pro';interface Props {open: boolean;@@ -39,6 +44,8 @@ interface Props {editTagGroup: (tagGroup: TS.TagGroup) => void;selectedTagGroupEntry: TS.TagGroup;onClose: () => void;+ locations: Array<TS.Location>;+ saveTagInLocation: boolean;}const EditTagGroupDialog = (props: Props) => {@@ -48,6 +55,9 @@ const EditTagGroupDialog = (props: Props) => {);const [inputError, setInputError] = useState<boolean>(false);const [applyChanges, setApplyChanges] = useState<boolean>(false);+ const [locationId, setLocationId] = useState<string>(+ props.selectedTagGroupEntry.locationId+ );const [title, setTitle] = useState<string>(props.selectedTagGroupEntry.title);const [color, setColor] = useState<string>(props.selectedTagGroupEntry.color);const [textcolor, setTextcolor] = useState<string>(@@ -86,11 +96,23 @@ const EditTagGroupDialog = (props: Props) => {}if (selectedTagGroupEntry && selectedTagGroupEntry.children) {+ if (Pro && locationId !== selectedTagGroupEntry.locationId) {+ const location: TS.Location = props.locations.find(+ l => l.uuid === selectedTagGroupEntry.locationId+ );+ if (location) {+ Pro.MetaOperations.removeTagGroup(+ location.path,+ selectedTagGroupEntry.uuid+ );+ }+ }props.editTagGroup({...selectedTagGroupEntry,title,color,textcolor,+ locationId,children: selectedTagGroupEntry.children.map(tag => ({...tag,color: applyChanges ? color : tag.color,@@ -150,6 +172,25 @@ const EditTagGroupDialog = (props: Props) => {return (<DialogContent style={{ overflow: 'visible' }}>+ {props.saveTagInLocation && (+ <FormControl fullWidth={true} error={inputError}>+ <Select+ defaultValue={locationId}+ onChange={(event: ChangeEvent<HTMLInputElement>) => {+ setLocationId(event.target.value);+ }}+ >+ {props.locations.map(location => (+ <MenuItem key={location.uuid} value={location.uuid}>+ {location.name}+ </MenuItem>+ ))}+ </Select>+ <FormHelperText>+ {i18n.t('core:tagGroupLocationHelper')}+ </FormHelperText>+ </FormControl>+ )}<FormControlfullWidth={true}error={inputError}@@ -270,4 +311,11 @@ const EditTagGroupDialog = (props: Props) => {);};-export default EditTagGroupDialog;+function mapStateToProps(state) {+ return {+ locations: getLocations(state),+ saveTagInLocation: state.settings.saveTagInLocation+ };+}++export default connect(mapStateToProps)(EditTagGroupDialog);diff --git a/app/components/dialogs/settings/SettingsAdvanced.tsx b/app/components/dialogs/settings/SettingsAdvanced.tsxindex 5b106e54b..039ffdaf8 100644--- a/app/components/dialogs/settings/SettingsAdvanced.tsx+++ b/app/components/dialogs/settings/SettingsAdvanced.tsx@@ -40,6 +40,7 @@ import {} from '-/reducers/settings';import { TS } from '-/tagspaces.namespace';import MapTileServerDialog from '-/components/dialogs/settings/MapTileServerDialog';+import { Pro } from '-/pro';const styles: any = {root: {@@ -62,6 +63,7 @@ interface Props {classes: any;settings: any;setDesktopMode: (desktopMode: boolean) => void;+ setSaveTagInLocation: (saveTagInLocation: boolean) => void;showResetSettings: (showDialog: boolean) => void;tileServers: Array<TS.MapTileServer>;}@@ -113,6 +115,17 @@ const SettingsAdvanced = (props: Props) => {checked={!props.settings.desktopMode}/></ListItem>+ <ListItem className={classes.listItem}>+ <ListItemText primary="Enable Location TagGroups" />+ <Switch+ data-tid="saveTagInLocationTID"+ disabled={!Pro}+ onClick={() =>+ props.setSaveTagInLocation(!props.settings.saveTagInLocation)+ }+ checked={props.settings.saveTagInLocation}+ />+ </ListItem><ListItem className={classes.listItem}><ListItemText primary={i18n.t('core:tileServerTitle')} /><ListItemSecondaryAction>@@ -213,7 +226,10 @@ function mapStateToProps(state) {function mapActionCreatorsToProps(dispatch) {return bindActionCreators(- { setDesktopMode: SettingsActions.setDesktopMode },+ {+ setDesktopMode: SettingsActions.setDesktopMode,+ setSaveTagInLocation: SettingsActions.setSaveTagInLocation+ },dispatch);}diff --git a/app/components/menus/TagLibraryMenu.tsx b/app/components/menus/TagLibraryMenu.tsxindex 8cda8a2f9..964bc7d4b 100644--- a/app/components/menus/TagLibraryMenu.tsx+++ b/app/components/menus/TagLibraryMenu.tsx@@ -27,6 +27,7 @@ import AddIcon from '@material-ui/icons/Add';import ImportExportTagGroupsDialog from '../dialogs/ImportExportTagGroupsDialog';import i18n from '-/services/i18n';import AppConfig from '-/config';+import { TS } from '-/tagspaces.namespace';interface Props {classes?: any;@@ -35,7 +36,7 @@ interface Props {openURLExternally: (path: string, skipConfirmation?: boolean) => void;open: boolean;onClose: () => void;- importTagGroups: () => void;+ importTagGroups: (entries: Array<TS.TagGroup>, replace?: boolean) => void;exportTagGroups: () => void;showCreateTagGroupDialog: () => void;showNotification: (@@ -43,6 +44,8 @@ interface Props {notificationType?: string, // NotificationTypesautohide?: boolean) => void;+ saveTagInLocation: boolean;+ refreshTagsFromLocation: () => void;}const TagLibraryMenu = (props: Props) => {@@ -125,6 +128,20 @@ const TagLibraryMenu = (props: Props) => {</ListItemIcon><ListItemText primary={i18n.t('core:createTagGroupTitle')} /></MenuItem>+ {props.saveTagInLocation && (+ <MenuItem+ data-tid="refreshTagGroups"+ onClick={() => {+ props.refreshTagsFromLocation();+ props.onClose();+ }}+ >+ <ListItemIcon>+ <ImportExportIcon />+ </ListItemIcon>+ <ListItemText primary={i18n.t('core:refreshTagGroups')} />+ </MenuItem>+ )}<MenuItem data-tid="importTagGroup" onClick={handleImportTagGroup}><ListItemIcon><ImportExportIcon />diff --git a/app/config.ts b/app/config.tsindex dc7333077..b135d9f56 100644--- a/app/config.ts+++ b/app/config.ts@@ -27,6 +27,7 @@ export const AppConfig = {tagspacesAppPath: '/tagspaces/',metaFolder: '.ts',metaFolderFile: 'tsm.json',+ folderLocationsFile: 'tsl.json',folderIndexFile: 'tsi.json',folderThumbFile: 'tst.jpg',metaFileExt: '.json',diff --git a/app/locales/en/core.json b/app/locales/en/core.jsonindex 6a43fa0be..cfa793e2d 100644--- a/app/locales/en/core.json+++ b/app/locales/en/core.json@@ -580,5 +580,6 @@"ignorePatternDialogTitle": "Add Ignore Pattern","ignorePatternRemove": "Remove ignore pattern","pathNotInCurrentLocation": "Ignore pattern path is not in the current location",+ "refreshTagGroups": "Refresh from Locations","-": "-"}diff --git a/app/reducers/settings-default.ts b/app/reducers/settings-default.tsindex 67cc9ab9c..f679f6c84 100644--- a/app/reducers/settings-default.ts+++ b/app/reducers/settings-default.ts@@ -128,6 +128,7 @@ export default {tagDelimiter: ' ',maxSearchResult: 1000,desktopMode,+ saveTagInLocation: false,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>',showUnixHiddenEntries: false,diff --git a/app/reducers/settings.ts b/app/reducers/settings.tsindex d4b1e5677..c9213ae1b 100644--- a/app/reducers/settings.ts+++ b/app/reducers/settings.ts@@ -31,6 +31,7 @@ export const types = {SET_LANGUAGE: 'SETTINGS/SET_LANGUAGE',TOGGLE_SHOWUNIXHIDDENENTRIES: 'SETTINGS/TOGGLE_SHOWUNIXHIDDENENTRIES',SET_DESKTOPMODE: 'SETTINGS/SET_DESKTOPMODE',+ SET_SAVE_TAGS_IN_LOCATION: 'SETTINGS/SET_SAVE_TAGS_IN_LOCATION',SET_TAG_DELIMITER: 'SETTINGS/SET_TAG_DELIMITER',SET_MAX_SEARCH_RESULT: 'SETTINGS/SET_MAX_SEARCH_RESULT',SET_CHECKFORUPDATES: 'SETTINGS/SET_CHECKFORUPDATES',@@ -122,6 +123,9 @@ export default (state: any = defaultSettings, action: any) => {case types.SET_DESKTOPMODE: {return { ...state, desktopMode: action.desktopMode };}+ case types.SET_SAVE_TAGS_IN_LOCATION: {+ return { ...state, saveTagInLocation: action.saveTagInLocation };+ }case types.SET_CHECKFORUPDATES: {return { ...state, checkForUpdates: action.checkForUpdates };}@@ -401,6 +405,10 @@ export const actions = {type: types.SET_DESKTOPMODE,desktopMode}),+ setSaveTagInLocation: (saveTagInLocation: boolean) => ({+ type: types.SET_SAVE_TAGS_IN_LOCATION,+ saveTagInLocation+ }),toggleShowUnixHiddenEntries: () => ({type: types.TOGGLE_SHOWUNIXHIDDENENTRIES}),diff --git a/app/reducers/tagging-actions.ts b/app/reducers/tagging-actions.tsindex d7da36578..0140b6c05 100644--- a/app/reducers/tagging-actions.ts+++ b/app/reducers/tagging-actions.ts@@ -141,8 +141,8 @@ const actions = {color: settings.tagBackgroundColor,textcolor: settings.tagTextColor,children: uniqueTags,- created_date: new Date(),- modified_date: new Date()+ created_date: new Date().getTime(),+ modified_date: new Date().getTime()};dispatch(TagLibraryActions.mergeTagGroup(tagGroup));}@@ -489,8 +489,8 @@ const actions = {color: settings.tagBackgroundColor,textcolor: settings.tagTextColor,children: uniqueTags,- created_date: new Date(),- modified_date: new Date()+ created_date: new Date().getTime(),+ modified_date: new Date().getTime()};dispatch(TagLibraryActions.mergeTagGroup(tagGroup));}@@ -773,7 +773,7 @@ const actions = {const changedTagGroup = {...tagGroup,children: uniqueTags,- modified_date: new Date()+ modified_date: new Date().getTime()};dispatch(TagLibraryActions.mergeTagGroup(changedTagGroup));}diff --git a/app/reducers/taglibrary.ts b/app/reducers/taglibrary.tsindex aecbe0c78..5decb3bce 100644--- a/app/reducers/taglibrary.ts+++ b/app/reducers/taglibrary.ts@@ -17,11 +17,12 @@*/import uuidv1 from 'uuid';import { immutablySwapItems, formatDateTime4Tag, extend } from '-/utils/misc';-import { saveAsTextFile } from '-/services/utils-io';+import { parseNewTags, saveAsTextFile } from '-/services/utils-io';import versionMeta from '../version.json';import defaultTagLibrary from './taglibrary-default';import AppConfig from '../config';import { TS } from '-/tagspaces.namespace';+import { Pro } from '-/pro';export const types = {CREATE_TAGGROUP: 'CREATE_TAGGROUP',@@ -32,10 +33,10 @@ export const types = {REMOVE_TAGGROUP: 'REMOVE_TAGGROUP',UPDATE_TAGGROUP: 'UPDATE_TAGGROUP',// TOGGLE_TAGGROUP: 'TOGGLE_TAGGROUP',+ ADD_TAGS: 'ADD_TAGS',ADD_TAG: 'ADD_TAG',- COPY_TAG: 'COPY_TAG',- REMOVE_TAG: 'REMOVE_TAG',- UPDATE_TAG: 'UPDATE_TAG',+ // REMOVE_TAG: 'REMOVE_TAG',+ // UPDATE_TAG: 'UPDATE_TAG',SORT_TAG_GROUP_UP: 'SORT_TAG_GROUP_UP',MOVE_TAG_GROUP_UP: 'MOVE_TAG_GROUP_UP',MOVE_TAG_GROUP_DOWN: 'MOVE_TAG_GROUP_DOWN',@@ -49,11 +50,7 @@ export default (state: Array<TS.TagGroup> = defaultTagLibrary, action: any) => {return [...state,{- uuid: uuidv1(),- title: action.entry.title,- color: action.entry.color,- textcolor: action.entry.textcolor,- children: [],+ ...action.entry,created_date: new Date(),modified_date: new Date()}@@ -156,57 +153,26 @@ export default (state: Array<TS.TagGroup> = defaultTagLibrary, action: any) => {}return state;}- case types.ADD_TAG: {+ case types.ADD_TAGS: {let indexForEditing = -1;state.forEach((tagGroup, index) => {- if (tagGroup.uuid === action.uuid) {+ if (tagGroup.uuid === action.tagGroup.uuid) {indexForEditing = index;}});-if (indexForEditing >= 0) {- let tags = action.tag- .split(' ')- .join(',')- .split(','); // handle spaces around commas- tags = [...new Set(tags)]; // remove duplicates- tags = tags.filter(tag => tag && tag.length > 0); // zero length tags-- const taggroupTags = state[indexForEditing].children;- taggroupTags.forEach(tag => {- // filter out duplicated tags- tags = tags.filter(e => e !== tag.title);- });return [...state.slice(0, indexForEditing),{...state[indexForEditing],- children: taggroupTags.concat(- tags.map(tagTitle => ({- type:- taggroupTags.length > 0 ? taggroupTags[0].type : 'sidecar',- title: tagTitle.trim(),- functionality: '',- description: '',- icon: '',- color: state[indexForEditing].color- ? state[indexForEditing].color- : action.defaultTagBackgroundColor,- textcolor: state[indexForEditing].textcolor- ? state[indexForEditing].textcolor- : action.defaultTagTextColor,- style: taggroupTags.length > 0 ? taggroupTags[0].style : '',- created_date: new Date(),- modified_date: new Date()- }))- )+ children: action.tags},...state.slice(indexForEditing + 1)];}return state;}- case types.COPY_TAG: {+ case types.ADD_TAG: {let indexForEditing = -1;state.forEach((tagGroup, index) => {if (tagGroup.uuid === action.uuid) {@@ -216,13 +182,13 @@ export default (state: Array<TS.TagGroup> = defaultTagLibrary, action: any) => {if (indexForEditing >= 0) {const taggroupTags = state[indexForEditing].children;- const copyTag = action.tag;- if (!taggroupTags.some(tag => tag.title === copyTag.title)) {+ const newTag = action.tag;+ if (!taggroupTags.some(tag => tag.title === newTag.title)) {return [...state.slice(0, indexForEditing),{...state[indexForEditing],- children: [...taggroupTags, copyTag]+ children: [...taggroupTags, newTag]},...state.slice(indexForEditing + 1)];@@ -230,7 +196,7 @@ export default (state: Array<TS.TagGroup> = defaultTagLibrary, action: any) => {}return state;}- case types.UPDATE_TAG: {+ /* case types.UPDATE_TAG: {let tagIndexForUpdating = -1;let tagGroupIndexForUpdating = -1;state.forEach((tagGroup, index) => {@@ -266,8 +232,8 @@ export default (state: Array<TS.TagGroup> = defaultTagLibrary, action: any) => {];}return state;- }- case types.REMOVE_TAG: {+ } */+ /* case types.REMOVE_TAG: {let tagIndexForRemoving = -1;let tagGroupIndexForEditing = -1;state.forEach((tagGroup, index) => {@@ -299,7 +265,7 @@ export default (state: Array<TS.TagGroup> = defaultTagLibrary, action: any) => {];}return state;- }+ } */case types.MOVE_TAG_GROUP_DOWN: {let indexForUpdating = -1;state.forEach((tagGroup, index) => {@@ -395,8 +361,8 @@ export default (state: Array<TS.TagGroup> = defaultTagLibrary, action: any) => {case types.IMPORT_TAGGROUP: {const arr = action.replace ? [] : [...state];console.log(arr);- if (action.entry[0].key) {- action.entry.forEach((tagGroup, index) => {+ if (action.entries[0] && action.entries[0].key) {+ action.entries.forEach((tagGroup, index) => {// migration of old tag groups 2.9 or less in the new version 3.0-present// @ts-ignoreif (tagGroup.key === state.uuid || tagGroup.key !== state.uuid) {@@ -414,7 +380,7 @@ export default (state: Array<TS.TagGroup> = defaultTagLibrary, action: any) => {}});} else {- action.entry.forEach(tagGroup => {+ action.entries.forEach(tagGroup => {const index = arr.findIndex(obj => obj.uuid === tagGroup.uuid);if (index > -1) {tagGroup.children.forEach(tag => {@@ -425,6 +391,9 @@ export default (state: Array<TS.TagGroup> = defaultTagLibrary, action: any) => {arr[index].children.push(tag);}});+ if (tagGroup.locationId) {+ arr[index].locationId = tagGroup.locationId;+ }} else {arr.push(tagGroup);}@@ -440,87 +409,223 @@ export default (state: Array<TS.TagGroup> = defaultTagLibrary, action: any) => {};export const actions = {- createTagGroup: (entry: TS.TagGroup) => ({+ createTagGroup: (entry: TS.TagGroup) => (+ dispatch: (actions: Object) => void,+ getState: () => any+ ) => {+ if (Pro && entry.locationId) {+ const { locations } = getState();+ const location: TS.Location = locations.find(+ l => l.uuid === entry.locationId+ );+ if (location) {+ Pro.MetaOperations.createTagGroup(location.path, entry);+ }+ }+ dispatch(actions.createTagGroupInt(entry));+ },+ createTagGroupInt: (entry: TS.TagGroup) => ({type: types.CREATE_TAGGROUP,entry}),- editTagGroup: (entry: TS.TagGroup) => ({+ editTagGroup: (entry: TS.TagGroup) => (+ dispatch: (actions: Object) => void,+ getState: () => any+ ) => {+ if (Pro && entry.locationId) {+ const { locations } = getState();+ const location: TS.Location = locations.find(+ l => l.uuid === entry.locationId+ );+ if (location) {+ Pro.MetaOperations.editTagGroup(location.path, entry);+ }+ }+ dispatch(actions.editTagGroupInt(entry));+ },+ editTagGroupInt: (entry: TS.TagGroup) => ({type: types.UPDATE_TAGGROUP,entry}),- removeTagGroup: (parentTagGroupUuid: TS.Uuid) => ({+ removeTagGroup: (parentTagGroupUuid: TS.Uuid) => (+ dispatch: (actions: Object) => void,+ getState: () => any+ ) => {+ const { taglibrary } = getState();+ const tagGroup: TS.TagGroup = taglibrary.find(+ t => t.uuid === parentTagGroupUuid+ );+ if (Pro && tagGroup && tagGroup.locationId) {+ const { locations } = getState();+ const location: TS.Location = locations.find(+ l => l.uuid === tagGroup.locationId+ );+ if (location) {+ Pro.MetaOperations.removeTagGroup(location.path, parentTagGroupUuid);+ }+ }+ dispatch(actions.removeTagGroupInt(parentTagGroupUuid));+ },+ removeTagGroupInt: (parentTagGroupUuid: TS.Uuid) => ({type: types.REMOVE_TAGGROUP,uuid: parentTagGroupUuid}),- addTagGroup: (entry: TS.TagGroup) => ({+ /* addTagGroup: (entry: TS.TagGroup) => ({type: types.ADD_TAGGROUP,entry- }),- mergeTagGroup: (entry: TS.TagGroup) => ({+ }), */+ mergeTagGroup: (entry: TS.TagGroup) => (+ dispatch: (actions: Object) => void,+ getState: () => any+ ) => {+ if (Pro && entry.locationId) {+ const { locations } = getState();+ const location: TS.Location = locations.find(+ l => l.uuid === entry.locationId+ );+ if (location) {+ Pro.MetaOperations.mergeTagGroup(location.path, entry);+ }+ }+ dispatch(actions.mergeTagGroupInt(entry));+ },+ mergeTagGroupInt: (entry: TS.TagGroup) => ({type: types.MERGE_TAGGROUP,entry}),- addTag: (tag: string | Object, parentTagGroupUuid: TS.Uuid) => (+ addTag: (tag: any, parentTagGroupUuid: TS.Uuid) => (dispatch: (actions: Object) => void,getState: () => any) => {- const { settings } = getState();+ const { settings, taglibrary } = getState();const { tagTextColor, tagBackgroundColor } = settings;- // console.log('INSIDE ADD TAG');- // console.log(tag, parentTagGroupUuid);++ const tagGroup: TS.TagGroup = taglibrary.find(+ t => t.uuid === parentTagGroupUuid+ );++ let newTags: Array<TS.Tag>;if (typeof tag === 'object' && tag !== null) {- dispatch(- actions.copyTag(- {- ...tag,- // @ts-ignore- textcolor: tag.textcolor || tagTextColor,- // @ts-ignore- color: tag.color || tagBackgroundColor- },- parentTagGroupUuid- )- );+ if (!tagGroup.children.some(t => t.title === tag.title)) {+ // tag exist+ return;+ }+ const tagObject: TS.Tag = {+ ...tag,+ textcolor: tag.textcolor || tagTextColor,+ color: tag.color || tagBackgroundColor+ };+ newTags = [tagObject];+ dispatch(actions.addTagInt(tagObject, parentTagGroupUuid));} else {- dispatch(- actions.addTagIntern(- // @ts-ignore- tag,- parentTagGroupUuid,- tagTextColor,- tagBackgroundColor- )+ const newTagGroup = {+ ...tagGroup,+ color: tagGroup.color ? tagGroup.color : tagBackgroundColor,+ textcolor: tagGroup.textcolor ? tagGroup.textcolor : tagTextColor+ };+ newTags = parseNewTags(tag, newTagGroup);+ dispatch(actions.addTags(newTags, newTagGroup));+ }++ if (Pro && tagGroup && tagGroup.locationId) {+ const { locations } = getState();+ const location: TS.Location = locations.find(+ l => l.uuid === tagGroup.locationId);+ if (location) {+ tagGroup.children = newTags;+ Pro.MetaOperations.editTagGroup(location.path, tagGroup);+ }}},- addTagIntern: (- tag: string,- parentTagGroupUuid: TS.Uuid,- defaultTagTextColor: string,- defaultTagBackgroundColor: string- ) => ({- type: types.ADD_TAG,- tag,- uuid: parentTagGroupUuid,- defaultTagTextColor,- defaultTagBackgroundColor+ addTags: (tags: Array<TS.Tag>, tagGroup: TS.TagGroup) => ({+ type: types.ADD_TAGS,+ tags,+ tagGroup}),- copyTag: (tag: TS.Tag, parentTagGroupUuid: TS.Uuid) => ({- type: types.COPY_TAG,+ addTagInt: (tag: TS.Tag, parentTagGroupUuid: TS.Uuid) => ({+ type: types.ADD_TAG,tag,uuid: parentTagGroupUuid}),- editTag: (tag: TS.Tag, parentTagGroupUuid: TS.Uuid, origTitle: string) => ({+ editTag: (tag: TS.Tag, parentTagGroupUuid: TS.Uuid, origTitle: string) => (+ dispatch: (actions: Object) => void,+ getState: () => any+ ) => {+ const { taglibrary } = getState();+ const tagGroup: TS.TagGroup = taglibrary.find(+ t => t.uuid === parentTagGroupUuid+ );+ const newTagGroup = {+ ...tagGroup,+ children: tagGroup.children.map(t => {+ if (t.title === origTitle) {+ return tag;+ }+ return t;+ })+ };++ if (Pro && tagGroup && tagGroup.locationId) {+ const { locations } = getState();+ const location: TS.Location = locations.find(+ l => l.uuid === tagGroup.locationId+ );+ if (location) {+ Pro.MetaOperations.editTagGroup(location.path, newTagGroup, true);+ }+ }+ dispatch(actions.editTagGroupInt(newTagGroup));+ },+ /* editTagInt: (+ tag: TS.Tag,+ parentTagGroupUuid: TS.Uuid,+ origTitle: string+ ) => ({type: types.UPDATE_TAG,tag,uuid: parentTagGroupUuid,origTitle- }),- deleteTag: (tagTitle: string, parentTagGroupUuid: TS.Uuid) => ({+ }), */+ deleteTag: (tagTitle: string, parentTagGroupUuid: TS.Uuid) => (+ dispatch: (actions: Object) => void,+ getState: () => any+ ) => {+ const { taglibrary } = getState();++ const tagGroup: TS.TagGroup = taglibrary.find(+ t => t.uuid === parentTagGroupUuid+ );++ const tagIndexForRemoving = tagGroup.children.findIndex(+ tag => tag.title === tagTitle+ );+ if (tagIndexForRemoving >= 0) {+ const editedTagGroup = {+ ...tagGroup,+ children: [+ ...tagGroup.children.slice(0, tagIndexForRemoving),+ ...tagGroup.children.slice(tagIndexForRemoving + 1)+ ]+ };++ if (Pro && tagGroup.locationId) {+ const { locations } = getState();+ const location: TS.Location = locations.find(+ l => l.uuid === tagGroup.locationId+ );+ if (location) {+ Pro.MetaOperations.editTagGroup(location.path, editedTagGroup, true);+ }+ }+ dispatch(actions.editTagGroupInt(editedTagGroup));+ }+ },+ /* deleteTagInt: (tagTitle: string, parentTagGroupUuid: TS.Uuid) => ({type: types.REMOVE_TAG,tagTitle,uuid: parentTagGroupUuid- }),+ }), */moveTagGroupUp: (parentTagGroupUuid: TS.Uuid) => ({type: types.MOVE_TAG_GROUP_UP,uuid: parentTagGroupUuid@@ -543,9 +648,9 @@ export const actions = {fromTagGroupId: fromTagGroupUuid,toTagGroupId: toTagGroupUuid}),- importTagGroups: (entry, replace: boolean = false) => ({+ importTagGroups: (entries: Array<TS.TagGroup>, replace: boolean = false) => ({type: types.IMPORT_TAGGROUP,- entry,+ entries,replace}),/**diff --git a/app/services/utils-io.ts b/app/services/utils-io.tsindex e79bd4d01..135e53772 100644--- a/app/services/utils-io.ts+++ b/app/services/utils-io.ts@@ -730,6 +730,60 @@ export function generateFileName(return newFileName;}+export function parseNewTags(tagsInput: string, tagGroup: TS.TagGroup) {+ if (tagGroup) {+ let tags = tagsInput+ .split(' ')+ .join(',')+ .split(','); // handle spaces around commas+ tags = [...new Set(tags)]; // remove duplicates+ tags = tags.filter(tag => tag && tag.length > 0); // zero length tags++ const taggroupTags = tagGroup.children;+ taggroupTags.forEach(tag => {+ // filter out duplicated tags+ tags = tags.filter(t => t !== tag.title);+ });+ return taggroupTags.concat(+ tags.map(tagTitle => {+ const tag: TS.Tag = {+ type: taggroupTags.length > 0 ? taggroupTags[0].type : 'sidecar',+ title: tagTitle.trim(),+ functionality: '',+ description: '',+ icon: '',+ color: tagGroup.color,+ textcolor: tagGroup.textcolor,+ style: taggroupTags.length > 0 ? taggroupTags[0].style : '',+ modified_date: new Date().getTime()+ };+ return tag;+ })+ );+ }+}++export async function loadLocationDataPromise(+ path: string+): Promise<TS.FileSystemEntryMeta> {+ const entryProperties = await PlatformIO.getPropertiesPromise(path);+ if (!entryProperties.isFile) {+ const metaFilePath = getMetaFileLocationForDir(+ path,+ PlatformIO.getDirSeparator(),+ AppConfig.folderLocationsFile+ );+ let metaData;+ try {+ metaData = await loadJSONFile(metaFilePath);+ } catch (e) {+ console.debug('cannot load json:' + metaFilePath, e);+ }+ return metaData;+ }+ return undefined;+}+export async function loadMetaDataPromise(path: string): Promise<TS.FileSystemEntryMeta> {@@ -750,6 +804,7 @@ export async function loadMetaDataPromise(metaData = {};}metaDataObject = {+ ...metaData,description: metaData.description || '',color: metaData.color || '',tags: metaData.tags || [],@@ -772,6 +827,7 @@ export async function loadMetaDataPromise(metaData = {};}metaDataObject = {+ ...metaData,id: metaData.id || uuidv1(),description: metaData.description || '',color: metaData.color || '',@@ -809,6 +865,9 @@ export function cleanMetaData(if (metaData.dirs && metaData.dirs.length > 0) {cleanedMeta.dirs = metaData.dirs;}+ if (metaData.tagGroups && metaData.tagGroups.length > 0) {+ cleanedMeta.tagGroups = metaData.tagGroups;+ }if (metaData.tags && metaData.tags.length > 0) {cleanedMeta.tags = [];metaData.tags.forEach(tag => {@@ -833,6 +892,44 @@ export function cleanMetaData(return cleanedMeta;}+export async function saveLocationDataPromise(+ path: string,+ metaData: any+): Promise<any> {+ const entryProperties = await PlatformIO.getPropertiesPromise(path);+ if (entryProperties) {+ let metaFilePath;+ if (!entryProperties.isFile) {+ // check and create meta folder if not exist+ // todo not need to check if folder exist first createDirectoryPromise() recursively will skip creation of existing folders https://nodejs.org/api/fs.html#fs_fs_mkdir_path_options_callback+ const metaDirectoryPath = getMetaDirectoryPath(+ path,+ PlatformIO.getDirSeparator()+ );+ const metaDirectoryProperties = await PlatformIO.getPropertiesPromise(+ metaDirectoryPath+ );+ if (!metaDirectoryProperties) {+ await PlatformIO.createDirectoryPromise(metaDirectoryPath);+ }++ metaFilePath = getMetaFileLocationForDir(+ path,+ PlatformIO.getDirSeparator(),+ AppConfig.folderLocationsFile+ );+ }+ const content = JSON.stringify({+ ...metaData,+ appName: versionMeta.name,+ appVersion: versionMeta.version,+ lastUpdated: new Date().toJSON()+ });+ return PlatformIO.saveTextFilePromise(metaFilePath, content, true);+ }+ return Promise.reject(new Error('file not found' + path));+}+export async function saveMetaDataPromise(path: string,metaData: anydiff --git a/app/tagspaces.namespace.d.ts b/app/tagspaces.namespace.d.tsindex 695b7abea..14e074c8d 100644--- a/app/tagspaces.namespace.d.ts+++ b/app/tagspaces.namespace.d.ts@@ -78,7 +78,7 @@ export namespace TS {description?: string;style?: string;path?: string; // needed for geo tagging should be removed- modified_date?: string;+ modified_date?: number;functionality?: string;keyBinding?: string;color?: string;@@ -89,6 +89,7 @@ export namespace TS {interface TagGroup {uuid: Uuid;title: string;+ locationId?: Uuid;expanded?: boolean;description?: string;categoryId?: string;@@ -96,6 +97,8 @@ export namespace TS {color?: string;textcolor?: string;children?: Array<Tag>;+ created_date?: number;+ modified_date?: number;}interface FileSystemEntry {@@ -122,6 +125,7 @@ export namespace TS {id?: string;description?: string;tags?: Array<TS.Tag>;+ tagGroups?: Array<TS.TagGroup>;color?: string;perspective?: string;appName: string;diff --git a/app/utils/paths.ts b/app/utils/paths.tsindex 0c2a7038f..745ab31d8 100644--- a/app/utils/paths.ts+++ b/app/utils/paths.ts@@ -143,10 +143,11 @@ export function getThumbFileLocationForDirectory(export function getMetaFileLocationForDir(entryPath: string,- dirSeparator: string // = AppConfig.dirSeparator+ dirSeparator: string, // = AppConfig.dirSeparator+ metaFile: string = AppConfig.metaFolderFile) {const metaFolder = getMetaDirectoryPath(entryPath, dirSeparator);- return metaFolder + dirSeparator + AppConfig.metaFolderFile;+ return metaFolder + dirSeparator + metaFile;}export function extractFileName(