1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-22 08:47:22 +00:00
seahub/frontend/src/pages/repo-wiki-mode/main-panel.js

164 lines
5.6 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
2018-10-13 09:07:54 +00:00
import PropTypes from 'prop-types';
import { gettext, repoID, serviceUrl, slug, siteRoot } from '../../utils/constants';
2018-10-13 09:07:54 +00:00
import { seafileAPI } from '../../utils/seafile-api';
import CommonToolbar from '../../components/toolbar/common-toolbar';
2018-09-19 01:57:17 +00:00
import PathToolbar from '../../components/toolbar/path-toolbar';
import MarkdownViewer from '../../components/markdown-viewer';
2018-10-13 09:07:54 +00:00
import DirentListView from '../../components/dirent-list-view/dirent-list-view';
import Dirent from '../../models/dirent';
const propTypes = {
content: PropTypes.string,
lastModified: PropTypes.string,
latestContributor: PropTypes.string,
permission: PropTypes.string,
filePath: PropTypes.string.isRequired,
isFileLoading: PropTypes.bool.isRequired,
isViewFileState: PropTypes.bool.isRequired,
onMenuClick: PropTypes.func.isRequired,
onSearchedClick: PropTypes.func.isRequired,
onMainNavBarClick: PropTypes.func.isRequired,
onMainItemClick: PropTypes.func.isRequired,
onMainItemDelete: PropTypes.func.isRequired,
}
class MainPanel extends Component {
2018-09-19 01:57:17 +00:00
constructor(props) {
super(props);
this.state = {
2018-09-29 07:47:53 +00:00
isWikiMode: true,
2018-10-13 09:07:54 +00:00
direntList: []
2018-09-29 07:47:53 +00:00
};
2018-09-19 01:57:17 +00:00
}
2018-10-13 09:07:54 +00:00
componentWillReceiveProps(nextProps) {
let node = nextProps.changedNode;
if (node && node.isDir()) {
let path = node.path;
this.updateViewList(path);
}
}
2018-10-13 09:07:54 +00:00
updateViewList = (filePath) => {
seafileAPI.listDir(repoID, filePath, 48).then(res => {
let direntList = [];
res.data.forEach(item => {
let dirent = new Dirent(item);
direntList.push(dirent);
});
this.setState({
direntList: direntList,
});
});
}
onMenuClick = () => {
this.props.onMenuClick();
}
onMainNavBarClick = (e) => {
this.props.onMainNavBarClick(e.target.dataset.path);
}
switchViewMode = (e) => {
e.preventDefault();
2018-09-19 01:57:17 +00:00
if (e.target.id === 'wiki') {
return;
}
this.setState({isWikiMode: false});
this.props.switchViewMode(e.target.id);
}
2018-10-13 09:07:54 +00:00
onEditClick = (e) => {
e.preventDefault();
window.location.href= serviceUrl + '/lib/' + repoID + '/file' + this.props.filePath + '?mode=edit';
}
2018-10-13 09:07:54 +00:00
render() {
let filePathList = this.props.filePath.split('/');
let nodePath = '';
let pathElem = filePathList.map((item, index) => {
if (item === '') {
return;
}
if (index === (filePathList.length - 1)) {
return (
<span key={index}><span className="path-split">/</span>{item}</span>
);
} else {
nodePath += '/' + item;
return (
2018-09-19 01:57:17 +00:00
<span key={index} >
<span className="path-split">/</span>
<a
className="path-link"
data-path={nodePath}
onClick={this.onMainNavBarClick}>
{item}
</a>
</span>
);
}
});
return (
<div className="main-panel wiki-main-panel o-hidden">
<div className="main-panel-top panel-top">
<div className="cur-view-toolbar border-left-show">
<span className="sf2-icon-menu hidden-md-up d-md-none side-nav-toggle" title={gettext('Side Nav Menu')} onClick={this.onMenuClick}></span>
2018-09-19 01:57:17 +00:00
{
this.props.permission === 'rw' &&
<button className="btn btn-secondary top-toolbar-btn" title={gettext('Edit File')} onClick={this.onEditClick}>{gettext('Edit')}</button>
2018-09-19 01:57:17 +00:00
}
<div className="btn-group">
<button className="btn btn-secondary btn-icon sf-view-mode-change-btn sf2-icon-list-view" id='list' title={gettext('List')} onClick={this.switchViewMode}></button>
<button className="btn btn-secondary btn-icon sf-view-mode-change-btn sf2-icon-grid-view" id='grid' title={gettext('Grid')} onClick={this.switchViewMode}></button>
<button className={`btn btn-secondary btn-icon sf-view-mode-change-btn sf2-icon-wiki-view ${this.state.isWikiMode ? 'current-mode' : ''}`} id='wiki' title={gettext('wiki')} onClick={this.switchViewMode}></button>
2018-09-19 01:57:17 +00:00
</div>
</div>
<CommonToolbar onSearchedClick={this.props.onSearchedClick} searchPlaceholder={'Search files in this library'}/>
</div>
2018-09-21 06:16:15 +00:00
<div className="cur-view-container">
<div className="cur-view-path">
<div className="path-containter">
<a href={siteRoot + '#common/'} className="normal">{gettext('Libraries')}</a>
<span className="path-split">/</span>
2018-10-13 09:07:54 +00:00
{
this.props.filePath === '/' ?
<span>{slug}</span> :
<a className="path-link" data-path="/" onClick={this.onMainNavBarClick}>{slug}</a>
}
{pathElem}
</div>
2018-09-29 07:47:53 +00:00
<PathToolbar filePath={this.props.filePath}/>
</div>
2018-09-21 06:16:15 +00:00
<div className="cur-view-content">
2018-10-13 09:07:54 +00:00
{ this.props.isViewFileState ?
2018-09-21 06:16:15 +00:00
<MarkdownViewer
markdownContent={this.props.content}
latestContributor={this.props.latestContributor}
lastModified = {this.props.lastModified}
onLinkClick={this.props.onLinkClick}
isFileLoading={this.props.isFileLoading}
2018-10-13 09:07:54 +00:00
/> :
<DirentListView
direntList={this.state.direntList}
filePath={this.props.filePath}
onItemClick={this.props.onMainItemClick}
onItemDelete={this.props.onMainItemDelete}
updateViewList={this.updateViewList}
2018-09-21 06:16:15 +00:00
/>
}
</div>
</div>
</div>
);
}
}
2018-10-13 09:07:54 +00:00
MainPanel.propTypes = propTypes;
export default MainPanel;