mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-07 01:41:39 +00:00
[SVG file view] rewrote it with react (#3125)
This commit is contained in:
@@ -134,6 +134,11 @@ module.exports = {
|
||||
require.resolve('react-dev-utils/webpackHotDevClient'),
|
||||
paths.appSrc + "/view-file-pdf.js",
|
||||
],
|
||||
viewFileSVG: [
|
||||
require.resolve('./polyfills'),
|
||||
require.resolve('react-dev-utils/webpackHotDevClient'),
|
||||
paths.appSrc + "/view-file-svg.js",
|
||||
],
|
||||
orgAdmin: [
|
||||
require.resolve('./polyfills'),
|
||||
require.resolve('react-dev-utils/webpackHotDevClient'),
|
||||
|
@@ -75,6 +75,7 @@ module.exports = {
|
||||
viewFileXmind: [require.resolve('./polyfills'), paths.appSrc + "/view-file-xmind.js"],
|
||||
viewFileVideo: [require.resolve('./polyfills'), paths.appSrc + "/view-file-video.js"],
|
||||
viewFilePDF: [require.resolve('./polyfills'), paths.appSrc + "/view-file-pdf.js"],
|
||||
viewFileSVG: [require.resolve('./polyfills'), paths.appSrc + "/view-file-svg.js"],
|
||||
orgAdmin: [require.resolve('./polyfills'), paths.appSrc + "/pages/org-admin"],
|
||||
viewFileUMind: [require.resolve('./polyfills'), paths.appSrc + "/view-file-umind.js"],
|
||||
sysAdmin: [require.resolve('./polyfills'), paths.appSrc + "/pages/sys-admin"],
|
||||
|
16
frontend/src/css/svg-file-view.css
Normal file
16
frontend/src/css/svg-file-view.css
Normal file
@@ -0,0 +1,16 @@
|
||||
.svg-file-view {
|
||||
position: relative;
|
||||
text-align: center;
|
||||
}
|
||||
.svg-file-view:before {
|
||||
content: ' ';
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
height: 100%;
|
||||
font-size: 0;
|
||||
line-height: 0;
|
||||
}
|
||||
#svg-view {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
123
frontend/src/view-file-svg.js
Normal file
123
frontend/src/view-file-svg.js
Normal file
@@ -0,0 +1,123 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import watermark from 'watermark-dom';
|
||||
import { seafileAPI } from './utils/seafile-api';
|
||||
import { siteName } from './utils/constants';
|
||||
import FileInfo from './components/file-view/file-info';
|
||||
import FileToolbar from './components/file-view/file-toolbar';
|
||||
import FileViewTip from './components/file-view/file-view-tip';
|
||||
import CommentPanel from './components/file-view/comment-panel';
|
||||
|
||||
import './css/file-view.css';
|
||||
import './css/svg-file-view.css';
|
||||
|
||||
const { isStarred, isLocked, lockedByMe,
|
||||
repoID, filePath, err, enableWatermark, userNickName,
|
||||
// the following are only for svg file view
|
||||
fileName, rawPath
|
||||
} = window.app.pageOptions;
|
||||
|
||||
class ViewFileSVG extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
isStarred: isStarred,
|
||||
isLocked: isLocked,
|
||||
lockedByMe: lockedByMe,
|
||||
isCommentPanelOpen: false
|
||||
};
|
||||
}
|
||||
|
||||
toggleCommentPanel = () => {
|
||||
this.setState({
|
||||
isCommentPanelOpen: !this.state.isCommentPanelOpen
|
||||
});
|
||||
}
|
||||
|
||||
toggleStar = () => {
|
||||
if (this.state.isStarred) {
|
||||
seafileAPI.unStarItem(repoID, filePath).then((res) => {
|
||||
this.setState({
|
||||
isStarred: false
|
||||
});
|
||||
});
|
||||
} else {
|
||||
seafileAPI.starItem(repoID, filePath).then((res) => {
|
||||
this.setState({
|
||||
isStarred: true
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
toggleLockFile = () => {
|
||||
if (this.state.isLocked) {
|
||||
seafileAPI.unlockfile(repoID, filePath).then((res) => {
|
||||
this.setState({
|
||||
isLocked: false,
|
||||
lockedByMe: false
|
||||
});
|
||||
});
|
||||
} else {
|
||||
seafileAPI.lockfile(repoID, filePath).then((res) => {
|
||||
this.setState({
|
||||
isLocked: true,
|
||||
lockedByMe: true
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="h-100 d-flex flex-column">
|
||||
<div className="file-view-header d-flex justify-content-between">
|
||||
<FileInfo
|
||||
isStarred={this.state.isStarred}
|
||||
isLocked={this.state.isLocked}
|
||||
toggleStar={this.toggleStar}
|
||||
/>
|
||||
<FileToolbar
|
||||
isLocked={this.state.isLocked}
|
||||
lockedByMe={this.state.lockedByMe}
|
||||
toggleLockFile={this.toggleLockFile}
|
||||
toggleCommentPanel={this.toggleCommentPanel}
|
||||
/>
|
||||
</div>
|
||||
<div className="file-view-body flex-auto d-flex">
|
||||
<FileContent />
|
||||
{this.state.isCommentPanelOpen &&
|
||||
<CommentPanel toggleCommentPanel={this.toggleCommentPanel} />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class FileContent extends React.Component {
|
||||
|
||||
render() {
|
||||
if (err) {
|
||||
return <FileViewTip />;
|
||||
}
|
||||
return (
|
||||
<div className="file-view-content flex-1 svg-file-view">
|
||||
<img src={rawPath} alt={fileName} id="svg-view" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (enableWatermark) {
|
||||
watermark.init({
|
||||
watermark_txt: `${siteName} ${userNickName}`,
|
||||
watermark_alpha: 0.075
|
||||
});
|
||||
}
|
||||
|
||||
ReactDOM.render (
|
||||
<ViewFileSVG />,
|
||||
document.getElementById('wrapper')
|
||||
);
|
15
seahub/templates/svg_file_view_react.html
Normal file
15
seahub/templates/svg_file_view_react.html
Normal file
@@ -0,0 +1,15 @@
|
||||
{% extends 'file_view_react.html' %}
|
||||
{% load render_bundle from webpack_loader %}
|
||||
{% load seahub_tags %}
|
||||
|
||||
{% block extra_style %}
|
||||
{% render_bundle 'viewFileSVG' 'css' %}
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_data %}
|
||||
rawPath: '{{ raw_path|escapejs }}'
|
||||
{% endblock %}
|
||||
|
||||
{% block render_bundle %}
|
||||
{% render_bundle 'viewFileSVG' 'js' %}
|
||||
{% endblock %}
|
@@ -697,7 +697,7 @@ def view_lib_file(request, repo_id, path):
|
||||
return_dict['raw_path'] = raw_path
|
||||
send_file_access_msg(request, repo, path, 'web')
|
||||
|
||||
if filetype in (VIDEO, PDF):
|
||||
if filetype in (VIDEO, PDF, SVG):
|
||||
template = '%s_file_view_react.html' % filetype.lower()
|
||||
return render(request, template, return_dict)
|
||||
|
||||
|
Reference in New Issue
Block a user