1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-21 18:32:37 +00:00
seahub/frontend/src/pages/lib-content-view/lib-content-container.js

362 lines
15 KiB
JavaScript
Raw Normal View History

import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import { gettext } from '../../utils/constants';
import CurDirPath from '../../components/cur-dir-path';
import DirentDetail from '../../components/dirent-detail/dirent-details';
import LibDetail from '../../components/dirent-detail/lib-details';
import DirListView from '../../components/dir-view-mode/dir-list-view';
import DirGridView from '../../components/dir-view-mode/dir-grid-view';
import DirColumnView from '../../components/dir-view-mode/dir-column-view';
2019-04-17 06:18:12 +00:00
import '../../css/lib-content-view.css';
const propTypes = {
pathPrefix: PropTypes.array.isRequired,
currentMode: PropTypes.string.isRequired,
path: PropTypes.string.isRequired,
pathExist: PropTypes.bool.isRequired,
// repoinfo
currentRepoInfo: PropTypes.object.isRequired,
repoID: PropTypes.string.isRequired,
repoPermission: PropTypes.bool.isRequired,
enableDirPrivateShare: PropTypes.bool.isRequired,
isGroupOwnedRepo: PropTypes.bool.isRequired,
userPerm: PropTypes.string,
// path func
onTabNavClick: PropTypes.func.isRequired,
onMainNavBarClick: PropTypes.func.isRequired,
// file
isViewFile: PropTypes.bool.isRequired,
isFileLoadedErr: PropTypes.bool.isRequired,
hash: PropTypes.string,
isDraft: PropTypes.bool.isRequired,
hasDraft: PropTypes.bool.isRequired,
fileTags: PropTypes.array.isRequired,
goDraftPage: PropTypes.func.isRequired,
isFileLoading: PropTypes.bool.isRequired,
2019-04-19 07:50:27 +00:00
filePermission: PropTypes.string,
content: PropTypes.string,
lastModified: PropTypes.string,
latestContributor: PropTypes.string,
onLinkClick: PropTypes.func.isRequired,
// tree
isTreeDataLoading: PropTypes.bool.isRequired,
treeData: PropTypes.object.isRequired,
currentNode: PropTypes.object,
onNodeClick: PropTypes.func.isRequired,
onNodeCollapse: PropTypes.func.isRequired,
onNodeExpanded: PropTypes.func.isRequired,
onRenameNode: PropTypes.func.isRequired,
onDeleteNode: PropTypes.func.isRequired,
onAddFileNode: PropTypes.func.isRequired,
onAddFolderNode: PropTypes.func.isRequired,
// repo content
draftCounts: PropTypes.number,
usedRepoTags: PropTypes.array.isRequired,
readmeMarkdown: PropTypes.object,
updateUsedRepoTags: PropTypes.func.isRequired,
// list
isDirentListLoading: PropTypes.bool.isRequired,
direntList: PropTypes.array.isRequired,
sortBy: PropTypes.string.isRequired,
sortOrder: PropTypes.string.isRequired,
sortItems: PropTypes.func.isRequired,
updateDirent: PropTypes.func.isRequired,
onItemClick: PropTypes.func.isRequired,
onItemSelected: PropTypes.func.isRequired,
onItemDelete: PropTypes.func.isRequired,
onItemRename: PropTypes.func.isRequired,
onItemMove: PropTypes.func.isRequired,
onItemCopy: PropTypes.func.isRequired,
onAddFolder: PropTypes.func.isRequired,
onAddFile: PropTypes.func.isRequired,
onFileTagChanged: PropTypes.func.isRequired,
isDirentSelected: PropTypes.bool.isRequired,
isAllDirentSelected: PropTypes.bool.isRequired,
onAllDirentSelected: PropTypes.func.isRequired,
2019-03-19 10:20:45 +00:00
isDirentDetailShow: PropTypes.bool.isRequired,
selectedDirent: PropTypes.object,
selectedDirentList: PropTypes.array.isRequired,
onItemsMove: PropTypes.func.isRequired,
onItemsCopy: PropTypes.func.isRequired,
onItemsDelete: PropTypes.func.isRequired,
2019-03-19 10:20:45 +00:00
closeDirentDetail: PropTypes.func.isRequired,
showDirentDetail: PropTypes.func.isRequired,
onDeleteRepoTag: PropTypes.func.isRequired,
2019-04-18 05:39:42 +00:00
updateDetail: PropTypes.bool.isRequired,
2019-04-24 07:16:26 +00:00
onListContainerScroll: PropTypes.func.isRequired,
onDirentClick: PropTypes.func.isRequired,
2019-05-29 04:02:07 +00:00
direntDetailPanelTab: PropTypes.string,
};
class LibContentContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
currentDirent: null,
};
this.errMessage = (<div className="message err-tip">{gettext('Folder does not exist.')}</div>);
}
componentWillReceiveProps(nextProps) {
2019-04-18 05:39:42 +00:00
if (nextProps.path !== this.props.path || nextProps.updateDetail !== this.props.updateDetail) {
this.setState({currentDirent: null});
}
}
onPathClick = (path) => {
this.props.onMainNavBarClick(path);
2019-03-19 10:20:45 +00:00
this.props.closeDirentDetail();
}
onItemClick = (dirent) => {
this.props.onItemClick(dirent);
2019-03-19 10:20:45 +00:00
this.props.closeDirentDetail();
}
2019-04-18 14:36:07 +00:00
onGridItemClick = (dirent) => {
this.setState({currentDirent: dirent});
2019-04-21 12:41:14 +00:00
this.props.onDirentClick(dirent);
2019-04-18 14:36:07 +00:00
}
// on '<tr>'
onDirentClick = (dirent) => {
this.setState({currentDirent: dirent});
this.props.onDirentClick(dirent);
}
onItemSelected = (dirent) => {
this.setState({currentDirent: dirent});
2019-04-13 08:56:06 +00:00
this.props.onItemSelected(dirent);
2019-03-18 09:32:49 +00:00
}
2019-04-18 05:39:42 +00:00
onItemDelete = (dirent) => {
2019-07-16 08:21:20 +00:00
this.checkCurrentDirent(dirent);
this.props.onItemDelete(dirent);
}
onItemMove = (destRepo, dirent, selectedPath, currentPath) => {
this.checkCurrentDirent(dirent);
this.props.onItemMove(destRepo, dirent, selectedPath, currentPath);
}
checkCurrentDirent = (deletedDirent) => {
if (deletedDirent.name === this.state.currentDirent.name) {
2019-04-18 05:39:42 +00:00
this.setState({currentDirent: null});
}
}
2019-04-24 05:37:48 +00:00
onItemsScroll = (e) => {
2019-04-24 02:10:28 +00:00
let target = e.target;
if (target.scrollTop === 0) {
return;
}
2019-04-29 06:22:20 +00:00
if (target.scrollTop + target.clientHeight + 1 >= target.scrollHeight) {
2019-04-24 07:16:26 +00:00
this.props.onListContainerScroll();
2019-04-24 02:10:28 +00:00
}
}
render() {
2019-04-24 06:39:46 +00:00
let { path, repoID, usedRepoTags, readmeMarkdown, draftCounts } = this.props;
let isRepoInfoBarShow = false;
if (path === '/') {
if (usedRepoTags.length !== 0 || readmeMarkdown !== null || draftCounts !== 0) {
isRepoInfoBarShow = true;
}
}
return (
<Fragment>
<div className="cur-view-container">
2019-05-17 08:30:56 +00:00
{this.props.currentRepoInfo.status === 'read-only' &&
2019-05-20 02:49:56 +00:00
<div className="readonly-tip-message">
{gettext('This library has been set to read-only by admin and cannot be updated.')}
2019-05-17 08:30:56 +00:00
</div>
}
<div className="cur-view-path">
<CurDirPath
repoID={repoID}
repoName={this.props.currentRepoInfo.repo_name}
pathPrefix={this.props.pathPrefix}
currentPath={this.props.path}
permission={this.props.repoPermission}
isViewFile={this.props.isViewFile}
onTabNavClick={this.props.onTabNavClick}
onPathClick={this.onPathClick}
updateUsedRepoTags={this.props.updateUsedRepoTags}
fileTags={this.props.fileTags}
onDeleteRepoTag={this.props.onDeleteRepoTag}
/>
</div>
2019-04-24 05:37:48 +00:00
<div className={`cur-view-content lib-content-container ${this.props.currentMode === 'column' ? 'view-mode-container' : ''}`} onScroll={this.onItemsScroll}>
{!this.props.pathExist && this.errMessage}
{this.props.pathExist && (
<Fragment>
{this.props.currentMode === 'list' && (
<DirListView
path={this.props.path}
repoID={repoID}
currentRepoInfo={this.props.currentRepoInfo}
isGroupOwnedRepo={this.props.isGroupOwnedRepo}
userPerm={this.props.userPerm}
enableDirPrivateShare={this.props.enableDirPrivateShare}
isRepoInfoBarShow={isRepoInfoBarShow}
usedRepoTags={this.props.usedRepoTags}
readmeMarkdown={this.props.readmeMarkdown}
draftCounts={this.props.draftCounts}
updateUsedRepoTags={this.props.updateUsedRepoTags}
isDirentListLoading={this.props.isDirentListLoading}
2019-04-24 05:52:09 +00:00
direntList={this.props.direntList}
sortBy={this.props.sortBy}
sortOrder={this.props.sortOrder}
sortItems={this.props.sortItems}
onAddFolder={this.props.onAddFolder}
onAddFile={this.props.onAddFile}
onItemClick={this.onItemClick}
2019-04-13 08:56:06 +00:00
onItemSelected={this.onItemSelected}
2019-04-18 05:39:42 +00:00
onItemDelete={this.onItemDelete}
onItemRename={this.props.onItemRename}
2019-07-16 08:21:20 +00:00
onItemMove={this.onItemMove}
onItemCopy={this.props.onItemCopy}
onDirentClick={this.onDirentClick}
updateDirent={this.props.updateDirent}
isAllItemSelected={this.props.isAllDirentSelected}
onAllItemSelected={this.props.onAllDirentSelected}
selectedDirentList={this.props.selectedDirentList}
onItemsMove={this.props.onItemsMove}
onItemsCopy={this.props.onItemsCopy}
onItemsDelete={this.props.onItemsDelete}
2019-04-17 02:48:44 +00:00
onFileTagChanged={this.props.onFileTagChanged}
2019-05-29 04:02:07 +00:00
showDirentDetail={this.props.showDirentDetail}
/>
)}
{this.props.currentMode === 'grid' && (
<DirGridView
2019-04-18 14:36:07 +00:00
path={this.props.path}
repoID={repoID}
currentRepoInfo={this.props.currentRepoInfo}
repoPermission={this.props.repoPermission}
isGroupOwnedRepo={this.props.isGroupOwnedRepo}
userPerm={this.props.userPerm}
2019-04-18 14:36:07 +00:00
enableDirPrivateShare={this.props.enableDirPrivateShare}
onRenameNode={this.props.onRenameNode}
isRepoInfoBarShow={isRepoInfoBarShow}
usedRepoTags={this.props.usedRepoTags}
readmeMarkdown={this.props.readmeMarkdown}
draftCounts={this.props.draftCounts}
updateUsedRepoTags={this.props.updateUsedRepoTags}
isDirentListLoading={this.props.isDirentListLoading}
2019-04-24 05:52:09 +00:00
direntList={this.props.direntList}
2019-04-18 14:36:07 +00:00
onAddFile={this.props.onAddFile}
onItemClick={this.onItemClick}
onItemDelete={this.props.onItemDelete}
2019-07-16 08:21:20 +00:00
onItemMove={this.onItemMove}
2019-04-18 14:36:07 +00:00
onItemCopy={this.props.onItemCopy}
updateDirent={this.props.updateDirent}
onAddFolder={this.props.onAddFolder}
showDirentDetail={this.props.showDirentDetail}
onGridItemClick={this.onGridItemClick}
isDirentDetailShow={this.props.isDirentDetailShow}
onItemRename={this.props.onItemRename}
2019-04-22 10:34:36 +00:00
onFileTagChanged={this.props.onFileTagChanged}
/>
)}
{this.props.currentMode === 'column' && (
<DirColumnView
path={this.props.path}
repoID={repoID}
currentRepoInfo={this.props.currentRepoInfo}
repoPermission={this.props.repoPermission}
isGroupOwnedRepo={this.props.isGroupOwnedRepo}
userPerm={this.props.userPerm}
enableDirPrivateShare={this.props.enableDirPrivateShare}
isTreeDataLoading={this.props.isTreeDataLoading}
treeData={this.props.treeData}
currentNode={this.props.currentNode}
onNodeClick={this.props.onNodeClick}
onNodeCollapse={this.props.onNodeCollapse}
onNodeExpanded={this.props.onNodeExpanded}
onAddFolderNode={this.props.onAddFolder}
onAddFileNode={this.props.onAddFile}
onRenameNode={this.props.onRenameNode}
onDeleteNode={this.props.onDeleteNode}
isViewFile={this.props.isViewFile}
isFileLoading={this.props.isFileLoading}
isFileLoadedErr={this.props.isFileLoadedErr}
hash={this.props.hash}
isDraft={this.props.isDraft}
hasDraft={this.props.hasDraft}
goDraftPage={this.props.goDraftPage}
filePermission={this.props.filePermission}
content={this.props.content}
lastModified={this.props.lastModified}
latestContributor={this.props.latestContributor}
onLinkClick={this.props.onLinkClick}
isRepoInfoBarShow={isRepoInfoBarShow}
usedRepoTags={this.props.usedRepoTags}
readmeMarkdown={this.props.readmeMarkdown}
draftCounts={this.props.draftCounts}
updateUsedRepoTags={this.props.updateUsedRepoTags}
isDirentListLoading={this.props.isDirentListLoading}
2019-04-24 05:52:09 +00:00
direntList={this.props.direntList}
sortBy={this.props.sortBy}
sortOrder={this.props.sortOrder}
sortItems={this.props.sortItems}
onAddFolder={this.props.onAddFolder}
onAddFile={this.props.onAddFile}
onItemClick={this.onItemClick}
2019-04-13 08:56:06 +00:00
onItemSelected={this.onItemSelected}
2019-04-18 05:39:42 +00:00
onItemDelete={this.onItemDelete}
onItemRename={this.props.onItemRename}
2019-07-16 08:21:20 +00:00
onItemMove={this.onItemMove}
onItemCopy={this.props.onItemCopy}
onDirentClick={this.onDirentClick}
updateDirent={this.props.updateDirent}
isAllItemSelected={this.props.isAllDirentSelected}
onAllItemSelected={this.props.onAllDirentSelected}
selectedDirentList={this.props.selectedDirentList}
onItemsMove={this.props.onItemsMove}
onItemsCopy={this.props.onItemsCopy}
onItemsDelete={this.props.onItemsDelete}
2019-04-17 02:48:44 +00:00
onFileTagChanged={this.props.onFileTagChanged}
showDirentDetail={this.props.showDirentDetail}
/>
)}
</Fragment>
)}
</div>
</div>
{this.props.isDirentDetailShow &&
<Fragment>
<div className="cur-view-detail">
2019-04-12 12:34:19 +00:00
{(this.props.path === '/' && !this.state.currentDirent) ?
<LibDetail
currentRepo={this.props.currentRepoInfo}
closeDetails={this.props.closeDirentDetail}
/> :
<DirentDetail
repoID={repoID}
path={this.props.path}
dirent={this.state.currentDirent}
currentRepoInfo={this.props.currentRepoInfo}
onFileTagChanged={this.props.onFileTagChanged}
onItemDetailsClose={this.props.closeDirentDetail}
2019-05-29 04:02:07 +00:00
direntDetailPanelTab={this.props.direntDetailPanelTab}
/>
}
</div>
</Fragment>
}
</Fragment>
);
}
}
LibContentContainer.propTypes = propTypes;
export default LibContentContainer;