1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-19 01:29:05 +00:00
seahub/frontend/src/file-history.js

107 lines
3.5 KiB
JavaScript
Raw Normal View History

2018-12-25 02:39:57 +00:00
import React, { Fragment } from 'react';
2018-09-12 09:01:48 +00:00
import ReactDOM from 'react-dom';
2018-12-25 02:39:57 +00:00
import axios from 'axios';
2018-09-12 09:01:48 +00:00
import editUtilties from './utils/editor-utilties';
2018-12-25 02:39:57 +00:00
import { siteRoot, filePath, fileName } from './utils/constants';
import { Utils } from './utils/utils';
2018-09-12 09:01:48 +00:00
import URLDecorator from './utils/url-decorator';
2018-12-25 02:39:57 +00:00
import CommonToolbar from './components/toolbar/common-toolbar';
2018-09-12 09:01:48 +00:00
import SidePanel from './pages/file-history/side-panel';
import MainPanel from './pages/file-history/main-panel';
2018-12-25 02:39:57 +00:00
2018-09-12 09:01:48 +00:00
import './assets/css/fa-solid.css';
import './assets/css/fa-regular.css';
import './assets/css/fontawesome.css';
import './css/layout.css';
import './css/file-history.css';
2018-09-19 01:57:17 +00:00
import './css/toolbar.css';
import './css/search.css';
2018-09-12 09:01:48 +00:00
class FileHistory extends React.Component {
constructor(props) {
super(props);
this.state = {
renderingContent: true,
2018-12-25 02:39:57 +00:00
newMarkdownContent: '',
oldMarkdownContent: ''
2018-09-12 09:01:48 +00:00
};
}
2018-12-25 02:39:57 +00:00
onSearchedClick = (selectedItem) => {
if (selectedItem.is_dir === true) {
let url = siteRoot + 'library/' + selectedItem.repo_id + '/' + selectedItem.repo_name + selectedItem.path;
let newWindow = window.open('about:blank');
newWindow.location.href = url;
} else {
let url = siteRoot + 'lib/' + selectedItem.repo_id + '/file' + Utils.encodePath(selectedItem.path);
let newWindow = window.open('about:blank');
newWindow.location.href = url;
}
}
2018-09-26 09:27:14 +00:00
2018-12-25 02:39:57 +00:00
setDiffContent = (newmarkdownContent, oldMarkdownContent)=> {
2018-09-26 09:27:14 +00:00
this.setState({
renderingContent: false,
2018-12-25 02:39:57 +00:00
newmarkdownContent: newmarkdownContent,
oldMarkdownContent: oldMarkdownContent,
2018-09-12 09:01:48 +00:00
});
}
2018-09-26 09:27:14 +00:00
2018-12-25 02:39:57 +00:00
onHistoryItemClick = (item, preItem)=> {
2018-09-12 09:01:48 +00:00
this.setState({renderingContent: true});
2018-12-25 02:39:57 +00:00
if (preItem) {
let currID = item.rev_file_id;
let preID = preItem.rev_file_id;
let downLoadURL = URLDecorator.getUrl({type: 'download_historic_file', filePath: filePath, objID: currID});
let downLoadURL1 = URLDecorator.getUrl({type: 'download_historic_file', filePath: filePath, objID: preID});
axios.all([
editUtilties.getFileContent(downLoadURL),
editUtilties.getFileContent(downLoadURL1)
]).then(axios.spread((res1, res2) => {
this.setDiffContent(res1.data, res2.data);
}));
} else {
let currID = item.rev_file_id;
let downLoadURL = URLDecorator.getUrl({type: 'download_historic_file', filePath: filePath, objID: currID});
axios.all([
editUtilties.getFileContent(downLoadURL),
]).then(axios.spread((res1) => {
this.setDiffContent(res1.data, '');
}));
}
2018-09-12 09:01:48 +00:00
}
render() {
return(
2018-12-25 02:39:57 +00:00
<Fragment>
<div id="header" className="history-header">
<div className="title">
<a href="javascript:window.history.back()" className="go-back" title="Back">
<span className="fas fa-chevron-left"></span>
</a>
<span className="name">{fileName}</span>
</div>
<div className='toolbar'>
<CommonToolbar onSearchedClick={this.onSearchedClick} />
</div>
</div>
<div id="main" className="history-content">
<SidePanel onItemClick={this.onHistoryItemClick}/>
<MainPanel
newMarkdownContent={this.state.newMarkdownContent}
oldMarkdownContent={this.state.oldMarkdownContent}
renderingContent={this.state.renderingContent}
/>
</div>
</Fragment>
2018-09-12 09:01:48 +00:00
);
}
}
ReactDOM.render (
<FileHistory />,
document.getElementById('wrapper')
);