1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 07:01:12 +00:00

Merge pull request #3573 from haiwen/sort_size

Sort size
This commit is contained in:
Daniel Pan
2019-05-31 20:37:20 +08:00
committed by GitHub
11 changed files with 80 additions and 10 deletions

View File

@@ -134,6 +134,13 @@ class DirentListView extends React.Component {
this.props.sortItems(sortBy, sortOrder);
}
sortBySize = (e) => {
e.preventDefault();
const sortBy = 'size';
const sortOrder = this.props.sortOrder == 'asc' ? 'desc' : 'asc';
this.props.sortItems(sortBy, sortOrder);
}
// for image popup
prepareImageItem = (item) => {
const useThumbnail = !this.repoEncrypted;
@@ -580,6 +587,7 @@ class DirentListView extends React.Component {
// sort
const sortByName = sortBy == 'name';
const sortByTime = sortBy == 'time';
const sortBySize = sortBy == 'size';
const sortIcon = sortOrder == 'asc' ? <span className="fas fa-caret-up"></span> : <span className="fas fa-caret-down"></span>;
return (
@@ -604,7 +612,7 @@ class DirentListView extends React.Component {
<th width="39%"><a className="d-block table-sort-op" href="#" onClick={this.sortByName}>{gettext('Name')} {sortByName && sortIcon}</a></th>
<th width="6%">{/*tag */}</th>
<th width="18%">{/*operation */}</th>
<th width="11%">{gettext('Size')}</th>
<th width="11%"><a className="d-block table-sort-op" href="#" onClick={this.sortBySize}>{gettext('Size')} {sortBySize && sortIcon}</a></th>
<th width="15%"><a className="d-block table-sort-op" href="#" onClick={this.sortByTime}>{gettext('Last Update')} {sortByTime && sortIcon}</a></th>
</tr>
</thead>

View File

@@ -42,10 +42,18 @@ class SharedRepoListView extends React.Component {
this.props.sortItems(sortBy, sortOrder);
}
sortBySize = (e) => {
e.preventDefault();
const sortBy = 'size';
const sortOrder = this.props.sortOrder == 'asc' ? 'desc' : 'asc';
this.props.sortItems(sortBy, sortOrder);
}
getSortMetaData = () => {
return {
sortByName: this.props.sortBy == 'name',
sortByTime: this.props.sortBy == 'time',
sortBySize: this.props.sortBy == 'size',
sortIcon: this.props.sortOrder == 'asc' ? <span className="fas fa-caret-up"></span> : <span className="fas fa-caret-down"></span>
};
}
@@ -98,7 +106,7 @@ class SharedRepoListView extends React.Component {
renderPCUI = () => {
let isShowTableThread = this.props.isShowTableThread !== undefined ? this.props.isShowTableThread : true;
const { sortByName, sortByTime, sortIcon } = this.getSortMetaData();
const { sortByName, sortByTime, sortBySize, sortIcon } = this.getSortMetaData();
return (
<table className={isShowTableThread ? '' : 'table-thead-hidden'}>
@@ -108,7 +116,7 @@ class SharedRepoListView extends React.Component {
<th width="4%"><span className="sr-only">{gettext('Library Type')}</span></th>
<th width="36%"><a className="d-block table-sort-op" href="#" onClick={this.sortByName}>{gettext('Name')} {sortByName && sortIcon}</a></th>
<th width="12%"><span className="sr-only">{gettext('Actions')}</span></th>
<th width={'14%'}>{gettext('Size')}</th>
<th width={'14%'}><a className="d-block table-sort-op" href="#" onClick={this.sortBySize}>{gettext('Size')} {sortBySize && sortIcon}</a></th>
<th width={'14%'}><a className="d-block table-sort-op" href="#" onClick={this.sortByTime}>{gettext('Last Update')} {sortByTime && sortIcon}</a></th>
<th width="16%">{gettext('Owner')}</th>
</tr>

View File

@@ -13,6 +13,7 @@ class Dirent {
this.isSelected = false; // is check or not
this.starred = json.starred || false;
if (json.type === 'file') {
this.size_original = json.size;
this.size = Utils.bytesToSize(json.size);
this.is_locked = json.is_locked || false;
this.lock_time = json.lock_time || '';

View File

@@ -5,6 +5,7 @@ class Repo {
this.repo_id = object.repo_id;
this.repo_name = object.repo_name;
this.permission = object.permission;
this.size_original = object.size;
this.size = Utils.bytesToSize(object.size);
this.owner_name = object.owner_name;
this.owner_email = object.owner_email;

View File

@@ -44,7 +44,7 @@ class GroupView extends React.Component {
currentRepo: null,
isStaff: false,
isOwner: false,
sortBy: cookie.load('seafile-repo-dir-sort-by') || 'name', // 'name' or 'time'
sortBy: cookie.load('seafile-repo-dir-sort-by') || 'name', // 'name' or 'time' or 'size'
sortOrder: cookie.load('seafile-repo-dir-sort-order') || 'asc', // 'asc' or 'desc'
repoList: [],
libraryType: 'group',

View File

@@ -65,7 +65,7 @@ class LibContentView extends React.Component {
isDirentListLoading: true,
direntList: [],
isDirentSelected: false,
sortBy: cookie.load('seafile-repo-dir-sort-by') || 'name', // 'name' or 'time'
sortBy: cookie.load('seafile-repo-dir-sort-by') || 'name', // 'name' or 'time' or 'size'
sortOrder: cookie.load('seafile-repo-dir-sort-order') || 'asc', // 'asc' or 'desc'
isAllDirentSelected: false,
dirID: '', // for update dir list

View File

@@ -24,7 +24,7 @@ class MyLibraries extends Component {
isLoading: true,
repoList: [],
isShowDetails: false,
sortBy: cookie.load('seafile-repo-dir-sort-by') || 'name', // 'name' or 'time'
sortBy: cookie.load('seafile-repo-dir-sort-by') || 'name', // 'name' or 'time' or 'size'
sortOrder: cookie.load('seafile-repo-dir-sort-order') || 'asc', // 'asc' or 'desc'
};

View File

@@ -46,6 +46,13 @@ class MylibRepoListView extends React.Component {
this.props.sortRepoList(sortBy, sortOrder);
}
sortBySize = (e) => {
e.preventDefault();
const sortBy = 'size';
const sortOrder = this.props.sortOrder == 'asc' ? 'desc' : 'asc';
this.props.sortRepoList(sortBy, sortOrder);
}
renderRepoListView = () => {
return (
<Fragment>
@@ -79,7 +86,7 @@ class MylibRepoListView extends React.Component {
<th width="4%"><span className="sr-only">{gettext('Library Type')}</span></th>
<th width="38%"><a className="d-block table-sort-op" href="#" onClick={this.sortByName}>{gettext('Name')} {this.props.sortBy === 'name' && sortIcon}</a></th>
<th width="14%"><span className="sr-only">{gettext('Actions')}</span></th>
<th width={showStorageBackend ? '15%' : '20%'}>{gettext('Size')}</th>
<th width={showStorageBackend ? '15%' : '20%'}><a className="d-block table-sort-op" href="#" onClick={this.sortBySize}>{gettext('Size')} {this.props.sortBy === 'size' && sortIcon}</a></th>
{showStorageBackend ? <th width="10%">{gettext('Storage backend')}</th> : null}
<th width={showStorageBackend ? '15%' : '20%'}><a className="d-block table-sort-op" href="#" onClick={this.sortByTime}>{gettext('Last Update')} {this.props.sortBy === 'time' && sortIcon}</a></th>
</tr>

View File

@@ -27,6 +27,13 @@ class Content extends Component {
this.props.sortItems(sortBy, sortOrder);
}
sortBySize = (e) => {
e.preventDefault();
const sortBy = 'size';
const sortOrder = this.props.sortOrder == 'asc' ? 'desc' : 'asc';
this.props.sortItems(sortBy, sortOrder);
}
render() {
const { loading, errorMsg, items, sortBy, sortOrder } = this.props;
@@ -45,6 +52,7 @@ class Content extends Component {
// sort
const sortByName = sortBy == 'name';
const sortByTime = sortBy == 'time';
const sortBySize = sortBy == 'size';
const sortIcon = sortOrder == 'asc' ? <span className="fas fa-caret-up"></span> : <span className="fas fa-caret-down"></span>;
const desktopThead = (
@@ -54,7 +62,7 @@ class Content extends Component {
<th width="4%"><span className="sr-only">{gettext('Library Type')}</span></th>
<th width="34%"><a className="d-block table-sort-op" href="#" onClick={this.sortByName}>{gettext('Name')} {sortByName && sortIcon}</a></th>
<th width="10%"><span className="sr-only">{gettext('Actions')}</span></th>
<th width="14%">{gettext('Size')}</th>
<th width="14%"><a className="d-block table-sort-op" href="#" onClick={this.sortBySize}>{gettext('Size')} {sortBySize && sortIcon}</a></th>
<th width="18%"><a className="d-block table-sort-op" href="#" onClick={this.sortByTime}>{gettext('Last Update')} {sortByTime && sortIcon}</a></th>
<th width="16%">{gettext('Owner')}</th>
</tr>
@@ -293,7 +301,7 @@ class SharedLibraries extends Component {
loading: true,
errorMsg: '',
items: [],
sortBy: cookie.load('seafile-repo-dir-sort-by') || 'name', // 'name' or 'time'
sortBy: cookie.load('seafile-repo-dir-sort-by') || 'name', // 'name' or 'time' or 'size'
sortOrder: cookie.load('seafile-repo-dir-sort-order') || 'asc', // 'asc' or 'desc'
};
}

View File

@@ -29,7 +29,7 @@ class PublicSharedView extends React.Component {
errMessage: '',
emptyTip: '',
repoList: [],
sortBy: cookie.load('seafile-repo-dir-sort-by') || 'name', // 'name' or 'time'
sortBy: cookie.load('seafile-repo-dir-sort-by') || 'name', // 'name' or 'time' or 'size'
sortOrder: cookie.load('seafile-repo-dir-sort-order') || 'asc', // 'asc' or 'desc'
libraryType: 'public',
isCreateMenuShow: false,

View File

@@ -629,6 +629,25 @@ export const Utils = {
return a.last_modified < b.last_modified ? 1 : -1;
};
break;
case 'size-asc':
comparator = function(a, b) {
if (a.size === b.size) {
let result = _this.compareTwoWord(a.repo_name, b.repo_name);
return result;
}
return a.size_original < b.size_original ? -1 : 1;
};
break;
case 'size-desc':
comparator = function(a, b) {
if (a.size === b.size) {
let result = _this.compareTwoWord(a.repo_name, b.repo_name);
return -result;
}
return a.size_original < b.size_original ? 1 : -1;
};
break;
}
repos.sort(comparator);
@@ -662,6 +681,24 @@ export const Utils = {
return a.mtime < b.mtime ? 1 : -1;
};
break;
case 'size-asc':
comparator = function(a, b) {
if (a.type == 'dir' && b.type == 'dir') {
let result = _this.compareTwoWord(a.name, b.name);
return result;
}
return a.size_original < b.size_original ? -1 : 1;
};
break;
case 'size-desc':
comparator = function(a, b) {
if (a.type == 'dir' && b.type == 'dir') {
let result = _this.compareTwoWord(a.name, b.name);
return -result;
}
return a.size_original < b.size_original ? 1 : -1;
};
break;
}
items.sort((a, b) => {