1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-17 15:53:28 +00:00

added pagination for 'system admin - orgs' & improved paginator (#4260)

This commit is contained in:
llj
2019-11-15 18:00:20 +08:00
committed by Daniel Pan
parent 4b809999a6
commit b4aa1b2f38
4 changed files with 57 additions and 12 deletions

View File

@@ -39,15 +39,18 @@ class Paginator extends Component {
{this.props.hasNextPage && {this.props.hasNextPage &&
<a href="#" onClick={this.goToNext} className="ml-4">{gettext('Next')}</a> <a href="#" onClick={this.goToNext} className="ml-4">{gettext('Next')}</a>
} }
</div> {(this.props.currentPage != 1 || this.props.hasNextPage) &&
{this.props.canResetPerPage && <span className="d-inline-block mx-2">|</span>
<div className="text-center">
{gettext('Per page:')}{' '}
<span className={`${curPerPage === 25 ? '' : 'a-simulate '} mr-1`} onClick={() => {return this.resetPerPage(25);}}>25</span>
<span className={`${curPerPage === 50 ? '' : 'a-simulate '} mr-1`} onClick={() => {return this.resetPerPage(50);}}>50</span>
<span className={`${curPerPage === 100 ? '' : 'a-simulate '} mr-1`} onClick={() => {return this.resetPerPage(100);}}>100</span>
</div>
} }
{this.props.canResetPerPage &&
<Fragment>
{gettext('Per page:')}
<span className={`${curPerPage === 25 ? '' : 'a-simulate '} mx-1`} onClick={() => {return this.resetPerPage(25);}}>25</span>
<span className={`${curPerPage === 50 ? '' : 'a-simulate '} mr-1`} onClick={() => {return this.resetPerPage(50);}}>50</span>
<span className={`${curPerPage === 100 ? '' : 'a-simulate '}`} onClick={() => {return this.resetPerPage(100);}}>100</span>
</Fragment>
}
</div>
</Fragment> </Fragment>
); );
} }

View File

@@ -5,6 +5,7 @@ import { Utils } from '../../../utils/utils';
import { siteRoot, gettext } from '../../../utils/constants'; import { siteRoot, gettext } from '../../../utils/constants';
import EmptyTip from '../../../components/empty-tip'; import EmptyTip from '../../../components/empty-tip';
import Loading from '../../../components/loading'; import Loading from '../../../components/loading';
import Paginator from '../../../components/paginator';
import SysAdminUserRoleEditor from '../../../components/select-editor/sysadmin-user-role-editor'; import SysAdminUserRoleEditor from '../../../components/select-editor/sysadmin-user-role-editor';
import CommonOperationConfirmationDialog from '../../../components/dialog/common-operation-confirmation-dialog'; import CommonOperationConfirmationDialog from '../../../components/dialog/common-operation-confirmation-dialog';
import UserLink from '../user-link'; import UserLink from '../user-link';
@@ -17,6 +18,14 @@ class Content extends Component {
super(props); super(props);
} }
getPreviousPage = () => {
this.props.getListByPage(this.props.currentPage - 1);
}
getNextPage = () => {
this.props.getListByPage(this.props.currentPage + 1);
}
render() { render() {
const { loading, errorMsg, items } = this.props; const { loading, errorMsg, items } = this.props;
if (loading) { if (loading) {
@@ -53,6 +62,17 @@ class Content extends Component {
})} })}
</tbody> </tbody>
</table> </table>
{this.props.currentPage &&
<Paginator
currentPage={this.props.currentPage}
hasNextPage={this.props.hasNextPage}
curPerPage={this.props.curPerPage}
canResetPerPage={true}
resetPerPage={this.props.resetPerPage}
gotoPreviousPage={this.getPreviousPage}
gotoNextPage={this.getNextPage}
/>
}
</Fragment> </Fragment>
); );
return items.length ? table : emptyTip; return items.length ? table : emptyTip;

View File

@@ -19,15 +19,25 @@ class Orgs extends Component {
loading: true, loading: true,
errorMsg: '', errorMsg: '',
orgList: [], orgList: [],
currentPage: 1,
perPage: 25,
hasNextPage: false,
isAddOrgDialogOpen: false isAddOrgDialogOpen: false
}; };
} }
componentDidMount () { componentDidMount() {
seafileAPI.sysAdminListOrgs().then((res) => { this.getItemsByPage(1);
}
getItemsByPage = (page) => {
const { perPage } = this.state;
seafileAPI.sysAdminListOrgs(page, perPage).then((res) => {
this.setState({ this.setState({
loading: false, loading: false,
orgList: res.data.organizations orgList: res.data.organizations,
currentPage: page,
hasNextPage: Utils.hasNextPage(page, perPage, res.data.total_count)
}); });
}).catch((error) => { }).catch((error) => {
if (error.response) { if (error.response) {
@@ -52,6 +62,14 @@ class Orgs extends Component {
}); });
} }
resetPerPage = (perPage) => {
this.setState({
perPage: perPage
}, () => {
this.getItemsByPage(1);
});
}
toggleAddOrgDialog = () => { toggleAddOrgDialog = () => {
this.setState({isAddOrgDialogOpen: !this.state.isAddOrgDialogOpen}); this.setState({isAddOrgDialogOpen: !this.state.isAddOrgDialogOpen});
} }
@@ -127,6 +145,11 @@ class Orgs extends Component {
loading={this.state.loading} loading={this.state.loading}
errorMsg={this.state.errorMsg} errorMsg={this.state.errorMsg}
items={this.state.orgList} items={this.state.orgList}
currentPage={this.state.currentPage}
hasNextPage={this.state.hasNextPage}
curPerPage={this.state.perPage}
resetPerPage={this.resetPerPage}
getListByPage={this.getItemsByPage}
updateRole={this.updateRole} updateRole={this.updateRole}
deleteOrg={this.deleteOrg} deleteOrg={this.deleteOrg}
/> />

View File

@@ -27,7 +27,6 @@ class Users extends Component {
loading: true, loading: true,
errorMsg: '', errorMsg: '',
userList: [], userList: [],
totalItemCount: 0,
hasNextPage: false, hasNextPage: false,
currentPage: 1, currentPage: 1,
perPage: 25, perPage: 25,