1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-21 18:32:37 +00:00
seahub/frontend/src/components/shared-repo-list-view/shared-repo-list-view.js

168 lines
5.4 KiB
JavaScript
Raw Normal View History

2018-12-08 08:35:00 +00:00
import React, {Fragment} from 'react';
2018-12-08 00:37:18 +00:00
import PropTypes from 'prop-types';
import { gettext } from '../../utils/constants';
import { Utils } from '../../utils/utils';
2018-12-10 10:19:03 +00:00
import SharedRepoListItem from './shared-repo-list-item';
import toaster from '../toast';
2018-12-08 00:37:18 +00:00
const propTypes = {
2018-12-21 07:40:59 +00:00
libraryType: PropTypes.string,
2018-12-08 08:35:00 +00:00
currentGroup: PropTypes.object,
2018-12-10 03:52:44 +00:00
isShowTableThread: PropTypes.bool,
sortBy: PropTypes.string,
sortOrder: PropTypes.string,
sortItems: PropTypes.func,
2018-12-21 07:40:59 +00:00
repoList: PropTypes.array.isRequired,
2018-12-10 10:37:59 +00:00
onItemUnshare: PropTypes.func.isRequired,
2018-12-16 03:17:17 +00:00
onItemDelete: PropTypes.func.isRequired,
onItemDetails: PropTypes.func,
onItemRename: PropTypes.func,
2018-12-08 00:37:18 +00:00
};
2018-12-10 10:19:03 +00:00
class SharedRepoListView extends React.Component {
2018-12-08 00:37:18 +00:00
constructor(props) {
super(props);
this.state = {
isItemFreezed: false,
};
}
sortByName = (e) => {
e.preventDefault();
const sortBy = 'name';
const sortOrder = this.props.sortOrder == 'asc' ? 'desc' : 'asc';
this.props.sortItems(sortBy, sortOrder);
}
sortByTime = (e) => {
e.preventDefault();
const sortBy = 'time';
const sortOrder = this.props.sortOrder == 'asc' ? 'desc' : 'asc';
this.props.sortItems(sortBy, sortOrder);
}
2019-05-29 05:57:12 +00:00
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',
2019-05-29 05:57:12 +00:00
sortBySize: this.props.sortBy == 'size',
sortIcon: this.props.sortOrder == 'asc' ? <span className="fas fa-caret-up"></span> : <span className="fas fa-caret-down"></span>
};
}
2018-12-10 01:01:05 +00:00
onFreezedItem = () => {
this.setState({isItemFreezed: true});
}
onUnfreezedItem = () => {
this.setState({isItemFreezed: false});
}
onItemRename = (repo, newName) => {
let isDuplicated = this.props.repoList.some(item => {
return item.name === newName;
2018-12-10 01:01:05 +00:00
});
if (isDuplicated) {
let errMessage = gettext('The name "{name}" is already taken. Please choose a different name.');
errMessage = errMessage.replace('{name}', Utils.HTMLescape(newName));
toaster.danger(errMessage);
return false;
}
this.props.onItemRename(repo, newName);
2018-12-10 01:01:05 +00:00
}
renderRepoListView = () => {
return (
<Fragment>
{this.props.repoList.map(repo => {
return (
2018-12-10 10:19:03 +00:00
<SharedRepoListItem
2018-12-10 01:01:05 +00:00
key={repo.repo_id}
repo={repo}
2018-12-21 07:40:59 +00:00
libraryType={this.props.libraryType}
2018-12-10 01:01:05 +00:00
currentGroup={this.props.currentGroup}
isItemFreezed={this.state.isItemFreezed}
onFreezedItem={this.onFreezedItem}
onUnfreezedItem={this.onUnfreezedItem}
2018-12-10 10:37:59 +00:00
onItemUnshare={this.props.onItemUnshare}
2018-12-16 03:17:17 +00:00
onItemDelete={this.props.onItemDelete}
onItemDetails={this.props.onItemDetails}
onItemRename={this.props.onItemRename}
2018-12-10 01:01:05 +00:00
/>
);
})}
</Fragment>
);
}
2018-12-08 00:37:18 +00:00
renderPCUI = () => {
2018-12-10 03:52:44 +00:00
let isShowTableThread = this.props.isShowTableThread !== undefined ? this.props.isShowTableThread : true;
2019-05-29 05:57:12 +00:00
const { sortByName, sortByTime, sortBySize, sortIcon } = this.getSortMetaData();
2018-12-08 00:37:18 +00:00
return (
2018-12-29 08:16:20 +00:00
<table className={isShowTableThread ? '' : 'table-thead-hidden'}>
<thead>
2018-12-08 00:37:18 +00:00
<tr>
<th width="4%"></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="12%"><span className="sr-only">{gettext('Actions')}</span></th>
2019-05-29 05:57:12 +00:00
<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>
2018-12-08 00:37:18 +00:00
</tr>
</thead>
<tbody>
2018-12-10 01:01:05 +00:00
{this.renderRepoListView()}
2018-12-08 00:37:18 +00:00
</tbody>
</table>
);
}
renderMobileUI = () => {
2018-12-10 03:52:44 +00:00
let isShowTableThread = this.props.isShowTableThread !== undefined ? this.props.isShowTableThread : true;
const { sortByName, sortByTime, sortIcon } = this.getSortMetaData();
2018-12-08 00:37:18 +00:00
return (
2018-12-29 08:16:20 +00:00
<table className={isShowTableThread ? '' : 'table-thead-hidden'}>
<thead>
2018-12-08 00:37:18 +00:00
<tr>
<th width="18%"><span className="sr-only">{gettext('Library Type')}</span></th>
2018-12-08 00:37:18 +00:00
<th width="68%">
{gettext('Sort:')}
<a className="table-sort-op" href="#" onClick={this.sortByName}>{gettext('name')} {sortByName && sortIcon}</a>
<a className="table-sort-op" href="#" onClick={this.sortByTime}>{gettext('last update')} {sortByTime && sortIcon}</a>
2018-12-08 00:37:18 +00:00
</th>
<th width="14%"><span className="sr-only">{gettext('Actions')}</span></th>
2018-12-08 00:37:18 +00:00
</tr>
</thead>
<tbody>
2018-12-10 01:01:05 +00:00
{this.renderRepoListView()}
2018-12-08 00:37:18 +00:00
</tbody>
</table>
);
}
render() {
if (window.innerWidth >= 768) {
return this.renderPCUI();
} else {
return this.renderMobileUI();
}
}
}
2018-12-10 10:19:03 +00:00
SharedRepoListView.propTypes = propTypes;
2018-12-08 00:37:18 +00:00
2018-12-10 10:19:03 +00:00
export default SharedRepoListView;