mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-12 21:30:39 +00:00
load rename history records && more history records
This commit is contained in:
@@ -25,6 +25,9 @@ class FileHistory extends React.Component {
|
|||||||
historyList: [],
|
historyList: [],
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
hasMore: false,
|
hasMore: false,
|
||||||
|
nextCommit: undefined,
|
||||||
|
filePath: '',
|
||||||
|
oldFilePath: '',
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
isError: false,
|
isError: false,
|
||||||
fileOwner: '',
|
fileOwner: '',
|
||||||
@@ -32,24 +35,15 @@ class FileHistory extends React.Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onCloseSidePanel = () => {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
if (useNewAPI) {
|
if (useNewAPI) {
|
||||||
|
this.listNewHistoryRecords(filePath, PER_PAGE);
|
||||||
|
} else {
|
||||||
|
this.listOldHistoryRecords(historyRepoID, filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
listNewHistoryRecords = (filePath, PER_PAGE) => {
|
||||||
editUtilties.listFileHistoryRecords(filePath, 1, PER_PAGE).then(res => {
|
editUtilties.listFileHistoryRecords(filePath, 1, PER_PAGE).then(res => {
|
||||||
let historyList = res.data;
|
let historyList = res.data;
|
||||||
if (historyList.length === 0) {
|
if (historyList.length === 0) {
|
||||||
@@ -58,28 +52,22 @@ class FileHistory extends React.Component {
|
|||||||
}
|
}
|
||||||
this.initResultState(res.data);
|
this.initResultState(res.data);
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
seafileAPI.getFileHistory(historyRepoID, filePath).then((res) => {
|
|
||||||
|
listOldHistoryRecords = (repoID, filePath) => {
|
||||||
|
seafileAPI.listOldFileHistoryRecords(repoID, filePath).then((res) => {
|
||||||
let historyList = res.data;
|
let historyList = res.data;
|
||||||
if (historyList.length === 0) {
|
if (historyList.length === 0) {
|
||||||
this.setState({isLoading: false});
|
this.setState({isLoading: false});
|
||||||
throw Error('there has an error in server');
|
throw Error('there has an error in server');
|
||||||
}
|
}
|
||||||
this.initResultState(res.data);
|
this.initResultState(res.data);
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
refershFileList() {
|
|
||||||
editUtilties.listFileHistoryRecords(filePath, 1, PER_PAGE).then(res => {
|
|
||||||
this.initResultState(res.data);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
initResultState(result) {
|
initResultState(result) {
|
||||||
|
if (result.data.length) {
|
||||||
if (useNewAPI) {
|
if (useNewAPI) {
|
||||||
if (result.data.length) {
|
|
||||||
this.setState({
|
this.setState({
|
||||||
historyList: result.data,
|
historyList: result.data,
|
||||||
currentPage: result.page,
|
currentPage: result.page,
|
||||||
@@ -88,44 +76,22 @@ class FileHistory extends React.Component {
|
|||||||
isError: false,
|
isError: false,
|
||||||
fileOwner: result.data[0].creator_email,
|
fileOwner: result.data[0].creator_email,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (result.data.length) {
|
|
||||||
this.setState({
|
this.setState({
|
||||||
historyList: result.data,
|
historyList: result.data,
|
||||||
|
nextCommit: result.next_start_commit,
|
||||||
|
hasMore: result.next_start_commit ? true : false,
|
||||||
|
filePath: result.data[result.data.length-1].path,
|
||||||
|
oldFilePath: result.data[result.data.length-1].rev_renamed_old_path,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isError: false,
|
isError: false,
|
||||||
fileOwner: result.data[0].creator_email,
|
fileOwner: result.data[0].creator_email,
|
||||||
});
|
});
|
||||||
|
if (result.data.length < 25 && this.state.hasMore) {
|
||||||
|
this.reloadMore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateResultState(result) {
|
|
||||||
if (result.data.length) {
|
|
||||||
this.setState({
|
|
||||||
historyList: [...this.state.historyList, ...result.data],
|
|
||||||
currentPage: result.page,
|
|
||||||
hasMore: result.total_count > (PER_PAGE * this.state.currentPage),
|
|
||||||
isLoading: false,
|
|
||||||
isError: false,
|
|
||||||
fileOwner: result.data[0].creator_email
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
reloadMore = () => {
|
|
||||||
if (!this.state.isReloadingData) {
|
|
||||||
let currentPage = this.state.currentPage + 1;
|
|
||||||
this.setState({
|
|
||||||
currentPage: currentPage,
|
|
||||||
isReloadingData: true,
|
|
||||||
});
|
|
||||||
editUtilties.listFileHistoryRecords(filePath, currentPage, PER_PAGE).then(res => {
|
|
||||||
this.updateResultState(res.data);
|
|
||||||
this.setState({isReloadingData: false});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onScrollHandler = (event) => {
|
onScrollHandler = (event) => {
|
||||||
@@ -139,8 +105,78 @@ class FileHistory extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reloadMore = () => {
|
||||||
|
if (!this.state.isReloadingData) {
|
||||||
|
if (useNewAPI) {
|
||||||
|
let currentPage = this.state.currentPage + 1;
|
||||||
|
this.setState({
|
||||||
|
currentPage: currentPage,
|
||||||
|
isReloadingData: true,
|
||||||
|
});
|
||||||
|
editUtilties.listFileHistoryRecords(filePath, currentPage, PER_PAGE).then(res => {
|
||||||
|
this.updateResultState(res.data);
|
||||||
|
this.setState({isReloadingData: false});
|
||||||
|
});
|
||||||
|
} 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) => {
|
||||||
|
this.setState({isReloadingData: false});
|
||||||
|
this.updateResultState(res.data);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
seafileAPI.listOldFileHistoryRecords(historyRepoID, filePath, commitID).then((res) => {
|
||||||
|
this.setState({isReloadingData: false});
|
||||||
|
this.updateResultState(res.data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateResultState(result) {
|
||||||
|
if (result.data.length) {
|
||||||
|
if (useNewAPI) {
|
||||||
|
this.setState({
|
||||||
|
historyList: [...this.state.historyList, ...result.data],
|
||||||
|
currentPage: result.page,
|
||||||
|
hasMore: result.total_count > (PER_PAGE * this.state.currentPage),
|
||||||
|
isLoading: false,
|
||||||
|
isError: false,
|
||||||
|
fileOwner: result.data[0].creator_email
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
historyList: [...this.state.historyList, ...result.data],
|
||||||
|
nextCommit: result.next_start_commit,
|
||||||
|
hasMore: result.next_start_commit ? true : false,
|
||||||
|
filePath: result.data[result.data.length-1].path,
|
||||||
|
oldFilePath: result.data[result.data.length-1].rev_renamed_old_path,
|
||||||
|
isLoading: false,
|
||||||
|
isError: false,
|
||||||
|
fileOwner: result.data[0].creator_email,
|
||||||
|
});
|
||||||
|
if (result.data.length < 25 && this.state.hasMore) {
|
||||||
|
this.reloadMore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
historyList: [...this.state.historyList, ...result.data],
|
||||||
|
nextCommit: result.next_start_commit,
|
||||||
|
isLoading: false,
|
||||||
|
isError: false,
|
||||||
|
});
|
||||||
|
this.reloadMore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onItemRestore = (item) => {
|
onItemRestore = (item) => {
|
||||||
let commitId = item.commit_id;
|
let commitId = item.commit_id;
|
||||||
|
let filePath = item.path;
|
||||||
editUtilties.revertFile(filePath, commitId).then(res => {
|
editUtilties.revertFile(filePath, commitId).then(res => {
|
||||||
if (res.data.success) {
|
if (res.data.success) {
|
||||||
this.setState({isLoading: true});
|
this.setState({isLoading: true});
|
||||||
@@ -149,6 +185,32 @@ class FileHistory extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refershFileList() {
|
||||||
|
if (useNewAPI) {
|
||||||
|
editUtilties.listFileHistoryRecords(filePath, 1, PER_PAGE).then((res) => {
|
||||||
|
this.initResultState(res.data);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
seafileAPI.listOldFileHistoryRecords(historyRepoID, filePath).then((res) => {
|
||||||
|
this.initResultState(res.data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onCloseSidePanel = () => {}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
@@ -166,8 +228,8 @@ class FileHistory extends React.Component {
|
|||||||
<a href="javascript:window.history.back()" className="go-back" title="Back">
|
<a href="javascript:window.history.back()" className="go-back" title="Back">
|
||||||
<span className="fas fa-chevron-left"></span>
|
<span className="fas fa-chevron-left"></span>
|
||||||
</a>
|
</a>
|
||||||
<h2><span className="file-name">{fileName}</span>{gettext(' History Versions')}</h2>
|
<h2><span className="file-name">{fileName}</span>{' '}{gettext('History Versions')}</h2>
|
||||||
<p>{gettext('Tip: a new version will be generated after each modification, and you can restore the file to a previous version.')}</p>
|
<p>{gettext('A new version will be generated after each modification, and you can restore the file to a previous version.')}</p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{this.state.isLoading && <Loading />}
|
{this.state.isLoading && <Loading />}
|
||||||
@@ -195,6 +257,7 @@ class FileHistory extends React.Component {
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
}
|
}
|
||||||
|
{this.state.isReloadingData && <Loading />}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -33,7 +33,8 @@ class HistoryItem extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onItemRestore = () => {
|
onItemRestore = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
this.props.onItemRestore(this.props.item);
|
this.props.onItemRestore(this.props.item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ class HistoryItem extends React.Component {
|
|||||||
<tr onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}>
|
<tr onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}>
|
||||||
<td>
|
<td>
|
||||||
<time datetime={item.time} is="relative-time" title={moment(item.ctime).format('llll')}>{moment(item.ctime).fromNow()}</time>
|
<time datetime={item.time} is="relative-time" title={moment(item.ctime).format('llll')}>{moment(item.ctime).fromNow()}</time>
|
||||||
{this.props.index === 0 ? gettext('(current version)') : ''}
|
{this.props.index === 0 && gettext('(current version)')}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<img className="avatar" src={item.creator_avatar_url}></img>{' '}
|
<img className="avatar" src={item.creator_avatar_url}></img>{' '}
|
||||||
@@ -58,7 +59,7 @@ class HistoryItem extends React.Component {
|
|||||||
<td>
|
<td>
|
||||||
{this.state.active &&
|
{this.state.active &&
|
||||||
<span className="attr-action-icon">
|
<span className="attr-action-icon">
|
||||||
{this.props.index === 0 ? '' : <a href=" " onClick={this.onItemRestore}>{gettext('Restore')}</a>}
|
{this.props.index !== 0 && <a href="#" onClick={this.onItemRestore}>{gettext('Restore')}</a>}
|
||||||
<a href={downloadUrl}>{gettext('Download')}</a>
|
<a href={downloadUrl}>{gettext('Download')}</a>
|
||||||
<a href={viewUrl}>{gettext('View')}</a>
|
<a href={viewUrl}>{gettext('View')}</a>
|
||||||
<a href={diffUrl}>{gettext('Diff')}</a>
|
<a href={diffUrl}>{gettext('Diff')}</a>
|
||||||
|
@@ -7,7 +7,8 @@ class RepoBasicInfoTest(BaseTestCase):
|
|||||||
self.login_as(self.user)
|
self.login_as(self.user)
|
||||||
|
|
||||||
def test_can_render(self):
|
def test_can_render(self):
|
||||||
resp = self.client.get(reverse('file_revisions', args=[self.repo.id]) + '?p=' + self.file + '&_new=0')
|
resp = self.client.get(reverse('file_revisions', args=[self.repo.id]) + '?p=' + self.file + '&_new=0'
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(200, resp.status_code)
|
self.assertEqual(200, resp.status_code)
|
||||||
self.assertTemplateUsed(resp, 'file_revisions.html')
|
self.assertTemplateUsed(resp, 'file_revisions.html')
|
||||||
|
Reference in New Issue
Block a user