diff --git a/src/model/common.model.ts b/src/model/common.model.ts index 7bd6ddb7813d2f8e3d6b6978ba71f994fa5e8056..c6693c49afc1364bc46e18e96e18f549ee29594d 100644 --- a/src/model/common.model.ts +++ b/src/model/common.model.ts @@ -75,8 +75,8 @@ export abstract class AuditedVersionedModel extends VersionedModel { public lastModifiedDate: Date; public static SORT_OPTIONS = { - createdDate: { label: 'Created date', dir: 'DESC' }, - lastModifiedDate: { label: 'Last updated', dir: 'DESC' }, + createdDate: { label: 'Created date', direction: 'DESC' }, + lastModifiedDate: { label: 'Last updated', direction: 'DESC' }, }; public constructor(obj?) { diff --git a/src/model/dataset.model.ts b/src/model/dataset.model.ts index f5c78505d685eec2a17da7c1476e24f1304dbaf7..47ab7061a3d3ac5134b39f66b94e9aa82328983b 100644 --- a/src/model/dataset.model.ts +++ b/src/model/dataset.model.ts @@ -1,4 +1,4 @@ -import {EmptyModel, UuidModel, CurrentPermissions, IUserPermissions, PublishState} from 'model/common.model'; +import { EmptyModel, UuidModel, CurrentPermissions, IUserPermissions, PublishState } from 'model/common.model'; import { RepositoryFile } from 'model/repositoryFile.model'; import { Location } from 'model/location.model'; import { Partner } from 'model/partner.model'; @@ -50,8 +50,12 @@ export class Dataset extends UuidModel implements IUserPermissions { public static SORT_OPTIONS = { title: { label: 'Title' }, - accessionCount: { label: 'Accession count' }, - descriptorCount: { label: 'Descriptor count' }, + accessionCount: { property: 'accessionCount', label: 'Accession count (low to high)', direction: 'ASC' }, + accessionCountD: { property: 'accessionCount', label: 'Accession count (high to low)', direction: 'DESC' }, + descriptorCount: { property: 'descriptorCount', label: 'Descriptor count (low to high)', direction: 'ASC' }, + descriptorCountD: { property: 'descriptorCount', label: 'Descriptor count (high to low)', direction: 'DESC' }, + startDate: { label: 'Experiment start date' }, + endDate: { label: 'Experiment end date' }, versionTag: { label: 'Version' }, ...UuidModel.SORT_OPTIONS, }; diff --git a/src/model/descriptor.model.ts b/src/model/descriptor.model.ts index 19badbeacee3b35752c33f70638300634c5e3c08..8a89ce280bf897160924830dd226bd05e40614ea 100644 --- a/src/model/descriptor.model.ts +++ b/src/model/descriptor.model.ts @@ -71,7 +71,7 @@ export class Descriptor extends UuidModel implements IUserPermissions { // publisher: { label: 'Publisher' }, versionTag: { label: 'Version' }, dataType: { label: 'Data type' }, - key: { label: 'Key', dir: 'DESC' }, + key: { label: 'Key', direction: 'DESC' }, uom: { label: 'Unit of measure' }, columnName: { label: 'Column name' }, owner: { label: 'Maintainer' }, diff --git a/src/ui/common/pagination/index.tsx b/src/ui/common/pagination/index.tsx index e69366ef4aa8ff30bc39a6ab490c1fe09dc9bed7..73299c887d9c9c483cfd4b79a3c252cbb250db63 100644 --- a/src/ui/common/pagination/index.tsx +++ b/src/ui/common/pagination/index.tsx @@ -6,131 +6,131 @@ import FastRewind from '@material-ui/icons/FastRewind'; import PlayArrow from '@material-ui/icons/PlayArrow'; import Button from '@material-ui/core/Button'; import Grid from '@material-ui/core/Grid'; -import {StyleRules, withStyles} from '@material-ui/core/styles'; +import { StyleRules, withStyles } from '@material-ui/core/styles'; import Select from '@material-ui/core/Select'; import Input from '@material-ui/core/Input'; import MenuItem from '@material-ui/core/MenuItem'; import compose from 'recompose/compose'; import withWidth from '@material-ui/core/withWidth'; import Hidden from '@material-ui/core/Hidden'; -import {Breakpoint} from '@material-ui/core/styles/createBreakpoints'; +import { Breakpoint } from '@material-ui/core/styles/createBreakpoints'; import Number from 'ui/common/Number'; -import {Page} from 'model/common.model'; +import { Page } from 'model/common.model'; interface IPaginationComponentProps extends React.ClassAttributes { - classes: any; - t: any; + classes: any; + t: any; - width: Breakpoint; - pageObj: Page; - onChange: (page?: number, results?: number, sortBy?: string, dir?: string) => void; - displayName: string; - sortBy?: string; - sortOptions?: object; - infinite?: boolean; + width: Breakpoint; + pageObj: Page; + onChange: (page?: number, results?: number, sortBy?: string, dir?: string) => void; + displayName: string; + sortBy?: string; + sortOptions?: object; + infinite?: boolean; } const styles = (theme) => ({ - root: { - backgroundColor: '#D4D2C6', - padding: '1px 20px 1px', - fontFamily: 'Roboto', + root: { + backgroundColor: '#D4D2C6', + padding: '1px 20px 1px', + fontFamily: 'Roboto', + }, + arrowRevert: { + webkitTransform: 'rotate(180deg)', + transform: 'rotate(180deg)', + }, + checkedPage: { + width: '50px', + borderBottom: '1px solid black', + display: 'inline-block', + textAlign: 'center', + padding: '0 0 3px', + margin: '0 8px', + position: 'relative', + bottom: '2px', + }, + /* tslint:disable */ + paginationBut: { + backgroundColor: '#e8e6e0', + width: '30px', + height: '30px', + margin: '10px 5px', + minHeight: 'auto', + '& > span > svg': { + width: '17px', + height: '17px', }, - arrowRevert: { - webkitTransform: 'rotate(180deg)', - transform: 'rotate(180deg)', + }, + showResults: { + float: 'right', + marginTop: '12px', + marginLeft: '12px', + '& > div > div': { + marginRight: '35px', + [theme.breakpoints.down('sm')]: { + marginRight: '0px', + }, }, - checkedPage: { - width: '50px', - borderBottom: '1px solid black', - display: 'inline-block', - textAlign: 'center', - padding: '0 0 3px', - margin: '0 8px', - position: 'relative', - bottom: '2px', + '& > div > svg': { + top: '1px', + width: '26px', + height: '26px', + color: '#050708', + [theme.breakpoints.down('sm')]: { + top: '0px', + }, }, - /* tslint:disable */ - paginationBut: { - backgroundColor: '#e8e6e0', - width: '30px', - height: '30px', - margin: '10px 5px', - minHeight: 'auto', - '& > span > svg': { - width: '17px', - height: '17px', - }, + '& > div > div:focus': { + backgroundColor: 'transparent', }, - showResults: { - float: 'right', - marginTop: '12px', - marginLeft: '12px', - '& > div > div': { - marginRight: '35px', - [theme.breakpoints.down('sm')]: { - marginRight: '0px', - }, - }, - '& > div > svg': { - top: '1px', - width: '26px', - height: '26px', - color: '#050708', - [theme.breakpoints.down('sm')]: { - top: '0px', - }, - }, - '& > div > div:focus': { - backgroundColor: 'transparent', - }, - [theme.breakpoints.down('sm')]: { - border: '1px #e8e6e0 solid', - borderRadius: '3px', - padding: '2px 0 0 7px', - margin: '9px 0 0 4px', - '&:before': { - content: 'none', - }, - }, + [theme.breakpoints.down('sm')]: { + border: '1px #e8e6e0 solid', + borderRadius: '3px', + padding: '2px 0 0 7px', + margin: '9px 0 0 4px', + '&:before': { + content: 'none', + }, }, - floatRight: { - float: 'right', - '&:after': { - content: 'none', - }, + }, + floatRight: { + float: 'right', + '&:after': { + content: 'none', }, - liItem: { - height: '34px', - fontSize: '14px', - '&:focus': { - backgroundColor: '#E8E5E0', - }, - '&:hover': { - backgroundColor: '#E8E5E0', - }, + }, + liItem: { + height: '34px', + fontSize: '14px', + '&:focus': { + backgroundColor: '#E8E5E0', }, - /* tslint:enable */ - textPagination: { - lineHeight: '50px', + '&:hover': { + backgroundColor: '#E8E5E0', }, - bold: { - fontWeight: 'bold', - }, - floatLeft: { - float: 'left', - paddingRight: '5px', - }, - verticalAlign: { - verticalAlign: 'text-bottom', - paddingLeft: '5px', - [theme.breakpoints.down('sm')]: { - padding: '0 5px 0px 2px', - }, - }, - inline: { - display: 'inline', + }, + /* tslint:enable */ + textPagination: { + lineHeight: '50px', + }, + bold: { + fontWeight: 'bold', + }, + floatLeft: { + float: 'left', + paddingRight: '5px', + }, + verticalAlign: { + verticalAlign: 'text-bottom', + paddingLeft: '5px', + [theme.breakpoints.down('sm')]: { + padding: '0 5px 0px 2px', }, + }, + inline: { + display: 'inline', + }, }) as StyleRules; const results = [5, 10, 20, 40, 50, 75, 100]; @@ -138,164 +138,179 @@ const mobile = ['sm', 'xs'] as Breakpoint[]; class PaginationComponent extends React.Component { - public render() { - const { t, classes, displayName, width, pageObj, onChange, sortOptions, infinite } = this.props; - let { sortBy } = this.props; + public render() { + const { t, classes, displayName, width, pageObj, onChange, sortOptions, infinite } = this.props; + let { sortBy } = this.props; - if (!sortBy) { - sortBy = pageObj && pageObj.sort ? pageObj.sort[0].property : null; - if (sortBy && sortOptions && sortOptions[sortBy]) { - // console.log('Using auto-detected sortBy', sortBy); - } else { - sortBy = ''; + if (pageObj && pageObj.sort && pageObj && pageObj.sort[0] !== null) { + sortBy = pageObj && pageObj.sort ? pageObj.sort[0].property : null; + if (sortBy && sortOptions) { + console.log('Using auto-detected sortBy', sortBy); + sortBy = Object.keys(sortOptions).find((key) => { + const sortOption = sortOptions[key]; + console.log(`Inspecting for ${pageObj.sort[0].property}`, sortOption); + if (sortOption.property && pageObj.sort[0].property === sortOption.property) { + if (sortOption.direction && pageObj.sort[0].direction !== sortOption.direction) { + console.log('Direction doesnt match'); + return false; + } + console.log('Matching sort'); + return true; } - } + return false; + }) || sortBy; + console.log(`Sort by is ${sortBy}`, sortBy); + } + } else { + sortBy = ''; + } - const isMobile = mobile.indexOf(width) !== -1; + const isMobile = mobile.indexOf(width) !== -1; - const fireSortChange = (page, results, sortBy) => { - if (sortBy && sortOptions && sortOptions[sortBy] && typeof sortOptions[sortBy] !== 'string') { - onChange(page, results, sortBy, sortOptions[sortBy].dir); - } else { - onChange(page, results, sortBy); - } - }; + const fireSortChange = (page, results, sortBy) => { + if (sortBy && sortOptions && sortOptions[sortBy] && typeof sortOptions[sortBy] !== 'string') { + onChange(page, results, sortOptions[sortBy].property || sortBy, sortOptions[sortBy].direction); + } else { + onChange(page, results, sortBy); + } + }; - return ( - - -
- { t('common:paginate.numberOfItems', { count: pageObj ? pageObj.totalElements : 0, what: t(displayName || 'common:label.item', { count: pageObj ? pageObj.totalElements : 0 }) }) } -
- { ! infinite && - } - MenuProps={ { - PaperProps: { - style: { - width: 188, - }, - }, - } } - > - { - results.map((e, i) => ( - - { isMobile ? e : `Show ${e} results` } - - )) - } - - } - { - sortOptions && ( - } - MenuProps={ { - PaperProps: { - style: { - width: 188, - }, - }, - } } - > - Sort By - { - Object.keys(sortOptions).map((key, i) => { - if (typeof sortOptions[key] === 'string') { - return ( - - { sortOptions[key] } - - ); - } else { - return ( - - { sortOptions[key].label } - - ); - } - }) - } - - ) - } - { ! infinite && -
- - - { pageObj ? pageObj.number + 1 : 0 }/{ pageObj ? pageObj.totalPages : 0 } - - - - - - - - - { pageObj ? pageObj.number + 1 : 0 } - - - - - - - - of pages - -
+ return ( + + +
+ { t('common:paginate.numberOfItems', { count: pageObj ? pageObj.totalElements : 0, what: t(displayName || 'common:label.item', { count: pageObj ? pageObj.totalElements : 0 }) }) } +
+ { !infinite && + } + MenuProps={ { + PaperProps: { + style: { + width: 188, + }, + }, + } } + > + { + results.map((e, i) => ( + + { isMobile ? e : `Show ${e} results` } + + )) + } + + } + { + sortOptions && ( + } + MenuProps={ { + PaperProps: { + style: { + width: 200, + }, + }, + } } + > + Sort By + { + Object.keys(sortOptions).map((key, i) => { + if (typeof sortOptions[key] === 'string') { + return ( + + { sortOptions[key] } + + ); + } else { + return ( + + { sortOptions[key].label } + + ); } -
-
- ); - } + }) + } + + ) + } + { !infinite && +
+ + + { pageObj ? pageObj.number + 1 : 0 }/{ pageObj ? pageObj.totalPages : 0 } + + + + + + + + + { pageObj ? pageObj.number + 1 : 0 } + + + + + + + + of pages + +
+ } +
+
+ ); + } } export default translate()(compose(withStyles(styles), withWidth())(PaginationComponent));