Skip to content

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

Improvements in the search (#1508)

Stanimir648a00098f5c
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsx
index ddc237610..9ca3382d2 100644
--- a/app/components/FolderContainer.tsx
+++ b/app/components/FolderContainer.tsx
@@ -21,12 +21,14 @@ import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import Button from '@material-ui/core/Button';
import SearchIcon from '@material-ui/icons/Search';
+import AdvancedSearchIcon from '@material-ui/icons/Tune';
import MenuIcon from '@material-ui/icons/MenuOpen';
import Badge from '@material-ui/core/Badge';
import {
Box,
CircularProgress,
IconButton,
+ Popover,
Tooltip,
Typography
} from '@material-ui/core';
@@ -36,7 +38,6 @@ import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup';
import DefaultPerspectiveIcon from '@material-ui/icons/GridOn';
import GalleryPerspectiveIcon from '@material-ui/icons/Camera';
import MapiquePerspectiveIcon from '@material-ui/icons/Map';
-// import KanBanPerspectiveIcon from '@material-ui/icons/Dashboard';
import LocationMenu from './menus/LocationMenu';
import i18n from '../services/i18n';
import { getMaxSearchResults, getDesktopMode } from '-/reducers/settings';
@@ -61,6 +62,9 @@ import RenameEntryDialog from '-/components/dialogs/RenameEntryDialog';
import { TS } from '-/tagspaces.namespace';
import PathBreadcrumbs from './PathBreadcrumbs';
import { enhanceOpenedEntry } from '-/services/utils-io';
+import SearchInline from '-/components/SearchInline';
+import SearchPopover from '-/components/SearchPopover';
+import { getSearchQuery } from '-/reducers/location-index';
const GridPerspective = React.lazy(() =>
import(
@@ -159,11 +163,11 @@ const styles: any = (theme: any) => ({
paddingLeft: 5,
paddingRight: 5,
paddingTop: 5,
- display: 'flex',
- overflowX: AppConfig.isFirefox ? 'auto' : 'overlay'
+ display: 'flex'
+ // overflowX: AppConfig.isFirefox ? 'auto' : 'overlay'
},
topPanel: {
- height: 50,
+ // height: 50,
width: '100%',
backgroundColor: theme.palette.background.default
},
@@ -239,6 +243,7 @@ interface Props {
selectedEntries: Array<TS.FileSystemEntry>;
toggleUploadDialog: () => void;
progress?: Array<any>;
+ searchQuery: TS.SearchQuery;
}
const FolderContainer = (props: Props) => {
@@ -267,9 +272,22 @@ const FolderContainer = (props: Props) => {
}
}, [props.openedFiles]);
+ useEffect(() => {
+ if (!props.searchQuery || Object.keys(props.searchQuery).length === 0) {
+ setSearchVisible(false);
+ } else {
+ setSearchVisible(true);
+ }
+ }, [props.searchQuery]);
+
const [isRenameEntryDialogOpened, setIsRenameEntryDialogOpened] = useState<
boolean
>(false);
+ const [isSearchVisible, setSearchVisible] = useState<boolean>(false);
+ // const [advancedSearch, setAdvancedSearch] = useState<boolean>(false);
+ const [anchorSearch, setAnchorSearch] = useState<HTMLButtonElement | null>(
+ null
+ );
const switchPerspective = (perspectiveId: string) => {
props.setCurrentDirectoryPerspective(perspectiveId);
@@ -465,39 +483,80 @@ const FolderContainer = (props: Props) => {
marginLeft: -8,
maxHeight: 40
}}
- onClick={toggleDrawer}
+ size="small"
+ onClick={() => setSearchVisible(!isSearchVisible)}
>
<SearchIcon />
</Button>
- <div className={classes.flexMiddle} />
- {props.progress && props.progress.length > 0 && (
- <IconButton
- id="progressButton"
- title={i18n.t('core:progress')}
- data-tid="uploadProgress"
- onClick={() => props.toggleUploadDialog()}
- // @ts-ignore
- className={[classes.button, classes.upgradeButton].join(' ')}
- >
- <CircularProgressWithLabel value={getProgressValue()} />
- </IconButton>
+ {isSearchVisible ? (
+ <>
+ <SearchInline />
+ <Button
+ id="advancedButton"
+ title={i18n.t('core:advancedSearch')}
+ data-tid="advancedSearch"
+ onClick={(event: React.MouseEvent<HTMLButtonElement>) =>
+ setAnchorSearch(event.currentTarget)
+ }
+ // @ts-ignore
+ className={[classes.button, classes.upgradeButton].join(' ')}
+ >
+ <AdvancedSearchIcon />
+ </Button>
+ <Popover
+ open={Boolean(anchorSearch)}
+ anchorEl={anchorSearch}
+ onClose={() => setAnchorSearch(null)}
+ anchorOrigin={{
+ vertical: 'bottom',
+ horizontal: 'right'
+ }}
+ style={{
+ marginLeft: -8
+ }}
+ transformOrigin={{
+ vertical: 'top',
+ horizontal: 'right'
+ }}
+ >
+ <SearchPopover onClose={() => setAnchorSearch(null)} />
+ </Popover>
+ </>
+ ) : (
+ <>
+ <div className={classes.flexMiddle} />
+ {props.progress && props.progress.length > 0 && (
+ <IconButton
+ id="progressButton"
+ title={i18n.t('core:progress')}
+ data-tid="uploadProgress"
+ onClick={() => props.toggleUploadDialog()}
+ // @ts-ignore
+ className={[classes.button, classes.upgradeButton].join(
+ ' '
+ )}
+ >
+ <CircularProgressWithLabel value={getProgressValue()} />
+ </IconButton>
+ )}
+ <LocationMenu />
+ <PathBreadcrumbs
+ currentDirectoryPath={currentDirectoryPath}
+ currentLocationPath={currentLocationPath}
+ loadDirectoryContent={loadDirectoryContent}
+ switchPerspective={switchPerspective}
+ setSelectedEntries={setSelectedEntries}
+ openDirectory={openDirectory}
+ reflectCreateEntry={reflectCreateEntry}
+ openFsEntry={openFsEntry}
+ isReadOnlyMode={props.isReadOnlyMode}
+ isDesktopMode={isDesktopMode}
+ openRenameDirectoryDialog={() =>
+ setIsRenameEntryDialogOpened(true)
+ }
+ />
+ </>
)}
- <LocationMenu />
- <PathBreadcrumbs
- currentDirectoryPath={currentDirectoryPath}
- currentLocationPath={currentLocationPath}
- loadDirectoryContent={loadDirectoryContent}
- switchPerspective={switchPerspective}
- setSelectedEntries={setSelectedEntries}
- openDirectory={openDirectory}
- reflectCreateEntry={reflectCreateEntry}
- openFsEntry={openFsEntry}
- isReadOnlyMode={props.isReadOnlyMode}
- isDesktopMode={isDesktopMode}
- openRenameDirectoryDialog={() =>
- setIsRenameEntryDialogOpened(true)
- }
- />
</div>
</div>
<div
@@ -579,7 +638,8 @@ function mapStateToProps(state) {
maxSearchResults: getMaxSearchResults(state),
isDesktopMode: getDesktopMode(state),
isReadOnlyMode: isReadOnlyMode(state),
- progress: getProgress(state)
+ progress: getProgress(state),
+ searchQuery: getSearchQuery(state)
};
}
@@ -623,7 +683,8 @@ const areEqual = (prevProp: Props, nextProp: Props) =>
JSON.stringify(prevProp.openedFiles) &&
JSON.stringify(nextProp.theme) === JSON.stringify(prevProp.theme) &&
nextProp.windowWidth === prevProp.windowWidth &&
- nextProp.windowHeight === prevProp.windowHeight;
+ nextProp.windowHeight === prevProp.windowHeight &&
+ nextProp.searchQuery === prevProp.searchQuery;
export default connect(
mapStateToProps,
diff --git a/app/components/MobileNavigation.tsx b/app/components/MobileNavigation.tsx
index 6b0281d52..80178d8b5 100644
--- a/app/components/MobileNavigation.tsx
+++ b/app/components/MobileNavigation.tsx
@@ -45,7 +45,6 @@ import ProTeaser from '../assets/images/spacerocket_undraw.svg';
import { Pro } from '-/pro';
import CustomLogo from './CustomLogo';
import TagLibrary from '../components/TagLibrary';
-import Search from '../components/Search';
import LocationManager from '../components/LocationManager';
import HelpFeedbackPanel from '../components/HelpFeedbackPanel';
import i18n from '../services/i18n';
@@ -62,6 +61,7 @@ import {
import LoadingLazy from './LoadingLazy';
import { actions as SettingsActions, isFirstRun } from '../reducers/settings';
import Links from '-/links';
+import StoredSearches from '-/components/StoredSearches';
const styles: any = (theme: any) => ({
selectedButton: {
@@ -206,7 +206,7 @@ const MobileNavigation = (props: Props) => {
<LocationManager reduceHeightBy={180} />
)}
{props.isTagLibraryPanelOpened && <TagLibrary reduceHeightBy={180} />}
- {props.isSearchPanelOpened && <Search />}
+ {props.isSearchPanelOpened && <StoredSearches />}
{props.isHelpFeedbackPanelOpened && (
<HelpFeedbackPanel
reduceHeightBy={180}
diff --git a/app/components/Search.tsx b/app/components/Search.tsx
index da6c11db5..49f5241dc 100644
--- a/app/components/Search.tsx
+++ b/app/components/Search.tsx
@@ -1,4 +1,5 @@
-/**
+/*
+/!**
* TagSpaces - universal file and folder organizer
* Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)
*
@@ -14,7 +15,7 @@
* 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 React, { useEffect, useReducer, useRef, useState } from 'react';
import { bindActionCreators } from 'redux';
@@ -451,11 +452,11 @@ const Search = (props: Props) => {
if (trimmedPart.startsWith(identifier)) {
const tagTitle = trimmedPart.substr(1).trim();
extractedTags.push({ title: tagTitle });
- } /* else if (trimmedPart.startsWith('-')) {
+ } /!* else if (trimmedPart.startsWith('-')) {
// add to searchQuery.tagsNOT
} else if (trimmedPart.startsWith('?')) {
// add to searchQuery.tagsOR
- */ else {
+ *!/ else {
newTextQuery += trimmedPart + ' ';
}
});
@@ -752,7 +753,7 @@ const Search = (props: Props) => {
</ToggleButton>
</ToggleButtonGroup>
</FormControl>
- {/* <FormControlLabel
+ {/!* <FormControlLabel
title={i18n.t('core:enableIndexingBySearch')}
control={
<Switch
@@ -769,7 +770,7 @@ const Search = (props: Props) => {
{i18n.t('forceReindexing')}
</Typography>
}
- /> */}
+ /> *!/}
<br />
<FormControl className={classes.formControl}>
<ButtonGroup style={{ justifyContent: 'center' }}>
@@ -928,7 +929,7 @@ const Search = (props: Props) => {
{i18n.t('core:searchEbooks')}
</MenuItem>
</Select>
- {/* <FormHelperText>{i18n.t('core:searchFileTypes')}</FormHelperText> */}
+ {/!* <FormHelperText>{i18n.t('core:searchFileTypes')}</FormHelperText> *!/}
</ProTooltip>
</FormControl>
<FormControl
@@ -1041,7 +1042,7 @@ const Search = (props: Props) => {
}}
/>
</ProTooltip>
- {/* <TextField
+ {/!* <TextField
id="tagPlace"
label={i18n.t('GPS coordinates or plus code')}
value={tagPlace}
@@ -1062,7 +1063,7 @@ const Search = (props: Props) => {
</InputAdornment>
)
}}
- /> */}
+ /> *!/}
</FormControl>
<FormControl
className={classes.formControl}
@@ -1228,3 +1229,4 @@ export default connect(
mapStateToProps,
mapDispatchToProps
)(withStyles(styles, { withTheme: true })(React.memo(Search, areEqual)));
+*/
diff --git a/app/components/SearchAdvanced.tsx b/app/components/SearchAdvanced.tsx
new file mode 100644
index 000000000..afd55151f
--- /dev/null
+++ b/app/components/SearchAdvanced.tsx
@@ -0,0 +1,1094 @@
+/*
+/!**
+ * 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 React, { useEffect, useReducer, useRef, useState } from 'react';
+import { bindActionCreators } from 'redux';
+import { connect } from 'react-redux';
+import { makeStyles, Theme, 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';
+import PictureIcon from '@material-ui/icons/Panorama';
+import DocumentIcon from '@material-ui/icons/PictureAsPdf';
+import NoteIcon from '@material-ui/icons/Note';
+import AudioIcon from '@material-ui/icons/MusicVideo';
+import VideoIcon from '@material-ui/icons/OndemandVideo';
+import ArchiveIcon from '@material-ui/icons/Archive';
+import FolderIcon from '@material-ui/icons/FolderOpen';
+import UntaggedIcon from '@material-ui/icons/LabelOffOutlined';
+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 DateIcon from '@material-ui/icons/DateRange';
+import Button from '@material-ui/core/Button';
+import Input from '@material-ui/core/Input';
+import OutlinedInput from '@material-ui/core/OutlinedInput';
+import TextField from '@material-ui/core/TextField';
+import InputLabel from '@material-ui/core/InputLabel';
+import InputAdornment from '@material-ui/core/InputAdornment';
+import IconButton from '@material-ui/core/IconButton';
+import Select from '@material-ui/core/Select';
+import FormControl from '@material-ui/core/FormControl';
+import MoreVertIcon from '@material-ui/icons/MoreVert';
+import ButtonGroup from '@material-ui/core/ButtonGroup';
+import ToggleButton from '@material-ui/lab/ToggleButton';
+import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup';
+// import { FormControlLabel, Switch } from '@material-ui/core';
+import TagsSelect from './TagsSelect';
+import { actions as AppActions, getDirectoryPath } from '../reducers/app';
+import {
+ actions as LocationIndexActions,
+ getIndexedEntriesCount,
+ isIndexing,
+ getSearchQuery
+} from '../reducers/location-index';
+import {
+ getMaxSearchResults,
+ getShowUnixHiddenEntries
+} from '-/reducers/settings';
+import { styles, StyleProps } from './SearchInline.css';
+import i18n from '../services/i18n';
+import { FileTypeGroups } from '-/services/search';
+import { Pro } from '../pro';
+import SearchMenu from './menus/SearchMenu';
+import { formatDateTime, extractTimePeriod } from '-/utils/dates';
+import { parseGeoLocation, parseLatLon } from '-/utils/misc';
+import { AppConfig } from '-/config';
+import { actions as SearchActions, getSearches } from '-/reducers/searches';
+import { TS } from '-/tagspaces.namespace';
+import { ProLabel, BetaLabel, ProTooltip } from '-/components/HelperComponents';
+import FormGroup from '@material-ui/core/FormGroup';
+import FormControlLabel from '@material-ui/core/FormControlLabel';
+import ListItem from '@material-ui/core/ListItem';
+import List from '@material-ui/core/List';
+import ListItemText from '@material-ui/core/ListItemText';
+import Switch from '@material-ui/core/Switch';
+
+const SaveSearchDialog = Pro && Pro.UI ? Pro.UI.SaveSearchDialog : false;
+
+type PropsClasses = Record<keyof StyleProps, string>;
+
+interface Props {
+ classes?: PropsClasses;
+ style?: any;
+ theme?: any;
+ searchLocationIndex: (searchQuery: TS.SearchQuery) => void;
+ createLocationsIndexes: () => void;
+ searchAllLocations: (searchQuery: TS.SearchQuery) => void;
+ loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;
+ openURLExternally: (url: string) => void;
+ hideDrawer?: () => void;
+ searchQuery: TS.SearchQuery; // () => any;
+ setSearchResults: (entries: Array<any>) => void;
+ setSearchQuery: (searchQuery: TS.SearchQuery) => void;
+ currentDirectory: string;
+ indexedEntriesCount: number;
+ maxSearchResults: number;
+ indexing: boolean;
+ searches: Array<TS.SearchQuery>;
+ addSearches: (searches: Array<TS.SearchQuery>) => void;
+ showUnixHiddenEntries: boolean;
+ openSearchPanel: () => void;
+}
+
+const useStyles = makeStyles<Theme, StyleProps>(styles);
+
+const SearchAdvanced = (props: Props) => {
+ const classes: PropsClasses = useStyles({} as StyleProps);
+ const [, forceUpdate] = useReducer(x => x + 1, 0);
+ const textQuery = useRef<string>(props.searchQuery.textQuery);
+ // const tagsAND = useRef<Array<TS.Tag>>(props.searchQuery.tagsAND);
+ const fileTypes = useRef<Array<string>>(
+ props.searchQuery.fileTypes
+ ? props.searchQuery.fileTypes
+ : FileTypeGroups.any
+ );
+
+ const searchBoxing = useRef<'location' | 'folder' | 'global'>(
+ props.searchQuery.searchBoxing ? props.searchQuery.searchBoxing : 'location'
+ );
+ const searchType = useRef<'fuzzy' | 'semistrict' | 'strict'>(
+ props.searchQuery.searchType ? props.searchQuery.searchType : 'fuzzy'
+ );
+ const lastModified = useRef<string>(
+ props.searchQuery.lastModified ? props.searchQuery.lastModified : ''
+ );
+ const [saveSearchDialogOpened, setSaveSearchDialogOpened] = useState<
+ TS.SearchQuery
+ >(undefined);
+ const tagTimePeriod = useRef<string>('');
+ const tagTimePeriodHelper = useRef<string>(' ');
+ const [tagPlace, setTagPlace] = useState<string>(' ');
+ const [tagPlaceHelper, setTagPlaceHelper] = useState<string>(' ');
+ const tagTimePeriodFrom = useRef<number | null>(
+ props.searchQuery.tagTimePeriodFrom
+ ? props.searchQuery.tagTimePeriodFrom
+ : null
+ );
+ const tagTimePeriodTo = useRef<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 = useRef<boolean>(
+ props.searchQuery.forceIndexing ? props.searchQuery.forceIndexing : false
+ );
+ const fileSize = useRef<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;
+
+ useEffect(() => {
+ textQuery.current = props.searchQuery.textQuery;
+ /!*if (props.searchQuery.fileTypes) {
+ fileTypes.current = props.searchQuery.fileTypes;
+ }
+ if (props.searchQuery.searchBoxing) {
+ searchBoxing.current = props.searchQuery.searchBoxing;
+ }
+ if (props.searchQuery.searchType) {
+ searchType.current = props.searchQuery.searchType;
+ }
+ if (props.searchQuery.lastModified) {
+ lastModified.current = props.searchQuery.lastModified;
+ }
+ if (props.searchQuery.tagTimePeriodFrom) {
+ tagTimePeriodFrom.current = props.searchQuery.tagTimePeriodFrom;
+ }
+ if (props.searchQuery.tagTimePeriodTo) {
+ tagTimePeriodTo.current = props.searchQuery.tagTimePeriodTo;
+ }
+ if (props.searchQuery.forceIndexing) {
+ forceIndexing.current = props.searchQuery.forceIndexing;
+ }
+ if (props.searchQuery.fileSize) {
+ fileSize.current = props.searchQuery.fileSize;
+ }*!/
+ }, [props.searchQuery]);
+
+ 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') {
+ const types = JSON.parse(value);
+ fileTypes.current = types;
+ if (searchBoxing.current !== 'global') {
+ props.searchLocationIndex({
+ ...props.searchQuery,
+ fileTypes: types,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ }
+ }
+ };
+
+ const handleFileSizeChange = (event: React.ChangeEvent<HTMLInputElement>) => {
+ const { target } = event;
+ const { value, name } = target;
+
+ if (name === 'fileSize') {
+ fileSize.current = value;
+ if (searchBoxing.current !== 'global') {
+ props.searchLocationIndex({
+ ...props.searchQuery,
+ fileSize: value,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ }
+ }
+ };
+
+ const handleLastModifiedChange = (
+ event: React.ChangeEvent<HTMLInputElement>
+ ) => {
+ const { target } = event;
+ const { value, name } = target;
+
+ if (name === 'lastModified') {
+ lastModified.current = value;
+ if (searchBoxing.current !== 'global') {
+ props.searchLocationIndex({
+ ...props.searchQuery,
+ lastModified: value,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ }
+ }
+ };
+
+ const handleSavedSearchChange = (
+ event: React.ChangeEvent<HTMLInputElement>
+ ) => {
+ const { target } = event;
+ const { value } = target;
+
+ const savedSearch = props.searches.find(search => search.uuid === value);
+ if (!savedSearch) {
+ return true;
+ }
+ textQuery.current = savedSearch.textQuery;
+ fileTypes.current = savedSearch.fileTypes;
+ lastModified.current = savedSearch.lastModified;
+ fileSize.current = savedSearch.fileSize;
+ searchType.current = savedSearch.searchType;
+ searchBoxing.current = savedSearch.searchBoxing;
+ forceIndexing.current = savedSearch.forceIndexing;
+
+ let ttPeriod;
+ tagTimePeriodFrom.current = savedSearch.tagTimePeriodFrom;
+ if (savedSearch.tagTimePeriodFrom) {
+ ttPeriod = format(new Date(savedSearch.tagTimePeriodFrom), 'yyyyMMdd');
+ }
+
+ tagTimePeriodTo.current = savedSearch.tagTimePeriodTo;
+ if (savedSearch.tagTimePeriodTo) {
+ ttPeriod +=
+ '-' + format(new Date(savedSearch.tagTimePeriodTo), 'yyyyMMdd');
+ }
+
+ if (ttPeriod) {
+ tagTimePeriod.current = ttPeriod;
+ }
+
+ if (savedSearch.searchBoxing === 'global') {
+ props.searchAllLocations({
+ ...savedSearch,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ } else {
+ props.searchLocationIndex({
+ ...savedSearch,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ }
+ };
+
+ function removeTags(tagsArray, removeTagsArray) {
+ // eslint-disable-next-line react/no-access-state-in-setstate
+ return tagsArray.filter(tag =>
+ removeTagsArray.some(valueTag => valueTag.title !== tag.title)
+ );
+ }
+
+ const handleTagFieldChange = (name, value, reason) => {
+ let searchQuery;
+ if (reason === 'remove-value') {
+ if (name === 'tagsAND') {
+ searchQuery = {
+ ...props.searchQuery,
+ tagsAND: removeTags(props.searchQuery.tagsAND, value)
+ };
+ } else if (name === 'tagsNOT') {
+ searchQuery = {
+ ...props.searchQuery,
+ tagsNOT: removeTags(props.searchQuery.tagsNOT, value)
+ };
+ } else if (name === 'tagsOR') {
+ searchQuery = {
+ ...props.searchQuery,
+ tagsOR: removeTags(props.searchQuery.tagsOR, value)
+ };
+ }
+ if (!haveSearchFilters(searchQuery)) {
+ clearSearch();
+ }
+ } else {
+ // eslint-disable-next-line no-lonely-if
+ if (name === 'tagsAND') {
+ searchQuery = { ...props.searchQuery, tagsAND: value };
+ } else if (name === 'tagsNOT') {
+ searchQuery = { ...props.searchQuery, tagsNOT: value };
+ } else if (name === 'tagsOR') {
+ searchQuery = { ...props.searchQuery, tagsOR: value };
+ }
+ }
+ props.searchLocationIndex({
+ ...searchQuery,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ // if (searchBoxing !== 'global') { // TODO disable automatic search in global mode
+ //
+ // }
+ };
+
+ function haveSearchFilters(searchQuery) {
+ return (
+ searchQuery.textQuery ||
+ (searchQuery.tagsAND !== undefined && searchQuery.tagsAND.length > 0) ||
+ (searchQuery.tagsNOT !== undefined && searchQuery.tagsNOT.length > 0) ||
+ (searchQuery.tagsOR !== undefined && searchQuery.tagsOR.length > 0) ||
+ (searchQuery.fileTypes !== undefined &&
+ searchQuery.fileTypes !== FileTypeGroups.any) ||
+ searchQuery.lastModified ||
+ searchQuery.tagTimePeriodFrom ||
+ searchQuery.tagTimePeriodTo ||
+ searchQuery.tagPlaceLat ||
+ searchQuery.tagPlaceLong ||
+ searchQuery.fileSize
+ );
+ }
+
+ const handleTimePeriodChange = event => {
+ const { target } = event;
+ const { value } = target;
+ const { fromDateTime, toDateTime } = extractTimePeriod(value);
+
+ if (toDateTime && fromDateTime) {
+ const tagTPeriodHelper =
+ 'From: ' +
+ formatDateTime(fromDateTime) +
+ ' To: ' +
+ formatDateTime(toDateTime);
+ tagTimePeriodFrom.current = fromDateTime.getTime();
+ tagTimePeriodTo.current = toDateTime.getTime();
+ tagTimePeriodHelper.current = tagTPeriodHelper;
+ } else {
+ tagTimePeriodFrom.current = null;
+ tagTimePeriodTo.current = null;
+ tagTimePeriodHelper.current = ' ';
+ }
+ tagTimePeriod.current = value;
+ forceUpdate();
+ };
+
+ const handlePlaceChange = event => {
+ const { target } = event;
+ const { value } = target;
+ let lat = null;
+ let lng = null;
+ let tagPHelper;
+
+ const location = parseGeoLocation(value);
+ if (location !== undefined) {
+ ({ lat, lng } = location);
+ } else {
+ const latLon = parseLatLon(value);
+ if (latLon) {
+ ({ lat } = latLon);
+ lng = latLon.lon;
+ }
+ }
+
+ if (lat && lng) {
+ tagPHelper = 'Place at lat: ' + lat + ' long: ' + lng;
+ } else {
+ tagPHelper = '';
+ }
+ setTagPlace(value);
+ setTagPlaceLat(lat);
+ setTagPlaceLong(lng);
+ setTagPlaceHelper(tagPHelper);
+ };
+
+ const mergeWithExtractedTags = (tags: Array<TS.Tag>, identifier: string) => {
+ const extractedTags = parseTextQuery(identifier);
+ if (tags) {
+ if (extractedTags.length > 0) {
+ return getUniqueTags(tags, extractedTags);
+ }
+ return tags;
+ }
+ if (extractedTags.length > 0) {
+ return extractedTags;
+ }
+ return undefined;
+ };
+
+ function getUniqueTags(tags1: Array<TS.Tag>, tags2: Array<TS.Tag>) {
+ const mergedArray = [...tags1, ...tags2];
+ // mergedArray have duplicates, lets remove the duplicates using Set
+ const set = new Set();
+ return mergedArray.filter(tag => {
+ if (!set.has(tag.title)) {
+ set.add(tag.title);
+ return true;
+ }
+ return false;
+ }, set);
+ }
+
+ function escapeRegExp(string) {
+ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
+ }
+
+ const parseTextQuery = (identifier: string) => {
+ const extractedTags = [];
+ if (!textQuery.current) {
+ return extractedTags;
+ }
+ let query = textQuery.current;
+ if (query && query.length > 0) {
+ query = query
+ .trim()
+ .replace(
+ new RegExp(escapeRegExp(identifier) + '\\s+', 'g'),
+ identifier
+ );
+ }
+ const textQueryParts = query.split(' ');
+ let newTextQuery = '';
+ if (textQueryParts) {
+ // && textQueryParts.length > 1) {
+ textQueryParts.forEach(part => {
+ const trimmedPart = part.trim();
+ if (trimmedPart.startsWith(identifier)) {
+ const tagTitle = trimmedPart.substr(1).trim();
+ extractedTags.push({ title: tagTitle });
+ } /!* else if (trimmedPart.startsWith('-')) {
+ // add to searchQuery.tagsNOT
+ } else if (trimmedPart.startsWith('?')) {
+ // add to searchQuery.tagsOR
+ *!/ else {
+ newTextQuery += trimmedPart + ' ';
+ }
+ });
+ }
+ textQuery.current = newTextQuery.trim();
+ return extractedTags;
+ };
+
+ const clickSearchButton = () => {
+ executeSearch();
+ if (props.hideDrawer) {
+ props.hideDrawer();
+ }
+ };
+
+ const startSearch = event => {
+ if (event.key === 'Enter' || event.keyCode === 13) {
+ if (props.hideDrawer) {
+ props.hideDrawer();
+ }
+ executeSearch();
+ }
+ };
+
+ function openCurrentDirectory() {
+ if (props.currentDirectory) {
+ props.loadDirectoryContent(props.currentDirectory, false);
+ } else {
+ props.setSearchResults([]);
+ }
+ }
+
+ const clearSearch = () => {
+ textQuery.current = '';
+ searchBoxing.current = 'location';
+ searchType.current = 'fuzzy';
+ fileTypes.current = FileTypeGroups.any;
+ lastModified.current = '';
+ tagTimePeriod.current = '';
+ tagTimePeriodHelper.current = ' ';
+ setTagPlace(' ');
+ setTagPlaceHelper(' ');
+ tagTimePeriodFrom.current = null;
+ tagTimePeriodTo.current = null;
+ setTagPlaceLat(null);
+ setTagPlaceLong(null);
+ // setTagPlaceRadius(0);
+ forceIndexing.current = false;
+ fileSize.current = '';
+ props.setSearchQuery({});
+ openCurrentDirectory();
+ };
+
+ const saveSearch = (isNew: boolean = true) => {
+ const tagsAND = mergeWithExtractedTags(props.searchQuery.tagsAND, '+');
+ const tagsOR = mergeWithExtractedTags(props.searchQuery.tagsOR, '?');
+ const tagsNOT = mergeWithExtractedTags(props.searchQuery.tagsNOT, '-');
+ setSaveSearchDialogOpened({
+ uuid: isNew ? undefined : props.searchQuery.uuid,
+ title: props.searchQuery.title,
+ textQuery: textQuery.current,
+ tagsAND,
+ tagsOR,
+ tagsNOT,
+ // @ts-ignore
+ searchBoxing: searchBoxing.current,
+ searchType: searchType.current,
+ fileTypes: fileTypes.current,
+ lastModified: lastModified.current,
+ fileSize: fileSize.current,
+ tagTimePeriodFrom: tagTimePeriodFrom.current,
+ tagTimePeriodTo: tagTimePeriodTo.current,
+ tagPlaceLat,
+ tagPlaceLong,
+ // tagPlaceRadius,
+ maxSearchResults: props.maxSearchResults,
+ currentDirectory: props.currentDirectory,
+ forceIndexing: forceIndexing.current
+ });
+ };
+
+ const switchSearchBoxing = (
+ event: React.MouseEvent<HTMLElement>,
+ boxing: 'location' | 'folder' | 'global'
+ ) => {
+ if (boxing !== null) {
+ searchBoxing.current = boxing;
+ forceUpdate();
+ }
+ };
+
+ const switchSearchType = (
+ event: React.MouseEvent<HTMLElement>,
+ type: 'fuzzy' | 'semistrict' | 'strict'
+ ) => {
+ if (type !== null) {
+ searchType.current = type;
+ forceUpdate();
+ }
+ };
+
+ const executeSearch = () => {
+ const { searchAllLocations, searchLocationIndex } = props;
+ const tagsAND = mergeWithExtractedTags(props.searchQuery.tagsAND, '+');
+ const tagsOR = mergeWithExtractedTags(props.searchQuery.tagsOR, '?');
+ const tagsNOT = mergeWithExtractedTags(props.searchQuery.tagsNOT, '-');
+ const searchQuery: TS.SearchQuery = {
+ textQuery: textQuery.current,
+ tagsAND,
+ tagsOR,
+ tagsNOT,
+ // @ts-ignore
+ searchBoxing: searchBoxing.current,
+ searchType: searchType.current,
+ fileTypes: fileTypes.current,
+ lastModified: lastModified.current,
+ fileSize: fileSize.current,
+ tagTimePeriodFrom: tagTimePeriodFrom.current,
+ tagTimePeriodTo: tagTimePeriodTo.current,
+ tagPlaceLat,
+ tagPlaceLong,
+ // tagPlaceRadius,
+ maxSearchResults: props.maxSearchResults,
+ currentDirectory: props.currentDirectory,
+ forceIndexing: forceIndexing.current,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ };
+ console.log('Search object: ' + JSON.stringify(searchQuery));
+ if (searchBoxing.current === 'global') {
+ searchAllLocations(searchQuery);
+ } else {
+ searchLocationIndex(searchQuery);
+ }
+ };
+
+ const handleSearchMenu = (event: any) => {
+ setSearchMenuAnchorEl(event.currentTarget);
+ };
+
+ const handleCloseSearchMenu = () => {
+ setSearchMenuAnchorEl(null);
+ };
+
+ const { indexing, indexedEntriesCount } = props;
+
+ const indexStatus = indexedEntriesCount
+ ? indexedEntriesCount + ' indexed entries'
+ : '';
+ return (
+ <div className={classes.panel} style={props.style}>
+ <div className={classes.searchArea}>
+ <List>
+ <ListItem disabled={indexing}>
+ <ListItemText primary={i18n.t('core:whereToSearch')} />
+ <ToggleButtonGroup
+ onChange={switchSearchBoxing}
+ size="small"
+ exclusive
+ value={searchBoxing.current}
+ >
+ <ToggleButton value="location">
+ <Tooltip arrow title={i18n.t('searchPlaceholder')}>
+ <div>{i18n.t('location')}</div>
+ </Tooltip>
+ </ToggleButton>
+ <ToggleButton value="folder">
+ <Tooltip
+ arrow
+ title={i18n.t('searchCurrentFolderWithSubFolders')}
+ >
+ <div>{i18n.t('folder')}</div>
+ </Tooltip>
+ </ToggleButton>
+ <ToggleButton disabled={!Pro} value="global">
+ <Tooltip arrow title={i18n.t('searchInAllLocationTooltip')}>
+ <div>{i18n.t('globalSearch')}</div>
+ </Tooltip>
+ {Pro ? <BetaLabel /> : <ProLabel />}
+ </ToggleButton>
+ </ToggleButtonGroup>
+ </ListItem>
+ <ListItem disabled={indexing}>
+ <ListItemText primary={i18n.t('core:searchType')} />
+ <ToggleButtonGroup
+ onChange={switchSearchType}
+ size="small"
+ exclusive
+ value={searchType.current}
+ >
+ <ToggleButton value="fuzzy" data-tid="fuzzySearchTID">
+ <Tooltip arrow title={i18n.t('searchTypeFuzzyTooltip')}>
+ <div>{i18n.t('searchTypeFuzzy')}</div>
+ </Tooltip>
+ </ToggleButton>
+ <ToggleButton value="semistrict" data-tid="semiStrictSearchTID">
+ <Tooltip arrow title={i18n.t('searchTypeSemiStrictTooltip')}>
+ <div>{i18n.t('searchTypeSemiStrict')}</div>
+ </Tooltip>
+ </ToggleButton>
+ <ToggleButton value="strict" data-tid="strictSearchTID">
+ <Tooltip arrow title={i18n.t('searchTypeStrictTooltip')}>
+ <div>{i18n.t('searchTypeStrict')}</div>
+ </Tooltip>
+ </ToggleButton>
+ </ToggleButtonGroup>
+ </ListItem>
+ <ListItem disabled={indexing}>
+ <ListItemText primary={i18n.t('core:mustContainTheseTags')} />
+ <TagsSelect
+ placeholderText={i18n.t('core:selectTags')}
+ label={i18n.t('core:mustContainTheseTags')}
+ tags={props.searchQuery.tagsAND}
+ handleChange={handleTagFieldChange}
+ tagSearchType="tagsAND"
+ tagMode="remove"
+ />
+ </ListItem>
+ <ListItem disabled={indexing}>
+ <TagsSelect
+ placeholderText={i18n.t('core:selectTags')}
+ tags={props.searchQuery.tagsOR}
+ label={i18n.t('core:atLeastOneOfTheseTags')}
+ handleChange={handleTagFieldChange}
+ tagSearchType="tagsOR"
+ tagMode="remove"
+ />
+ </ListItem>
+ <ListItem disabled={indexing}>
+ <TagsSelect
+ placeholderText={i18n.t('core:selectTags')}
+ tags={props.searchQuery.tagsNOT}
+ label={i18n.t('core:noneOfTheseTags')}
+ handleChange={handleTagFieldChange}
+ tagSearchType="tagsNOT"
+ tagMode="remove"
+ />
+ </ListItem>
+ {/!* {AppConfig.showAdvancedSearch && (*!/}
+ <ListItem disabled={indexing}>
+ <ListItemText primary={i18n.t('core:fileType')} />
+ <ProTooltip tooltip={i18n.t('filterByTypTooltip')}>
+ <Select
+ style={{ width: '100%' }}
+ value={JSON.stringify(fileTypes.current)}
+ onChange={handleFileTypeChange}
+ input={<Input name="fileTypes" id="file-type" />}
+ >
+ <MenuItem value={JSON.stringify(FileTypeGroups.any)}>
+ {i18n.t('core:anyType')}
+ </MenuItem>
+ <MenuItem value={JSON.stringify(FileTypeGroups.folders)}>
+ <IconButton>
+ <FolderIcon />
+ </IconButton>
+ {i18n.t('core:searchFolders')}
+ </MenuItem>
+ <MenuItem value={JSON.stringify(FileTypeGroups.files)}>
+ <IconButton>
+ <FileIcon />
+ </IconButton>
+ {i18n.t('core:searchFiles')}
+ </MenuItem>
+ <MenuItem value={JSON.stringify(FileTypeGroups.untagged)}>
+ <IconButton>
+ <UntaggedIcon />
+ </IconButton>
+ {i18n.t('core:searchUntaggedEntries')}
+ </MenuItem>
+ <MenuItem
+ value={JSON.stringify(FileTypeGroups.images)}
+ title={FileTypeGroups.images.toString()}
+ >
+ <IconButton>
+ <PictureIcon />
+ </IconButton>
+ {i18n.t('core:searchPictures')}
+ </MenuItem>
+ <MenuItem
+ value={JSON.stringify(FileTypeGroups.documents)}
+ title={FileTypeGroups.documents.toString()}
+ >
+ <IconButton>
+ <DocumentIcon />
+ </IconButton>
+ {i18n.t('core:searchDocuments')}
+ </MenuItem>
+ <MenuItem
+ value={JSON.stringify(FileTypeGroups.notes)}
+ title={FileTypeGroups.notes.toString()}
+ >
+ <IconButton>
+ <NoteIcon />
+ </IconButton>
+ {i18n.t('core:searchNotes')}
+ </MenuItem>
+ <MenuItem
+ value={JSON.stringify(FileTypeGroups.audio)}
+ title={FileTypeGroups.audio.toString()}
+ >
+ <IconButton>
+ <AudioIcon />
+ </IconButton>
+ {i18n.t('core:searchAudio')}
+ </MenuItem>
+ <MenuItem
+ value={JSON.stringify(FileTypeGroups.video)}
+ title={FileTypeGroups.video.toString()}
+ >
+ <IconButton>
+ <VideoIcon />
+ </IconButton>
+ {i18n.t('core:searchVideoFiles')}
+ </MenuItem>
+ <MenuItem
+ value={JSON.stringify(FileTypeGroups.archives)}
+ title={FileTypeGroups.archives.toString()}
+ >
+ <IconButton>
+ <ArchiveIcon />
+ </IconButton>
+ {i18n.t('core:searchArchives')}
+ </MenuItem>
+ <MenuItem
+ value={JSON.stringify(FileTypeGroups.bookmarks)}
+ title={FileTypeGroups.bookmarks.toString()}
+ >
+ <IconButton>
+ <BookmarkIcon />
+ </IconButton>
+ {i18n.t('core:searchBookmarks')}
+ </MenuItem>
+ <MenuItem
+ value={JSON.stringify(FileTypeGroups.ebooks)}
+ title={FileTypeGroups.ebooks.toString()}
+ >
+ <IconButton>
+ <BookIcon />
+ </IconButton>
+ {i18n.t('core:searchEbooks')}
+ </MenuItem>
+ </Select>
+ {/!* <FormHelperText>{i18n.t('core:searchFileTypes')}</FormHelperText> *!/}
+ </ProTooltip>
+ </ListItem>
+ <ListItem disabled={indexing || !Pro}>
+ <ListItemText primary={i18n.t('core:sizeSearchTitle')} />
+ <ProTooltip tooltip={i18n.t('filterBySizeTooltip')}>
+ <Select
+ style={{ width: '100%' }}
+ value={fileSize.current}
+ onChange={handleFileSizeChange}
+ input={<Input name="fileSize" id="file-size" />}
+ displayEmpty
+ >
+ <MenuItem value="">{i18n.t('core:sizeAny')}</MenuItem>
+ <MenuItem value="sizeEmpty">
+ {i18n.t('core:sizeEmpty')}
+ </MenuItem>
+ <MenuItem value="sizeTiny">
+ {i18n.t('core:sizeTiny')}
+ &nbsp;(&lt;&nbsp;10KB)
+ </MenuItem>
+ <MenuItem value="sizeVerySmall">
+ {i18n.t('core:sizeVerySmall')}
+ &nbsp;(&lt;&nbsp;100KB)
+ </MenuItem>
+ <MenuItem value="sizeSmall">
+ {i18n.t('core:sizeSmall')}
+ &nbsp;(&lt;&nbsp;1MB)
+ </MenuItem>
+ <MenuItem value="sizeMedium">
+ {i18n.t('core:sizeMedium')}
+ &nbsp;(&lt;&nbsp;50MB)
+ </MenuItem>
+ <MenuItem value="sizeLarge">
+ {i18n.t('core:sizeLarge')}
+ &nbsp;(&lt;&nbsp;1GB)
+ </MenuItem>
+ <MenuItem value="sizeHuge">
+ {i18n.t('core:sizeHuge')}
+ &nbsp;(&gt;&nbsp;1GB)
+ </MenuItem>
+ </Select>
+ </ProTooltip>
+ </ListItem>
+ <ListItem disabled={indexing || !Pro}>
+ <ListItemText primary={i18n.t('core:lastModifiedSearchTitle')} />
+ <ProTooltip tooltip={i18n.t('filterByLastModifiedDateTooltip')}>
+ <Select
+ value={lastModified.current}
+ style={{ width: '100%' }}
+ onChange={handleLastModifiedChange}
+ input={<Input name="lastModified" id="modification-date" />}
+ displayEmpty
+ >
+ <MenuItem value="">{i18n.t('core:anyTime')}</MenuItem>
+ <MenuItem value="today">{i18n.t('core:today')}</MenuItem>
+ <MenuItem value="yesterday">
+ {i18n.t('core:yesterday')}
+ </MenuItem>
+ <MenuItem value="past7Days">
+ {i18n.t('core:past7Days')}
+ </MenuItem>
+ <MenuItem value="past30Days">
+ {i18n.t('core:past30Days')}
+ </MenuItem>
+ <MenuItem value="past6Months">
+ {i18n.t('core:past6Months')}
+ </MenuItem>
+ <MenuItem value="pastYear">{i18n.t('core:pastYear')}</MenuItem>
+ <MenuItem value="moreThanYear">
+ {i18n.t('core:moreThanYear')}
+ </MenuItem>
+ </Select>
+ </ProTooltip>
+ </ListItem>
+ <ListItem>
+ <ProTooltip tooltip={i18n.t('enterTimePeriodTooltip')}>
+ <TextField
+ id="tagTimePeriod"
+ label={i18n.t('enterTimePeriod')}
+ value={tagTimePeriod.current}
+ disabled={indexing || !Pro}
+ onChange={handleTimePeriodChange}
+ onKeyDown={startSearch}
+ helperText={tagTimePeriodHelper.current}
+ error={tagTimePeriodHelper.current.length < 1}
+ style={{ width: '100%' }}
+ InputProps={{
+ endAdornment: (
+ <InputAdornment
+ position="end"
+ title="201905 for May 2019 / 20190412 for 12th of April 2019 / 20190501~124523 for specific time"
+ >
+ <IconButton>
+ <DateIcon />
+ </IconButton>
+ </InputAdornment>
+ )
+ }}
+ />
+ </ProTooltip>
+ </ListItem>
+ <ListItem disabled={indexing || !Pro}>
+ <ProTooltip tooltip={i18n.t('storedSearchQueriesTooltip')}>
+ <InputLabel shrink htmlFor="saved-searches">
+ {i18n.t('core:savedSearchesTitle')}
+ </InputLabel>
+ <Select
+ style={{ width: '100%' }}
+ 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.length < 1 && (
+ <MenuItem>{i18n.t('noSavedSearches')}</MenuItem>
+ )}
+ {props.searches.map(search => (
+ <MenuItem key={search.uuid} value={search.uuid}>
+ <span style={{ width: '100%' }}>{search.title}</span>
+ </MenuItem>
+ ))}
+ </Select>
+ </ProTooltip>
+ </ListItem>
+ <ListItem disabled={indexing}>
+ <ListItemText primary={i18n.t('core:forceReindex')} />
+ <Switch
+ data-tid="forceReindexTID"
+ onClick={() => {
+ forceIndexing.current = !forceIndexing.current;
+ forceUpdate();
+ }}
+ checked={forceIndexing.current}
+ />
+ </ListItem>
+ {Pro && (
+ <ListItem>
+ <ButtonGroup style={{ justifyContent: 'center' }}>
+ <Button
+ variant="outlined"
+ color="secondary"
+ size="medium"
+ onClick={() => saveSearch()}
+ >
+ {i18n.t('searchSaveBtn')}
+ </Button>
+ {props.searchQuery.uuid && (
+ <Button
+ variant="outlined"
+ color="secondary"
+ size="medium"
+ onClick={() => saveSearch(false)}
+ >
+ {i18n.t('searchEditBtn')}
+ </Button>
+ )}
+ <Button
+ variant="outlined"
+ color="secondary"
+ size="medium"
+ onClick={() => {}}
+ >
+ {i18n.t('helpBtn')}
+ </Button>
+ </ButtonGroup>
+ </ListItem>
+ )}
+ {SaveSearchDialog && saveSearchDialogOpened !== undefined && (
+ <SaveSearchDialog
+ open={saveSearchDialogOpened !== undefined}
+ onClose={(searchQuery: TS.SearchQuery) => {
+ setSaveSearchDialogOpened(undefined);
+ props.openSearchPanel();
+ if (searchQuery) {
+ if (searchQuery.searchBoxing === 'global') {
+ props.searchAllLocations({
+ ...searchQuery,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ } else {
+ props.searchLocationIndex({
+ ...searchQuery,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ }
+ }
+ }}
+ 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}
+ />
+ )}
+ {/!* </>
+ )}*!/}
+ </List>
+ </div>
+ </div>
+ );
+};
+
+function mapStateToProps(state) {
+ return {
+ indexing: isIndexing(state),
+ searchQuery: getSearchQuery(state),
+ currentDirectory: getDirectoryPath(state),
+ indexedEntriesCount: getIndexedEntriesCount(state),
+ maxSearchResults: getMaxSearchResults(state),
+ searches: getSearches(state),
+ showUnixHiddenEntries: getShowUnixHiddenEntries(state)
+ };
+}
+
+function mapDispatchToProps(dispatch) {
+ return bindActionCreators(
+ {
+ searchAllLocations: LocationIndexActions.searchAllLocations,
+ setSearchQuery: LocationIndexActions.setSearchQuery,
+ searchLocationIndex: LocationIndexActions.searchLocationIndex,
+ createLocationsIndexes: LocationIndexActions.createLocationsIndexes,
+ loadDirectoryContent: AppActions.loadDirectoryContent,
+ openURLExternally: AppActions.openURLExternally,
+ setSearchResults: AppActions.setSearchResults,
+ addSearches: SearchActions.addSearches,
+ openSearchPanel: AppActions.openSearchPanel
+ },
+ dispatch
+ );
+}
+
+const areEqual = (prevProp, nextProp) =>
+ nextProp.indexing === prevProp.indexing &&
+ nextProp.searchQuery === prevProp.searchQuery &&
+ nextProp.currentDirectory === prevProp.currentDirectory &&
+ nextProp.indexedEntriesCount === prevProp.indexedEntriesCount &&
+ JSON.stringify(nextProp.searches) === JSON.stringify(prevProp.searches) &&
+ JSON.stringify(nextProp.classes) === JSON.stringify(prevProp.classes);
+
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(React.memo(SearchAdvanced, areEqual));
+*/
diff --git a/app/components/SearchInline.css.tsx b/app/components/SearchInline.css.tsx
new file mode 100644
index 000000000..181e5c107
--- /dev/null
+++ b/app/components/SearchInline.css.tsx
@@ -0,0 +1,125 @@
+/**
+ * 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 { BaseCSSProperties } from '@material-ui/core/styles/withStyles';
+
+export interface StyleProps {
+ panel: BaseCSSProperties;
+ fontIcon: BaseCSSProperties;
+ header: BaseCSSProperties;
+ icon: BaseCSSProperties;
+ locationListArea: BaseCSSProperties;
+ searchArea: BaseCSSProperties;
+ topShadow: BaseCSSProperties;
+ listItem: BaseCSSProperties;
+ listItemSelected: BaseCSSProperties;
+ panelTitle: BaseCSSProperties;
+ nested: BaseCSSProperties;
+ listItemTitleText: BaseCSSProperties;
+ hiddenFileInput: BaseCSSProperties;
+ toolbar: BaseCSSProperties;
+ formControl: BaseCSSProperties;
+ mainActionButton: BaseCSSProperties;
+ leftIcon: BaseCSSProperties;
+}
+
+export const styles = (theme: any) => {
+ const baseStyle: StyleProps = {
+ panel: {
+ height: '100%',
+ paddingLeft: 5,
+ paddingRight: 5
+ },
+ fontIcon: {
+ color: theme.palette.text.primary
+ },
+ header: {
+ color: theme.palette.text.primary
+ },
+ icon: {
+ margin: theme.spacing(1)
+ },
+ locationListArea: {
+ paddingTop: 0,
+ marginTop: 0
+ // @ts-ignore
+ // overflowY: AppConfig.isFirefox ? 'auto' : 'overlay'
+ },
+ searchArea: {
+ paddingTop: 0,
+ paddingLeft: 5,
+ paddingRight: 5,
+ marginTop: 0,
+ height: 'calc(100% - 110px)',
+ maxHeight: 'calc(100% - 110px)',
+ overflowX: 'hidden'
+ // overflowY: AppConfig.isFirefox ? 'auto' : 'overlay'
+ },
+ topShadow: {
+ borderTop: '1px solid lightgray',
+ height: 10,
+ boxShadow: '0px -7px 20px 0px rgba(255, 255, 255, 1)'
+ },
+ listItem: {
+ paddingLeft: 0,
+ paddingTop: 2,
+ paddingBottom: 2,
+ paddingRight: 0,
+ borderRadius: 5,
+ backgroundColor: 'transparent'
+ },
+ listItemSelected: {
+ paddingLeft: 0,
+ paddingRight: 0,
+ paddingTop: 2,
+ paddingBottom: 2,
+ borderRadius: 5,
+ backgroundColor: theme.palette.primary.light
+ },
+ panelTitle: {
+ textTransform: 'uppercase',
+ flex: 1,
+ paddingLeft: 7,
+ paddingTop: 12
+ },
+ nested: {
+ paddingLeft: theme.spacing(4)
+ },
+ listItemTitleText: {
+ fontWeight: 'bold'
+ },
+ hiddenFileInput: {
+ display: 'none'
+ },
+ toolbar: {
+ display: 'flex'
+ },
+ formControl: {
+ width: '100%',
+ marginBottom: 10
+ },
+ mainActionButton: {
+ marginTop: 10,
+ marginLeft: 0,
+ paddingLeft: 8
+ },
+ leftIcon: {
+ marginRight: theme.spacing(1)
+ }
+ };
+ return baseStyle as any;
+};
diff --git a/app/components/SearchInline.tsx b/app/components/SearchInline.tsx
new file mode 100644
index 000000000..0ffeff155
--- /dev/null
+++ b/app/components/SearchInline.tsx
@@ -0,0 +1,350 @@
+/**
+ * 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 React, { useEffect, useReducer, useRef, useState } from 'react';
+import { bindActionCreators } from 'redux';
+import { connect } from 'react-redux';
+import { makeStyles, Theme } from '@material-ui/core/styles';
+import ClearSearchIcon from '@material-ui/icons/Clear';
+import { actions as AppActions, getDirectoryPath } from '../reducers/app';
+import {
+ actions as LocationIndexActions,
+ getIndexedEntriesCount,
+ isIndexing,
+ getSearchQuery
+} from '../reducers/location-index';
+import {
+ getMaxSearchResults,
+ getShowUnixHiddenEntries
+} from '-/reducers/settings';
+import { styles, StyleProps } from './SearchInline.css';
+import i18n from '../services/i18n';
+import { FileTypeGroups } from '-/services/search';
+import { TS } from '-/tagspaces.namespace';
+import {
+ FormControl,
+ IconButton,
+ InputAdornment,
+ TextField,
+ OutlinedInput,
+ ButtonGroup,
+ Button,
+ Grid
+} from '@material-ui/core';
+
+type PropsClasses = Record<keyof StyleProps, string>;
+
+interface Props {
+ style?: any;
+ searchLocationIndex: (searchQuery: TS.SearchQuery) => void;
+ createLocationsIndexes: () => void;
+ searchAllLocations: (searchQuery: TS.SearchQuery) => void;
+ loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;
+ openURLExternally: (url: string) => void;
+ searchQuery: TS.SearchQuery; // () => any;
+ setSearchResults: (entries: Array<any>) => void;
+ setSearchQuery: (searchQuery: TS.SearchQuery) => void;
+ currentDirectory: string;
+ indexedEntriesCount: number;
+ maxSearchResults: number;
+ indexing: boolean;
+ showUnixHiddenEntries: boolean;
+}
+
+const useStyles = makeStyles<Theme, StyleProps>(styles);
+
+const SearchInline = (props: Props) => {
+ const classes: PropsClasses = useStyles({} as StyleProps);
+ const [, forceUpdate] = useReducer(x => x + 1, 0);
+ const textQuery = useRef<string>(props.searchQuery.textQuery);
+ const fileTypes = useRef<Array<string>>(
+ props.searchQuery.fileTypes
+ ? props.searchQuery.fileTypes
+ : FileTypeGroups.any
+ );
+
+ const searchBoxing = useRef<'location' | 'folder' | 'global'>(
+ props.searchQuery.searchBoxing ? props.searchQuery.searchBoxing : 'location'
+ );
+ const searchType = useRef<'fuzzy' | 'semistrict' | 'strict'>(
+ props.searchQuery.searchType ? props.searchQuery.searchType : 'fuzzy'
+ );
+ const lastModified = useRef<string>(
+ props.searchQuery.lastModified ? props.searchQuery.lastModified : ''
+ );
+ const tagTimePeriod = useRef<string>('');
+ const tagTimePeriodHelper = useRef<string>(' ');
+ const tagTimePeriodFrom = useRef<number | null>(
+ props.searchQuery.tagTimePeriodFrom
+ ? props.searchQuery.tagTimePeriodFrom
+ : null
+ );
+ const tagTimePeriodTo = useRef<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 = useRef<boolean>(
+ props.searchQuery.forceIndexing ? props.searchQuery.forceIndexing : false
+ );
+ const fileSize = useRef<string>(
+ props.searchQuery.fileSize ? props.searchQuery.fileSize : ''
+ );
+
+ const mainSearchField = useRef<HTMLInputElement>(null);
+
+ useEffect(() => {
+ // https://github.com/mui-org/material-ui/issues/1594
+ const timeout = setTimeout(() => {
+ if (mainSearchField && mainSearchField.current) {
+ mainSearchField.current.focus();
+ }
+ }, 100);
+
+ return () => {
+ clearTimeout(timeout);
+ };
+ }, []);
+
+ useEffect(() => {
+ textQuery.current = props.searchQuery.textQuery;
+ }, [props.searchQuery]);
+
+ const mergeWithExtractedTags = (tags: Array<TS.Tag>, identifier: string) => {
+ const extractedTags = parseTextQuery(identifier);
+ if (tags) {
+ if (extractedTags.length > 0) {
+ return getUniqueTags(tags, extractedTags);
+ }
+ return tags;
+ }
+ if (extractedTags.length > 0) {
+ return extractedTags;
+ }
+ return undefined;
+ };
+
+ function getUniqueTags(tags1: Array<TS.Tag>, tags2: Array<TS.Tag>) {
+ const mergedArray = [...tags1, ...tags2];
+ // mergedArray have duplicates, lets remove the duplicates using Set
+ const set = new Set();
+ return mergedArray.filter(tag => {
+ if (!set.has(tag.title)) {
+ set.add(tag.title);
+ return true;
+ }
+ return false;
+ }, set);
+ }
+
+ function escapeRegExp(string) {
+ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
+ }
+
+ const parseTextQuery = (identifier: string) => {
+ const extractedTags = [];
+ let query = textQuery.current;
+ if (query && query.length > 0) {
+ query = query
+ .trim()
+ .replace(
+ new RegExp(escapeRegExp(identifier) + '\\s+', 'g'),
+ identifier
+ );
+ }
+ const textQueryParts = query.split(' ');
+ let newTextQuery = '';
+ if (textQueryParts) {
+ // && textQueryParts.length > 1) {
+ textQueryParts.forEach(part => {
+ const trimmedPart = part.trim();
+ if (trimmedPart.startsWith(identifier)) {
+ const tagTitle = trimmedPart.substr(1).trim();
+ extractedTags.push({ title: tagTitle });
+ } /* else if (trimmedPart.startsWith('-')) {
+ // add to searchQuery.tagsNOT
+ } else if (trimmedPart.startsWith('?')) {
+ // add to searchQuery.tagsOR
+ */ else {
+ newTextQuery += trimmedPart + ' ';
+ }
+ });
+ }
+ textQuery.current = newTextQuery.trim();
+ return extractedTags;
+ };
+
+ const clickSearchButton = () => {
+ executeSearch();
+ };
+
+ const startSearch = event => {
+ if (event.key === 'Enter' || event.keyCode === 13) {
+ executeSearch();
+ }
+ };
+
+ function openCurrentDirectory() {
+ if (props.currentDirectory) {
+ props.loadDirectoryContent(props.currentDirectory, false);
+ } else {
+ props.setSearchResults([]);
+ }
+ }
+
+ const clearSearch = () => {
+ textQuery.current = '';
+ searchBoxing.current = 'location';
+ searchType.current = 'fuzzy';
+ fileTypes.current = FileTypeGroups.any;
+ lastModified.current = '';
+ tagTimePeriod.current = '';
+ tagTimePeriodHelper.current = ' ';
+ tagTimePeriodFrom.current = null;
+ tagTimePeriodTo.current = null;
+ setTagPlaceLat(null);
+ setTagPlaceLong(null);
+ // setTagPlaceRadius(0);
+ forceIndexing.current = false;
+ fileSize.current = '';
+ props.setSearchQuery({});
+ openCurrentDirectory();
+ };
+
+ const executeSearch = () => {
+ const { searchAllLocations, searchLocationIndex } = props;
+ const tagsAND = mergeWithExtractedTags(props.searchQuery.tagsAND, '+');
+ const tagsOR = mergeWithExtractedTags(props.searchQuery.tagsOR, '?');
+ const tagsNOT = mergeWithExtractedTags(props.searchQuery.tagsNOT, '-');
+ const searchQuery: TS.SearchQuery = {
+ textQuery: textQuery.current,
+ tagsAND,
+ tagsOR,
+ tagsNOT,
+ // @ts-ignore
+ searchBoxing: searchBoxing.current,
+ searchType: searchType.current,
+ fileTypes: fileTypes.current,
+ lastModified: lastModified.current,
+ fileSize: fileSize.current,
+ tagTimePeriodFrom: tagTimePeriodFrom.current,
+ tagTimePeriodTo: tagTimePeriodTo.current,
+ tagPlaceLat,
+ tagPlaceLong,
+ // tagPlaceRadius,
+ maxSearchResults: props.maxSearchResults,
+ currentDirectory: props.currentDirectory,
+ forceIndexing: forceIndexing.current,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ };
+ console.log('Search object: ' + JSON.stringify(searchQuery));
+ if (searchBoxing.current === 'global') {
+ searchAllLocations(searchQuery);
+ } else {
+ searchLocationIndex(searchQuery);
+ }
+ };
+
+ const { indexing } = props;
+
+ return (
+ <div style={{ width: '100%', whiteSpace: 'nowrap' }}>
+ <TextField
+ fullWidth
+ id="textQuery"
+ name="textQuery"
+ value={textQuery.current}
+ // variant="filled"
+ onChange={event => {
+ textQuery.current = event.target.value;
+ // rerender
+ forceUpdate();
+ }}
+ style={{ marginTop: 0, width: 'calc(100% - 80px)', marginRight: 10 }}
+ inputRef={mainSearchField}
+ margin="dense"
+ autoFocus
+ onKeyDown={startSearch}
+ title={i18n.t('core:searchWordsWithInterval')}
+ InputProps={{
+ endAdornment: (
+ <InputAdornment position="end">
+ <IconButton
+ id="clearSearchID"
+ onClick={clearSearch}
+ size="small"
+ edge="end"
+ >
+ <ClearSearchIcon />
+ </IconButton>
+ </InputAdornment>
+ )
+ }}
+ />
+ <Button
+ id="searchButton"
+ variant="outlined"
+ size="small"
+ disabled={indexing}
+ // variant="outlined"
+ color="primary"
+ onClick={clickSearchButton}
+ >
+ {indexing ? 'Search disabled while indexing' : i18n.t('searchTitle')}
+ </Button>
+ </div>
+ );
+};
+
+function mapStateToProps(state) {
+ return {
+ indexing: isIndexing(state),
+ searchQuery: getSearchQuery(state),
+ currentDirectory: getDirectoryPath(state),
+ indexedEntriesCount: getIndexedEntriesCount(state),
+ maxSearchResults: getMaxSearchResults(state),
+ showUnixHiddenEntries: getShowUnixHiddenEntries(state)
+ };
+}
+
+function mapDispatchToProps(dispatch) {
+ return bindActionCreators(
+ {
+ searchAllLocations: LocationIndexActions.searchAllLocations,
+ setSearchQuery: LocationIndexActions.setSearchQuery,
+ searchLocationIndex: LocationIndexActions.searchLocationIndex,
+ createLocationsIndexes: LocationIndexActions.createLocationsIndexes,
+ loadDirectoryContent: AppActions.loadDirectoryContent,
+ openURLExternally: AppActions.openURLExternally,
+ setSearchResults: AppActions.setSearchResults
+ },
+ dispatch
+ );
+}
+
+const areEqual = (prevProp, nextProp) =>
+ nextProp.indexing === prevProp.indexing &&
+ nextProp.searchQuery === prevProp.searchQuery &&
+ nextProp.currentDirectory === prevProp.currentDirectory &&
+ nextProp.indexedEntriesCount === prevProp.indexedEntriesCount;
+
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(React.memo(SearchInline, areEqual));
diff --git a/app/components/SearchPopover.tsx b/app/components/SearchPopover.tsx
new file mode 100644
index 000000000..3ba37a46c
--- /dev/null
+++ b/app/components/SearchPopover.tsx
@@ -0,0 +1,1169 @@
+/**
+ * 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 React, { useEffect, useReducer, useRef, useState } from 'react';
+import { bindActionCreators } from 'redux';
+import { connect } from 'react-redux';
+import { makeStyles, Theme } 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';
+import PictureIcon from '@material-ui/icons/Panorama';
+import DocumentIcon from '@material-ui/icons/PictureAsPdf';
+import NoteIcon from '@material-ui/icons/Note';
+import AudioIcon from '@material-ui/icons/MusicVideo';
+import VideoIcon from '@material-ui/icons/OndemandVideo';
+import ArchiveIcon from '@material-ui/icons/Archive';
+import FolderIcon from '@material-ui/icons/FolderOpen';
+import UntaggedIcon from '@material-ui/icons/LabelOffOutlined';
+import FileIcon from '@material-ui/icons/InsertDriveFileOutlined';
+import BookmarkIcon from '@material-ui/icons/BookmarkBorder';
+import BookIcon from '@material-ui/icons/LocalLibraryOutlined';
+import DateIcon from '@material-ui/icons/DateRange';
+import Button from '@material-ui/core/Button';
+import Input from '@material-ui/core/Input';
+import TextField from '@material-ui/core/TextField';
+import InputLabel from '@material-ui/core/InputLabel';
+import InputAdornment from '@material-ui/core/InputAdornment';
+import IconButton from '@material-ui/core/IconButton';
+import Select from '@material-ui/core/Select';
+import FormControl from '@material-ui/core/FormControl';
+import MoreVertIcon from '@material-ui/icons/MoreVert';
+import ButtonGroup from '@material-ui/core/ButtonGroup';
+import ToggleButton from '@material-ui/lab/ToggleButton';
+import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup';
+import TagsSelect from './TagsSelect';
+import { actions as AppActions, getDirectoryPath } from '../reducers/app';
+import {
+ actions as LocationIndexActions,
+ getIndexedEntriesCount,
+ isIndexing,
+ getSearchQuery
+} from '../reducers/location-index';
+import {
+ getMaxSearchResults,
+ getShowUnixHiddenEntries
+} from '-/reducers/settings';
+import { styles, StyleProps } from './SearchInline.css';
+import i18n from '../services/i18n';
+import { FileTypeGroups } from '-/services/search';
+import { Pro } from '../pro';
+import SearchMenu from './menus/SearchMenu';
+import { formatDateTime, extractTimePeriod } from '-/utils/dates';
+import { parseGeoLocation, parseLatLon } from '-/utils/misc';
+import { AppConfig } from '-/config';
+import { actions as SearchActions, getSearches } from '-/reducers/searches';
+import { TS } from '-/tagspaces.namespace';
+import { ProLabel, BetaLabel, ProTooltip } from '-/components/HelperComponents';
+
+const SaveSearchDialog = Pro && Pro.UI ? Pro.UI.SaveSearchDialog : false;
+
+type PropsClasses = Record<keyof StyleProps, string>;
+
+interface Props {
+ style?: any;
+ theme?: any;
+ searchLocationIndex: (searchQuery: TS.SearchQuery) => void;
+ createLocationsIndexes: () => void;
+ searchAllLocations: (searchQuery: TS.SearchQuery) => void;
+ loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;
+ openURLExternally: (url: string) => void;
+ hideDrawer?: () => void;
+ searchQuery: TS.SearchQuery; // () => any;
+ setSearchResults: (entries: Array<any>) => void;
+ setSearchQuery: (searchQuery: TS.SearchQuery) => void;
+ currentDirectory: string;
+ indexedEntriesCount: number;
+ maxSearchResults: number;
+ indexing: boolean;
+ searches: Array<TS.SearchQuery>;
+ addSearches: (searches: Array<TS.SearchQuery>) => void;
+ showUnixHiddenEntries: boolean;
+ openSearchPanel: () => void;
+ onClose: () => void;
+}
+
+const useStyles = makeStyles<Theme, StyleProps>(styles);
+
+const SearchPopover = (props: Props) => {
+ const classes: PropsClasses = useStyles({} as StyleProps);
+ const [, forceUpdate] = useReducer(x => x + 1, 0);
+ const textQuery = useRef<string>(props.searchQuery.textQuery);
+ // const tagsAND = useRef<Array<TS.Tag>>(props.searchQuery.tagsAND);
+ const fileTypes = useRef<Array<string>>(
+ props.searchQuery.fileTypes
+ ? props.searchQuery.fileTypes
+ : FileTypeGroups.any
+ );
+
+ const searchBoxing = useRef<'location' | 'folder' | 'global'>(
+ props.searchQuery.searchBoxing ? props.searchQuery.searchBoxing : 'location'
+ );
+ const searchType = useRef<'fuzzy' | 'semistrict' | 'strict'>(
+ props.searchQuery.searchType ? props.searchQuery.searchType : 'fuzzy'
+ );
+ const lastModified = useRef<string>(
+ props.searchQuery.lastModified ? props.searchQuery.lastModified : ''
+ );
+ const [saveSearchDialogOpened, setSaveSearchDialogOpened] = useState<
+ TS.SearchQuery
+ >(undefined);
+ const tagTimePeriod = useRef<string>('');
+ const tagTimePeriodHelper = useRef<string>(' ');
+ const [tagPlace, setTagPlace] = useState<string>(' ');
+ const [tagPlaceHelper, setTagPlaceHelper] = useState<string>(' ');
+ const tagTimePeriodFrom = useRef<number | null>(
+ props.searchQuery.tagTimePeriodFrom
+ ? props.searchQuery.tagTimePeriodFrom
+ : null
+ );
+ const tagTimePeriodTo = useRef<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 = useRef<boolean>(
+ props.searchQuery.forceIndexing ? props.searchQuery.forceIndexing : false
+ );
+ const fileSize = useRef<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;
+
+ useEffect(() => {
+ textQuery.current = props.searchQuery.textQuery;
+ /*if (props.searchQuery.fileTypes) {
+ fileTypes.current = props.searchQuery.fileTypes;
+ }
+ if (props.searchQuery.searchBoxing) {
+ searchBoxing.current = props.searchQuery.searchBoxing;
+ }
+ if (props.searchQuery.searchType) {
+ searchType.current = props.searchQuery.searchType;
+ }
+ if (props.searchQuery.lastModified) {
+ lastModified.current = props.searchQuery.lastModified;
+ }
+ if (props.searchQuery.tagTimePeriodFrom) {
+ tagTimePeriodFrom.current = props.searchQuery.tagTimePeriodFrom;
+ }
+ if (props.searchQuery.tagTimePeriodTo) {
+ tagTimePeriodTo.current = props.searchQuery.tagTimePeriodTo;
+ }
+ if (props.searchQuery.forceIndexing) {
+ forceIndexing.current = props.searchQuery.forceIndexing;
+ }
+ if (props.searchQuery.fileSize) {
+ fileSize.current = props.searchQuery.fileSize;
+ }*/
+ }, [props.searchQuery]);
+
+ 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') {
+ const types = JSON.parse(value);
+ fileTypes.current = types;
+ if (searchBoxing.current !== 'global') {
+ props.searchLocationIndex({
+ ...props.searchQuery,
+ fileTypes: types,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ }
+ }
+ };
+
+ const handleFileSizeChange = (event: React.ChangeEvent<HTMLInputElement>) => {
+ const { target } = event;
+ const { value, name } = target;
+
+ if (name === 'fileSize') {
+ fileSize.current = value;
+ if (searchBoxing.current !== 'global') {
+ props.searchLocationIndex({
+ ...props.searchQuery,
+ fileSize: value,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ }
+ }
+ };
+
+ const handleLastModifiedChange = (
+ event: React.ChangeEvent<HTMLInputElement>
+ ) => {
+ const { target } = event;
+ const { value, name } = target;
+
+ if (name === 'lastModified') {
+ lastModified.current = value;
+ if (searchBoxing.current !== 'global') {
+ props.searchLocationIndex({
+ ...props.searchQuery,
+ lastModified: value,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ }
+ }
+ };
+
+ const handleSavedSearchChange = (
+ event: React.ChangeEvent<HTMLInputElement>
+ ) => {
+ const { target } = event;
+ const { value } = target;
+
+ const savedSearch = props.searches.find(search => search.uuid === value);
+ if (!savedSearch) {
+ return true;
+ }
+ textQuery.current = savedSearch.textQuery;
+ fileTypes.current = savedSearch.fileTypes;
+ lastModified.current = savedSearch.lastModified;
+ fileSize.current = savedSearch.fileSize;
+ searchType.current = savedSearch.searchType;
+ searchBoxing.current = savedSearch.searchBoxing;
+ forceIndexing.current = savedSearch.forceIndexing;
+
+ let ttPeriod;
+ tagTimePeriodFrom.current = savedSearch.tagTimePeriodFrom;
+ if (savedSearch.tagTimePeriodFrom) {
+ ttPeriod = format(new Date(savedSearch.tagTimePeriodFrom), 'yyyyMMdd');
+ }
+
+ tagTimePeriodTo.current = savedSearch.tagTimePeriodTo;
+ if (savedSearch.tagTimePeriodTo) {
+ ttPeriod +=
+ '-' + format(new Date(savedSearch.tagTimePeriodTo), 'yyyyMMdd');
+ }
+
+ if (ttPeriod) {
+ tagTimePeriod.current = ttPeriod;
+ }
+
+ if (savedSearch.searchBoxing === 'global') {
+ props.searchAllLocations({
+ ...savedSearch,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ } else {
+ props.searchLocationIndex({
+ ...savedSearch,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ }
+ };
+
+ function removeTags(tagsArray, removeTagsArray) {
+ // eslint-disable-next-line react/no-access-state-in-setstate
+ return tagsArray.filter(tag =>
+ removeTagsArray.some(valueTag => valueTag.title !== tag.title)
+ );
+ }
+
+ const handleTagFieldChange = (name, value, reason) => {
+ let searchQuery;
+ if (reason === 'remove-value') {
+ if (name === 'tagsAND') {
+ searchQuery = {
+ ...props.searchQuery,
+ tagsAND: removeTags(props.searchQuery.tagsAND, value)
+ };
+ } else if (name === 'tagsNOT') {
+ searchQuery = {
+ ...props.searchQuery,
+ tagsNOT: removeTags(props.searchQuery.tagsNOT, value)
+ };
+ } else if (name === 'tagsOR') {
+ searchQuery = {
+ ...props.searchQuery,
+ tagsOR: removeTags(props.searchQuery.tagsOR, value)
+ };
+ }
+ if (!haveSearchFilters(searchQuery)) {
+ clearSearch();
+ }
+ } else {
+ // eslint-disable-next-line no-lonely-if
+ if (name === 'tagsAND') {
+ searchQuery = { ...props.searchQuery, tagsAND: value };
+ } else if (name === 'tagsNOT') {
+ searchQuery = { ...props.searchQuery, tagsNOT: value };
+ } else if (name === 'tagsOR') {
+ searchQuery = { ...props.searchQuery, tagsOR: value };
+ }
+ }
+ props.searchLocationIndex({
+ ...searchQuery,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ // if (searchBoxing !== 'global') { // TODO disable automatic search in global mode
+ //
+ // }
+ };
+
+ function haveSearchFilters(searchQuery) {
+ return (
+ searchQuery.textQuery ||
+ (searchQuery.tagsAND !== undefined && searchQuery.tagsAND.length > 0) ||
+ (searchQuery.tagsNOT !== undefined && searchQuery.tagsNOT.length > 0) ||
+ (searchQuery.tagsOR !== undefined && searchQuery.tagsOR.length > 0) ||
+ (searchQuery.fileTypes !== undefined &&
+ searchQuery.fileTypes !== FileTypeGroups.any) ||
+ searchQuery.lastModified ||
+ searchQuery.tagTimePeriodFrom ||
+ searchQuery.tagTimePeriodTo ||
+ searchQuery.tagPlaceLat ||
+ searchQuery.tagPlaceLong ||
+ searchQuery.fileSize
+ );
+ }
+
+ const handleTimePeriodChange = event => {
+ const { target } = event;
+ const { value } = target;
+ const { fromDateTime, toDateTime } = extractTimePeriod(value);
+
+ if (toDateTime && fromDateTime) {
+ const tagTPeriodHelper =
+ 'From: ' +
+ formatDateTime(fromDateTime) +
+ ' To: ' +
+ formatDateTime(toDateTime);
+ tagTimePeriodFrom.current = fromDateTime.getTime();
+ tagTimePeriodTo.current = toDateTime.getTime();
+ tagTimePeriodHelper.current = tagTPeriodHelper;
+ } else {
+ tagTimePeriodFrom.current = null;
+ tagTimePeriodTo.current = null;
+ tagTimePeriodHelper.current = ' ';
+ }
+ tagTimePeriod.current = value;
+ forceUpdate();
+ };
+
+ const handlePlaceChange = event => {
+ const { target } = event;
+ const { value } = target;
+ let lat = null;
+ let lng = null;
+ let tagPHelper;
+
+ const location = parseGeoLocation(value);
+ if (location !== undefined) {
+ ({ lat, lng } = location);
+ } else {
+ const latLon = parseLatLon(value);
+ if (latLon) {
+ ({ lat } = latLon);
+ lng = latLon.lon;
+ }
+ }
+
+ if (lat && lng) {
+ tagPHelper = 'Place at lat: ' + lat + ' long: ' + lng;
+ } else {
+ tagPHelper = '';
+ }
+ setTagPlace(value);
+ setTagPlaceLat(lat);
+ setTagPlaceLong(lng);
+ setTagPlaceHelper(tagPHelper);
+ };
+
+ const mergeWithExtractedTags = (tags: Array<TS.Tag>, identifier: string) => {
+ const extractedTags = parseTextQuery(identifier);
+ if (tags) {
+ if (extractedTags.length > 0) {
+ return getUniqueTags(tags, extractedTags);
+ }
+ return tags;
+ }
+ if (extractedTags.length > 0) {
+ return extractedTags;
+ }
+ return undefined;
+ };
+
+ function getUniqueTags(tags1: Array<TS.Tag>, tags2: Array<TS.Tag>) {
+ const mergedArray = [...tags1, ...tags2];
+ // mergedArray have duplicates, lets remove the duplicates using Set
+ const set = new Set();
+ return mergedArray.filter(tag => {
+ if (!set.has(tag.title)) {
+ set.add(tag.title);
+ return true;
+ }
+ return false;
+ }, set);
+ }
+
+ function escapeRegExp(string) {
+ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
+ }
+
+ const parseTextQuery = (identifier: string) => {
+ const extractedTags = [];
+ if (!textQuery.current) {
+ return extractedTags;
+ }
+ let query = textQuery.current;
+ if (query && query.length > 0) {
+ query = query
+ .trim()
+ .replace(
+ new RegExp(escapeRegExp(identifier) + '\\s+', 'g'),
+ identifier
+ );
+ }
+ const textQueryParts = query.split(' ');
+ let newTextQuery = '';
+ if (textQueryParts) {
+ // && textQueryParts.length > 1) {
+ textQueryParts.forEach(part => {
+ const trimmedPart = part.trim();
+ if (trimmedPart.startsWith(identifier)) {
+ const tagTitle = trimmedPart.substr(1).trim();
+ extractedTags.push({ title: tagTitle });
+ } /* else if (trimmedPart.startsWith('-')) {
+ // add to searchQuery.tagsNOT
+ } else if (trimmedPart.startsWith('?')) {
+ // add to searchQuery.tagsOR
+ */ else {
+ newTextQuery += trimmedPart + ' ';
+ }
+ });
+ }
+ textQuery.current = newTextQuery.trim();
+ return extractedTags;
+ };
+
+ const startSearch = event => {
+ if (event.key === 'Enter' || event.keyCode === 13) {
+ if (props.hideDrawer) {
+ props.hideDrawer();
+ }
+ executeSearch();
+ }
+ };
+
+ function openCurrentDirectory() {
+ if (props.currentDirectory) {
+ props.loadDirectoryContent(props.currentDirectory, false);
+ } else {
+ props.setSearchResults([]);
+ }
+ }
+
+ const clearSearch = () => {
+ textQuery.current = '';
+ searchBoxing.current = 'location';
+ searchType.current = 'fuzzy';
+ fileTypes.current = FileTypeGroups.any;
+ lastModified.current = '';
+ tagTimePeriod.current = '';
+ tagTimePeriodHelper.current = ' ';
+ setTagPlace(' ');
+ setTagPlaceHelper(' ');
+ tagTimePeriodFrom.current = null;
+ tagTimePeriodTo.current = null;
+ setTagPlaceLat(null);
+ setTagPlaceLong(null);
+ // setTagPlaceRadius(0);
+ forceIndexing.current = false;
+ fileSize.current = '';
+ props.setSearchQuery({});
+ openCurrentDirectory();
+ props.onClose();
+ };
+
+ const saveSearch = (isNew: boolean = true) => {
+ const tagsAND = mergeWithExtractedTags(props.searchQuery.tagsAND, '+');
+ const tagsOR = mergeWithExtractedTags(props.searchQuery.tagsOR, '?');
+ const tagsNOT = mergeWithExtractedTags(props.searchQuery.tagsNOT, '-');
+ setSaveSearchDialogOpened({
+ uuid: isNew ? undefined : props.searchQuery.uuid,
+ title: props.searchQuery.title,
+ textQuery: textQuery.current,
+ tagsAND,
+ tagsOR,
+ tagsNOT,
+ // @ts-ignore
+ searchBoxing: searchBoxing.current,
+ searchType: searchType.current,
+ fileTypes: fileTypes.current,
+ lastModified: lastModified.current,
+ fileSize: fileSize.current,
+ tagTimePeriodFrom: tagTimePeriodFrom.current,
+ tagTimePeriodTo: tagTimePeriodTo.current,
+ tagPlaceLat,
+ tagPlaceLong,
+ // tagPlaceRadius,
+ maxSearchResults: props.maxSearchResults,
+ currentDirectory: props.currentDirectory,
+ forceIndexing: forceIndexing.current
+ });
+ };
+
+ const switchSearchBoxing = (
+ event: React.MouseEvent<HTMLElement>,
+ boxing: 'location' | 'folder' | 'global'
+ ) => {
+ if (boxing !== null) {
+ searchBoxing.current = boxing;
+ forceUpdate();
+ }
+ };
+
+ const switchSearchType = (
+ event: React.MouseEvent<HTMLElement>,
+ type: 'fuzzy' | 'semistrict' | 'strict'
+ ) => {
+ if (type !== null) {
+ searchType.current = type;
+ forceUpdate();
+ }
+ };
+
+ const executeSearch = () => {
+ const { searchAllLocations, searchLocationIndex } = props;
+ const tagsAND = mergeWithExtractedTags(props.searchQuery.tagsAND, '+');
+ const tagsOR = mergeWithExtractedTags(props.searchQuery.tagsOR, '?');
+ const tagsNOT = mergeWithExtractedTags(props.searchQuery.tagsNOT, '-');
+ const searchQuery: TS.SearchQuery = {
+ textQuery: textQuery.current,
+ tagsAND,
+ tagsOR,
+ tagsNOT,
+ // @ts-ignore
+ searchBoxing: searchBoxing.current,
+ searchType: searchType.current,
+ fileTypes: fileTypes.current,
+ lastModified: lastModified.current,
+ fileSize: fileSize.current,
+ tagTimePeriodFrom: tagTimePeriodFrom.current,
+ tagTimePeriodTo: tagTimePeriodTo.current,
+ tagPlaceLat,
+ tagPlaceLong,
+ // tagPlaceRadius,
+ maxSearchResults: props.maxSearchResults,
+ currentDirectory: props.currentDirectory,
+ forceIndexing: forceIndexing.current,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ };
+ console.log('Search object: ' + JSON.stringify(searchQuery));
+ if (searchBoxing.current === 'global') {
+ searchAllLocations(searchQuery);
+ } else {
+ searchLocationIndex(searchQuery);
+ }
+ };
+
+ const handleSearchMenu = (event: any) => {
+ setSearchMenuAnchorEl(event.currentTarget);
+ };
+
+ const handleCloseSearchMenu = () => {
+ setSearchMenuAnchorEl(null);
+ };
+
+ const { indexing, indexedEntriesCount } = props;
+
+ const indexStatus = indexedEntriesCount
+ ? indexedEntriesCount + ' indexed entries'
+ : '';
+ return (
+ <div style={{ maxWidth: 400 }}>
+ <div className={classes.toolbar}>
+ <Typography
+ className={classNames(classes.panelTitle, classes.header)}
+ style={{ flex: 0 }}
+ >
+ {i18n.t('searchTitle')}
+ </Typography>
+ <Typography
+ variant="caption"
+ className={classes.header}
+ style={{ alignSelf: 'center', paddingLeft: 5, display: 'block' }}
+ >
+ {indexStatus}
+ </Typography>
+ <IconButton
+ style={{ marginLeft: 'auto' }}
+ data-tid="searchMenu"
+ onClick={handleSearchMenu}
+ >
+ <MoreVertIcon />
+ </IconButton>
+ </div>
+ <SearchMenu
+ anchorEl={searchMenuAnchorEl}
+ open={Boolean(searchMenuAnchorEl)}
+ onClose={handleCloseSearchMenu}
+ createLocationsIndexes={props.createLocationsIndexes}
+ openURLExternally={props.openURLExternally}
+ exportSearches={() => {
+ setExportSearchesDialogOpened(true);
+ }}
+ importSearches={() => {
+ fileInputRef.current.click();
+ }}
+ />
+ <div className={classes.searchArea}>
+ <FormControl className={classes.formControl} disabled={indexing}>
+ <ToggleButtonGroup
+ onChange={switchSearchBoxing}
+ size="small"
+ exclusive
+ style={{ marginBottom: 10, alignSelf: 'center' }}
+ value={searchBoxing.current}
+ >
+ <ToggleButton value="location">
+ <Tooltip arrow title={i18n.t('searchPlaceholder')}>
+ <div>{i18n.t('location')}</div>
+ </Tooltip>
+ </ToggleButton>
+ <ToggleButton value="folder">
+ <Tooltip
+ arrow
+ title={i18n.t('searchCurrentFolderWithSubFolders')}
+ >
+ <div>{i18n.t('folder')}</div>
+ </Tooltip>
+ </ToggleButton>
+ <ToggleButton disabled={!Pro} value="global">
+ <Tooltip arrow title={i18n.t('searchInAllLocationTooltip')}>
+ <div>{i18n.t('globalSearch')}</div>
+ </Tooltip>
+ {Pro ? <BetaLabel /> : <ProLabel />}
+ </ToggleButton>
+ </ToggleButtonGroup>
+ </FormControl>
+ <FormControl className={classes.formControl} disabled={indexing}>
+ <ToggleButtonGroup
+ onChange={switchSearchType}
+ size="small"
+ exclusive
+ style={{ marginBottom: 10, alignSelf: 'center' }}
+ value={searchType.current}
+ >
+ <ToggleButton value="fuzzy" data-tid="fuzzySearchTID">
+ <Tooltip arrow title={i18n.t('searchTypeFuzzyTooltip')}>
+ <div>{i18n.t('searchTypeFuzzy')}</div>
+ </Tooltip>
+ </ToggleButton>
+ <ToggleButton value="semistrict" data-tid="semiStrictSearchTID">
+ <Tooltip arrow title={i18n.t('searchTypeSemiStrictTooltip')}>
+ <div>{i18n.t('searchTypeSemiStrict')}</div>
+ </Tooltip>
+ </ToggleButton>
+ <ToggleButton value="strict" data-tid="strictSearchTID">
+ <Tooltip arrow title={i18n.t('searchTypeStrictTooltip')}>
+ <div>{i18n.t('searchTypeStrict')}</div>
+ </Tooltip>
+ </ToggleButton>
+ </ToggleButtonGroup>
+ </FormControl>
+ <FormControl className={classes.formControl} disabled={indexing}>
+ <ToggleButtonGroup
+ onChange={() => {
+ forceIndexing.current = !forceIndexing.current;
+ forceUpdate();
+ }}
+ size="small"
+ exclusive
+ style={{ marginBottom: 10, alignSelf: 'center' }}
+ value={forceIndexing.current}
+ >
+ <ToggleButton value={false}>
+ <Tooltip arrow title={i18n.t('useCurrentIndexTooltip')}>
+ <div>{i18n.t('useCurrentIndex')}</div>
+ </Tooltip>
+ </ToggleButton>
+ <ToggleButton value={true} data-tid="forceIndexingTID">
+ <Tooltip arrow title={i18n.t('forceReindexTooltip')}>
+ <div>{i18n.t('forceReindex')}</div>
+ </Tooltip>
+ </ToggleButton>
+ </ToggleButtonGroup>
+ </FormControl>
+ <FormControl className={classes.formControl} disabled={indexing}>
+ <TagsSelect
+ placeholderText={i18n.t('core:selectTags')}
+ label={i18n.t('core:mustContainTheseTags')}
+ tags={props.searchQuery.tagsAND}
+ handleChange={handleTagFieldChange}
+ tagSearchType="tagsAND"
+ tagMode="remove"
+ />
+ </FormControl>
+ <FormControl className={classes.formControl} disabled={indexing}>
+ <TagsSelect
+ placeholderText={i18n.t('core:selectTags')}
+ tags={props.searchQuery.tagsOR}
+ label={i18n.t('core:atLeastOneOfTheseTags')}
+ handleChange={handleTagFieldChange}
+ tagSearchType="tagsOR"
+ tagMode="remove"
+ />
+ </FormControl>
+ <FormControl className={classes.formControl} disabled={indexing}>
+ <TagsSelect
+ placeholderText={i18n.t('core:selectTags')}
+ tags={props.searchQuery.tagsNOT}
+ label={i18n.t('core:noneOfTheseTags')}
+ handleChange={handleTagFieldChange}
+ tagSearchType="tagsNOT"
+ tagMode="remove"
+ />
+ </FormControl>
+ {AppConfig.showAdvancedSearch && (
+ <>
+ <FormControl
+ className={classes.formControl}
+ disabled={indexing || !Pro}
+ >
+ <ProTooltip tooltip={i18n.t('filterByTypTooltip')}>
+ <InputLabel htmlFor="file-type">
+ {i18n.t('core:fileType')}
+ </InputLabel>
+ <Select
+ style={{ width: '100%' }}
+ value={JSON.stringify(fileTypes.current)}
+ onChange={handleFileTypeChange}
+ input={<Input name="fileTypes" id="file-type" />}
+ >
+ <MenuItem value={JSON.stringify(FileTypeGroups.any)}>
+ {i18n.t('core:anyType')}
+ </MenuItem>
+ <MenuItem value={JSON.stringify(FileTypeGroups.folders)}>
+ <IconButton>
+ <FolderIcon />
+ </IconButton>
+ {i18n.t('core:searchFolders')}
+ </MenuItem>
+ <MenuItem value={JSON.stringify(FileTypeGroups.files)}>
+ <IconButton>
+ <FileIcon />
+ </IconButton>
+ {i18n.t('core:searchFiles')}
+ </MenuItem>
+ <MenuItem value={JSON.stringify(FileTypeGroups.untagged)}>
+ <IconButton>
+ <UntaggedIcon />
+ </IconButton>
+ {i18n.t('core:searchUntaggedEntries')}
+ </MenuItem>
+ <MenuItem
+ value={JSON.stringify(FileTypeGroups.images)}
+ title={FileTypeGroups.images.toString()}
+ >
+ <IconButton>
+ <PictureIcon />
+ </IconButton>
+ {i18n.t('core:searchPictures')}
+ </MenuItem>
+ <MenuItem
+ value={JSON.stringify(FileTypeGroups.documents)}
+ title={FileTypeGroups.documents.toString()}
+ >
+ <IconButton>
+ <DocumentIcon />
+ </IconButton>
+ {i18n.t('core:searchDocuments')}
+ </MenuItem>
+ <MenuItem
+ value={JSON.stringify(FileTypeGroups.notes)}
+ title={FileTypeGroups.notes.toString()}
+ >
+ <IconButton>
+ <NoteIcon />
+ </IconButton>
+ {i18n.t('core:searchNotes')}
+ </MenuItem>
+ <MenuItem
+ value={JSON.stringify(FileTypeGroups.audio)}
+ title={FileTypeGroups.audio.toString()}
+ >
+ <IconButton>
+ <AudioIcon />
+ </IconButton>
+ {i18n.t('core:searchAudio')}
+ </MenuItem>
+ <MenuItem
+ value={JSON.stringify(FileTypeGroups.video)}
+ title={FileTypeGroups.video.toString()}
+ >
+ <IconButton>
+ <VideoIcon />
+ </IconButton>
+ {i18n.t('core:searchVideoFiles')}
+ </MenuItem>
+ <MenuItem
+ value={JSON.stringify(FileTypeGroups.archives)}
+ title={FileTypeGroups.archives.toString()}
+ >
+ <IconButton>
+ <ArchiveIcon />
+ </IconButton>
+ {i18n.t('core:searchArchives')}
+ </MenuItem>
+ <MenuItem
+ value={JSON.stringify(FileTypeGroups.bookmarks)}
+ title={FileTypeGroups.bookmarks.toString()}
+ >
+ <IconButton>
+ <BookmarkIcon />
+ </IconButton>
+ {i18n.t('core:searchBookmarks')}
+ </MenuItem>
+ <MenuItem
+ value={JSON.stringify(FileTypeGroups.ebooks)}
+ title={FileTypeGroups.ebooks.toString()}
+ >
+ <IconButton>
+ <BookIcon />
+ </IconButton>
+ {i18n.t('core:searchEbooks')}
+ </MenuItem>
+ </Select>
+ {/* <FormHelperText>{i18n.t('core:searchFileTypes')}</FormHelperText> */}
+ </ProTooltip>
+ </FormControl>
+ <FormControl
+ className={classes.formControl}
+ disabled={indexing || !Pro}
+ >
+ <ProTooltip tooltip={i18n.t('filterBySizeTooltip')}>
+ <InputLabel shrink htmlFor="file-size">
+ {i18n.t('core:sizeSearchTitle')}
+ </InputLabel>
+ <Select
+ style={{ width: '100%' }}
+ value={fileSize.current}
+ onChange={handleFileSizeChange}
+ input={<Input name="fileSize" id="file-size" />}
+ displayEmpty
+ >
+ <MenuItem value="">{i18n.t('core:sizeAny')}</MenuItem>
+ <MenuItem value="sizeEmpty">
+ {i18n.t('core:sizeEmpty')}
+ </MenuItem>
+ <MenuItem value="sizeTiny">
+ {i18n.t('core:sizeTiny')}
+ &nbsp;(&lt;&nbsp;10KB)
+ </MenuItem>
+ <MenuItem value="sizeVerySmall">
+ {i18n.t('core:sizeVerySmall')}
+ &nbsp;(&lt;&nbsp;100KB)
+ </MenuItem>
+ <MenuItem value="sizeSmall">
+ {i18n.t('core:sizeSmall')}
+ &nbsp;(&lt;&nbsp;1MB)
+ </MenuItem>
+ <MenuItem value="sizeMedium">
+ {i18n.t('core:sizeMedium')}
+ &nbsp;(&lt;&nbsp;50MB)
+ </MenuItem>
+ <MenuItem value="sizeLarge">
+ {i18n.t('core:sizeLarge')}
+ &nbsp;(&lt;&nbsp;1GB)
+ </MenuItem>
+ <MenuItem value="sizeHuge">
+ {i18n.t('core:sizeHuge')}
+ &nbsp;(&gt;&nbsp;1GB)
+ </MenuItem>
+ </Select>
+ </ProTooltip>
+ </FormControl>
+ <FormControl
+ className={classes.formControl}
+ disabled={indexing || !Pro}
+ >
+ <ProTooltip tooltip={i18n.t('filterByLastModifiedDateTooltip')}>
+ <InputLabel shrink htmlFor="modification-date">
+ {i18n.t('core:lastModifiedSearchTitle')}
+ </InputLabel>
+ <Select
+ value={lastModified.current}
+ style={{ width: '100%' }}
+ onChange={handleLastModifiedChange}
+ input={<Input name="lastModified" id="modification-date" />}
+ displayEmpty
+ >
+ <MenuItem value="">{i18n.t('core:anyTime')}</MenuItem>
+ <MenuItem value="today">{i18n.t('core:today')}</MenuItem>
+ <MenuItem value="yesterday">
+ {i18n.t('core:yesterday')}
+ </MenuItem>
+ <MenuItem value="past7Days">
+ {i18n.t('core:past7Days')}
+ </MenuItem>
+ <MenuItem value="past30Days">
+ {i18n.t('core:past30Days')}
+ </MenuItem>
+ <MenuItem value="past6Months">
+ {i18n.t('core:past6Months')}
+ </MenuItem>
+ <MenuItem value="pastYear">
+ {i18n.t('core:pastYear')}
+ </MenuItem>
+ <MenuItem value="moreThanYear">
+ {i18n.t('core:moreThanYear')}
+ </MenuItem>
+ </Select>
+ </ProTooltip>
+ </FormControl>
+ <FormControl className={classes.formControl}>
+ <ProTooltip tooltip={i18n.t('enterTimePeriodTooltip')}>
+ <TextField
+ id="tagTimePeriod"
+ label={i18n.t('enterTimePeriod')}
+ value={tagTimePeriod.current}
+ disabled={indexing || !Pro}
+ onChange={handleTimePeriodChange}
+ onKeyDown={startSearch}
+ helperText={tagTimePeriodHelper.current}
+ error={tagTimePeriodHelper.current.length < 1}
+ style={{ width: '100%' }}
+ InputProps={{
+ endAdornment: (
+ <InputAdornment
+ position="end"
+ title="201905 for May 2019 / 20190412 for 12th of April 2019 / 20190501~124523 for specific time"
+ >
+ <IconButton>
+ <DateIcon />
+ </IconButton>
+ </InputAdornment>
+ )
+ }}
+ />
+ </ProTooltip>
+ {/* <TextField
+ id="tagPlace"
+ label={i18n.t('GPS coordinates or plus code')}
+ value={tagPlace}
+ disabled={indexing || !Pro}
+ onChange={handlePlaceChange}
+ onKeyDown={startSearch}
+ helperText={tagPlaceHelper}
+ error={tagPlaceHelper.length < 1}
+ InputProps={{
+ endAdornment: (
+ <InputAdornment
+ position="end"
+ title="GPS: 49.23276,12.43123 PlusCode: 8FRG8Q87+6X"
+ >
+ <IconButton onClick={openPlace}>
+ <PlaceIcon />
+ </IconButton>
+ </InputAdornment>
+ )
+ }}
+ /> */}
+ </FormControl>
+ <FormControl
+ className={classes.formControl}
+ disabled={indexing || !Pro}
+ >
+ <ProTooltip tooltip={i18n.t('storedSearchQueriesTooltip')}>
+ <InputLabel shrink htmlFor="saved-searches">
+ {i18n.t('core:savedSearchesTitle')}
+ </InputLabel>
+ <Select
+ style={{ width: '100%' }}
+ 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.length < 1 && (
+ <MenuItem>{i18n.t('noSavedSearches')}</MenuItem>
+ )}
+ {props.searches.map(search => (
+ <MenuItem key={search.uuid} value={search.uuid}>
+ <span style={{ width: '100%' }}>{search.title}</span>
+ </MenuItem>
+ ))}
+ </Select>
+ </ProTooltip>
+ </FormControl>
+ <FormControl className={classes.formControl}>
+ <ButtonGroup fullWidth style={{ justifyContent: 'center' }}>
+ {Pro && (
+ <>
+ <Button
+ variant="outlined"
+ color="secondary"
+ size="medium"
+ style={{ flex: 1 }}
+ onClick={() => saveSearch()}
+ >
+ {i18n.t('searchSaveBtn')}
+ </Button>
+ {props.searchQuery.uuid && (
+ <Button
+ variant="outlined"
+ color="secondary"
+ size="medium"
+ style={{ flex: 1 }}
+ onClick={() => saveSearch(false)}
+ >
+ {i18n.t('searchEditBtn')}
+ </Button>
+ )}
+ </>
+ )}
+ <Button
+ variant="outlined"
+ color="secondary"
+ size="medium"
+ style={{ flex: 1 }}
+ onClick={clearSearch}
+ id="resetSearchButton"
+ >
+ {i18n.t('resetBtn')}
+ </Button>
+ </ButtonGroup>
+ </FormControl>
+
+ {SaveSearchDialog && saveSearchDialogOpened !== undefined && (
+ <SaveSearchDialog
+ open={saveSearchDialogOpened !== undefined}
+ onClose={(searchQuery: TS.SearchQuery) => {
+ setSaveSearchDialogOpened(undefined);
+ if (searchQuery) {
+ if (searchQuery.searchBoxing === 'global') {
+ props.searchAllLocations({
+ ...searchQuery,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ } else {
+ props.searchLocationIndex({
+ ...searchQuery,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ }
+ }
+ }}
+ 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}
+ />
+ )}
+ </>
+ )}
+ </div>
+ </div>
+ );
+};
+
+function mapStateToProps(state) {
+ return {
+ indexing: isIndexing(state),
+ searchQuery: getSearchQuery(state),
+ currentDirectory: getDirectoryPath(state),
+ indexedEntriesCount: getIndexedEntriesCount(state),
+ maxSearchResults: getMaxSearchResults(state),
+ searches: getSearches(state),
+ showUnixHiddenEntries: getShowUnixHiddenEntries(state)
+ };
+}
+
+function mapDispatchToProps(dispatch) {
+ return bindActionCreators(
+ {
+ searchAllLocations: LocationIndexActions.searchAllLocations,
+ setSearchQuery: LocationIndexActions.setSearchQuery,
+ searchLocationIndex: LocationIndexActions.searchLocationIndex,
+ createLocationsIndexes: LocationIndexActions.createLocationsIndexes,
+ loadDirectoryContent: AppActions.loadDirectoryContent,
+ openURLExternally: AppActions.openURLExternally,
+ setSearchResults: AppActions.setSearchResults,
+ addSearches: SearchActions.addSearches,
+ openSearchPanel: AppActions.openSearchPanel
+ },
+ dispatch
+ );
+}
+
+const areEqual = (prevProp, nextProp) =>
+ nextProp.indexing === prevProp.indexing &&
+ nextProp.searchQuery === prevProp.searchQuery &&
+ nextProp.currentDirectory === prevProp.currentDirectory &&
+ nextProp.indexedEntriesCount === prevProp.indexedEntriesCount &&
+ JSON.stringify(nextProp.searches) === JSON.stringify(prevProp.searches) &&
+ JSON.stringify(nextProp.classes) === JSON.stringify(prevProp.classes);
+
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(React.memo(SearchPopover, areEqual));
diff --git a/app/components/StoredSearches.tsx b/app/components/StoredSearches.tsx
new file mode 100644
index 000000000..2276fa95f
--- /dev/null
+++ b/app/components/StoredSearches.tsx
@@ -0,0 +1,194 @@
+/**
+ * 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 React, { useState } from 'react';
+import { bindActionCreators } from 'redux';
+import { connect } from 'react-redux';
+import { Link, IconButton, Collapse, Grid, styled } from '@material-ui/core';
+import EditIcon from '@material-ui/icons/Edit';
+import SearchIcon from '@material-ui/icons/Search';
+import {
+ actions as LocationIndexActions,
+ getSearchQuery
+} from '../reducers/location-index';
+import { getShowUnixHiddenEntries } from '-/reducers/settings';
+import i18n from '../services/i18n';
+import { Pro } from '../pro';
+import { actions as SearchActions, getSearches } from '-/reducers/searches';
+import { TS } from '-/tagspaces.namespace';
+import ArrowDownIcon from '@material-ui/icons/KeyboardArrowDown';
+import ArrowUpIcon from '@material-ui/icons/KeyboardArrowUp';
+
+interface Props {
+ style?: any;
+ searchQuery: TS.SearchQuery;
+ searches: Array<TS.SearchQuery>;
+ searchLocationIndex: (searchQuery: TS.SearchQuery) => void;
+ searchAllLocations: (searchQuery: TS.SearchQuery) => void;
+ showUnixHiddenEntries: boolean;
+}
+
+const SaveSearchDialog = Pro && Pro.UI ? Pro.UI.SaveSearchDialog : false;
+
+const StoredSearches = (props: Props) => {
+ const [saveSearchDialogOpened, setSaveSearchDialogOpened] = useState<
+ TS.SearchQuery
+ >(undefined);
+ const [storedSearchesVisible, setStoredSearchesVisible] = useState<boolean>(
+ true
+ );
+
+ const editSearch = (uuid: string) => {
+ const savedSearch = props.searches.find(search => search.uuid === uuid);
+ if (!savedSearch) {
+ return true;
+ }
+ setSaveSearchDialogOpened(savedSearch);
+ };
+
+ const handleSavedSearchClick = (uuid: string) => {
+ const savedSearch = props.searches.find(search => search.uuid === uuid);
+ if (!savedSearch) {
+ return true;
+ }
+
+ if (savedSearch.searchBoxing === 'global') {
+ props.searchAllLocations({
+ ...savedSearch,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ } else {
+ props.searchLocationIndex({
+ ...savedSearch,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ }
+ };
+
+ const preventDefault = (event: React.SyntheticEvent) =>
+ event.preventDefault();
+
+ const LinkStyled = styled(Link)(({ theme }) => ({
+ ...theme.typography.subtitle1,
+ padding: theme.spacing(1),
+ textAlign: 'left',
+ alignSelf: 'center'
+ // color: theme.palette.text.secondary
+ }));
+
+ return (
+ <div style={{ ...props.style, width: '100%' }}>
+ <Link
+ underline="none"
+ style={{ marginLeft: 10, display: 'flex' }}
+ onClick={() => setStoredSearchesVisible(!storedSearchesVisible)}
+ >
+ <span>{i18n.t('core:savedSearchesTitle')} </span>
+ {storedSearchesVisible ? <ArrowDownIcon /> : <ArrowUpIcon />}
+ </Link>
+ {props.searches.length < 1 && <div>{i18n.t('noSavedSearches')}</div>}
+ <Collapse in={storedSearchesVisible} timeout="auto" unmountOnExit>
+ <Grid container onClick={preventDefault}>
+ {props.searches.map(search => (
+ <React.Fragment key={search.uuid}>
+ <Grid
+ item
+ xs={10}
+ style={{
+ display: 'flex'
+ }}
+ >
+ <SearchIcon style={{ alignSelf: 'center' }} />
+ <LinkStyled
+ variant="body2"
+ onClick={() => handleSavedSearchClick(search.uuid)}
+ >
+ {search.title}
+ </LinkStyled>
+ </Grid>
+ <Grid item xs={2}>
+ <IconButton
+ aria-label={i18n.t('core:searchEditBtn')}
+ onClick={() => editSearch(search.uuid)}
+ data-tid="editSearchTID"
+ >
+ <EditIcon />
+ </IconButton>
+ </Grid>
+ </React.Fragment>
+ ))}
+ </Grid>
+ </Collapse>
+ {SaveSearchDialog && saveSearchDialogOpened !== undefined && (
+ <SaveSearchDialog
+ open={saveSearchDialogOpened !== undefined}
+ onClose={(searchQuery: TS.SearchQuery) => {
+ setSaveSearchDialogOpened(undefined);
+ if (searchQuery) {
+ if (searchQuery.searchBoxing === 'global') {
+ props.searchAllLocations({
+ ...searchQuery,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ } else {
+ props.searchLocationIndex({
+ ...searchQuery,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ }
+ }
+ }}
+ onClearSearch={() => console.log('search deleted')}
+ searchQuery={saveSearchDialogOpened}
+ />
+ )}
+ </div>
+ );
+};
+
+function mapStateToProps(state) {
+ return {
+ searchQuery: getSearchQuery(state),
+ searches: getSearches(state),
+ showUnixHiddenEntries: getShowUnixHiddenEntries(state)
+ };
+}
+
+function mapDispatchToProps(dispatch) {
+ return bindActionCreators(
+ {
+ addSearches: SearchActions.addSearches,
+ searchAllLocations: LocationIndexActions.searchAllLocations,
+ searchLocationIndex: LocationIndexActions.searchLocationIndex
+ },
+ dispatch
+ );
+}
+
+const areEqual = (prevProp, nextProp) =>
+ nextProp.indexing === prevProp.indexing &&
+ nextProp.searchQuery === prevProp.searchQuery &&
+ nextProp.currentDirectory === prevProp.currentDirectory &&
+ nextProp.indexedEntriesCount === prevProp.indexedEntriesCount &&
+ JSON.stringify(nextProp.searches) === JSON.stringify(prevProp.searches) &&
+ JSON.stringify(nextProp.classes) === JSON.stringify(prevProp.classes);
+
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(React.memo(StoredSearches, areEqual));
diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsx
index 9886364a5..812ee4d7a 100644
--- a/app/containers/MainPage.tsx
+++ b/app/containers/MainPage.tsx
@@ -85,6 +85,7 @@ import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import { TS } from '-/tagspaces.namespace';
import PageNotification from '-/containers/PageNotification';
import listen from '-/containers/RendererListener';
+import { actions as LocationIndexActions } from '-/reducers/location-index';
const drawerWidth = 320;
const body = document.getElementsByTagName('body')[0];
@@ -199,6 +200,7 @@ interface Props {
deleteFile: (path: string) => void;
deleteDirectory: (path: string) => void;
user: CognitoUserInterface;
+ setSearchQuery: (searchQuery: TS.SearchQuery) => void;
}
const CreateEditLocationDialog = React.lazy(() =>
@@ -400,7 +402,7 @@ const MainPage = (props: Props) => {
toggleShowHiddenEntries: props.toggleShowUnixHiddenEntries,
showFolderNavigator: props.openLocationManagerPanel,
showTagLibrary: props.openTagLibraryPanel,
- openSearch: props.openSearchPanel,
+ openSearch: () => props.setSearchQuery({ textQuery: '' }), // props.openSearchPanel,
showHelp: props.openHelpFeedbackPanel
};
@@ -766,7 +768,8 @@ function mapDispatchToProps(dispatch) {
setFirstRun: SettingsActions.setFirstRun,
uploadFilesAPI: IOActions.uploadFilesAPI,
deleteDirectory: AppActions.deleteDirectory,
- deleteFile: AppActions.deleteFile
+ deleteFile: AppActions.deleteFile,
+ setSearchQuery: LocationIndexActions.setSearchQuery
},
dispatch
);
diff --git a/app/locales/en/core.json b/app/locales/en/core.json
index 0c5d083ec..875a3e92e 100644
--- a/app/locales/en/core.json
+++ b/app/locales/en/core.json
@@ -224,7 +224,7 @@
"next": "Next",
"prev": "Back",
"done": "Done",
- "searchWordsWithInterval": "Search words separated by space",
+ "searchWordsWithInterval": "Your search query",
"tagsWithInterval": "Tags separated by spaces",
"searchTags": "Tags",
"searchFileTypes": "File Type (e.g. documents, pictures, ...)",