2019-04-19 10:23:02 +00:00
|
|
|
import React, { Fragment } from 'react';
|
2022-12-24 02:41:34 +00:00
|
|
|
import { createRoot } from 'react-dom/client';
|
2019-04-24 03:55:48 +00:00
|
|
|
import { Button } from 'reactstrap';
|
2019-04-19 10:23:02 +00:00
|
|
|
import { Utils } from './utils/utils';
|
|
|
|
import { seafileAPI } from './utils/seafile-api';
|
2019-05-11 12:38:17 +00:00
|
|
|
import { gettext, PER_PAGE, filePath, fileName, historyRepoID, useNewAPI, canDownload, canCompare } from './utils/constants';
|
2019-12-28 10:18:23 +00:00
|
|
|
import editUtilities from './utils/editor-utilities';
|
2019-04-19 10:23:02 +00:00
|
|
|
import Loading from './components/loading';
|
|
|
|
import Logo from './components/logo';
|
|
|
|
import CommonToolbar from './components/toolbar/common-toolbar';
|
|
|
|
import HistoryItem from './pages/file-history-old/history-item';
|
|
|
|
|
|
|
|
import './css/layout.css';
|
|
|
|
import './css/toolbar.css';
|
|
|
|
import './css/search.css';
|
|
|
|
import './css/file-history-old.css';
|
|
|
|
|
|
|
|
class FileHistory extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
historyList: [],
|
|
|
|
currentPage: 1,
|
|
|
|
hasMore: false,
|
2019-04-22 14:32:52 +00:00
|
|
|
nextCommit: undefined,
|
|
|
|
filePath: '',
|
|
|
|
oldFilePath: '',
|
2019-04-19 10:23:02 +00:00
|
|
|
isLoading: true,
|
|
|
|
isReloadingData: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
if (useNewAPI) {
|
2019-04-22 14:32:52 +00:00
|
|
|
this.listNewHistoryRecords(filePath, PER_PAGE);
|
2019-04-19 10:23:02 +00:00
|
|
|
} else {
|
2019-04-22 14:32:52 +00:00
|
|
|
this.listOldHistoryRecords(historyRepoID, filePath);
|
2019-04-19 10:23:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-22 14:32:52 +00:00
|
|
|
listNewHistoryRecords = (filePath, PER_PAGE) => {
|
2019-12-28 10:18:23 +00:00
|
|
|
editUtilities.listFileHistoryRecords(filePath, 1, PER_PAGE).then(res => {
|
2019-04-23 02:45:42 +00:00
|
|
|
let historyData = res.data;
|
|
|
|
if (!historyData) {
|
2019-04-22 14:32:52 +00:00
|
|
|
this.setState({isLoading: false});
|
2019-04-23 02:55:00 +00:00
|
|
|
throw Error('There is an error in server.');
|
2019-04-22 14:32:52 +00:00
|
|
|
}
|
2019-04-24 06:49:39 +00:00
|
|
|
this.initNewRecords(res.data);
|
2019-04-22 14:32:52 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
listOldHistoryRecords = (repoID, filePath) => {
|
|
|
|
seafileAPI.listOldFileHistoryRecords(repoID, filePath).then((res) => {
|
2019-04-23 02:45:42 +00:00
|
|
|
let historyData = res.data;
|
|
|
|
if (!historyData) {
|
2019-04-22 14:32:52 +00:00
|
|
|
this.setState({isLoading: false});
|
2019-04-23 02:55:00 +00:00
|
|
|
throw Error('There is an error in server.');
|
2019-04-22 14:32:52 +00:00
|
|
|
}
|
2019-04-24 06:49:39 +00:00
|
|
|
this.initOldRecords(res.data);
|
2019-04-19 10:23:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-24 06:49:39 +00:00
|
|
|
initNewRecords(result) {
|
2019-05-28 10:21:47 +00:00
|
|
|
if (result.total_count < 5) {
|
|
|
|
if (result.data.length) {
|
|
|
|
let commitID = result.data[result.data.length-1].commit_id;
|
2019-10-10 09:53:28 +00:00
|
|
|
let path = result.data[result.data.length-1].path;
|
|
|
|
let oldPath = result.data[result.data.length-1].old_path;
|
|
|
|
path = oldPath ? oldPath : path;
|
|
|
|
seafileAPI.listOldFileHistoryRecords(historyRepoID, path, commitID).then((res) => {
|
2019-05-28 10:21:47 +00:00
|
|
|
if (!res.data) {
|
|
|
|
this.setState({isLoading: false});
|
|
|
|
throw Error('There is an error in server.');
|
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
historyList: result.data.concat(res.data.data.slice(1, res.data.data.length)),
|
|
|
|
isLoading: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
seafileAPI.listOldFileHistoryRecords(historyRepoID, filePath).then((res) => {
|
|
|
|
if (!res.data) {
|
|
|
|
this.setState({isLoading: false});
|
|
|
|
throw Error('There is an error in server.');
|
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
historyList: res.data.data,
|
|
|
|
isLoading: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
historyList: result.data,
|
|
|
|
currentPage: result.page,
|
|
|
|
hasMore: result.total_count > (PER_PAGE * this.state.currentPage),
|
|
|
|
isLoading: false,
|
|
|
|
});
|
|
|
|
}
|
2019-04-24 06:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
initOldRecords(result) {
|
2019-04-22 14:32:52 +00:00
|
|
|
if (result.data.length) {
|
2019-04-23 02:18:30 +00:00
|
|
|
this.setState({
|
2019-04-24 06:49:39 +00:00
|
|
|
historyList: result.data,
|
2019-04-23 02:18:30 +00:00
|
|
|
nextCommit: result.next_start_commit,
|
2019-04-24 06:49:39 +00:00
|
|
|
filePath: result.data[result.data.length-1].path,
|
|
|
|
oldFilePath: result.data[result.data.length-1].rev_renamed_old_path,
|
|
|
|
isLoading: false,
|
2019-04-23 02:18:30 +00:00
|
|
|
});
|
2019-04-24 06:49:39 +00:00
|
|
|
} else {
|
|
|
|
this.setState({nextCommit: result.next_start_commit,});
|
2019-04-23 02:18:30 +00:00
|
|
|
if (this.state.nextCommit) {
|
|
|
|
seafileAPI.listOldFileHistoryRecords(historyRepoID, filePath, this.state.nextCommit).then((res) => {
|
2019-04-24 06:49:39 +00:00
|
|
|
this.initOldRecords(res.data);
|
2019-04-23 02:18:30 +00:00
|
|
|
});
|
2020-03-17 12:40:31 +00:00
|
|
|
} else {
|
|
|
|
this.setState({isLoading: false});
|
2019-04-23 02:18:30 +00:00
|
|
|
}
|
2019-04-19 10:23:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-22 14:32:52 +00:00
|
|
|
onScrollHandler = (event) => {
|
2019-04-24 06:49:39 +00:00
|
|
|
const clientHeight = event.target.clientHeight;
|
|
|
|
const scrollHeight = event.target.scrollHeight;
|
|
|
|
const scrollTop = event.target.scrollTop;
|
|
|
|
const isBottom = (clientHeight + scrollTop + 1 >= scrollHeight);
|
|
|
|
let hasMore = this.state.hasMore;
|
|
|
|
if (isBottom && hasMore) {
|
|
|
|
this.reloadMore();
|
2019-04-19 10:23:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reloadMore = () => {
|
|
|
|
if (!this.state.isReloadingData) {
|
2019-04-22 14:32:52 +00:00
|
|
|
if (useNewAPI) {
|
|
|
|
let currentPage = this.state.currentPage + 1;
|
|
|
|
this.setState({
|
|
|
|
currentPage: currentPage,
|
|
|
|
isReloadingData: true,
|
|
|
|
});
|
2019-12-28 10:18:23 +00:00
|
|
|
editUtilities.listFileHistoryRecords(filePath, currentPage, PER_PAGE).then(res => {
|
2019-04-24 06:49:39 +00:00
|
|
|
this.updateNewRecords(res.data);
|
2019-04-22 14:32:52 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
let commitID = this.state.nextCommit;
|
|
|
|
let filePath = this.state.filePath;
|
|
|
|
let oldFilePath = this.state.oldFilePath;
|
|
|
|
this.setState({isReloadingData: true});
|
|
|
|
if (oldFilePath) {
|
|
|
|
seafileAPI.listOldFileHistoryRecords(historyRepoID, oldFilePath, commitID).then((res) => {
|
2019-04-26 06:35:30 +00:00
|
|
|
this.updateOldRecords(res.data, oldFilePath);
|
2019-04-22 14:32:52 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
seafileAPI.listOldFileHistoryRecords(historyRepoID, filePath, commitID).then((res) => {
|
2019-04-26 06:35:30 +00:00
|
|
|
this.updateOldRecords(res.data, filePath);
|
2019-04-22 14:32:52 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-04-19 10:23:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 06:49:39 +00:00
|
|
|
updateNewRecords(result) {
|
|
|
|
this.setState({
|
|
|
|
historyList: [...this.state.historyList, ...result.data],
|
|
|
|
currentPage: result.page,
|
|
|
|
hasMore: result.total_count > (PER_PAGE * this.state.currentPage),
|
2019-04-26 07:34:22 +00:00
|
|
|
isReloadingData: false,
|
2019-04-24 06:49:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-26 06:35:30 +00:00
|
|
|
updateOldRecords(result, filePath) {
|
2019-04-22 14:32:52 +00:00
|
|
|
if (result.data.length) {
|
|
|
|
this.setState({
|
2019-04-24 06:49:39 +00:00
|
|
|
historyList: [...this.state.historyList, ...result.data],
|
2019-04-22 14:32:52 +00:00
|
|
|
nextCommit: result.next_start_commit,
|
2019-04-24 06:49:39 +00:00
|
|
|
filePath: result.data[result.data.length-1].path,
|
|
|
|
oldFilePath: result.data[result.data.length-1].rev_renamed_old_path,
|
2019-04-26 07:34:22 +00:00
|
|
|
isReloadingData: false,
|
2019-04-22 14:32:52 +00:00
|
|
|
});
|
2019-04-24 06:49:39 +00:00
|
|
|
} else {
|
|
|
|
this.setState({nextCommit: result.next_start_commit,});
|
2019-04-23 02:18:30 +00:00
|
|
|
if (this.state.nextCommit) {
|
|
|
|
seafileAPI.listOldFileHistoryRecords(historyRepoID, filePath, this.state.nextCommit).then((res) => {
|
2019-04-26 06:35:30 +00:00
|
|
|
this.updateOldRecords(res.data, filePath);
|
2019-04-23 02:18:30 +00:00
|
|
|
});
|
|
|
|
}
|
2019-04-19 10:23:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onItemRestore = (item) => {
|
|
|
|
let commitId = item.commit_id;
|
2019-04-22 14:32:52 +00:00
|
|
|
let filePath = item.path;
|
2019-12-28 10:18:23 +00:00
|
|
|
editUtilities.revertFile(filePath, commitId).then(res => {
|
2019-04-19 10:23:02 +00:00
|
|
|
if (res.data.success) {
|
|
|
|
this.setState({isLoading: true});
|
|
|
|
this.refershFileList();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-22 14:32:52 +00:00
|
|
|
refershFileList() {
|
|
|
|
if (useNewAPI) {
|
2019-12-28 10:18:23 +00:00
|
|
|
editUtilities.listFileHistoryRecords(filePath, 1, PER_PAGE).then((res) => {
|
2019-04-24 06:49:39 +00:00
|
|
|
this.initNewRecords(res.data);
|
2019-04-22 14:32:52 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
seafileAPI.listOldFileHistoryRecords(historyRepoID, filePath).then((res) => {
|
2019-04-24 06:49:39 +00:00
|
|
|
this.initOldRecords(res.data);
|
2019-04-22 14:32:52 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-26 03:34:11 +00:00
|
|
|
onSearchedClick = (searchedItem) => {
|
|
|
|
Utils.handleSearchedItemClick(searchedItem);
|
2019-04-22 14:32:52 +00:00
|
|
|
}
|
|
|
|
|
2019-04-19 10:23:02 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<div id="header" className="old-history-header">
|
|
|
|
<div className="logo">
|
2019-04-25 02:50:06 +00:00
|
|
|
<Logo showCloseSidePanelIcon={false}/>
|
2019-04-19 10:23:02 +00:00
|
|
|
</div>
|
|
|
|
<div className='toolbar'>
|
|
|
|
<CommonToolbar onSearchedClick={this.onSearchedClick} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="main" onScroll={this.onScrollHandler}>
|
|
|
|
<div className="old-history-main">
|
2019-04-26 07:33:11 +00:00
|
|
|
<Fragment>
|
2019-04-19 10:23:02 +00:00
|
|
|
<a href="javascript:window.history.back()" className="go-back" title="Back">
|
|
|
|
<span className="fas fa-chevron-left"></span>
|
|
|
|
</a>
|
2019-04-22 14:32:52 +00:00
|
|
|
<h2><span className="file-name">{fileName}</span>{' '}{gettext('History Versions')}</h2>
|
2019-04-26 07:33:11 +00:00
|
|
|
</Fragment>
|
|
|
|
<Fragment>
|
|
|
|
<table className="commit-list">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th width="40%" >{gettext('Time')}</th>
|
|
|
|
<th width="30%" >{gettext('Modifier')}</th>
|
|
|
|
<th width="25%" >{gettext('Size')}</th>
|
|
|
|
<th width="5%" ></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
{!this.state.isLoading &&
|
2019-04-19 10:23:02 +00:00
|
|
|
<tbody>
|
|
|
|
{this.state.historyList.map((item, index) => {
|
|
|
|
return (
|
|
|
|
<HistoryItem
|
2020-11-02 05:56:35 +00:00
|
|
|
key={index}
|
2019-04-19 10:23:02 +00:00
|
|
|
item={item}
|
|
|
|
index={index}
|
2019-04-24 13:27:12 +00:00
|
|
|
canDownload={canDownload}
|
|
|
|
canCompare={canCompare}
|
2019-04-19 10:23:02 +00:00
|
|
|
onItemRestore={this.onItemRestore}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</tbody>
|
2019-04-26 07:33:11 +00:00
|
|
|
}
|
|
|
|
</table>
|
|
|
|
{(this.state.isReloadingData || this.state.isLoading) && <Loading />}
|
2019-04-24 06:49:39 +00:00
|
|
|
{this.state.nextCommit && !this.state.isLoading && !this.state.isReloadingData &&
|
|
|
|
<Button className="get-more-btn" onClick={this.reloadMore}>{gettext('More')}</Button>
|
|
|
|
}
|
2019-04-26 07:33:11 +00:00
|
|
|
</Fragment>
|
2019-04-19 10:23:02 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-24 02:41:34 +00:00
|
|
|
const root = createRoot(document.getElementById('wrapper'));
|
|
|
|
root.render(<FileHistory />);
|