mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-02 15:38:15 +00:00
add file-diff (#2398)
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@reach/router": "^1.2.0",
|
"@reach/router": "^1.2.0",
|
||||||
"@seafile/seafile-editor": "^0.1.20",
|
"@seafile/seafile-editor": "^0.1.24",
|
||||||
"autoprefixer": "7.1.6",
|
"autoprefixer": "7.1.6",
|
||||||
"chalk": "1.1.3",
|
"chalk": "1.1.3",
|
||||||
"css-loader": "0.28.7",
|
"css-loader": "0.28.7",
|
||||||
|
@@ -39,7 +39,7 @@ class HistoryListItem extends React.Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.setState({isShowOperationIcon: false}); //restore to default state
|
this.setState({isShowOperationIcon: false}); //restore to default state
|
||||||
this.props.onHistoryItemClick(this.props.item);
|
this.props.onHistoryItemClick(this.props.item, this.props.preCommitID);
|
||||||
}
|
}
|
||||||
|
|
||||||
onMenuControlClick = (e) => {
|
onMenuControlClick = (e) => {
|
||||||
|
@@ -2,6 +2,10 @@ import React from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import HisotyListItem from './history-list-item';
|
import HisotyListItem from './history-list-item';
|
||||||
import Loading from '../loading';
|
import Loading from '../loading';
|
||||||
|
import axios from 'axios';
|
||||||
|
import editUtilties from '../../utils/editor-utilties';
|
||||||
|
import URLDecorator from '../../utils/url-decorator';
|
||||||
|
import { filePath } from '../constants';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
hasMore: PropTypes.bool.isRequired,
|
hasMore: PropTypes.bool.isRequired,
|
||||||
@@ -27,15 +31,42 @@ class HistoryListView extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
let historyList = this.props.historyList;
|
||||||
|
if (historyList.length > 1) {
|
||||||
|
let downLoadURL = URLDecorator.getUrl({type: 'download_historic_file', filePath: filePath, objID: historyList[0].rev_file_id});
|
||||||
|
let downLoadURL1 = URLDecorator.getUrl({type: 'download_historic_file', filePath: filePath, objID: historyList[1].rev_file_id});
|
||||||
|
axios.all([
|
||||||
|
editUtilties.getFileContent(downLoadURL),
|
||||||
|
editUtilties.getFileContent(downLoadURL1)
|
||||||
|
]).then(axios.spread((res1, res2) => {
|
||||||
|
this.props.setDiffContent(res1.data, res2.data);
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
let downLoadURL = URLDecorator.getUrl({type: 'download_historic_file', filePath: filePath, objID: historyList[0].rev_file_id});
|
||||||
|
axios.all([
|
||||||
|
editUtilties.getFileContent(downLoadURL),
|
||||||
|
]).then(axios.spread((res1) => {
|
||||||
|
this.props.setDiffContent(res1.data, '');
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<ul className="history-list-container" onScroll={this.onScrollHandler}>
|
<ul className="history-list-container" onScroll={this.onScrollHandler}>
|
||||||
{this.props.historyList.map((item, index) => {
|
{this.props.historyList.map((item, index, historyList) => {
|
||||||
|
let preItemIndex = index + 1;
|
||||||
|
if (preItemIndex === historyList.length) {
|
||||||
|
preItemIndex = index;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<HisotyListItem
|
<HisotyListItem
|
||||||
key={index}
|
key={index}
|
||||||
item={item}
|
item={item}
|
||||||
isFirstItem={index === 0}
|
isFirstItem={index === 0}
|
||||||
|
preCommitID={historyList[preItemIndex].rev_file_id}
|
||||||
currentItem={this.props.currentItem}
|
currentItem={this.props.currentItem}
|
||||||
isItemFrezeed={this.props.isItemFrezeed}
|
isItemFrezeed={this.props.isItemFrezeed}
|
||||||
onMenuControlClick={this.props.onMenuControlClick}
|
onMenuControlClick={this.props.onMenuControlClick}
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
.history, .markdown-viewer-render-content {
|
.history, .markdown-viewer-render-content {
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
|
word-break: break-word;
|
||||||
}
|
}
|
||||||
|
|
||||||
.history-heading {
|
.history-heading {
|
||||||
|
@@ -6,6 +6,7 @@ import URLDecorator from './utils/url-decorator';
|
|||||||
import { processor } from '@seafile/seafile-editor/src/lib/seafile-markdown2html';
|
import { processor } from '@seafile/seafile-editor/src/lib/seafile-markdown2html';
|
||||||
import SidePanel from './pages/file-history/side-panel';
|
import SidePanel from './pages/file-history/side-panel';
|
||||||
import MainPanel from './pages/file-history/main-panel';
|
import MainPanel from './pages/file-history/main-panel';
|
||||||
|
import axios from 'axios';
|
||||||
import 'seafile-ui';
|
import 'seafile-ui';
|
||||||
import './assets/css/fa-solid.css';
|
import './assets/css/fa-solid.css';
|
||||||
import './assets/css/fa-regular.css';
|
import './assets/css/fa-regular.css';
|
||||||
@@ -23,39 +24,33 @@ class FileHistory extends React.Component {
|
|||||||
content: '',
|
content: '',
|
||||||
renderingContent: true,
|
renderingContent: true,
|
||||||
fileOwner: '',
|
fileOwner: '',
|
||||||
|
markdownContent: '',
|
||||||
|
markdownContentOld: ''
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
let _this = this;
|
setDiffContent = (markdownContent, markdownContentOld)=> {
|
||||||
editUtilties.getFileDownloadLink(filePath).then(res => {
|
this.setState({
|
||||||
const downLoadUrl = res.data;
|
renderingContent: false,
|
||||||
editUtilties.getFileContent(downLoadUrl).then((res) => {
|
markdownContent: markdownContent,
|
||||||
let content = res.data;
|
markdownContentOld: markdownContentOld
|
||||||
processor.process(content, function(err, file) {
|
|
||||||
_this.setState({
|
|
||||||
renderingContent: false,
|
|
||||||
content: String(file)
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onHistoryItemClick = (item) => {
|
|
||||||
|
onHistoryItemClick = (item, preCommitID)=> {
|
||||||
let _this = this;
|
let _this = this;
|
||||||
let objID = item.rev_file_id;
|
let objID = item.rev_file_id;
|
||||||
let downLoadURL = URLDecorator.getUrl({type: 'download_historic_file', filePath: filePath, objID: objID});
|
let downLoadURL = URLDecorator.getUrl({type: 'download_historic_file', filePath: filePath, objID: objID});
|
||||||
|
let downLoadURL1 = URLDecorator.getUrl({type: 'download_historic_file', filePath: filePath, objID: preCommitID});
|
||||||
this.setState({renderingContent: true});
|
this.setState({renderingContent: true});
|
||||||
editUtilties.getFileContent(downLoadURL).then((res) => {
|
axios.all([
|
||||||
let content = res.data;
|
editUtilties.getFileContent(downLoadURL),
|
||||||
processor.process(content, function(err, file) {
|
editUtilties.getFileContent(downLoadURL1)
|
||||||
_this.setState({
|
]).then(axios.spread((res1, res2) => {
|
||||||
renderingContent: false,
|
this.setDiffContent(res1.data, res2.data);
|
||||||
content: String(file)
|
}));
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -64,11 +59,14 @@ class FileHistory extends React.Component {
|
|||||||
<SidePanel
|
<SidePanel
|
||||||
fileOwner={this.state.fileOwner}
|
fileOwner={this.state.fileOwner}
|
||||||
onHistoryItemClick={this.onHistoryItemClick}
|
onHistoryItemClick={this.onHistoryItemClick}
|
||||||
|
setDiffContent={this.setDiffContent}
|
||||||
/>
|
/>
|
||||||
<MainPanel
|
<MainPanel
|
||||||
content={this.state.content}
|
markdownContent={this.state.markdownContent}
|
||||||
|
markdownContentOld={this.state.markdownContentOld}
|
||||||
renderingContent={this.state.renderingContent}
|
renderingContent={this.state.renderingContent}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,9 @@ import PropTypes from 'prop-types';
|
|||||||
import Prism from 'prismjs';
|
import Prism from 'prismjs';
|
||||||
import Loading from '../../components/loading';
|
import Loading from '../../components/loading';
|
||||||
import CommonToolbar from '../../components/toolbar/common-toolbar';
|
import CommonToolbar from '../../components/toolbar/common-toolbar';
|
||||||
|
import DiffViewer from '@seafile/seafile-editor/dist/diff-viewer/diff-viewer'
|
||||||
import '../../css/initial-style.css';
|
import '../../css/initial-style.css';
|
||||||
|
|
||||||
require('@seafile/seafile-editor/src/lib/code-hight-package');
|
require('@seafile/seafile-editor/src/lib/code-hight-package');
|
||||||
|
|
||||||
const contentClass = 'markdown-viewer-render-content';
|
const contentClass = 'markdown-viewer-render-content';
|
||||||
@@ -33,10 +35,7 @@ class MainPanel extends React.Component {
|
|||||||
{
|
{
|
||||||
this.props.renderingContent ?
|
this.props.renderingContent ?
|
||||||
(<div className={contentClass + ' article'}><Loading /></div>) :
|
(<div className={contentClass + ' article'}><Loading /></div>) :
|
||||||
(<div
|
(<div className={contentClass + ' article'}><DiffViewer markdownContent={this.props.markdownContent} markdownContent1={this.props.markdownContentOld}/></div>)
|
||||||
className={contentClass + ' article'}
|
|
||||||
dangerouslySetInnerHTML={{ __html: this.props.content }}
|
|
||||||
/>)
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -124,9 +124,9 @@ class SidePanel extends React.Component {
|
|||||||
this.onHideContextMenu();
|
this.onHideContextMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
onHistoryItemClick =(item) => {
|
onHistoryItemClick =(item, preCommitID) => {
|
||||||
this.setState({currentItem: item});
|
this.setState({currentItem: item});
|
||||||
this.props.onHistoryItemClick(item);
|
this.props.onHistoryItemClick(item, preCommitID);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -154,6 +154,7 @@ class SidePanel extends React.Component {
|
|||||||
reloadMore={this.reloadMore}
|
reloadMore={this.reloadMore}
|
||||||
currentItem={this.state.currentItem}
|
currentItem={this.state.currentItem}
|
||||||
onHistoryItemClick={this.onHistoryItemClick}
|
onHistoryItemClick={this.onHistoryItemClick}
|
||||||
|
setDiffContent={this.props.setDiffContent}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
<HistoryListMenu
|
<HistoryListMenu
|
||||||
|
Reference in New Issue
Block a user