mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-08 02:10:24 +00:00
[system admin] all repos: added 'sort by size & file count' (#4414)
This commit is contained in:
@@ -17,7 +17,7 @@ const propTypes = {
|
|||||||
class Paginator extends Component {
|
class Paginator extends Component {
|
||||||
|
|
||||||
resetPerPage = (e) => {
|
resetPerPage = (e) => {
|
||||||
const perPage = e.target.value;
|
const perPage = parseInt(e.target.value);
|
||||||
this.updateURL(1, perPage);
|
this.updateURL(1, perPage);
|
||||||
this.props.resetPerPage(perPage);
|
this.props.resetPerPage(perPage);
|
||||||
}
|
}
|
||||||
|
@@ -21,14 +21,16 @@ class AllRepos extends Component {
|
|||||||
repos: [],
|
repos: [],
|
||||||
pageInfo: {},
|
pageInfo: {},
|
||||||
perPage: 25,
|
perPage: 25,
|
||||||
|
sortBy: '',
|
||||||
isCreateRepoDialogOpen: false
|
isCreateRepoDialogOpen: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
let urlParams = (new URL(window.location)).searchParams;
|
let urlParams = (new URL(window.location)).searchParams;
|
||||||
const { currentPage = 1, perPage } = this.state;
|
const { currentPage = 1, perPage, sortBy } = this.state;
|
||||||
this.setState({
|
this.setState({
|
||||||
|
sortBy: urlParams.get('order_by') || sortBy,
|
||||||
perPage: parseInt(urlParams.get('per_page') || perPage),
|
perPage: parseInt(urlParams.get('per_page') || perPage),
|
||||||
currentPage: parseInt(urlParams.get('page') || currentPage)
|
currentPage: parseInt(urlParams.get('page') || currentPage)
|
||||||
}, () => {
|
}, () => {
|
||||||
@@ -41,7 +43,8 @@ class AllRepos extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getReposByPage = (page) => {
|
getReposByPage = (page) => {
|
||||||
seafileAPI.sysAdminListAllRepos(page, this.state.perPage).then((res) => {
|
const { perPage, sortBy } = this.state;
|
||||||
|
seafileAPI.sysAdminListAllRepos(page, perPage, sortBy).then((res) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
loading: false,
|
loading: false,
|
||||||
repos: res.data.repos,
|
repos: res.data.repos,
|
||||||
@@ -55,6 +58,22 @@ class AllRepos extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortItems = (sortBy) => {
|
||||||
|
this.setState({
|
||||||
|
currentPage: 1,
|
||||||
|
sortBy: sortBy
|
||||||
|
}, () => {
|
||||||
|
let url = new URL(location.href);
|
||||||
|
let searchParams = new URLSearchParams(url.search);
|
||||||
|
const { currentPage, sortBy } = this.state;
|
||||||
|
searchParams.set('page', currentPage);
|
||||||
|
searchParams.set('order_by', sortBy);
|
||||||
|
url.search = searchParams.toString();
|
||||||
|
navigate(url.toString());
|
||||||
|
this.getReposByPage(currentPage);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
resetPerPage = (perPage) => {
|
resetPerPage = (perPage) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
perPage: perPage
|
perPage: perPage
|
||||||
@@ -121,6 +140,8 @@ class AllRepos extends Component {
|
|||||||
loading={this.state.loading}
|
loading={this.state.loading}
|
||||||
errorMsg={this.state.errorMsg}
|
errorMsg={this.state.errorMsg}
|
||||||
items={this.state.repos}
|
items={this.state.repos}
|
||||||
|
sortBy={this.state.sortBy}
|
||||||
|
sortItems={this.sortItems}
|
||||||
pageInfo={this.state.pageInfo}
|
pageInfo={this.state.pageInfo}
|
||||||
curPerPage={this.state.perPage}
|
curPerPage={this.state.perPage}
|
||||||
getListByPage={this.getReposByPage}
|
getListByPage={this.getReposByPage}
|
||||||
|
@@ -42,8 +42,19 @@ class Content extends Component {
|
|||||||
this.props.getListByPage(this.props.pageInfo.current_page + 1);
|
this.props.getListByPage(this.props.pageInfo.current_page + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortByFileCount = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
this.props.sortItems('file_count');
|
||||||
|
}
|
||||||
|
|
||||||
|
sortBySize = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
this.props.sortItems('size');
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { loading, errorMsg, items, pageInfo, curPerPage } = this.props;
|
// offer 'sort' only for 'all repos'
|
||||||
|
const { loading, errorMsg, items, pageInfo, curPerPage, sortBy } = this.props;
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <Loading />;
|
return <Loading />;
|
||||||
} else if (errorMsg) {
|
} else if (errorMsg) {
|
||||||
@@ -54,6 +65,7 @@ class Content extends Component {
|
|||||||
<h2>{gettext('No libraries')}</h2>
|
<h2>{gettext('No libraries')}</h2>
|
||||||
</EmptyTip>
|
</EmptyTip>
|
||||||
);
|
);
|
||||||
|
const sortIcon = <span className="fas fa-caret-down"></span>;
|
||||||
const table = (
|
const table = (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<table>
|
<table>
|
||||||
@@ -61,7 +73,15 @@ class Content extends Component {
|
|||||||
<tr>
|
<tr>
|
||||||
<th width="5%">{/*icon*/}</th>
|
<th width="5%">{/*icon*/}</th>
|
||||||
<th width="25%">{gettext('Name')}</th>
|
<th width="25%">{gettext('Name')}</th>
|
||||||
<th width="15%">{gettext('Files')}{' / '}{gettext('Size')}</th>
|
<th width="15%">
|
||||||
|
{sortBy != undefined ?
|
||||||
|
<Fragment>
|
||||||
|
<a className="d-inline-block table-sort-op" href="#" onClick={this.sortByFileCount}>{gettext('Files')} {sortBy == 'file_count' && sortIcon}</a>{' / '}
|
||||||
|
<a className="d-inline-block table-sort-op" href="#" onClick={this.sortBySize}>{gettext('Size')} {sortBy == 'size' && sortIcon}</a>
|
||||||
|
</Fragment> :
|
||||||
|
gettext('Files') / gettext('Size')
|
||||||
|
}
|
||||||
|
</th>
|
||||||
<th width="32%">ID</th>
|
<th width="32%">ID</th>
|
||||||
<th width="18%">{gettext('Owner')}</th>
|
<th width="18%">{gettext('Owner')}</th>
|
||||||
<th width="5%">{/*Operations*/}</th>
|
<th width="5%">{/*Operations*/}</th>
|
||||||
|
Reference in New Issue
Block a user