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';
|
2019-02-11 07:22:42 +00:00
|
|
|
import { Utils } from '../../utils/utils';
|
2018-12-10 10:19:03 +00:00
|
|
|
import SharedRepoListItem from './shared-repo-list-item';
|
2019-02-11 07:22:42 +00:00
|
|
|
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,
|
2019-01-02 02:53:38 +00:00
|
|
|
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,
|
2018-12-29 10:25:18 +00:00
|
|
|
onItemDetails: PropTypes.func,
|
2019-02-11 07:22:42 +00:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-02 02:53:38 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-01-02 02:53:38 +00:00
|
|
|
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',
|
2019-01-02 02:53:38 +00:00
|
|
|
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 = () => {
|
2019-02-11 07:22:42 +00:00
|
|
|
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
|
|
|
});
|
2019-02-11 07:22:42 +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}
|
2019-02-11 07:22:42 +00:00
|
|
|
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}
|
2018-12-29 10:25:18 +00:00
|
|
|
onItemDetails={this.props.onItemDetails}
|
2019-02-11 07:22:42 +00:00
|
|
|
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-01-02 02:53:38 +00:00
|
|
|
|
2019-05-29 05:57:12 +00:00
|
|
|
const { sortByName, sortByTime, sortBySize, sortIcon } = this.getSortMetaData();
|
2019-01-02 02:53:38 +00:00
|
|
|
|
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>
|
2019-02-26 06:14:00 +00:00
|
|
|
<th width="4%"></th>
|
2019-01-31 09:37:02 +00:00
|
|
|
<th width="4%"><span className="sr-only">{gettext('Library Type')}</span></th>
|
2019-02-26 06:14:00 +00:00
|
|
|
<th width="36%"><a className="d-block table-sort-op" href="#" onClick={this.sortByName}>{gettext('Name')} {sortByName && sortIcon}</a></th>
|
2019-01-31 09:37:02 +00:00
|
|
|
<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>
|
2019-01-02 02:53:38 +00:00
|
|
|
<th width={'14%'}><a className="d-block table-sort-op" href="#" onClick={this.sortByTime}>{gettext('Last Update')} {sortByTime && sortIcon}</a></th>
|
2019-01-31 09:37:02 +00:00
|
|
|
<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;
|
2019-01-02 02:53:38 +00:00
|
|
|
|
|
|
|
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>
|
2019-01-31 09:37:02 +00:00
|
|
|
<th width="18%"><span className="sr-only">{gettext('Library Type')}</span></th>
|
2018-12-08 00:37:18 +00:00
|
|
|
<th width="68%">
|
2019-01-31 09:37:02 +00:00
|
|
|
{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>
|
2019-01-31 09:37:02 +00:00
|
|
|
<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;
|