1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-15 23:00:57 +00:00

Add restore version (#6515)

* add-restore-version

* update template

* add Permissions

* code normal
This commit is contained in:
yinjianfei-user
2024-08-09 14:45:04 +08:00
committed by GitHub
parent c99e0765aa
commit ffd94856fc
6 changed files with 35 additions and 7 deletions

View File

@@ -166,7 +166,7 @@ class HistoryVersion extends React.Component {
aria-label={gettext('More operations')}
/>
<DropdownMenu>
{/* {(this.props.index !== 0) && <DropdownItem onClick={this.onItemRestore}>{gettext('Restore')}</DropdownItem>} */}
{(path[0] + path[1] + path[2] !== 0) && <DropdownItem onClick={this.onRestore}>{gettext('Restore')}</DropdownItem>}
<DropdownItem tag='a' href={url} onClick={this.onItemDownLoad}>{gettext('Download')}</DropdownItem>
{(path[0] !== 0 && path[1] !== 0 && path[2] !== 0) && <DropdownItem onClick={this.onItemCopy}>{gettext('Copy')}</DropdownItem>}
<DropdownItem onClick={this.toggleRename}>{gettext('Rename')}</DropdownItem>

View File

@@ -7,6 +7,7 @@ import classnames from 'classnames';
import { DiffViewer } from '@seafile/sdoc-editor';
import moment from 'moment';
import { seafileAPI } from '../../../utils/seafile-api';
import SDocServerApi from '../../../utils/sdoc-server-api';
import { PER_PAGE, gettext, historyRepoID } from '../../../utils/constants';
import Loading from '../../../components/loading';
import GoBack from '../../../components/common/go-back';
@@ -20,7 +21,7 @@ import './index.css';
const { serviceURL, avatarURL, siteRoot } = window.app.config;
const { username, name } = window.app.pageOptions;
const { repoID, fileName, filePath, docUuid, assetsUrl } = window.fileHistory.pageOptions;
const { repoID, fileName, filePath, docUuid, assetsUrl, seadocAccessToken, seadocServerUrl } = window.fileHistory.pageOptions;
window.seafile = {
repoID,
@@ -53,6 +54,12 @@ class SdocFileHistory extends React.Component {
sidePanelInitData: {},
showSidePanel: true,
};
const config = {
docUuid,
sdocServer: seadocServerUrl,
accessToken: seadocAccessToken
};
this.sdocServerApi = new SDocServerApi(config);
}
componentDidMount() {
@@ -371,6 +378,13 @@ class SdocFileHistory extends React.Component {
});
}
reloadDocContent = () => {
this.sdocServerApi.reloadDocContent(fileName).catch((error) => {
const errorMessage = 'there has an error in server';
throw Error(errorMessage);
});
};
render() {
const { currentVersion, isShowChanges, currentVersionContent, lastVersionContent, isLoading, isMobile, sidePanelInitData, showSidePanel } = this.state;
return (
@@ -408,6 +422,7 @@ class SdocFileHistory extends React.Component {
onShowChanges={this.onShowChanges}
sidePanelInitData={sidePanelInitData}
onClose={this.changeSidePanelStatus}
reloadDocContent={this.reloadDocContent}
/>
)
}

View File

@@ -105,9 +105,7 @@ class SidePanel extends Component {
const { commit_id, path } = currentItem;
editUtilities.revertFile(path, commit_id).then(res => {
if (res.data.success) {
this.setState({ isLoading: true }, () => {
this.firstLoadSdocHistory();
});
this.props.reloadDocContent();
}
let message = gettext('Successfully restored.');
toaster.success(message);
@@ -294,6 +292,7 @@ SidePanel.propTypes = {
errorMessage: PropTypes.string,
}),
onClose: PropTypes.func,
reloadDocContent: PropTypes.func,
};
export default SidePanel;

View File

@@ -14,6 +14,15 @@ class SDocServerApi {
return axios.get(url, { headers: { Authorization: `Token ${accessToken}` } });
}
reloadDocContent(fileName) {
const { server, docUuid, accessToken } = this;
const url = `${server}/api/v1/docs/${docUuid}/replace/`;
const formData = new FormData();
formData.append('doc_uuid', docUuid);
formData.append('doc_name', fileName);
return axios.post(url, formData, { headers: { Authorization: `Token ${accessToken}` } });
}
}
export default SDocServerApi;