TagSpaces is an offline, open source, document manager with tagging support
add custom thumbnail form and dialog
Stanimir Marinov2c69e05a6cc8
diff --git a/app/components/EntryProperties.js b/app/components/EntryProperties.jsindex 9e4fca513..0203b117f 100644--- a/app/components/EntryProperties.js+++ b/app/components/EntryProperties.js@@ -32,15 +32,15 @@ import TagDropContainer from './TagDropContainer';import EntryTagMenu from './menus/EntryTagMenu';import ColorPickerDialog from './dialogs/ColorPickerDialog';import MoveCopyFilesDialog from './dialogs/MoveCopyFilesDialog';+import FileThumbChooseDialog from './dialogs/FileThumbChooseDialog';import i18n from '../services/i18n';import { getAllPropertiesPromise } from '../services/utils-io';import { formatFileSize } from '../utils/misc';-import { extractContainingDirectoryPath } from '../utils/paths';+import { extractContainingDirectoryPath, getThumbFileLocationForFile } from '../utils/paths';import AppConfig from '../config';import { Pro } from '../pro';import TagsSelect from './TagsSelect';import TransparentBackground from './TransparentBackground';-import { UUID } from 'builder-util-runtime';const styles = theme => ({entryProperties: {@@ -201,6 +201,7 @@ class EntryProperties extends Component<Props, State> {isEditName: false,isEditDescription: false,isMoveCopyFilesDialogOpened: false,+ isFileThumbChooseDialogOpened: false,displayColorPicker: false,isFile: false};@@ -378,6 +379,14 @@ class EntryProperties extends Component<Props, State> {);};+ toggleThumbFilesDialog = () => {+ this.setState(+ ({ isFileThumbChooseDialogOpened }) => ({+ isFileThumbChooseDialogOpened: !isFileThumbChooseDialogOpened+ })+ );+ };+saveEditDescription = () => {this.setState({ isEditDescription: false });};@@ -473,11 +482,19 @@ class EntryProperties extends Component<Props, State> {tagMenuAnchorEl,tagMenuOpened,selectedTag,- isMoveCopyFilesDialogOpened+ isMoveCopyFilesDialogOpened,+ isFileThumbChooseDialogOpened} = this.state;if (!path || path === '') {return <div />;}++ const thumbPath = getThumbFileLocationForFile(path);+ let thumbPathUrl = thumbPath ? 'url("' + thumbPath + '")' : '';+ if (AppConfig.isWin) {+ thumbPathUrl = thumbPathUrl.split('\\').join('\\\\');+ }+return (<div className={classes.entryProperties}><Grid container spacing={8}>@@ -757,6 +774,32 @@ class EntryProperties extends Component<Props, State> {/></FormControl></div>++ <div className={classes.entryItem}>+ <div className={classes.fluidGrid}>+ <Typography+ variant="caption"+ className={classes.entryLabel}+ style={{+ backgroundSize: 'cover',+ backgroundImage: thumbPathUrl,+ height: 150,+ width: '25%'+ }}+ >+ {i18n.t('core:filePreview')}+ </Typography>+ <Button+ color="primary"+ styles={{ paddingBottom: 0 }}+ // disabled={isEditPreview}+ className={classes.button}+ onClick={this.toggleThumbFilesDialog}+ >+ {i18n.t('core:edit')}+ </Button>+ </div>+ </div></Grid><EntryTagMenu@@ -774,6 +817,12 @@ class EntryProperties extends Component<Props, State> {onClose={this.toggleMoveCopyFilesDialog}selectedFiles={[entryPath]}/>+ <FileThumbChooseDialog+ key={uuidv1()}+ open={isFileThumbChooseDialogOpened}+ onClose={this.toggleThumbFilesDialog}+ selectedFile={thumbPath}+ /></div>);}diff --git a/app/components/dialogs/FileThumbChooseDialog.js b/app/components/dialogs/FileThumbChooseDialog.jsnew file mode 100644index 000000000..33dcf8324--- /dev/null+++ b/app/components/dialogs/FileThumbChooseDialog.js@@ -0,0 +1,175 @@+/**+ * 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/>.+ *+ * @flow+ */++import React, { useState, useEffect } from 'react';+import Button from '@material-ui/core/Button';+import List from '@material-ui/core/List';+import ListItem from '@material-ui/core/ListItem';+import ListItemIcon from '@material-ui/core/ListItemIcon';+import Input from '@material-ui/core/Input';+import InputAdornment from '@material-ui/core/InputAdornment';+import IconButton from '@material-ui/core/IconButton';+import FolderIcon from '@material-ui/icons/Folder';+import FileIcon from '@material-ui/icons/InsertDriveFileOutlined';+import DialogActions from '@material-ui/core/DialogActions';+import DialogContent from '@material-ui/core/DialogContent';+import DialogTitle from '@material-ui/core/DialogTitle';+import FormControl from '@material-ui/core/FormControl';+import FormHelperText from '@material-ui/core/FormHelperText';+import Typography from '@material-ui/core/Typography';+import GenericDialog from './GenericDialog';+import i18n from '../../services/i18n';+// import { extractContainingDirectoryPath } from '../../utils/paths';+import PlatformIO from '../../services/platform-io';+import AppConfig from '../../config';+import { extractFileName } from '../../utils/paths';++type Props = {+ classes: Object,+ open: boolean,+ onClose: () => void,+ selectedFile: string+};++const FileThumbChooseDialog = (props: Props) => {+ const [inputError, setInputError] = useState(false);+ const [disableConfirmButton, setDisableConfirmButton] = useState(true);+ const [targetPath, setTargetPath] = useState('');++ useEffect(() => {+ handleValidation();+ });++ function handleValidation() {+ if (targetPath && targetPath.length > 0) {+ setInputError(false);+ setDisableConfirmButton(false);+ } else {+ setInputError(true);+ setDisableConfirmButton(true);+ }+ }++ function handleSetThumb() {+ if (!disableConfirmButton) {+ // props.setThumb(props.selectedFile, targetPath);+ setInputError(false);+ setDisableConfirmButton(true);+ setTargetPath('');+ }+ props.onClose();+ }++ function selectDirectory() {+ if (AppConfig.isElectron) {+ PlatformIO.selectDirectoryDialog().then(selectedPaths => {+ setTargetPath(selectedPaths[0]);+ return true;+ }).catch((err) => {+ console.log('selectDirectoryDialog failed with: ' + err);+ });+ } else {+ // TODO handle case on other platforms+ // this.props.showSelectDirectoryDialog();+ }+ }++ function renderTitle() {+ return (+ <DialogTitle>{i18n.t('core:thumbChooseFileTitle')}</DialogTitle>+ );+ }++ function renderContent() {+ return (+ <DialogContent>+ <List dense style={{ width: 550 }}>+ <ListItem title={props.selectedFile}>+ <ListItemIcon>+ <FileIcon />+ </ListItemIcon>+ <Typography variant="inherit" noWrap>{extractFileName(props.selectedFile)}</Typography>+ </ListItem>+ </List>+ <FormControl fullWidth={true}>+ <Input+ autoFocus+ required+ margin="dense"+ name="targetPath"+ placeholder={i18n.t('core:ThumbPath')}+ fullWidth={true}+ data-tid="targetPathInput"+ onChange={event => {+ const target = event.target;+ setTargetPath(target.value);+ }}+ value={targetPath}+ endAdornment={+ PlatformIO.haveObjectStoreSupport() || AppConfig.isWeb ? undefined :+ (<InputAdornment position="end" style={{ height: 33 }}>+ <IconButton+ data-tid="openDirectoryMoveCopyDialog"+ onClick={selectDirectory}+ >+ <FolderIcon />+ </IconButton>+ </InputAdornment>)+ }+ />+ {inputError && <FormHelperText>Empty Input Field</FormHelperText>}+ </FormControl>+ </DialogContent>+ );+ }++ function renderActions() {+ return (+ <DialogActions>+ <Button+ data-tid="closeMoveCopyDialog"+ onClick={props.onClose}+ >+ {i18n.t('core:cancel')}+ </Button>+ <Button+ onClick={handleSetThumb}+ data-tid="confirmCopyFiles"+ disabled={disableConfirmButton}+ color="primary"+ >+ {i18n.t('core:setThumbButton')}+ </Button>+ </DialogActions>+ );+ }++ return (+ <GenericDialog+ open={props.open}+ onClose={props.onClose}+ // onEnterKey={(event) => onEnterKeyHandler(event, this.onConfirm)}+ renderTitle={renderTitle}+ renderContent={renderContent}+ renderActions={renderActions}+ />+ );+};++export default FileThumbChooseDialog;