mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-08 02:10:24 +00:00
add-history-URL (#2843)
This commit is contained in:
@@ -31,6 +31,7 @@ import './css/initial-style.css';
|
||||
import './css/toolbar.css';
|
||||
import './css/draft-review.css';
|
||||
|
||||
const URL = require('url-parse');
|
||||
require('@seafile/seafile-editor/dist/editor/code-hight-package');
|
||||
|
||||
class DraftReview extends React.Component {
|
||||
@@ -53,6 +54,7 @@ class DraftReview extends React.Component {
|
||||
totalReversionCount: 0,
|
||||
changedNodes: [],
|
||||
isShowCommentDialog: false,
|
||||
activeItem: null,
|
||||
};
|
||||
this.quote = '';
|
||||
this.newIndex = null;
|
||||
@@ -99,6 +101,39 @@ class DraftReview extends React.Component {
|
||||
return;
|
||||
}
|
||||
|
||||
const hash = window.location.hash;
|
||||
if (hash.indexOf('#history-') === 0) {
|
||||
const currentCommitID = hash.slice(9, 49);
|
||||
const preCommitID = hash.slice(50, 90);
|
||||
this.setState({
|
||||
isLoading: false,
|
||||
activeTab: 'history',
|
||||
});
|
||||
seafileAPI.listFileHistoryRecords(draftOriginRepoID, draftFilePath, 1, 25).then((res) => {
|
||||
const historyList = res.data.data;
|
||||
this.setState({
|
||||
historyList: historyList,
|
||||
totalReversionCount: res.data.total_count
|
||||
});
|
||||
for (let i = 0, length = historyList.length; i < length; i++) {
|
||||
if (preCommitID === historyList[i].commit_id) {
|
||||
this.setState({
|
||||
activeItem: i
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
axios.all([
|
||||
seafileAPI.getFileRevision(draftOriginRepoID, currentCommitID, draftFilePath),
|
||||
seafileAPI.getFileRevision(draftOriginRepoID, preCommitID, draftFilePath)
|
||||
]).then(axios.spread((res1, res2) => {
|
||||
axios.all([seafileAPI.getFileContent(res1.data), seafileAPI.getFileContent(res2.data)]).then(axios.spread((content1,content2) => {
|
||||
this.setDiffViewerContent(content2.data, content1.data);
|
||||
}));
|
||||
}));
|
||||
return;
|
||||
} else {
|
||||
axios.all([
|
||||
seafileAPI.getFileDownloadLink(draftOriginRepoID, draftFilePath),
|
||||
seafileAPI.getFileDownloadLink(draftOriginRepoID, draftOriginFilePath)
|
||||
@@ -118,6 +153,7 @@ class DraftReview extends React.Component {
|
||||
}, 100);
|
||||
}));
|
||||
}));
|
||||
}
|
||||
break;
|
||||
case "finished":
|
||||
if (!originFileExists) {
|
||||
@@ -148,6 +184,35 @@ class DraftReview extends React.Component {
|
||||
document.removeEventListener('selectionchange', this.setBtnPosition);
|
||||
}
|
||||
|
||||
onHistoryItemClick = (currentCommitID, preCommitID, activeItem) => {
|
||||
const url = 'history-' + preCommitID + '-' + currentCommitID;
|
||||
this.setURL(url);
|
||||
this.setState({
|
||||
activeItem: activeItem
|
||||
});
|
||||
|
||||
axios.all([
|
||||
seafileAPI.getFileRevision(draftOriginRepoID, currentCommitID, draftFilePath),
|
||||
seafileAPI.getFileRevision(draftOriginRepoID, preCommitID, draftFilePath)
|
||||
]).then(axios.spread((res1, res2) => {
|
||||
axios.all([seafileAPI.getFileContent(res1.data), seafileAPI.getFileContent(res2.data)]).then(axios.spread((content1,content2) => {
|
||||
this.setDiffViewerContent(content1.data, content2.data);
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
onHistoryListChange = (historyList) => {
|
||||
this.setState({
|
||||
historyList: historyList
|
||||
});
|
||||
}
|
||||
|
||||
setURL = (newurl) => {
|
||||
let url = new URL(window.location.href);
|
||||
url.set('hash', newurl);
|
||||
window.location.href = url.toString();
|
||||
}
|
||||
|
||||
onCloseReview = () => {
|
||||
seafileAPI.updateReviewStatus(reviewID, 'closed').then(res => {
|
||||
this.setState({reviewStatus: 'closed'});
|
||||
@@ -438,6 +503,9 @@ class DraftReview extends React.Component {
|
||||
|
||||
tabItemClick = (tab) => {
|
||||
if (this.state.activeTab !== tab) {
|
||||
if (tab !== 'history') {
|
||||
this.setURL('#');
|
||||
}
|
||||
if (tab == 'reviewInfo') {
|
||||
this.initialContent();
|
||||
}
|
||||
@@ -815,9 +883,13 @@ class DraftReview extends React.Component {
|
||||
</TabPane>
|
||||
{ this.state.reviewStatus == 'finished'? '':
|
||||
<TabPane tabId="history" className="history">
|
||||
<HistoryList setDiffViewerContent={this.setDiffViewerContent}
|
||||
<HistoryList
|
||||
activeItem={this.state.activeItem}
|
||||
historyList={this.state.historyList}
|
||||
totalReversionCount={this.state.totalReversionCount}/>
|
||||
onHistoryItemClick={this.onHistoryItemClick}
|
||||
onHistoryListChange={this.onHistoryListChange}
|
||||
totalReversionCount={this.state.totalReversionCount}
|
||||
/>
|
||||
</TabPane>
|
||||
}
|
||||
</TabContent>
|
||||
|
@@ -16,7 +16,6 @@ class HistoryList extends React.Component {
|
||||
super(props);
|
||||
this.perPage = 25;
|
||||
this.state = {
|
||||
activeItem: 0,
|
||||
currentPage: 1,
|
||||
loading: false
|
||||
};
|
||||
@@ -24,17 +23,7 @@ class HistoryList extends React.Component {
|
||||
|
||||
onClick = (event, key, preCommitID, currentCommitID)=> {
|
||||
if (key === this.state.activeItem) return false;
|
||||
this.setState({
|
||||
activeItem: key,
|
||||
});
|
||||
axios.all([
|
||||
seafileAPI.getFileRevision(draftOriginRepoID, currentCommitID, draftFilePath),
|
||||
seafileAPI.getFileRevision(draftOriginRepoID, preCommitID, draftFilePath)
|
||||
]).then(axios.spread((res1, res2) => {
|
||||
axios.all([seafileAPI.getFileContent(res1.data), seafileAPI.getFileContent(res2.data)]).then(axios.spread((content1,content2) => {
|
||||
this.props.setDiffViewerContent(content1.data, content2.data);
|
||||
}));
|
||||
}));
|
||||
this.props.onHistoryItemClick(currentCommitID, preCommitID, key);
|
||||
}
|
||||
|
||||
onScroll = (event) => {
|
||||
@@ -51,8 +40,8 @@ class HistoryList extends React.Component {
|
||||
});
|
||||
seafileAPI.listFileHistoryRecords(draftOriginRepoID, draftFilePath, currentPage, this.perPage).then((res) => {
|
||||
let currentHistoryList = Object.assign([], this.props.historyList);
|
||||
this.props.onHistoryListChange([...currentHistoryList, ...res.data.data]);
|
||||
this.setState({
|
||||
historyList: [...currentHistoryList, ...res.data.data],
|
||||
loading : false
|
||||
});
|
||||
});
|
||||
@@ -75,7 +64,7 @@ class HistoryList extends React.Component {
|
||||
<HistoryItem
|
||||
onClick={this.onClick}
|
||||
ctime={item.ctime}
|
||||
className={this.state.activeItem === index ? 'item-active': ''}
|
||||
className={this.props.activeItem === index ? 'item-active': ''}
|
||||
currentCommitId={item.commit_id}
|
||||
name={item.creator_name}
|
||||
index={index}
|
||||
|
Reference in New Issue
Block a user