1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-06 17:33:18 +00:00
Files
seahub/frontend/src/pages/my-libs/content.js

166 lines
5.4 KiB
JavaScript
Raw Normal View History

2018-12-12 15:34:54 +08:00
import React, { Component, Fragment } from 'react';
2018-12-12 11:38:27 +08:00
import PropTypes from 'prop-types';
import { gettext, storages} from '../../utils/constants';
2018-12-12 17:09:15 +08:00
import Loading from '../../components/loading';
2018-12-12 17:51:12 +08:00
import TableBody from './table-body';
2018-12-12 17:09:15 +08:00
import ModalPortal from '../../components/modal-portal';
2018-12-12 17:51:12 +08:00
import LibHistorySetting from '../../components/dialog/lib-history-setting-dialog';
import TransferDialog from '../../components/dialog/transfer-dialog';
2018-12-12 17:09:15 +08:00
import DeleteRepoDialog from '../../components/dialog/delete-repo-dialog';
2018-12-12 11:38:27 +08:00
2018-12-12 15:34:54 +08:00
const propTypes = {
loading: PropTypes.bool.isRequired,
errorMsg: PropTypes.string.isRequired,
items: PropTypes.array.isRequired,
onRenameRepo: PropTypes.func.isRequired,
onDeleteRepo: PropTypes.func.isRequired,
onTransferRepo: PropTypes.func.isRequired,
onRepoDetails: PropTypes.func.isRequired,
};
2018-12-12 11:38:27 +08:00
class Content extends Component {
constructor(props) {
super(props);
this.state = {
deleteItemPopupOpen: false,
showTransfer: false,
itemName: '',
showHistorySetting: false,
showDetails: false,
libID: '',
libSize: '',
libUpdateTime: ''
};
}
2018-12-12 15:34:54 +08:00
toggleDeleteItemPopup = () => {
2018-12-12 11:38:27 +08:00
this.setState({
deleteItemPopupOpen: !this.state.deleteItemPopupOpen
});
}
2018-12-12 15:34:54 +08:00
showDeleteItemPopup = (data) => {
2018-12-12 11:38:27 +08:00
this.toggleDeleteItemPopup();
this.setState({
deleteItemPopupData: data
});
}
2018-12-12 15:34:54 +08:00
onTransfer = (itemName, itemID) => {
2018-12-12 11:38:27 +08:00
this.setState({
showTransfer: !this.state.showTransfer,
itemName: itemName,
libID: itemID
});
}
2018-12-12 15:34:54 +08:00
onHistorySetting = (itemName, itemID) => {
2018-12-12 11:38:27 +08:00
this.setState({
showHistorySetting: !this.state.showHistorySetting,
itemName: itemName,
libID: itemID
});
}
render() {
2018-12-12 15:34:54 +08:00
const { loading, errorMsg, items } = this.props;
2018-12-12 11:38:27 +08:00
if (loading) {
return <Loading />;
} else if (errorMsg) {
return <p className="error text-center">{errorMsg}</p>;
} else {
const emptyTip = (
<div className="empty-tip">
<h2>{gettext('You have not created any libraries')}</h2>
<p>{gettext('You can create a library to organize your files. For example, you can create one for each of your projects. Each library can be synchronized and shared separately.')}</p>
</div>
);
// TODO: test 'storage backend'
const showStorageBackend = storages.length > 0; // only for desktop
const desktopThead = (
<thead>
<tr>
2018-12-12 17:51:12 +08:00
<th width="4%"><span className="sr-only">{gettext('Library Type')}</span></th>
<th width="42%">{gettext('Name')}<a className="table-sort-op by-name" href="#">{/*TODO: sort*/}<span className="sort-icon icon-caret-down hide"></span></a></th>
<th width="14%"><span className="sr-only">{gettext('Actions')}</span></th>
2018-12-12 11:38:27 +08:00
2018-12-12 17:51:12 +08:00
<th width={showStorageBackend ? '15%' : '20%'}>{gettext('Size')}</th>
2018-12-12 11:38:27 +08:00
{showStorageBackend ? <th width="10%">{gettext('Storage backend')}</th> : null}
2018-12-12 17:51:12 +08:00
<th width={showStorageBackend ? '15%' : '20%'}>{gettext('Last Update')}<a className="table-sort-op by-time" href="#">{/*TODO: sort*/}<span className="sort-icon icon-caret-up"></span></a></th>
2018-12-12 11:38:27 +08:00
</tr>
</thead>
);
const mobileThead = (
<thead>
<tr>
2018-12-12 17:51:12 +08:00
<th width="18%"><span className="sr-only">{gettext('Library Type')}</span></th>
2018-12-12 11:38:27 +08:00
<th width="76%">
{gettext("Sort:")} {/* TODO: sort */}
{gettext("name")}<a className="table-sort-op mobile-table-sort-op by-name" href="#"> <span className="sort-icon icon-caret-down hide"></span></a>
{gettext("last update")}<a className="table-sort-op mobile-table-sort-op by-time" href="#"> <span className="sort-icon icon-caret-up"></span></a>
</th>
2018-12-12 17:51:12 +08:00
<th width="6%"><span className="sr-only">{gettext('Actions')}</span></th>
2018-12-12 11:38:27 +08:00
</tr>
</thead>
);
const table = (
<table>
{window.innerWidth >= 768 ? desktopThead : mobileThead}
2018-12-12 15:34:54 +08:00
<TableBody
items={items}
onRenameRepo={this.props.onRenameRepo}
onDeleteRepo={this.props.onDeleteRepo}
onRepoDetails={this.props.onRepoDetails}
onTransfer={this.onTransfer}
showDeleteItemPopup={this.showDeleteItemPopup}
onHistorySetting={this.onHistorySetting}
/>
2018-12-12 11:38:27 +08:00
</table>
);
const nonEmpty = (
2018-12-12 15:34:54 +08:00
<Fragment>
2018-12-12 11:38:27 +08:00
{table}
2018-12-12 17:51:12 +08:00
{this.state.deleteItemPopupOpen && (
<ModalPortal>
<DeleteRepoDialog
toggle={this.toggleDeleteItemPopup}
data={this.state.deleteItemPopupData}
/>
</ModalPortal>
)}
2018-12-12 11:38:27 +08:00
{this.state.showTransfer &&
<ModalPortal>
2018-12-12 15:34:54 +08:00
<TransferDialog
toggleDialog={this.onTransfer}
itemName={this.state.itemName}
repoID={this.state.libID}
submit={this.props.onTransferRepo}
/>
2018-12-12 11:38:27 +08:00
</ModalPortal>
}
{this.state.showHistorySetting &&
<ModalPortal>
2018-12-12 15:34:54 +08:00
<LibHistorySetting
toggleDialog={this.onHistorySetting}
itemName={this.state.itemName}
repoID={this.state.libID}
/>
2018-12-12 11:38:27 +08:00
</ModalPortal>
}
2018-12-12 15:34:54 +08:00
</Fragment>
2018-12-12 11:38:27 +08:00
);
return items.length ? nonEmpty : emptyTip;
}
}
}
2018-12-12 15:34:54 +08:00
Content.propTypes = propTypes;
2018-12-12 11:38:27 +08:00
export default Content;