Skip to content

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

add pagination (#1183)

Stanimir34b268abc83a
diff --git a/app/locales/en/core.json b/app/locales/en/core.json
index 371fa46d8..010bca89c 100644
--- a/app/locales/en/core.json
+++ b/app/locales/en/core.json
@@ -469,5 +469,9 @@
"fileExist": "File with the same name already exist",
"importMacTags": "Import macOS tags",
"cantDownloadLocalFile": "You can't download local files",
+ "perspectiveSettingsTitle": "Perspective Settings",
+ "unlimited": "Unlimited",
+ "pageLimit": "Page Limit",
+ "pageLimitHelp": "Set number of files per page",
"-": "-"
}
diff --git a/app/perspectives/grid-perspective/components/GridOptionsMenu.tsx b/app/perspectives/grid-perspective/components/GridOptionsMenu.tsx
index 4d66b3907..e8378b9b1 100644
--- a/app/perspectives/grid-perspective/components/GridOptionsMenu.tsx
+++ b/app/perspectives/grid-perspective/components/GridOptionsMenu.tsx
@@ -28,6 +28,7 @@ import ThumbnailCoverIcon from '@material-ui/icons/PhotoSizeSelectActual';
import ThumbnailContainIcon from '@material-ui/icons/PhotoSizeSelectLarge';
import RadioCheckedIcon from '@material-ui/icons/RadioButtonChecked';
import RadioUncheckedIcon from '@material-ui/icons/RadioButtonUnchecked';
+import SettingsIcon from '@material-ui/icons/Settings';
import HelpIcon from '@material-ui/icons/Help';
import i18n from '-/services/i18n';
@@ -46,6 +47,7 @@ interface Props {
changeEntrySize: (entrySize: string) => void;
changeSingleClickAction: (actionType: string) => void;
openHelpWebPage: () => void;
+ openSettings: () => void;
}
const GridOptionsMenu = (props: Props) => {
@@ -63,7 +65,8 @@ const GridOptionsMenu = (props: Props) => {
changeSingleClickAction,
entrySize,
singleClickAction,
- openHelpWebPage
+ openHelpWebPage,
+ openSettings
} = props;
return (
@@ -195,6 +198,18 @@ const GridOptionsMenu = (props: Props) => {
<ListItemText primary={i18n.t('core:singleClickSelects')} />
</MenuItem>
<Divider />
+ <MenuItem
+ data-tid="gridPerspectiveSettings"
+ title={i18n.t('core:settings')}
+ aria-label={i18n.t('core:settings')}
+ onClick={openSettings}
+ >
+ <ListItemIcon>
+ <SettingsIcon />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:settings')} />
+ </MenuItem>
+ <Divider />
<MenuItem
data-tid="gridPerspectiveHelp"
title={i18n.t('core:help')}
diff --git a/app/perspectives/grid-perspective/components/GridPagination.tsx b/app/perspectives/grid-perspective/components/GridPagination.tsx
new file mode 100644
index 000000000..e85492fd1
--- /dev/null
+++ b/app/perspectives/grid-perspective/components/GridPagination.tsx
@@ -0,0 +1,149 @@
+/**
+ * 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, useEffect } from 'react';
+import { connect } from 'react-redux';
+import Typography from '@material-ui/core/Typography';
+import Pagination from '@material-ui/lab/Pagination';
+import { FileSystemEntry } from '-/services/utils-io';
+import i18n from '-/services/i18n';
+import { getCurrentDirectoryColor, isLoading } from '-/reducers/app';
+import AppConfig from '-/config';
+
+interface Props {
+ className: string;
+ style: Object;
+ theme: any;
+ // gridRef: Object;
+ directories: Array<FileSystemEntry>;
+ showDirectories: boolean;
+ files: Array<FileSystemEntry>;
+ renderCell: (FileSystemEntry) => void;
+ currentDirectoryColor: string;
+ isAppLoading: boolean;
+ currentPage: number;
+ gridPageLimit: number;
+}
+
+const GridPagination = (props: Props) => {
+ const {
+ className,
+ style,
+ theme,
+ directories,
+ showDirectories,
+ renderCell,
+ isAppLoading,
+ currentDirectoryColor,
+ gridPageLimit,
+ currentPage
+ } = props;
+ let { files } = props;
+ const [page, setPage] = useState(currentPage);
+
+ useEffect(() => {
+ setPage(props.currentPage);
+ }, [props.files]);
+
+ const handleChange = (event, value) => {
+ // props.currentPage = value;
+ setPage(value);
+ };
+
+ let paginationCount = 10;
+
+ let showPagination = false;
+ if (gridPageLimit && files.length > gridPageLimit) {
+ paginationCount = Math.ceil(files.length / gridPageLimit);
+ const start = (page - 1) * gridPageLimit;
+ files = files.slice(start, start + gridPageLimit);
+ showPagination = true;
+ }
+
+ return (
+ <div
+ style={{
+ height: '100%',
+ backgroundColor: theme.palette.background.default
+ }}
+ >
+ <div
+ style={{
+ height: '100%',
+ // @ts-ignore
+ overflowY: AppConfig.isFirefox ? 'auto' : 'overlay',
+ backgroundColor: currentDirectoryColor || 'transparent'
+ }}
+ >
+ <div
+ className={className}
+ style={style}
+ /* ref={ref => {
+ gridRef = ref;
+ }} */
+ data-tid="perspectiveGridFileTable"
+ >
+ {page === 1 && directories.map(entry => renderCell(entry))}
+ {files.map(entry => renderCell(entry))}
+ {isAppLoading && (
+ <Typography style={{ padding: 15 }}>
+ {i18n.t('core:loading')}
+ </Typography>
+ )}
+ {!isAppLoading && files.length < 1 && directories.length < 1 && (
+ <Typography style={{ padding: 15 }}>
+ {i18n.t('core:noFileFolderFound')}
+ </Typography>
+ )}
+ {!isAppLoading &&
+ files.length < 1 &&
+ directories.length >= 1 &&
+ !showDirectories && (
+ <Typography style={{ padding: 15 }}>
+ {i18n.t('core:noFileButFoldersFound')}
+ </Typography>
+ )}
+ </div>
+ {showPagination && (
+ <p
+ style={{
+ display: 'flex',
+ justifyContent: 'center',
+ alignItems: 'center'
+ }}
+ >
+ <Pagination
+ count={paginationCount}
+ page={page}
+ onChange={handleChange}
+ />
+ </p>
+ )}
+ </div>
+ </div>
+ );
+};
+
+function mapStateToProps(state) {
+ return {
+ isAppLoading: isLoading(state),
+ currentDirectoryColor: getCurrentDirectoryColor(state)
+ };
+}
+
+export default connect(mapStateToProps)(GridPagination);
diff --git a/app/perspectives/grid-perspective/components/GridSettingsDialog.tsx b/app/perspectives/grid-perspective/components/GridSettingsDialog.tsx
new file mode 100644
index 000000000..804a07e69
--- /dev/null
+++ b/app/perspectives/grid-perspective/components/GridSettingsDialog.tsx
@@ -0,0 +1,120 @@
+/**
+ * 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 from 'react';
+import {
+ Dialog,
+ DialogActions,
+ DialogContent,
+ DialogTitle,
+ withMobileDialog,
+ FormControl,
+ InputLabel,
+ Select,
+ MenuItem,
+ Button,
+ FormHelperText
+} from '@material-ui/core';
+import i18n from '-/services/i18n';
+
+interface Props {
+ open: boolean;
+ fullScreen: boolean;
+ gridPageLimit: number;
+ onClose: () => void;
+ setGridPageLimit: (number) => void;
+}
+
+const GridSettingsDialog = (props: Props) => {
+ const { open, onClose, fullScreen, gridPageLimit } = props;
+ let newGridPageLimit = gridPageLimit;
+
+ const handleGridPaginationLimit = (
+ event: React.ChangeEvent<HTMLInputElement>
+ ) => {
+ const { target } = event;
+ const { value, name } = target;
+
+ if (name === 'limit') {
+ newGridPageLimit = roughScale(value);
+ }
+ };
+
+ function roughScale(x) {
+ const parsed = parseInt(x, 10);
+ if (isNaN(parsed)) {
+ return 100;
+ }
+ return parsed;
+ }
+
+ return (
+ <Dialog
+ open={open}
+ onClose={onClose}
+ fullScreen={fullScreen}
+ keepMounted
+ scroll="paper"
+ >
+ <DialogTitle>{i18n.t('core:perspectiveSettingsTitle')}</DialogTitle>
+ <DialogContent>
+ <FormControl
+ fullWidth={true}
+ /* error={this.state.inputError} */
+ style={{ overflow: 'visible' }}
+ >
+ <InputLabel shrink htmlFor="pageLimit">
+ {i18n.t('core:pageLimit')}
+ </InputLabel>
+ <Select
+ name="limit"
+ defaultValue={gridPageLimit}
+ onChange={handleGridPaginationLimit}
+ >
+ <MenuItem value={20}>20</MenuItem>
+ <MenuItem value={50}>50</MenuItem>
+ <MenuItem value={100}>100</MenuItem>
+ <MenuItem value={500}>500</MenuItem>
+ <MenuItem value={undefined}>{i18n.t('core:unlimited')}</MenuItem>
+ </Select>
+ <FormHelperText>{i18n.t('core:pageLimitHelp')}</FormHelperText>
+ </FormControl>
+ </DialogContent>
+ <DialogActions>
+ <Button
+ data-tid="cancelDialog"
+ title={i18n.t('core:cancel')}
+ onClick={onClose}
+ color="primary"
+ >
+ {i18n.t('core:cancel')}
+ </Button>
+
+ <Button
+ data-tid="closeGridSettingsDialog"
+ onClick={() => props.setGridPageLimit(newGridPageLimit)}
+ color="primary"
+ >
+ {i18n.t('core:ok')}
+ </Button>
+ </DialogActions>
+ </Dialog>
+ );
+};
+
+export default withMobileDialog()(GridSettingsDialog);
diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsx
index 0abfe1a4c..9b270486d 100644
--- a/app/perspectives/grid-perspective/components/MainContainer.tsx
+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx
@@ -51,8 +51,6 @@ import {
actions as AppActions,
getLastSelectedEntry,
getSelectedEntries,
- getCurrentDirectoryColor,
- isLoading,
isReadOnlyMode
} from '-/reducers/app';
import TaggingActions from '-/reducers/tagging-actions';
@@ -63,6 +61,8 @@ import GridOptionsMenu from './GridOptionsMenu';
import { getLocation, Location, locationType } from '-/reducers/locations';
import PlatformIO from '-/services/platform-io';
import { extractFileName } from '-/utils/paths';
+import GridPagination from '-/perspectives/grid-perspective/components/GridPagination';
+import GridSettingsDialog from '-/perspectives/grid-perspective/components/GridSettingsDialog';
const settings = JSON.parse(localStorage.getItem('tsPerspectiveGrid')); // loading settings
@@ -71,11 +71,9 @@ interface Props {
theme: any;
desktopMode: boolean;
currentDirectoryPath: string;
- currentDirectoryColor: string;
lastSelectedEntryPath: string | null;
selectedEntries: Array<any>;
supportedFileTypes: Array<any>;
- isAppLoading: boolean;
isReadOnlyMode: boolean;
openFile: (path: string, isFile: boolean) => void;
getNextFile: () => any;
@@ -131,8 +129,10 @@ interface State {
isMoveCopyFilesDialogOpened: boolean;
isAddRemoveTagsDialogOpened: boolean;
isFileRenameDialogOpened: boolean;
+ isGridSettingsDialogOpened: boolean;
selectedEntryPath: string;
selectedTag: Tag | null;
+ gridPageLimit: number;
}
class GridPerspective extends React.Component<Props, State> {
@@ -182,7 +182,10 @@ class GridPerspective extends React.Component<Props, State> {
isMoveCopyFilesDialogOpened: false,
isAddRemoveTagsDialogOpened: false,
isFileRenameDialogOpened: false,
- selectedTag: null
+ isGridSettingsDialogOpened: false,
+ selectedTag: null,
+ gridPageLimit:
+ settings && settings.gridPageLimit ? settings.gridPageLimit : 100
};
}
@@ -224,6 +227,14 @@ class GridPerspective extends React.Component<Props, State> {
sortByCriteria(data, criteria, order)
);
+ getDirs = memoize(sortedContent =>
+ sortedContent.filter(entry => !entry.isFile)
+ );
+
+ getFiles = memoize(sortedContent =>
+ sortedContent.filter(entry => entry.isFile)
+ );
+
makeFirstSelectedEntryVisible = () => {
const { selectedEntries } = this.props;
if (selectedEntries && selectedEntries.length > 0) {
@@ -250,7 +261,8 @@ class GridPerspective extends React.Component<Props, State> {
singleClickAction: this.state.singleClickAction,
doubleClickAction: this.state.doubleClickAction,
entrySize: this.state.entrySize,
- thumbnailMode: this.state.thumbnailMode
+ thumbnailMode: this.state.thumbnailMode,
+ gridPageLimit: this.state.gridPageLimit
};
localStorage.setItem('tsPerspectiveGrid', JSON.stringify(settingsObj));
}
@@ -260,12 +272,17 @@ class GridPerspective extends React.Component<Props, State> {
messagesContainer.scrollTop = messagesContainer.scrollHeight;
}; */
- mainGrid;
+ // mainGrid;
handleLayoutSwitch = (layoutType: string) => {
this.setState({ layoutType }, this.saveSettings);
};
+ handleGridPageLimit = (gridPageLimit: number) => {
+ this.handleCloseDialogs();
+ this.setState({ gridPageLimit }, this.saveSettings);
+ };
+
handleSortBy = sortBy => {
this.closeSortingMenu();
this.setState(
@@ -429,6 +446,11 @@ class GridPerspective extends React.Component<Props, State> {
);
};
+ openSettings = () => {
+ this.closeOptionsMenu();
+ this.openGridSettingsDialog();
+ };
+
handleGridCellDblClick = (event, fsEntry: FileSystemEntry) => {
this.props.setSelectedEntries([]);
if (this.props.currentLocation.type === locationType.TYPE_CLOUD) {
@@ -546,7 +568,8 @@ class GridPerspective extends React.Component<Props, State> {
isFileRenameDialogOpened: false,
isDeleteMultipleFilesDialogOpened: false,
isAddRemoveTagsDialogOpened: false,
- isMoveCopyFilesDialogOpened: false
+ isMoveCopyFilesDialogOpened: false,
+ isGridSettingsDialogOpened: false
});
if (clearSelection) {
this.clearSelection();
@@ -569,6 +592,10 @@ class GridPerspective extends React.Component<Props, State> {
this.setState({ isAddRemoveTagsDialogOpened: true });
};
+ openGridSettingsDialog = () => {
+ this.setState({ isGridSettingsDialogOpened: true });
+ };
+
handleFileMoveDrop = (item, monitor) => {
if (this.props.isReadOnlyMode) {
this.props.showNotification(
@@ -754,9 +781,7 @@ class GridPerspective extends React.Component<Props, State> {
render() {
const {
classes,
- isAppLoading,
directoryContent,
- currentDirectoryColor,
selectedEntries,
loadParentDirectoryContent,
theme
@@ -766,8 +791,8 @@ class GridPerspective extends React.Component<Props, State> {
.filter(fsEntry => fsEntry.isFile)
.map(fsentry => fsentry.path);
const sortedContent = this.sort(directoryContent, sortBy, orderBy);
- const sortedDirectories = sortedContent.filter(entry => !entry.isFile);
- const sortedFiles = sortedContent.filter(entry => entry.isFile);
+ const sortedDirectories = this.getDirs(sortedContent);
+ const sortedFiles = this.getFiles(sortedContent);
let entryWidth = 200;
if (entrySize === 'small') {
entryWidth = 150;
@@ -777,7 +802,14 @@ class GridPerspective extends React.Component<Props, State> {
entryWidth = 300;
}
return (
- <div style={{ height: 'calc(100% - 104px)' }}>
+ <div
+ style={{
+ height:
+ 'calc(100% - ' +
+ (AppConfig.isCordova ? '290' /* '595' */ : '104') + // todo handle cordova screen sizes
+ 'px)'
+ }}
+ >
<style>
{`
#gridCellTags:hover, #gridCellDescription:hover {
@@ -802,62 +834,27 @@ class GridPerspective extends React.Component<Props, State> {
handleOptionsMenu={this.handleOptionsMenu}
/>
<GlobalHotKeys keyMap={this.keyMap} handlers={this.keyBindingHandlers}>
- <div
+ <GridPagination
+ gridPageLimit={this.state.gridPageLimit}
+ className={
+ layoutType === 'grid'
+ ? classes.gridContainer
+ : classes.rowContainer
+ }
style={{
- height: '100%',
- backgroundColor: theme.palette.background.default
+ gridTemplateColumns:
+ layoutType === 'grid'
+ ? 'repeat(auto-fit,minmax(' + entryWidth + 'px,1fr))'
+ : 'none'
}}
- >
- <div
- style={{
- height: '100%',
- // @ts-ignore
- overflowY: AppConfig.isFirefox ? 'auto' : 'overlay',
- backgroundColor: currentDirectoryColor || 'transparent'
- }}
- >
- <div
- className={
- layoutType === 'grid'
- ? classes.gridContainer
- : classes.rowContainer
- }
- style={{
- gridTemplateColumns:
- layoutType === 'grid'
- ? 'repeat(auto-fit,minmax(' + entryWidth + 'px,1fr))'
- : 'none'
- }}
- ref={ref => {
- this.mainGrid = ref;
- }}
- data-tid="perspectiveGridFileTable"
- >
- {sortedDirectories.map(entry => this.renderCell(entry))}
- {sortedFiles.map(entry => this.renderCell(entry))}
- {isAppLoading && (
- <Typography style={{ padding: 15 }}>
- {i18n.t('core:loading')}
- </Typography>
- )}
- {!isAppLoading &&
- sortedFiles.length < 1 &&
- sortedDirectories.length < 1 && (
- <Typography style={{ padding: 15 }}>
- {i18n.t('core:noFileFolderFound')}
- </Typography>
- )}
- {!isAppLoading &&
- sortedFiles.length < 1 &&
- sortedDirectories.length >= 1 &&
- !this.state.showDirectories && (
- <Typography style={{ padding: 15 }}>
- {i18n.t('core:noFileButFoldersFound')}
- </Typography>
- )}
- </div>
- </div>
- </div>
+ theme={theme}
+ // gridRef={this.mainGrid}
+ directories={sortedDirectories}
+ showDirectories={this.state.showDirectories}
+ files={sortedFiles}
+ renderCell={this.renderCell}
+ currentPage={1}
+ />
</GlobalHotKeys>
<AddRemoveTagsDialog
open={this.state.isAddRemoveTagsDialogOpened}
@@ -867,6 +864,12 @@ class GridPerspective extends React.Component<Props, State> {
removeAllTags={this.props.removeAllTags}
selectedEntries={this.props.selectedEntries}
/>
+ <GridSettingsDialog
+ open={this.state.isGridSettingsDialogOpened}
+ onClose={this.handleCloseDialogs}
+ setGridPageLimit={this.handleGridPageLimit}
+ gridPageLimit={this.state.gridPageLimit}
+ />
<MoveCopyFilesDialog
key={uuidv1()}
open={this.state.isMoveCopyFilesDialogOpened}
@@ -959,6 +962,7 @@ class GridPerspective extends React.Component<Props, State> {
singleClickAction={this.state.singleClickAction}
changeEntrySize={this.changeEntrySize}
openHelpWebPage={this.openHelpWebPage}
+ openSettings={this.openSettings}
/>
</div>
);
@@ -984,10 +988,8 @@ function mapActionCreatorsToProps(dispatch) {
function mapStateToProps(state) {
return {
supportedFileTypes: getSupportedFileTypes(state),
- isAppLoading: isLoading(state),
isReadOnlyMode: isReadOnlyMode(state),
lastSelectedEntryPath: getLastSelectedEntry(state),
- currentDirectoryColor: getCurrentDirectoryColor(state),
desktopMode: getDesktopMode(state),
selectedEntries: getSelectedEntries(state),
keyBindings: getKeyBindingObject(state),
diff --git a/app/perspectives/grid-perspective/components/styles.css.tsx b/app/perspectives/grid-perspective/components/styles.css.tsx
index bd2132a3d..74d123677 100644
--- a/app/perspectives/grid-perspective/components/styles.css.tsx
+++ b/app/perspectives/grid-perspective/components/styles.css.tsx
@@ -23,7 +23,7 @@ export default (theme: any): any => ({
gridGap: '0px 0px',
padding: 0,
paddingRight: 10,
- paddingBottom: 200
+ paddingBottom: 20
},
rowContainer: {
display: 'grid',
@@ -31,7 +31,7 @@ export default (theme: any): any => ({
padding: 0,
paddingRight: 10,
margin: 0,
- paddingBottom: 200
+ paddingBottom: 10
},
gridCell: {
border: '2px solid transparent',
diff --git a/package.json b/package.json
index 169ac67ee..ee6d706f8 100644
--- a/package.json
+++ b/package.json
@@ -78,7 +78,7 @@
"test-e2e-dev": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 node --trace-warnings ./tests/runTests.js e2e-dev",
"test-unit": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 jest --verbose ./tests/unit/",
"test-all": "yarn build && yarn test-unit && yarn build-e2e && yarn test-e2e",
- "test-one": "jest --config=jest.config.js -t 'show_sub_folders' --verbose ./tests/e2e/",
+ "test-one": "jest --config=jest.config.js -t 'show_sub_folders' --verbose ./tests/e2e/",
"test-e2e-electron": "node -r @babel/register ./internals/scripts/CheckBuiltsExist.js && cross-env NODE_ENV=test jest --config=jest.config.js -t 'electron' --verbose ./tests/e2e/",
"test-e2e-electron-minio": "node -r @babel/register ./internals/scripts/CheckBuiltsExist.js && cross-env NODE_JEST=test_minio jest --verbose ./tests/e2e/",
"test-e2e-web": "yarn prepare-web && cross-env NODE_JEST=test_web jest -t 'web' --verbose ./tests/e2e/",