2018-10-15 07:51:29 +00:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
2018-10-16 10:19:51 +00:00
|
|
|
/* eslint-disable */
|
2018-10-15 07:51:29 +00:00
|
|
|
import Prism from 'prismjs';
|
2018-10-16 10:19:51 +00:00
|
|
|
/* eslint-enable */
|
2018-10-23 05:13:44 +00:00
|
|
|
import { siteRoot, gettext, reviewID, draftOriginFilePath, draftFilePath, draftOriginRepoID, draftFileName, opStatus, publishFileVersion, originFileVersion } from './utils/constants';
|
2018-10-15 07:51:29 +00:00
|
|
|
import { seafileAPI } from './utils/seafile-api';
|
|
|
|
import axios from 'axios';
|
|
|
|
import DiffViewer from '@seafile/seafile-editor/dist/viewer/diff-viewer';
|
|
|
|
import Loading from './components/loading';
|
|
|
|
import Toast from './components/toast';
|
2018-10-23 05:13:44 +00:00
|
|
|
import ReviewComments from './components/review-list-view/review-comments';
|
2018-10-15 07:51:29 +00:00
|
|
|
|
|
|
|
import 'seafile-ui';
|
|
|
|
import './assets/css/fa-solid.css';
|
|
|
|
import './assets/css/fa-regular.css';
|
|
|
|
import './assets/css/fontawesome.css';
|
|
|
|
import './css/layout.css';
|
|
|
|
import './css/initial-style.css';
|
|
|
|
import './css/toolbar.css';
|
2018-10-23 05:13:44 +00:00
|
|
|
import './css/draft-review.css';
|
2018-10-15 07:51:29 +00:00
|
|
|
|
|
|
|
require('@seafile/seafile-editor/dist/editor/code-hight-package');
|
|
|
|
|
|
|
|
class DraftReview extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
draftContent: '',
|
|
|
|
draftOriginContent: '',
|
|
|
|
reviewStatus: opStatus,
|
|
|
|
isLoading: true,
|
2018-10-23 05:13:44 +00:00
|
|
|
commentsNumber: null,
|
|
|
|
isShowComments: false,
|
2018-10-15 07:51:29 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
if (publishFileVersion == 'None') {
|
2018-10-16 10:19:51 +00:00
|
|
|
axios.all([
|
|
|
|
seafileAPI.getFileDownloadLink(draftOriginRepoID, draftFilePath),
|
|
|
|
seafileAPI.getFileDownloadLink(draftOriginRepoID, draftOriginFilePath)
|
2018-10-15 07:51:29 +00:00
|
|
|
]).then(axios.spread((res1, res2) => {
|
|
|
|
axios.all([
|
|
|
|
seafileAPI.getFileContent(res1.data),
|
|
|
|
seafileAPI.getFileContent(res2.data)
|
|
|
|
]).then(axios.spread((draftContent, draftOriginContent) => {
|
|
|
|
this.setState({
|
|
|
|
draftContent: draftContent.data,
|
|
|
|
draftOriginContent: draftOriginContent.data,
|
|
|
|
isLoading: false
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
let dl0 = siteRoot + 'repo/' + draftOriginRepoID + '/' + publishFileVersion + '/download?' + 'p=' + draftOriginFilePath;
|
|
|
|
let dl = siteRoot + 'repo/' + draftOriginRepoID + '/' + originFileVersion + '/download?' + 'p=' + draftOriginFilePath;
|
|
|
|
axios.all([
|
|
|
|
seafileAPI.getFileContent(dl0),
|
|
|
|
seafileAPI.getFileContent(dl)
|
|
|
|
]).then(axios.spread((draftContent, draftOriginContent) => {
|
|
|
|
this.setState({
|
|
|
|
draftContent: draftContent.data,
|
|
|
|
draftOriginContent: draftOriginContent.data,
|
|
|
|
isLoading: false,
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onCloseReview = () => {
|
|
|
|
seafileAPI.updateReviewStatus(reviewID, 'closed').then(res => {
|
|
|
|
this.setState({reviewStatus: 'closed'});
|
2018-10-16 10:19:51 +00:00
|
|
|
Toast.success('Review close succeeded.');
|
2018-10-15 07:51:29 +00:00
|
|
|
}).catch(() => {
|
2018-10-16 10:19:51 +00:00
|
|
|
Toast.error('Review close failed.');
|
2018-10-15 07:51:29 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onPublishReview = () => {
|
|
|
|
seafileAPI.updateReviewStatus(reviewID, 'finished').then(res => {
|
|
|
|
this.setState({reviewStatus: 'finished'});
|
2018-10-16 10:19:51 +00:00
|
|
|
Toast.success('Review publish succeeded.');
|
2018-10-15 07:51:29 +00:00
|
|
|
}).catch(() => {
|
2018-10-16 10:19:51 +00:00
|
|
|
Toast.error('Review publish failed.');
|
2018-10-15 07:51:29 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-23 05:13:44 +00:00
|
|
|
toggleCommentList = () => {
|
|
|
|
this.setState({
|
|
|
|
isShowComments: !this.state.isShowComments
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getCommentsNumber = () => {
|
|
|
|
seafileAPI.listReviewComments(reviewID).then((res) => {
|
|
|
|
let number = res.data.total_count;
|
|
|
|
this.setState({
|
|
|
|
commentsNumber: number,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
this.getCommentsNumber();
|
|
|
|
}
|
|
|
|
|
2018-10-15 07:51:29 +00:00
|
|
|
render() {
|
|
|
|
return(
|
|
|
|
<div className="wrapper">
|
|
|
|
<div id="header" className="header review">
|
|
|
|
<div className="cur-file-info">
|
|
|
|
<div className="info-item file-feature">
|
|
|
|
<span className="fas fa-code-merge"></span>
|
|
|
|
</div>
|
|
|
|
<div className="info-item file-info">
|
|
|
|
<span className="file-name">{draftFileName}</span>
|
|
|
|
<span className="file-copywriting">{gettext('review')}</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-10-23 05:13:44 +00:00
|
|
|
<div className="button-group">
|
|
|
|
<button className="btn btn-icon btn-secondary btn-active common-list-btn"
|
|
|
|
id="commentsNumber" type="button" data-active="false"
|
|
|
|
onMouseDown={this.toggleCommentList}>
|
|
|
|
<i className="fa fa-comments"></i>
|
|
|
|
{ this.state.commentsNumber > 0 &&
|
|
|
|
<span> {this.state.commentsNumber}</span>
|
|
|
|
}
|
|
|
|
</button>
|
|
|
|
{
|
|
|
|
this.state.reviewStatus === 'open' &&
|
|
|
|
<div className="cur-file-operation">
|
|
|
|
<button className="btn btn-secondary file-operation-btn" title={gettext('Close Review')} onClick={this.onCloseReview}>{gettext("Close")}</button>
|
|
|
|
<button className="btn btn-success file-operation-btn" title={gettext('Publish Review')} onClick={this.onPublishReview}>{gettext("Publish")}</button>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
{
|
|
|
|
this.state.reviewStatus === 'finished' &&
|
|
|
|
<div className="review-state review-state-finished">{gettext('Finished')}</div>
|
|
|
|
}
|
|
|
|
{
|
|
|
|
this.state.reviewStatus === 'closed' &&
|
|
|
|
<div className="review-state review-state-closed">{gettext('Closed')}</div>
|
|
|
|
}
|
|
|
|
</div>
|
2018-10-15 07:51:29 +00:00
|
|
|
</div>
|
|
|
|
<div id="main" className="main">
|
|
|
|
<div className="cur-view-container content-container">
|
2018-10-23 05:13:44 +00:00
|
|
|
<div className={!this.state.isShowComments ? "cur-view-content" : "cur-view-content cur-view-content-commenton"}>
|
2018-10-15 07:51:29 +00:00
|
|
|
<div className="markdown-viewer-render-content article">
|
2018-10-16 10:19:51 +00:00
|
|
|
{this.state.isLoading ?
|
2018-10-15 07:51:29 +00:00
|
|
|
<Loading /> :
|
|
|
|
<DiffViewer markdownContent={this.state.draftContent} markdownContent1={this.state.draftOriginContent} />
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-10-23 05:13:44 +00:00
|
|
|
{ this.state.isShowComments &&
|
|
|
|
<ReviewComments
|
|
|
|
toggleCommentList={this.toggleCommentList}
|
|
|
|
commentsNumber={this.state.commentsNumber}
|
|
|
|
getCommentsNumber={this.getCommentsNumber}
|
|
|
|
/>
|
|
|
|
}
|
2018-10-15 07:51:29 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactDOM.render (
|
|
|
|
<DraftReview />,
|
|
|
|
document.getElementById('wrapper')
|
2018-10-23 05:13:44 +00:00
|
|
|
);
|