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

File size sort

This commit is contained in:
zxj96
2019-05-29 13:57:12 +08:00
parent d057518f5f
commit 8eba860bcb
9 changed files with 97 additions and 10 deletions

View File

@@ -133,6 +133,13 @@ class DirentListView extends React.Component {
this.props.sortItems(sortBy, sortOrder); 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 // for image popup
prepareImageItem = (item) => { prepareImageItem = (item) => {
const useThumbnail = !this.repoEncrypted; const useThumbnail = !this.repoEncrypted;
@@ -579,6 +586,7 @@ class DirentListView extends React.Component {
// sort // sort
const sortByName = sortBy == 'name'; const sortByName = sortBy == 'name';
const sortByTime = sortBy == 'time'; 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 sortIcon = sortOrder == 'asc' ? <span className="fas fa-caret-up"></span> : <span className="fas fa-caret-down"></span>;
return ( return (
@@ -603,7 +611,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="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="6%">{/*tag */}</th>
<th width="18%">{/*operation */}</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> <th width="15%"><a className="d-block table-sort-op" href="#" onClick={this.sortByTime}>{gettext('Last Update')} {sortByTime && sortIcon}</a></th>
</tr> </tr>
</thead> </thead>

View File

@@ -42,10 +42,18 @@ class SharedRepoListView extends React.Component {
this.props.sortItems(sortBy, sortOrder); 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 = () => { getSortMetaData = () => {
return { return {
sortByName: this.props.sortBy == 'name', sortByName: this.props.sortBy == 'name',
sortByTime: this.props.sortBy == 'time', 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> 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 = () => { renderPCUI = () => {
let isShowTableThread = this.props.isShowTableThread !== undefined ? this.props.isShowTableThread : true; let isShowTableThread = this.props.isShowTableThread !== undefined ? this.props.isShowTableThread : true;
const { sortByName, sortByTime, sortIcon } = this.getSortMetaData(); const { sortByName, sortByTime, sortBySize, sortIcon } = this.getSortMetaData();
return ( return (
<table className={isShowTableThread ? '' : 'table-thead-hidden'}> <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="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="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="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={'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> <th width="16%">{gettext('Owner')}</th>
</tr> </tr>

View File

@@ -43,7 +43,7 @@ class GroupView extends React.Component {
currentRepo: null, currentRepo: null,
isStaff: false, isStaff: false,
isOwner: 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' sortOrder: cookie.load('seafile-repo-dir-sort-order') || 'asc', // 'asc' or 'desc'
repoList: [], repoList: [],
libraryType: 'group', libraryType: 'group',

View File

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

View File

@@ -24,7 +24,7 @@ class MyLibraries extends Component {
isLoading: true, isLoading: true,
repoList: [], repoList: [],
isShowDetails: false, 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' 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); 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 = () => { renderRepoListView = () => {
return ( return (
<Fragment> <Fragment>
@@ -79,7 +86,7 @@ class MylibRepoListView extends React.Component {
<th width="4%"><span className="sr-only">{gettext('Library Type')}</span></th> <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="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="14%"><span className="sr-only">{gettext('Actions')}</span></th>
<th width={showStorageBackend ? '15%' : '20%'}>{gettext('Size')}</th> <th width={showStorageBackend ? '15%' : '20%'} onClick={this.sortBySize}>{gettext('Size')} {this.props.sortBy === 'size' && sortIcon}</th>
{showStorageBackend ? <th width="10%">{gettext('Storage backend')}</th> : null} {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> <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> </tr>

View File

@@ -27,6 +27,13 @@ class Content extends Component {
this.props.sortItems(sortBy, sortOrder); 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() { render() {
const { loading, errorMsg, items, sortBy, sortOrder } = this.props; const { loading, errorMsg, items, sortBy, sortOrder } = this.props;
@@ -45,6 +52,7 @@ class Content extends Component {
// sort // sort
const sortByName = sortBy == 'name'; const sortByName = sortBy == 'name';
const sortByTime = sortBy == 'time'; 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 sortIcon = sortOrder == 'asc' ? <span className="fas fa-caret-up"></span> : <span className="fas fa-caret-down"></span>;
const desktopThead = ( const desktopThead = (
@@ -54,7 +62,7 @@ class Content extends Component {
<th width="4%"><span className="sr-only">{gettext('Library Type')}</span></th> <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="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="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="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> <th width="16%">{gettext('Owner')}</th>
</tr> </tr>
@@ -293,7 +301,7 @@ class SharedLibraries extends Component {
loading: true, loading: true,
errorMsg: '', errorMsg: '',
items: [], 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' sortOrder: cookie.load('seafile-repo-dir-sort-order') || 'asc', // 'asc' or 'desc'
}; };
} }

View File

@@ -28,7 +28,7 @@ class PublicSharedView extends React.Component {
errMessage: '', errMessage: '',
emptyTip: '', emptyTip: '',
repoList: [], 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' sortOrder: cookie.load('seafile-repo-dir-sort-order') || 'asc', // 'asc' or 'desc'
libraryType: 'public', libraryType: 'public',
isCreateMenuShow: false, isCreateMenuShow: false,

View File

@@ -616,6 +616,18 @@ export const Utils = {
return a.last_modified < b.last_modified ? 1 : -1; return a.last_modified < b.last_modified ? 1 : -1;
}; };
break; break;
case 'size-asc':
comparator = function(a, b) {
let reult = _this.compareTwoSize(a.size, b.size);
return reult;
};
break;
case 'size-desc':
comparator = function(a, b) {
let reult = _this.compareTwoSize(a.size, b.size);
return -reult;
};
break;
} }
repos.sort(comparator); repos.sort(comparator);
@@ -649,6 +661,28 @@ export const Utils = {
return a.mtime < b.mtime ? 1 : -1; return a.mtime < b.mtime ? 1 : -1;
}; };
break; break;
case 'size-asc':
comparator = function(a, b) {
if (a.type == 'dir' && b.type == 'dir') {
let reult = _this.compareTwoWord(a.name, b.name);
return reult;
} else {
let reult = _this.compareTwoSize(a.size, b.size);
return reult;
}
};
break;
case 'size-desc':
comparator = function(a, b) {
if (a.type == 'dir' && b.type == 'dir') {
let reult = _this.compareTwoWord(a.name, b.name);
return -reult;
} else {
let reult = _this.compareTwoSize(a.size, b.size);
return -reult;
}
};
break;
} }
items.sort((a, b) => { items.sort((a, b) => {
@@ -663,6 +697,28 @@ export const Utils = {
return items; return items;
}, },
compareTwoSize: function(a, b) {
let suffix = /[A-Za-z]+/g;
let fileSizeName = /(\-|\+)?\d+(\.\d+)?/g;
let sizes = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
let aSuffixName = a.match(suffix)[0];
let bSuffixName = b.match(suffix)[0];
let aIndex = sizes.indexOf(aSuffixName);
let bIndex = sizes.indexOf(bSuffixName);
if (aIndex === bIndex) {
let aFileName = a.match(fileSizeName)[0];
let bFileName = b.match(fileSizeName)[0];
let aBytes = aFileName * (1000 ** aIndex);
let bBytes = bFileName * (1000 ** bIndex);
return aBytes < bBytes ? -1 : 1;
} else {
return aIndex < bIndex ? -1 : 1;
}
},
changeMarkdownNodes: function(nodes, fn) { changeMarkdownNodes: function(nodes, fn) {
nodes.map((item) => { nodes.map((item) => {
fn(item); fn(item);