From 968fef85ea06747b4626f357e67ec071c4049caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E9=A1=BA=E5=BC=BA?= <978987373@qq.com> Date: Tue, 18 Apr 2023 18:23:03 +0800 Subject: [PATCH] update sdoc module (#5437) --- .../src/components/file-content-view/sdoc.js | 4 +- .../history-trash-file-view/file-view.js | 2 +- frontend/src/shared-file-view-sdoc.js | 67 +++------ frontend/src/view-file-sdoc.js | 131 ++---------------- seahub/templates/shared_file_view_react.html | 2 + 5 files changed, 31 insertions(+), 175 deletions(-) diff --git a/frontend/src/components/file-content-view/sdoc.js b/frontend/src/components/file-content-view/sdoc.js index b34cabfa11..97823f637b 100644 --- a/frontend/src/components/file-content-view/sdoc.js +++ b/frontend/src/components/file-content-view/sdoc.js @@ -1,6 +1,5 @@ import React from 'react'; import { SDocViewer } from '@seafile/sdoc-editor'; -import { defaultContentForSDoc } from '../../utils/constants'; import '../../css/sdoc-file-view.css'; @@ -9,9 +8,10 @@ const { fileContent } = window.app.pageOptions; class FileContent extends React.Component { render() { + const document = fileContent ? JSON.parse(fileContent) : null; return (
- +
); } diff --git a/frontend/src/components/history-trash-file-view/file-view.js b/frontend/src/components/history-trash-file-view/file-view.js index ffa6ce3360..ea2e605a02 100644 --- a/frontend/src/components/history-trash-file-view/file-view.js +++ b/frontend/src/components/history-trash-file-view/file-view.js @@ -26,7 +26,7 @@ class FileView extends React.Component { render() { return ( -
+

{fileName}

diff --git a/frontend/src/shared-file-view-sdoc.js b/frontend/src/shared-file-view-sdoc.js index c4986554e2..170e8c3d2b 100644 --- a/frontend/src/shared-file-view-sdoc.js +++ b/frontend/src/shared-file-view-sdoc.js @@ -1,61 +1,26 @@ import React from 'react'; import ReactDom from 'react-dom'; -import { SDocViewer } from '@seafile/sdoc-editor'; -import { seafileAPI } from './utils/seafile-api'; -import { Utils } from './utils/utils'; -import { defaultContentForSDoc } from './utils/constants'; -import SharedFileView from './components/shared-file-view/shared-file-view'; -import SharedFileViewTip from './components/shared-file-view/shared-file-view-tip'; -import Loading from './components/loading'; -import toaster from './components/toast'; +import { SimpleViewer } from '@seafile/sdoc-editor'; -import './css/sdoc-file-view.css'; +const { serviceURL } = window.app.config; +const { repoID, filePath, fileName } = window.shared.pageOptions; -const { rawPath, err } = window.shared.pageOptions; +const { rawPath } = window.shared.pageOptions; + +window.seafile = { + repoID, + rawPath: rawPath, + docName: fileName, // required + docPath: filePath, + serviceUrl: serviceURL, +}; + +class ViewFileSdoc extends React.Component { -class SharedFileViewSdoc extends React.Component { render() { - return } />; + return ; } } -class FileContent extends React.Component { +ReactDom.render(, document.getElementById('wrapper')); - constructor(props) { - super(props); - this.state = { - loading: !err - }; - } - - componentDidMount() { - seafileAPI.getFileContent(rawPath).then((res) => { - this.setState({ - content: res.data || defaultContentForSDoc, - loading: false - }); - }).catch(error => { - let errMessage = Utils.getErrorMsg(error); - toaster.danger(errMessage); - }); - } - - render() { - const { loading, content } = this.state; - if (err) { - return ; - } - - if (loading) { - return ; - } - - return ( -
- {content && } -
- ); - } -} - -ReactDom.render(, document.getElementById('wrapper')); diff --git a/frontend/src/view-file-sdoc.js b/frontend/src/view-file-sdoc.js index b96db1348a..346bb8af07 100644 --- a/frontend/src/view-file-sdoc.js +++ b/frontend/src/view-file-sdoc.js @@ -1,138 +1,27 @@ import React from 'react'; import ReactDom from 'react-dom'; -import PropTypes from 'prop-types'; -import Url from 'url-parse'; -import axios from 'axios'; -import { SDocEditor } from '@seafile/sdoc-editor'; -import { Utils } from './utils/utils'; -import { defaultContentForSDoc } from './utils/constants'; -import { seafileAPI } from './utils/seafile-api'; -import FileView from './components/file-view/file-view'; -import FileViewTip from './components/file-view/file-view-tip'; +import { SimpleEditor } from '@seafile/sdoc-editor'; -import './css/sdoc-file-view.css'; +const { serviceURL } = window.app.config; +const { repoID, docPath, docName, docUuid, seadocAccessToken, seadocServerUrl } = window.app.pageOptions; -const { - err, repoID, filePath, username, +window.seafile = { + repoID, docPath, docName, docUuid, - seadocAccessToken, - seadocServerUrl -} = window.app.pageOptions; - -const propTypes = { - content: PropTypes.object, - errorMsg: PropTypes.string + isOpenSocket: true, + serviceUrl: serviceURL, + accessToken: seadocAccessToken, + sdocServer: seadocServerUrl, }; -const config = { - docPath: docPath, - docName: docName, - docUuid: docUuid, - sdocServer: (new Url(seadocServerUrl)).origin, - accessToken: seadocAccessToken -}; - -class FileContent extends React.Component { - - render() { - const { content, errorMsg } = this.props; - - if (err) { - return ; - } - if (errorMsg) { - return ; - } - - return ( -
- {content && {}} - />} -
- ); - } -} - -FileContent.propTypes = propTypes; - class ViewFileSdoc extends React.Component { - constructor(props) { - super(props); - this.state = { - participants: [] - }; - this.isParticipant = false; - } - getFileContent = () => { - const { - docPath, - docName, - docUuid, - accessToken - } = config; - const url = `${seadocServerUrl}/api/v1/docs/${docUuid}/?doc_path=${encodeURIComponent(docPath)}&doc_name=${encodeURIComponent(docName)}`; - return axios.get(url, {headers: {Authorization: `Token ${accessToken}`}}); - } - - componentDidMount() { - this.getParticipants(); - - this.getFileContent().then(res => { - const content = res.data || defaultContentForSDoc; - this.setState({ - content: content - }); - }).catch((error) => { - this.setState({ - errorMsg: Utils.getErrorMsg(error, true) // true: show login tip if 403 - }); - }); - } - - addParticipant = () => { - seafileAPI.addFileParticipants(repoID, filePath, [username]).then((res) => { - this.isParticipant = true; - this.getParticipants(); - }); - } - - getParticipants = () => { - seafileAPI.listFileParticipants(repoID, filePath).then((res) => { - const participants = res.data.participant_list; - this.setState({ participants: participants }); - if (participants.length > 0) { - this.isParticipant = participants.every((participant) => { - return participant.email == username; - }); - } - }); - } - - onParticipantsChange = () => { - this.getParticipants(); - } render() { - return ( - - } - participants={this.state.participants} - onParticipantsChange={this.onParticipantsChange} - /> - ); + return (); } } diff --git a/seahub/templates/shared_file_view_react.html b/seahub/templates/shared_file_view_react.html index fba8d7b7e5..9ae12f5dd6 100644 --- a/seahub/templates/shared_file_view_react.html +++ b/seahub/templates/shared_file_view_react.html @@ -33,6 +33,8 @@ {% render_bundle 'sharedFileViewDocument' 'css' %} {% elif filetype == 'SpreadSheet' %} {% render_bundle 'sharedFileViewSpreadsheet' 'css' %} +{% elif filetype == 'SDoc' %} + {% render_bundle 'sharedFileViewSdoc' 'css' %} {% elif filetype == 'Unknown' %} {% render_bundle 'sharedFileViewUnknown' 'css' %} {% endif %}