1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-10 03:11:07 +00:00
Files
seahub/frontend/src/pages/my-libs/mylib-repo-list-view.js

195 lines
6.1 KiB
JavaScript
Raw Normal View History

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';
import LibsMobileThead from '../../components/libs-mobile-thead';
2024-09-10 11:46:50 +08:00
import { LIST_MODE } from '../../components/dir-view-mode/constants';
import ContextMenu from '../../components/context-menu/context-menu';
import { Utils } from '../../utils/utils';
import { hideMenu, handleContextClick } from '../../components/context-menu/actions';
import NewLibrary from './new-library';
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,
onMonitorRepo: PropTypes.func.isRequired,
inAllLibs: PropTypes.bool, // for 'My Libraries' in 'Files' page
currentViewMode: PropTypes.string,
};
class MylibRepoListView extends React.Component {
constructor(props) {
super(props);
this.state = {
isItemFreezed: false,
};
this.repoItems = [];
}
onFreezedItem = () => {
2024-07-18 11:58:42 +08:00
this.setState({ isItemFreezed: true });
};
2019-07-22 17:09:10 +08:00
onUnfreezedItem = () => {
2024-07-18 11:58:42 +08:00
this.setState({ isItemFreezed: false });
};
sortByName = (e) => {
e.preventDefault();
const sortBy = 'name';
const sortOrder = this.props.sortOrder == 'asc' ? 'desc' : 'asc';
this.props.sortRepoList(sortBy, sortOrder);
};
sortByTime = (e) => {
e.preventDefault();
const sortBy = 'time';
const sortOrder = this.props.sortOrder == 'asc' ? 'desc' : 'asc';
this.props.sortRepoList(sortBy, sortOrder);
};
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);
};
2019-05-29 13:57:12 +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();
};
renderRepoListView = () => {
return (
<Fragment>
{this.props.repoList.map((item, index) => {
return (
2019-07-22 17:09:10 +08:00
<MylibRepoListItem
ref={this.setRepoItemRef(index)}
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}
onMonitorRepo={this.props.onMonitorRepo}
currentViewMode={this.props.currentViewMode}
onContextMenu={this.onContextMenu}
/>
);
})}
</Fragment>
);
};
renderPCUI = () => {
2024-09-10 11:46:50 +08:00
const { inAllLibs, currentViewMode = LIST_MODE } = this.props;
const showStorageBackend = !inAllLibs && storages.length > 0;
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-09-10 11:46:50 +08:00
return currentViewMode == LIST_MODE ? (
<>
<table className={inAllLibs ? 'table-thead-hidden' : ''}>
<thead>
<tr>
<th width="4%"></th>
<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>
</tr>
</thead>
<tbody>
{this.renderRepoListView()}
</tbody>
</table>
{!inAllLibs && <NewLibrary onClick={this.props.toggleCreateRepoDialog} />}
</>
) : (
<div className="d-flex justify-content-between flex-wrap">
{this.renderRepoListView()}
</div>
);
};
renderMobileUI = () => {
const { inAllLibs } = this.props;
return (
<table className="table-thead-hidden">
<LibsMobileThead inAllLibs={inAllLibs} />
<tbody>
{this.renderRepoListView()}
</tbody>
</table>
);
};
render() {
return (
<Fragment>
<MediaQuery query="(min-width: 768px)">
{this.renderPCUI()}
</MediaQuery>
<MediaQuery query="(max-width: 767.8px)">
{this.renderMobileUI()}
</MediaQuery>
<ContextMenu
id="mylib-repo-item-menu"
onMenuItemClick={this.onMenuItemClick}
/>
</Fragment>
);
}
}
MylibRepoListView.propTypes = propTypes;
export default MylibRepoListView;