Commit 5afc0c23 authored by Matija Obreza's avatar Matija Obreza
Browse files

Page and FilteredPage updated

- removed property totalElements (=== content.length)
- removed property first (=== number === 0)
- added reSort and nextPage methods
parent 7827d113
import Page, { IPageRequest } from 'model/Page';
import Page, { IPageRequest, SortDirection } from 'model/Page';
/*
* Defined in OpenAPI as '#/definitions/Page<T>'
*/
class FilteredPage<T> extends Page<T> {
filterCode: string;
filter: any;
public filterCode?: string;
public filter?: any;
public static reSort(paged: FilteredPage<any>, property?: string, direction?: SortDirection): FilteredPage<any> {
const resorted: FilteredPage<any> = {
filterCode: paged ? paged.filterCode : undefined,
number: undefined, // because loadMore defaults to 0
size: undefined,
sort: [ {
property: property ? property : undefined,
direction: direction ? direction : undefined,
} ],
};
console.log(`reSort for prop=${property} dir=${direction}`, resorted);
return resorted;
}
}
export { FilteredPage as default, IPageRequest };
/*
* Defined in OpenAPI as '#/definitions/Page<T>'
*/
class Page<T> {
public content: T[];
public first: boolean;
public last: boolean;
public number: number;
public numberOfElements: number;
public size: number;
public sort: ISort[];
public totalElements: number;
public totalPages: number;
public content?: T[];
public last?: boolean;
public number?: number;
public totalElements?: number;
public totalPages?: number;
public size?: number;
public sort?: ISort[];
public static nextPage(paged?: Page<any>): IPageRequest {
return {
page: paged ? paged.number : 0,
size: paged ? paged.size : 50,
direction: paged ? paged.sort[0].direction : undefined,
properties: paged ? [ paged.sort[0].property ] : undefined,
const nextPage: IPageRequest = {
page: paged && (paged.number || paged.number === 0) ? paged.number + 1 : 0,
size: paged && paged.size || 50,
direction: paged && paged.sort && paged.sort[0].direction || undefined,
properties: paged && paged.sort && paged.sort[0].property ? [ paged.sort[0].property ] : undefined,
};
console.log('Current/Next', paged, nextPage);
return nextPage;
}
public static fromQueryString(qs: any): IPageRequest {
return {
page: 0,
size: undefined,
direction: qs ? qs.d : undefined,
properties: qs ? [ qs.s ] : undefined,
direction: qs ? qs.d : undefined,
};
}
public static reSort(paged: Page<any>, property?: string, direction?: SortDirection): Page<any> {
const resorted: Page<any> = {
number: undefined, // because loadMore defaults to 0
size: undefined,
sort: [ {
property: property ? property : undefined,
direction: direction ? direction : undefined,
} ],
};
console.log(`Resort for prop=${property} dir={direction}`, resorted);
return resorted;
}
}
export enum SortDirection {
......
......@@ -77,7 +77,6 @@ function dashboardSubsets(state = INITIAL_STATE, action: IReducerAction) {
: update(state, {
paged: {
content: {$splice: [[removeIndex, 1]]},
numberOfElements: {$set: state.paged.numberOfElements - 1},
totalElements: {$set: state.paged.totalElements - 1},
},
});
......
......@@ -77,7 +77,6 @@ function publicSubsets(state = INITIAL_STATE, action: IReducerAction) {
: update(state, {
paged: {
content: {$splice: [[removeIndex, 1]]},
numberOfElements: {$set: state.paged.numberOfElements - 1},
totalElements: {$set: state.paged.totalElements - 1},
},
});
......
......@@ -26,7 +26,7 @@ export default class PagedLoader<T> extends React.Component<IProps<T>, any> {
if (paged && isVisible) {
// we should load some stuff
if (paged && paged.content && paged.totalElements > paged.content.length) {
if (paged && ! paged.last) {
log('Calling for next page', paged.number + 1);
loadPage(paged.number + 1, paged.size);
......
......@@ -6,14 +6,14 @@ 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/Page';
......@@ -269,7 +269,7 @@ class PaginationComponent extends React.Component<IPaginationComponentProps, any
<Button
variant="fab"
color="inherit"
disabled={ ! pageObj || pageObj.first }
disabled={ ! pageObj || pageObj.number === 0 }
className={ classes.paginationBut }
onClick={ fireSortChange.bind(this, 0, pageObj ? pageObj.size : 10, sortBy) }
>
......@@ -279,7 +279,7 @@ class PaginationComponent extends React.Component<IPaginationComponentProps, any
<Button
variant="fab"
color="inherit"
disabled={ ! pageObj || pageObj.first }
disabled={ ! pageObj || pageObj.number === 0 }
className={ classes.paginationBut }
onClick={ fireSortChange.bind(this, pageObj ? pageObj.number - 1 : 0, pageObj ? pageObj.size : 10, sortBy) }
>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment