2019-02-13 14:21:39 +08:00
|
|
|
import React, { Fragment } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import MediaQuery from 'react-responsive';
|
|
|
|
import { gettext, storages } from '../../utils/constants';
|
|
|
|
import MylibRepoListItem from './mylib-repo-list-item';
|
2019-07-18 20:21:50 +08:00
|
|
|
import LibsMobileThead from '../../components/libs-mobile-thead';
|
2024-09-10 11:46:50 +08:00
|
|
|
import { LIST_MODE } from '../../components/dir-view-mode/constants';
|
2024-10-18 10:54:58 +08:00
|
|
|
import ContextMenu from '../../components/context-menu/context-menu';
|
|
|
|
import { Utils } from '../../utils/utils';
|
|
|
|
import { hideMenu, handleContextClick } from '../../components/context-menu/actions';
|
2019-02-13 14:21:39 +08:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
sortBy: PropTypes.string.isRequired,
|
|
|
|
sortOrder: PropTypes.string.isRequired,
|
|
|
|
repoList: PropTypes.array.isRequired,
|
|
|
|
sortRepoList: PropTypes.func.isRequired,
|
|
|
|
onRenameRepo: PropTypes.func.isRequired,
|
|
|
|
onDeleteRepo: PropTypes.func.isRequired,
|
|
|
|
onTransferRepo: PropTypes.func.isRequired,
|
2023-09-13 08:40:50 +08:00
|
|
|
onMonitorRepo: PropTypes.func.isRequired,
|
2024-04-26 21:51:50 +08:00
|
|
|
inAllLibs: PropTypes.bool, // for 'My Libraries' in 'Files' page
|
2024-06-17 10:19:27 +08:00
|
|
|
currentViewMode: PropTypes.string,
|
2019-02-13 14:21:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class MylibRepoListView extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
isItemFreezed: false,
|
|
|
|
};
|
2024-10-18 10:54:58 +08:00
|
|
|
this.repoItems = [];
|
2019-02-13 14:21:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onFreezedItem = () => {
|
2024-07-18 11:58:42 +08:00
|
|
|
this.setState({ isItemFreezed: true });
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2019-07-22 17:09:10 +08:00
|
|
|
|
2019-02-13 14:21:39 +08:00
|
|
|
onUnfreezedItem = () => {
|
2024-07-18 11:58:42 +08:00
|
|
|
this.setState({ isItemFreezed: false });
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2019-02-13 14:21:39 +08:00
|
|
|
|
|
|
|
sortByName = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const sortBy = 'name';
|
|
|
|
const sortOrder = this.props.sortOrder == 'asc' ? 'desc' : 'asc';
|
|
|
|
this.props.sortRepoList(sortBy, sortOrder);
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2019-02-13 14:21:39 +08:00
|
|
|
|
|
|
|
sortByTime = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const sortBy = 'time';
|
|
|
|
const sortOrder = this.props.sortOrder == 'asc' ? 'desc' : 'asc';
|
|
|
|
this.props.sortRepoList(sortBy, sortOrder);
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2019-02-13 14:21:39 +08:00
|
|
|
|
2019-05-29 13:57:12 +08:00
|
|
|
sortBySize = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const sortBy = 'size';
|
|
|
|
const sortOrder = this.props.sortOrder == 'asc' ? 'desc' : 'asc';
|
|
|
|
this.props.sortRepoList(sortBy, sortOrder);
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2019-05-29 13:57:12 +08:00
|
|
|
|
2024-10-18 10:54:58 +08:00
|
|
|
onContextMenu = (event, repo) => {
|
|
|
|
event.preventDefault();
|
|
|
|
const id = 'mylib-repo-item-menu';
|
|
|
|
const menuList = Utils.getRepoOperationList(repo);
|
|
|
|
handleContextClick(event, id, menuList, repo);
|
|
|
|
};
|
|
|
|
|
|
|
|
setRepoItemRef = (index) => item => {
|
|
|
|
this.repoItems[index] = item;
|
|
|
|
};
|
|
|
|
|
|
|
|
getRepoIndex = (repo) => {
|
|
|
|
return this.props.repoList.findIndex(item => {
|
|
|
|
return item.repo_id === repo.repo_id;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
onMenuItemClick = (operation, currentObject) => {
|
|
|
|
const index = this.getRepoIndex(currentObject);
|
|
|
|
this.repoItems[index].onMenuItemClick(operation);
|
|
|
|
|
|
|
|
hideMenu();
|
|
|
|
};
|
|
|
|
|
2019-02-13 14:21:39 +08:00
|
|
|
renderRepoListView = () => {
|
|
|
|
return (
|
|
|
|
<Fragment>
|
2024-10-18 10:54:58 +08:00
|
|
|
{this.props.repoList.map((item, index) => {
|
2019-02-13 14:21:39 +08:00
|
|
|
return (
|
2019-07-22 17:09:10 +08:00
|
|
|
<MylibRepoListItem
|
2024-10-18 10:54:58 +08:00
|
|
|
ref={this.setRepoItemRef(index)}
|
2019-02-13 14:21:39 +08:00
|
|
|
key={item.repo_id}
|
|
|
|
repo={item}
|
|
|
|
isItemFreezed={this.state.isItemFreezed}
|
|
|
|
onFreezedItem={this.onFreezedItem}
|
|
|
|
onUnfreezedItem={this.onUnfreezedItem}
|
|
|
|
onRenameRepo={this.props.onRenameRepo}
|
|
|
|
onDeleteRepo={this.props.onDeleteRepo}
|
|
|
|
onTransferRepo={this.props.onTransferRepo}
|
2023-02-03 09:51:18 +08:00
|
|
|
onMonitorRepo={this.props.onMonitorRepo}
|
2024-06-17 09:32:05 +08:00
|
|
|
currentViewMode={this.props.currentViewMode}
|
2024-10-18 10:54:58 +08:00
|
|
|
onContextMenu={this.onContextMenu}
|
2019-02-13 14:21:39 +08:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</Fragment>
|
|
|
|
);
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2019-02-13 14:21:39 +08:00
|
|
|
|
|
|
|
renderPCUI = () => {
|
2024-09-10 11:46:50 +08:00
|
|
|
const { inAllLibs, currentViewMode = LIST_MODE } = this.props;
|
2024-04-26 21:51:50 +08:00
|
|
|
const showStorageBackend = !inAllLibs && storages.length > 0;
|
2024-06-21 12:07:58 +08:00
|
|
|
const sortIcon = this.props.sortOrder === 'asc' ? <span className="sf3-font sf3-font-down rotate-180 d-inline-block"></span> : <span className="sf3-font sf3-font-down"></span>;
|
2024-04-26 21:51:50 +08:00
|
|
|
|
2024-09-10 11:46:50 +08:00
|
|
|
return currentViewMode == LIST_MODE ? (
|
2024-04-26 21:51:50 +08:00
|
|
|
<table className={inAllLibs ? 'table-thead-hidden' : ''}>
|
2019-02-13 14:21:39 +08:00
|
|
|
<thead>
|
|
|
|
<tr>
|
2019-02-26 14:14:00 +08:00
|
|
|
<th width="4%"></th>
|
2024-04-26 21:51:50 +08:00
|
|
|
<th width="3%"><span className="sr-only">{gettext('Library Type')}</span></th>
|
|
|
|
<th width={showStorageBackend ? '36%' : '35%'}><a className="d-block table-sort-op" href="#" onClick={this.sortByName}>{gettext('Name')} {this.props.sortBy === 'name' && sortIcon}</a></th>
|
|
|
|
<th width="10%"><span className="sr-only">{gettext('Actions')}</span></th>
|
|
|
|
<th width={showStorageBackend ? '15%' : '14%'}><a className="d-block table-sort-op" href="#" onClick={this.sortBySize}>{gettext('Size')} {this.props.sortBy === 'size' && sortIcon}</a></th>
|
|
|
|
{showStorageBackend ? <th width="17%">{gettext('Storage Backend')}</th> : null}
|
|
|
|
<th width={showStorageBackend ? '15%' : '34%'}><a className="d-block table-sort-op" href="#" onClick={this.sortByTime}>{gettext('Last Update')} {this.props.sortBy === 'time' && sortIcon}</a></th>
|
2019-02-13 14:21:39 +08:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{this.renderRepoListView()}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2024-06-17 09:32:05 +08:00
|
|
|
) : (
|
|
|
|
<div className="d-flex justify-content-between flex-wrap">
|
2024-06-17 10:19:27 +08:00
|
|
|
{this.renderRepoListView()}
|
2024-06-17 09:32:05 +08:00
|
|
|
</div>
|
2019-02-13 14:21:39 +08:00
|
|
|
);
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2019-02-13 14:21:39 +08:00
|
|
|
|
|
|
|
renderMobileUI = () => {
|
2024-08-12 12:14:03 +08:00
|
|
|
const { inAllLibs } = this.props;
|
2019-02-13 14:21:39 +08:00
|
|
|
return (
|
2019-07-16 07:55:55 +08:00
|
|
|
<table className="table-thead-hidden">
|
2024-08-12 12:14:03 +08:00
|
|
|
<LibsMobileThead inAllLibs={inAllLibs} />
|
2019-02-13 14:21:39 +08:00
|
|
|
<tbody>
|
|
|
|
{this.renderRepoListView()}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
);
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2019-02-13 14:21:39 +08:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Fragment>
|
2019-02-13 18:09:01 +08:00
|
|
|
<MediaQuery query="(min-width: 768px)">
|
2019-02-13 14:21:39 +08:00
|
|
|
{this.renderPCUI()}
|
|
|
|
</MediaQuery>
|
2019-07-10 21:51:30 +08:00
|
|
|
<MediaQuery query="(max-width: 767.8px)">
|
2019-02-13 14:21:39 +08:00
|
|
|
{this.renderMobileUI()}
|
|
|
|
</MediaQuery>
|
2024-10-18 10:54:58 +08:00
|
|
|
<ContextMenu
|
|
|
|
id="mylib-repo-item-menu"
|
|
|
|
onMenuItemClick={this.onMenuItemClick}
|
|
|
|
/>
|
2019-02-13 14:21:39 +08:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MylibRepoListView.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default MylibRepoListView;
|