1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-07 01:41:39 +00:00

add-history-URL (#2843)

This commit is contained in:
Michael An
2019-01-18 18:40:45 +08:00
committed by Daniel Pan
parent f6533f0515
commit 857ea17544
2 changed files with 94 additions and 33 deletions

View File

@@ -31,6 +31,7 @@ import './css/initial-style.css';
import './css/toolbar.css'; import './css/toolbar.css';
import './css/draft-review.css'; import './css/draft-review.css';
const URL = require('url-parse');
require('@seafile/seafile-editor/dist/editor/code-hight-package'); require('@seafile/seafile-editor/dist/editor/code-hight-package');
class DraftReview extends React.Component { class DraftReview extends React.Component {
@@ -53,6 +54,7 @@ class DraftReview extends React.Component {
totalReversionCount: 0, totalReversionCount: 0,
changedNodes: [], changedNodes: [],
isShowCommentDialog: false, isShowCommentDialog: false,
activeItem: null,
}; };
this.quote = ''; this.quote = '';
this.newIndex = null; this.newIndex = null;
@@ -99,25 +101,59 @@ class DraftReview extends React.Component {
return; return;
} }
axios.all([ const hash = window.location.hash;
seafileAPI.getFileDownloadLink(draftOriginRepoID, draftFilePath), if (hash.indexOf('#history-') === 0) {
seafileAPI.getFileDownloadLink(draftOriginRepoID, draftOriginFilePath) const currentCommitID = hash.slice(9, 49);
]).then(axios.spread((res1, res2) => { const preCommitID = hash.slice(50, 90);
axios.all([ this.setState({
seafileAPI.getFileContent(res1.data), isLoading: false,
seafileAPI.getFileContent(res2.data) activeTab: 'history',
]).then(axios.spread((draftContent, draftOriginContent) => { });
seafileAPI.listFileHistoryRecords(draftOriginRepoID, draftFilePath, 1, 25).then((res) => {
const historyList = res.data.data;
this.setState({ this.setState({
draftContent: draftContent.data, historyList: historyList,
draftOriginContent: draftOriginContent.data, totalReversionCount: res.data.total_count
isLoading: false });
}); for (let i = 0, length = historyList.length; i < length; i++) {
let that = this; if (preCommitID === historyList[i].commit_id) {
setTimeout(() => { this.setState({
that.getChangedNodes(); activeItem: i
}, 100); });
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)
]).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
});
let that = this;
setTimeout(() => {
that.getChangedNodes();
}, 100);
}));
}));
}
break; break;
case "finished": case "finished":
if (!originFileExists) { if (!originFileExists) {
@@ -148,6 +184,35 @@ class DraftReview extends React.Component {
document.removeEventListener('selectionchange', this.setBtnPosition); 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 = () => { onCloseReview = () => {
seafileAPI.updateReviewStatus(reviewID, 'closed').then(res => { seafileAPI.updateReviewStatus(reviewID, 'closed').then(res => {
this.setState({reviewStatus: 'closed'}); this.setState({reviewStatus: 'closed'});
@@ -438,6 +503,9 @@ class DraftReview extends React.Component {
tabItemClick = (tab) => { tabItemClick = (tab) => {
if (this.state.activeTab !== tab) { if (this.state.activeTab !== tab) {
if (tab !== 'history') {
this.setURL('#');
}
if (tab == 'reviewInfo') { if (tab == 'reviewInfo') {
this.initialContent(); this.initialContent();
} }
@@ -815,9 +883,13 @@ class DraftReview extends React.Component {
</TabPane> </TabPane>
{ this.state.reviewStatus == 'finished'? '': { this.state.reviewStatus == 'finished'? '':
<TabPane tabId="history" className="history"> <TabPane tabId="history" className="history">
<HistoryList setDiffViewerContent={this.setDiffViewerContent} <HistoryList
activeItem={this.state.activeItem}
historyList={this.state.historyList} historyList={this.state.historyList}
totalReversionCount={this.state.totalReversionCount}/> onHistoryItemClick={this.onHistoryItemClick}
onHistoryListChange={this.onHistoryListChange}
totalReversionCount={this.state.totalReversionCount}
/>
</TabPane> </TabPane>
} }
</TabContent> </TabContent>

View File

@@ -16,7 +16,6 @@ class HistoryList extends React.Component {
super(props); super(props);
this.perPage = 25; this.perPage = 25;
this.state = { this.state = {
activeItem: 0,
currentPage: 1, currentPage: 1,
loading: false loading: false
}; };
@@ -24,17 +23,7 @@ class HistoryList extends React.Component {
onClick = (event, key, preCommitID, currentCommitID)=> { onClick = (event, key, preCommitID, currentCommitID)=> {
if (key === this.state.activeItem) return false; if (key === this.state.activeItem) return false;
this.setState({ this.props.onHistoryItemClick(currentCommitID, preCommitID, key);
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);
}));
}));
} }
onScroll = (event) => { onScroll = (event) => {
@@ -51,8 +40,8 @@ class HistoryList extends React.Component {
}); });
seafileAPI.listFileHistoryRecords(draftOriginRepoID, draftFilePath, currentPage, this.perPage).then((res) => { seafileAPI.listFileHistoryRecords(draftOriginRepoID, draftFilePath, currentPage, this.perPage).then((res) => {
let currentHistoryList = Object.assign([], this.props.historyList); let currentHistoryList = Object.assign([], this.props.historyList);
this.props.onHistoryListChange([...currentHistoryList, ...res.data.data]);
this.setState({ this.setState({
historyList: [...currentHistoryList, ...res.data.data],
loading : false loading : false
}); });
}); });
@@ -75,7 +64,7 @@ class HistoryList extends React.Component {
<HistoryItem <HistoryItem
onClick={this.onClick} onClick={this.onClick}
ctime={item.ctime} ctime={item.ctime}
className={this.state.activeItem === index ? 'item-active': ''} className={this.props.activeItem === index ? 'item-active': ''}
currentCommitId={item.commit_id} currentCommitId={item.commit_id}
name={item.creator_name} name={item.creator_name}
index={index} index={index}