TagSpaces is an offline, open source, document manager with tagging support
Tsn388 added support for saved searches (#1416)
Stanimir1cd84be803b7
diff --git a/app/components/Search.tsx b/app/components/Search.tsxindex 608f492f0..7ba786074 100644--- a/app/components/Search.tsx+++ b/app/components/Search.tsx@@ -21,6 +21,7 @@ import { bindActionCreators } from 'redux';import { connect } from 'react-redux';import { withStyles } from '@material-ui/core/styles';import classNames from 'classnames';+import format from 'date-fns/format';import Typography from '@material-ui/core/Typography';import MenuItem from '@material-ui/core/MenuItem';import Tooltip from '@material-ui/core/Tooltip';@@ -36,7 +37,7 @@ import FileIcon from '@material-ui/icons/InsertDriveFileOutlined';import ClearSearchIcon from '@material-ui/icons/Clear';import BookmarkIcon from '@material-ui/icons/BookmarkBorder';import BookIcon from '@material-ui/icons/LocalLibraryOutlined';-import PlaceIcon from '@material-ui/icons/Place';+// import PlaceIcon from '@material-ui/icons/Place';import DateIcon from '@material-ui/icons/DateRange';import Button from '@material-ui/core/Button';import Input from '@material-ui/core/Input';@@ -52,7 +53,7 @@ import ButtonGroup from '@material-ui/core/ButtonGroup';import ToggleButton from '@material-ui/lab/ToggleButton';import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup';import OpenLocationCode from 'open-location-code-typescript';-import { FormControlLabel, Switch } from '@material-ui/core';+// import { FormControlLabel, Switch } from '@material-ui/core';import TagsSelect from './TagsSelect';import CustomLogo from './CustomLogo';import { actions as AppActions, getDirectoryPath } from '../reducers/app';@@ -72,6 +73,9 @@ import { formatDateTime, extractTimePeriod } from '-/utils/dates';import { isPlusCode, parseLatLon } from '-/utils/misc';import PlatformIO from '../services/platform-io';import { AppConfig } from '-/config';+import { actions as SearchActions, getSearches } from '-/reducers/searches';++const SaveSearchDialog = Pro && Pro.UI ? Pro.UI.SaveSearchDialog : false;interface Props {classes: any;@@ -90,37 +94,76 @@ interface Props {indexedEntriesCount: number;maxSearchResults: number;indexing: boolean;+ searches: Array<SearchQuery>;+ addSearches: (searches: Array<SearchQuery>) => void;}const Search = React.memo((props: Props) => {- const [textQuery, setTextQuery] = useState<string>('');+ const [textQuery, setTextQuery] = useState<string>(+ props.searchQuery.textQuery+ );// const [tagsAND, setTagsAND] = useState<Array<Tag>>(props.searchQuery.tagsAND);// const [tagsOR, setTagsOR] = useState<Array<Tag>>(props.searchQuery.tagsAND);// const [tagsNOT, setTagsNOT] = useState<Array<Tag>>(props.searchQuery.tagsAND);- const [fileTypes, setFileTypes] = useState<Array<string>>(FileTypeGroups.any);+ const [fileTypes, setFileTypes] = useState<Array<string>>(+ props.searchQuery.fileTypes+ ? props.searchQuery.fileTypes+ : FileTypeGroups.any+ );const [searchBoxing, setSearchBoxing] = useState<'location' | 'folder' | 'global'- >('location');+ >(+ props.searchQuery.searchBoxing ? props.searchQuery.searchBoxing : 'location'+ );const [searchType, setSearchType] = useState<'fussy' | 'semistrict' | 'strict'- >('fussy');- const [lastModified, setLastModified] = useState<string>('');+ >(props.searchQuery.searchType ? props.searchQuery.searchType : 'fussy');+ const [lastModified, setLastModified] = useState<string>(+ props.searchQuery.lastModified ? props.searchQuery.lastModified : ''+ );+ const [saveSearchDialogOpened, setSaveSearchDialogOpened] = useState<+ SearchQuery+ >(undefined);const [tagTimePeriod, setTagTimePeriod] = useState<string>('');const [tagTimePeriodHelper, setTagTimePeriodHelper] = useState<string>(' ');const [tagPlace, setTagPlace] = useState<string>(' ');const [tagPlaceHelper, setTagPlaceHelper] = useState<string>(' ');- const [tagTimePeriodFrom, setTagTimePeriodFrom] = useState<Date | null>(null);- const [tagTimePeriodTo, setTagTimePeriodTo] = useState<Date | null>(null);+ const [tagTimePeriodFrom, setTagTimePeriodFrom] = useState<number | null>(+ props.searchQuery.tagTimePeriodFrom+ ? props.searchQuery.tagTimePeriodFrom+ : null+ );+ const [tagTimePeriodTo, setTagTimePeriodTo] = useState<number | null>(+ props.searchQuery.tagTimePeriodTo ? props.searchQuery.tagTimePeriodTo : null+ );const [tagPlaceLat, setTagPlaceLat] = useState<number | null>(null);const [tagPlaceLong, setTagPlaceLong] = useState<number | null>(null);// const [tagPlaceRadius, setTagPlaceRadius] = useState<number>(0);- const [forceIndexing, setForceIndexing] = useState<boolean>(false);- const [fileSize, setFileSize] = useState<string>('');+ const [forceIndexing, setForceIndexing] = useState<boolean>(+ props.searchQuery.forceIndexing ? props.searchQuery.forceIndexing : false+ );+ const [fileSize, setFileSize] = useState<string>(+ props.searchQuery.fileSize ? props.searchQuery.fileSize : ''+ );const [searchMenuAnchorEl,setSearchMenuAnchorEl] = useState<null | HTMLElement>(null);+ const [+ isExportSearchesDialogOpened,+ setExportSearchesDialogOpened+ ] = useState<boolean>(false);++ const ExportSearchesDialog =+ Pro && Pro.UI ? Pro.UI.ExportSearchesDialog : false;++ const fileInputRef = useRef<HTMLInputElement>(null);+ const [importFile, setImportFile] = useState<File>(undefined);++ const ImportSearchesDialog =+ Pro && Pro.UI ? Pro.UI.ImportSearchesDialog : false;+const mainSearchField = useRef<HTMLInputElement>(null);useEffect(() => {@@ -136,18 +179,24 @@ const Search = React.memo((props: Props) => {};}, []);+ function handleFileInputChange(selection: any) {+ const target = selection.currentTarget;+ const file = target.files[0];+ setImportFile(file);+ target.value = null;+ }+const handleFileTypeChange = (event: React.ChangeEvent<HTMLInputElement>) => {const { target } = event;const { value, name } = target;if (name === 'fileTypes') {- // @ts-ignore- setFileTypes(value);+ const types = JSON.parse(value);+ setFileTypes(types);if (searchBoxing !== 'global') {props.searchLocationIndex({...props.searchQuery,- // @ts-ignore- fileTypes: value+ fileTypes: types});}}@@ -185,6 +234,63 @@ const Search = React.memo((props: Props) => {}};+ const handleSavedSearchChange = (+ event: React.ChangeEvent<HTMLInputElement>+ ) => {+ const { target } = event;+ const { value } = target;++ const savedSearch = props.searches.find(search => search.uuid === value);+ setTextQuery(savedSearch.textQuery);+ if (savedSearch.fileTypes && savedSearch.fileTypes !== fileTypes) {+ setFileTypes(savedSearch.fileTypes);+ }+ if (savedSearch.fileSize && savedSearch.fileSize !== fileSize) {+ setFileSize(savedSearch.fileSize);+ }+ if (savedSearch.lastModified && savedSearch.lastModified !== lastModified) {+ setLastModified(savedSearch.lastModified);+ }+ if (savedSearch.searchType && savedSearch.searchType !== searchType) {+ setSearchType(savedSearch.searchType);+ }+ if (savedSearch.searchBoxing && savedSearch.searchBoxing !== searchBoxing) {+ setSearchBoxing(savedSearch.searchBoxing);+ }+ if (+ savedSearch.forceIndexing &&+ savedSearch.forceIndexing !== forceIndexing+ ) {+ setForceIndexing(savedSearch.forceIndexing);+ }+ let ttPeriod;+ if (+ savedSearch.tagTimePeriodFrom &&+ savedSearch.tagTimePeriodFrom !== tagTimePeriodFrom+ ) {+ setTagTimePeriodFrom(savedSearch.tagTimePeriodFrom);+ ttPeriod = format(new Date(savedSearch.tagTimePeriodFrom), 'yyyyMMdd');+ }+ if (+ savedSearch.tagTimePeriodTo &&+ savedSearch.tagTimePeriodTo !== tagTimePeriodTo+ ) {+ setTagTimePeriodTo(savedSearch.tagTimePeriodTo);+ ttPeriod +=+ '-' + format(new Date(savedSearch.tagTimePeriodTo), 'yyyyMMdd');+ }++ if (ttPeriod) {+ setTagTimePeriod(ttPeriod);+ }++ if (savedSearch.searchBoxing === 'global') {+ props.searchAllLocations(savedSearch);+ } else {+ props.searchLocationIndex(savedSearch);+ }+ };+function removeTags(tagsArray, removeTagsArray) {// eslint-disable-next-line react/no-access-state-in-setstatereturn tagsArray.filter(tag =>@@ -250,23 +356,22 @@ const Search = React.memo((props: Props) => {const handleTimePeriodChange = event => {const { target } = event;const { value } = target;- let tagTPeriodHelper = '';const { fromDateTime, toDateTime } = extractTimePeriod(value);if (toDateTime && fromDateTime) {- tagTPeriodHelper =+ const tagTPeriodHelper ='From: ' +formatDateTime(fromDateTime) +' To: ' +formatDateTime(toDateTime);+ setTagTimePeriodFrom(fromDateTime.getTime());+ setTagTimePeriodTo(toDateTime.getTime());+ setTagTimePeriodHelper(tagTPeriodHelper);} else {- tagTPeriodHelper = '';+ setTagTimePeriodHelper('');}setTagTimePeriod(value);- setTagTimePeriodFrom(fromDateTime);- setTagTimePeriodTo(toDateTime);- setTagTimePeriodHelper(tagTPeriodHelper);};const handlePlaceChange = event => {@@ -336,7 +441,7 @@ const Search = React.memo((props: Props) => {const clearSearch = () => {props.setSearchQuery({});openCurrentDirectory();- setTextQuery('');+ setTextQuery(''); // textQuery.current = '';setSearchBoxing('location');setSearchType('fussy');setFileTypes(FileTypeGroups.any);@@ -354,6 +459,31 @@ const Search = React.memo((props: Props) => {setFileSize('');};+ const saveSearch = (isNew: boolean = true) => {+ setSaveSearchDialogOpened({+ uuid: isNew ? undefined : props.searchQuery.uuid,+ title: props.searchQuery.title,+ textQuery, // .current,+ tagsAND: props.searchQuery.tagsAND,+ tagsOR: props.searchQuery.tagsOR,+ tagsNOT: props.searchQuery.tagsNOT,+ // @ts-ignore+ searchBoxing,+ searchType,+ fileTypes,+ lastModified,+ fileSize,+ tagTimePeriodFrom: tagTimePeriodFrom || null,+ tagTimePeriodTo: tagTimePeriodTo || null,+ tagPlaceLat,+ tagPlaceLong,+ // tagPlaceRadius,+ maxSearchResults: props.maxSearchResults,+ currentDirectory: props.currentDirectory,+ forceIndexing+ });+ };+const switchSearchBoxing = (event: React.MouseEvent<HTMLElement>,boxing: 'location' | 'folder' | 'global'@@ -375,7 +505,7 @@ const Search = React.memo((props: Props) => {const executeSearch = () => {const { searchAllLocations, searchLocationIndex } = props;const searchQuery: SearchQuery = {- textQuery,+ textQuery, // .current,tagsAND: props.searchQuery.tagsAND,tagsOR: props.searchQuery.tagsOR,tagsNOT: props.searchQuery.tagsNOT,@@ -385,8 +515,8 @@ const Search = React.memo((props: Props) => {fileTypes,lastModified,fileSize,- tagTimePeriodFrom: tagTimePeriodFrom ? tagTimePeriodFrom.getTime() : null,- tagTimePeriodTo: tagTimePeriodTo ? tagTimePeriodTo.getTime() : null,+ tagTimePeriodFrom: tagTimePeriodFrom || null,+ tagTimePeriodTo: tagTimePeriodTo || null,tagPlaceLat,tagPlaceLong,// tagPlaceRadius,@@ -446,6 +576,12 @@ const Search = React.memo((props: Props) => {onClose={handleCloseSearchMenu}createLocationsIndexes={props.createLocationsIndexes}openURLExternally={props.openURLExternally}+ exportSearches={() => {+ setExportSearchesDialogOpened(true);+ }}+ importSearches={() => {+ fileInputRef.current.click();+ }}/><div className={classes.searchArea}><FormControl@@ -655,33 +791,33 @@ const Search = React.memo((props: Props) => {{i18n.t('core:fileType')}</InputLabel><Select- value={fileTypes}+ value={JSON.stringify(fileTypes)}onChange={handleFileTypeChange}input={<Input name="fileTypes" id="file-type" />}>- <MenuItem value={FileTypeGroups.any}>+ <MenuItem value={JSON.stringify(FileTypeGroups.any)}>{i18n.t('core:anyType')}</MenuItem>- <MenuItem value={FileTypeGroups.folders}>+ <MenuItem value={JSON.stringify(FileTypeGroups.folders)}><IconButton><FolderIcon /></IconButton>{i18n.t('core:searchFolders')}</MenuItem>- <MenuItem value={FileTypeGroups.files}>+ <MenuItem value={JSON.stringify(FileTypeGroups.files)}><IconButton><FileIcon /></IconButton>{i18n.t('core:searchFiles')}</MenuItem>- <MenuItem value={FileTypeGroups.untagged}>+ <MenuItem value={JSON.stringify(FileTypeGroups.untagged)}><IconButton><UntaggedIcon /></IconButton>{i18n.t('core:searchUntaggedEntries')}</MenuItem><MenuItem- value={FileTypeGroups.images}+ value={JSON.stringify(FileTypeGroups.images)}title={FileTypeGroups.images.toString()}><IconButton>@@ -690,7 +826,7 @@ const Search = React.memo((props: Props) => {{i18n.t('core:searchPictures')}</MenuItem><MenuItem- value={FileTypeGroups.documents}+ value={JSON.stringify(FileTypeGroups.documents)}title={FileTypeGroups.documents.toString()}><IconButton>@@ -699,7 +835,7 @@ const Search = React.memo((props: Props) => {{i18n.t('core:searchDocuments')}</MenuItem><MenuItem- value={FileTypeGroups.notes}+ value={JSON.stringify(FileTypeGroups.notes)}title={FileTypeGroups.notes.toString()}><IconButton>@@ -708,7 +844,7 @@ const Search = React.memo((props: Props) => {{i18n.t('core:searchNotes')}</MenuItem><MenuItem- value={FileTypeGroups.audio}+ value={JSON.stringify(FileTypeGroups.audio)}title={FileTypeGroups.audio.toString()}><IconButton>@@ -717,7 +853,7 @@ const Search = React.memo((props: Props) => {{i18n.t('core:searchAudio')}</MenuItem><MenuItem- value={FileTypeGroups.video}+ value={JSON.stringify(FileTypeGroups.video)}title={FileTypeGroups.video.toString()}><IconButton>@@ -726,7 +862,7 @@ const Search = React.memo((props: Props) => {{i18n.t('core:searchVideoFiles')}</MenuItem><MenuItem- value={FileTypeGroups.archives}+ value={JSON.stringify(FileTypeGroups.archives)}title={FileTypeGroups.archives.toString()}><IconButton>@@ -735,7 +871,7 @@ const Search = React.memo((props: Props) => {{i18n.t('core:searchArchives')}</MenuItem><MenuItem- value={FileTypeGroups.bookmarks}+ value={JSON.stringify(FileTypeGroups.bookmarks)}title={FileTypeGroups.bookmarks.toString()}><IconButton>@@ -744,7 +880,7 @@ const Search = React.memo((props: Props) => {{i18n.t('core:searchBookmarks')}</MenuItem><MenuItem- value={FileTypeGroups.ebooks}+ value={JSON.stringify(FileTypeGroups.ebooks)}title={FileTypeGroups.ebooks.toString()}><IconButton>@@ -890,13 +1026,76 @@ const Search = React.memo((props: Props) => {}}/> */}</FormControl>+ <FormControl+ className={classes.formControl}+ disabled={indexing || !Pro}+ title={+ !Pro+ ? i18n.t('core:thisFunctionalityIsAvailableInPro')+ : undefined+ }+ >+ <InputLabel shrink htmlFor="saved-searches">+ {i18n.t('core:savedSearchesTitle')}+ </InputLabel>+ <Select+ onChange={handleSavedSearchChange}+ input={<Input name="savedSearch" id="saved-searches" />}+ displayEmpty+ value={props.searchQuery.uuid ? props.searchQuery.uuid : -1}+ >+ <MenuItem value={-1} style={{ display: 'none' }} />+ {props.searches.map(search => (+ <MenuItem key={search.uuid} value={search.uuid}>+ <span style={{ width: '100%' }}>{search.title}</span>+ {/* <IconButton+ onClick={event =>+ handleSavedSearchEdit(event, search.uuid)+ }+ >+ <FolderIcon />+ </IconButton> */}+ </MenuItem>+ ))}+ </Select>+ </FormControl>+ {Pro && (+ <FormControl className={classes.formControl}>+ <ButtonGroup style={{ justifyContent: 'center' }}>+ <Button+ variant="outlined"+ color="secondary"+ size="medium"+ style={+ props.searchQuery.uuid+ ? { width: '48%' }+ : { width: '100%' }+ }+ onClick={() => saveSearch()}+ >+ {i18n.t('searchSaveBtn')}+ </Button>+ {props.searchQuery.uuid && (+ <Button+ variant="outlined"+ color="secondary"+ size="medium"+ style={{ width: '48%' }}+ onClick={() => saveSearch(false)}+ >+ {i18n.t('searchEditBtn')}+ </Button>+ )}+ </ButtonGroup>+ </FormControl>+ )}<FormControl className={classes.formControl}><ButtonGroup style={{ justifyContent: 'center' }}><Buttonvariant="outlined"color="secondary"size="medium"- style={{ width: '98%' }}+ style={{ width: '100%' }}onClick={clearSearch}id="resetSearchButton">@@ -904,6 +1103,46 @@ const Search = React.memo((props: Props) => {</Button></ButtonGroup></FormControl>+ {SaveSearchDialog && saveSearchDialogOpened !== undefined && (+ <SaveSearchDialog+ open={saveSearchDialogOpened !== undefined}+ onClose={(searchQuery: SearchQuery) => {+ setSaveSearchDialogOpened(undefined);+ if (searchQuery) {+ if (searchQuery.searchBoxing === 'global') {+ props.searchAllLocations(searchQuery);+ } else {+ props.searchLocationIndex(searchQuery);+ }+ }+ }}+ onClearSearch={() => clearSearch()}+ searchQuery={saveSearchDialogOpened}+ />+ )}+ <input+ style={{ display: 'none' }}+ ref={fileInputRef}+ accept="*"+ type="file"+ onChange={handleFileInputChange}+ />+ {ExportSearchesDialog && isExportSearchesDialogOpened && (+ <ExportSearchesDialog+ open={isExportSearchesDialogOpened}+ onClose={() => setExportSearchesDialogOpened(false)}+ searches={props.searches}+ />+ )}+ {ImportSearchesDialog && importFile && (+ <ImportSearchesDialog+ open={Boolean(importFile)}+ onClose={() => setImportFile(undefined)}+ importFile={importFile}+ addSearches={props.addSearches}+ searches={props.searches}+ />+ )}</React.Fragment>)}</div>@@ -917,7 +1156,8 @@ function mapStateToProps(state) {searchQuery: getSearchQuery(state),currentDirectory: getDirectoryPath(state),indexedEntriesCount: getIndexedEntriesCount(state),- maxSearchResults: getMaxSearchResults(state)+ maxSearchResults: getMaxSearchResults(state),+ searches: getSearches(state)};}@@ -930,7 +1170,8 @@ function mapDispatchToProps(dispatch) {createLocationsIndexes: LocationIndexActions.createLocationsIndexes,loadDirectoryContent: AppActions.loadDirectoryContent,openURLExternally: AppActions.openURLExternally,- setSearchResults: AppActions.setSearchResults+ setSearchResults: AppActions.setSearchResults,+ addSearches: SearchActions.addSearches},dispatch);diff --git a/app/components/menus/SearchMenu.tsx b/app/components/menus/SearchMenu.tsxindex 7a52e15f8..3cd97445a 100644--- a/app/components/menus/SearchMenu.tsx+++ b/app/components/menus/SearchMenu.tsx@@ -23,8 +23,10 @@ import Menu from '@material-ui/core/Menu';import MenuItem from '@material-ui/core/MenuItem';import HelpIcon from '@material-ui/icons/Help';import UpdateIndexIcon from '@material-ui/icons/Update';+import ExportImportIcon from '@material-ui/icons/SwapHoriz';import i18n from '-/services/i18n';import AppConfig from '-/config';+import { Pro } from '../../pro';interface Props {classes?: any;@@ -32,6 +34,8 @@ interface Props {anchorEl: Element;onClose: () => void;openURLExternally: (url: string, skipConfirmation?: boolean) => void;+ importSearches: () => void;+ exportSearches: () => void;createLocationsIndexes: () => void;}@@ -48,7 +52,7 @@ const SearchMenu = (props: Props) => (<ListItemIcon><UpdateIndexIcon /></ListItemIcon>- <ListItemText primary={i18n.t('core:Update all location indexes')} />+ <ListItemText primary={i18n.t('core:updateAllLocationIndexes')} /></MenuItem><MenuItemdata-tid="searchMenuHelp"@@ -62,6 +66,34 @@ const SearchMenu = (props: Props) => (</ListItemIcon><ListItemText primary={i18n.t('core:help')} /></MenuItem>+ {Pro && (+ <>+ <MenuItem+ data-tid="exportSavedSearchTID"+ onClick={() => {+ props.onClose();+ props.exportSearches();+ }}+ >+ <ListItemIcon>+ <ExportImportIcon />+ </ListItemIcon>+ <ListItemText primary={i18n.t('core:exportSavedSearch')} />+ </MenuItem>+ <MenuItem+ data-tid="importSavedSearchTID"+ onClick={() => {+ props.onClose();+ props.importSearches();+ }}+ >+ <ListItemIcon>+ <ExportImportIcon />+ </ListItemIcon>+ <ListItemText primary={i18n.t('core:importSavedSearch')} />+ </MenuItem>+ </>+ )}</Menu></div>);diff --git a/app/locales/en/core.json b/app/locales/en/core.jsonindex 6cf3d5c66..da4c163b9 100644--- a/app/locales/en/core.json+++ b/app/locales/en/core.json@@ -537,5 +537,21 @@"maxIndexAgeHelp": "After this time elapses, the search index will be invalidated","chooseTagGroup": "Choose Tag Group","addTagToTagGroup": "Add Tag to Tag Group",+ "updateAllLocationIndexes": "Update all location indexes",+ "exportSavedSearch": "Export Saved Searches",+ "importSavedSearch": "Import Saved Searches",+ "exportSearchesTitle": "Export Searches",+ "selectAllSearches": "Select All Searches",+ "notImportedSearches": "Searches will not be imported",+ "searchExist": "Search already exist, it will be replaced with this one",+ "searchSaveBtn": "Save Search",+ "searchEditBtn": "Edit Search",+ "createNewSavedSearchTitle": "Create New Search",+ "editSavedSearchTitle": "Edit Search",+ "createNewSavedSearchName": "Search Name",+ "savedSearchHelp": "Save the current search parameters for a later use of this search",+ "emptyTitle": "Title cannot be empty!",+ "duplicateTitle": "Search name already exist!",+ "savedSearchesTitle": "Saved Searches","-": "-"}diff --git a/app/reducers/index.ts b/app/reducers/index.tsindex 176b33559..824ea566f 100644--- a/app/reducers/index.ts+++ b/app/reducers/index.ts@@ -24,10 +24,12 @@ import app from './app';import locations from './locations';import taglibrary from './taglibrary';import locationIndex from './location-index';+import searches from './searches';import AppConfig from '-/config';const externalLocations = window.ExtLocations || false;const externalTagLibrary = window.ExtTagLibrary || false;+const externalSearches = window.ExtSearches || false;let locationsInBlackList = false; // electron case@@ -43,7 +45,8 @@ const blacklist = ['app','locationIndex',locationsInBlackList ? 'locations' : '',- externalTagLibrary ? 'taglibrary' : ''+ externalTagLibrary ? 'taglibrary' : '',+ externalSearches ? 'searches' : ''];// const migrations = {@@ -116,6 +119,7 @@ const rootReducer = persistCombineReducers(rootPersistConfig, {app,locations: externalLocations ? () => externalLocations : locations,taglibrary: externalTagLibrary ? () => externalTagLibrary : taglibrary,+ searches: externalSearches ? () => externalSearches : searches,locationIndex});diff --git a/app/reducers/searches.ts b/app/reducers/searches.tsnew file mode 100644index 000000000..70b00e171--- /dev/null+++ b/app/reducers/searches.ts@@ -0,0 +1,143 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License (version 3) as+ * published by the Free Software Foundation.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++import { immutablySwapItems } from '-/utils/misc';+import { SearchQuery } from '-/services/search';+import { Location } from '-/reducers/locations';++export const initialState = [];++export const types = {+ ADD_SEARCH: 'SEARCH/ADD_SEARCH',+ EDIT_SEARCH: 'SEARCH/EDIT_SEARCH',+ MOVE_UP_SEARCH: 'SEARCH/MOVE_UP_SEARCH',+ MOVE_DOWN_SEARCH: 'SEARCH/MOVE_DOWN_SEARCH',+ REMOVE_SEARCH: 'SEARCH/REMOVE_SEARCH'+};++export default (state: Array<SearchQuery> = initialState, action: any) => {+ switch (action.type) {+ case types.ADD_SEARCH: {+ return [+ ...state,+ {+ ...action.search+ // creationDate: new Date().getTime()+ }+ ];+ }+ case types.EDIT_SEARCH: {+ const indexForEditing = state.findIndex(+ search => search.uuid === action.search.uuid+ );++ if (indexForEditing >= 0) {+ return [+ ...state.slice(0, indexForEditing),+ {+ // ...state[indexForEditing],+ ...action.search+ },+ ...state.slice(indexForEditing + 1)+ ];+ }+ return state;+ }+ case types.MOVE_UP_SEARCH: {+ const indexForUpdating = state.findIndex(+ search => search.uuid === action.uuid+ );++ if (indexForUpdating > 0) {+ const secondIndex = indexForUpdating - 1;+ return immutablySwapItems(state, indexForUpdating, secondIndex);+ }+ return state;+ }+ case types.MOVE_DOWN_SEARCH: {+ const indexForUpdating = state.findIndex(+ search => search.uuid === action.uuid+ );++ if (indexForUpdating >= 0 && indexForUpdating < state.length - 1) {+ const secondIndex = indexForUpdating + 1;+ return immutablySwapItems(state, indexForUpdating, secondIndex);+ }+ return state;+ }+ case types.REMOVE_SEARCH: {+ const indexForRemoving = state.findIndex(+ search => search.uuid === action.uuid+ );++ if (indexForRemoving >= 0) {+ return [+ ...state.slice(0, indexForRemoving),+ ...state.slice(indexForRemoving + 1)+ ];+ }+ return state;+ }+ default: {+ return state;+ }+ }+};++export const actions = {+ addSearch: (search: SearchQuery) => ({+ type: types.ADD_SEARCH,+ search+ }),+ addSearches: (arrSearches: Array<SearchQuery>, override: boolean = true) => (+ dispatch: (actions: Object) => void,+ getState: () => any+ ) => {+ arrSearches.forEach((newSearch: SearchQuery) => {+ const { searches } = getState();+ const searchExist: boolean = searches.some(+ location => location.uuid === newSearch.uuid+ );+ if (!searchExist) {+ dispatch(actions.addSearch(newSearch));+ } else if (override) {+ dispatch(actions.editSearch(newSearch));+ }+ });+ },+ moveSearchUp: (uuid: string) => ({ type: types.MOVE_UP_SEARCH, uuid }),+ moveSearchDown: (uuid: string) => ({+ type: types.MOVE_DOWN_SEARCH,+ uuid+ }),+ editSearch: (search: SearchQuery) => ({+ type: types.EDIT_SEARCH,+ search+ }),+ removeSearch: (uuid: string) => ({+ type: types.REMOVE_SEARCH,+ uuid+ })+ /* getSearch: (uuid: string) => (+ dispatch: (actions: Object) => void,+ getState: () => any+ ) => getState().searches.find(search => search.uuid === uuid) */+};++// Selectors+export const getSearches = (state: any): Array<SearchQuery> => state.searches;diff --git a/app/services/search.ts b/app/services/search.tsindex e164a0a86..97b55dc1b 100644--- a/app/services/search.ts+++ b/app/services/search.ts@@ -55,6 +55,9 @@ export const FileTypeGroups = {};export type SearchQuery = {+ uuid?: string; // for saved searches+ title?: string; // for saved searches+ // creationDate?: number; // for saved searches TODO rethink if this needed ?textQuery?: string;fileTypes?: Array<string>;tagsAND?: Array<Tag>;@@ -62,7 +65,7 @@ export type SearchQuery = {tagsNOT?: Array<Tag>;lastModified?: string;fileSize?: string;- searchBoxing?: 'location' | 'folder';+ searchBoxing?: 'location' | 'folder' | 'global';searchType?: 'fussy' | 'semistrict' | 'strict';forceIndexing?: boolean;currentDirectory?: string;diff --git a/app/tagspaces.d.ts b/app/tagspaces.d.tsindex 32fe93f1e..d428b4d84 100644--- a/app/tagspaces.d.ts+++ b/app/tagspaces.d.ts@@ -34,6 +34,7 @@ declare interface Window {ExtDefaultPerspective?: string;ExtTagLibrary?: Array<any>;ExtLocations?: Array<any>;+ ExtSearches?: Array<any>;ExtTheme?: string;ExtIsFirstRun?: boolean;ExtIsAmplify?: boolean;diff --git a/app/utils/dates.ts b/app/utils/dates.tsindex 3cb6b54e1..9bb7c693b 100644--- a/app/utils/dates.ts+++ b/app/utils/dates.ts@@ -126,7 +126,7 @@ export function getDaysInMonth(year: number, month: number): number {export const msInDay = 1000 * 60 * 60 * 24;-/** Extract the time period from string e.g. 201902 -> fromDate: 2019-01-01 00:00:00, toDate; 2019-01-31 23:59:59 */+/** Extract the time period from string e.g. 201901 -> fromDate: 2019-01-01 00:00:00, toDate; 2019-01-31 23:59:59 */export function extractTimePeriod(value: string): { fromDateTime: Date | null; toDateTime: Date | null } {@@ -174,12 +174,6 @@ export function extractTimePeriod(getDaysInMonth(parseInt(toYear, 10), parseInt(toMonth, 10)) +' 23:59:59.999');- } else if (isYearMonthDay(value)) {- const year = value.substring(0, 4);- const month = value.substring(4, 6);- const day = value.substring(6, 8);- fromDateTime = new Date(year + '-' + month + '-' + day);- toDateTime = new Date(year + '-' + month + '-' + day + ' 23:59:59.999');} else if (isYearMonthDayPeriod(value)) {const fromYear = value.substring(0, 4);const fromMonth = value.substring(4, 6);@@ -191,6 +185,12 @@ export function extractTimePeriod(toDateTime = new Date(toYear + '-' + toMonth + '-' + toDay + ' 23:59:59.999');+ } else if (isYearMonthDay(value)) {+ const year = value.substring(0, 4);+ const month = value.substring(4, 6);+ const day = value.substring(6, 8);+ fromDateTime = new Date(year + '-' + month + '-' + day);+ toDateTime = new Date(year + '-' + month + '-' + day + ' 23:59:59.999');} else if (isYearMonthDayHour(value)) {const year = value.substring(0, 4);const month = value.substring(4, 6);diff --git a/scripts/extconfig.js b/scripts/extconfig.jsindex fce94d537..c5fe8fe35 100644--- a/scripts/extconfig.js+++ b/scripts/extconfig.js@@ -9,7 +9,7 @@ window.ExtDarkThemeMainColor = '#3bc8ff';window.ExtIsFirstRun = false;window.ExtLocations = [{- uuid: '30565f09-c7fd-2333-fc67-a75db27rt5ba', // an inique id of the location+ uuid: '30565f09-c7fd-2333-fc67-a75db27rt5ba', // an unique id of the locationtype: '0', // 1 defines the locations a cloud basedname: 'supported-filestypes', // the name of the locationpath: './testdata-tmp/file-structure/supported-filestypes', // the path to sub folder in the location@@ -24,3 +24,23 @@ window.ExtLocations = [watchForChanges: false // activates the watching for changed files in the current location}];+window.ExtSearches = [+ {+ uuid: '16474266-0445-4f47-b092-25b884448d04', // an unique id of the search+ title: 'search by tag 1star', // the name of the search+ tagsAND: [+ {+ id: '6040a658-5e95-44da-acd0-b48d7aade9ce',+ type: 'plain',+ title: '1star',+ color: '#ffcc24',+ textcolor: '#ffffff'+ }+ ], // the tagsAND+ searchBoxing: 'location',+ searchType: 'semistrict',+ fileTypes: ['files'],+ maxSearchResults: 1000,+ forceIndexing: false+ }+];