diff --git a/frontend/src/components/shared-file-view/shared-file-view-tip.js b/frontend/src/components/shared-file-view/shared-file-view-tip.js
new file mode 100644
index 0000000000..e5d31c998b
--- /dev/null
+++ b/frontend/src/components/shared-file-view/shared-file-view-tip.js
@@ -0,0 +1,24 @@
+import React from 'react';
+import { gettext } from '../../utils/constants';
+
+const { err } = window.shared.pageOptions;
+
+class SharedFileViewTip extends React.Component {
+ render() {
+ let errorMsg;
+ if (err == 'File preview unsupported') {
+ errorMsg =
-
-
-
-
-
-
- { loginUser &&
}
-
-
-
-
-
{fileName}
-
{gettext('Shared by:')}{' '}{sharedBy}
-
- {download &&
-
- }
-
- {this.getContent()}
-
- {this.state.showSaveSharedFileDialog &&
-
- }
+
);
}
}
-if (enableWatermark) {
- let watermark_txt;
- if (loginUser) {
- watermark_txt = siteName + ' ' + loginUser;
- } else {
- watermark_txt = gettext('Anonymous User');
- }
- watermark.init({
- watermark_txt: watermark_txt,
- watermark_alpha: 0.075
- });
-}
-
ReactDOM.render(
-
,
+
,
document.getElementById('wrapper')
);
diff --git a/frontend/src/shared-file-view-text.js b/frontend/src/shared-file-view-text.js
index 7ef2a54b56..ff3f84d40b 100644
--- a/frontend/src/shared-file-view-text.js
+++ b/frontend/src/shared-file-view-text.js
@@ -1,16 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom';
-import Account from './components/common/account';
-import CodeMirror from 'react-codemirror';
-import { Button } from 'reactstrap';
import { Utils } from './utils/utils';
-import watermark from 'watermark-dom';
-import SaveSharedFileDialog from './components/dialog/save-shared-file-dialog';
-import toaster from './components/toast';
-import { serviceURL, gettext, siteRoot, mediaUrl, logoPath, logoWidth, logoHeight, siteTitle } 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 'codemirror/lib/codemirror.css';
-import './css/shared-file-view.css';
+import CodeMirror from 'react-codemirror';
import 'codemirror/mode/javascript/javascript';
import 'codemirror/mode/css/css';
import 'codemirror/mode/clike/clike';
@@ -21,133 +15,48 @@ import 'codemirror/mode/xml/xml';
import 'codemirror/mode/go/go';
import 'codemirror/mode/python/python';
import 'codemirror/mode/htmlmixed/htmlmixed';
+import 'codemirror/lib/codemirror.css';
-const loginUser = window.app.pageOptions.name;
-const { trafficOverLimit, fileName, fileSize, sharedBy, siteName, enableWatermark, download, encoding, fileContent, sharedToken, fileEncodingList, err, fileext } = window.shared.pageOptions;
-const URL = require('url-parse');
+import './css/text-file-view.css';
-const options={
- lineNumbers: false,
- mode: Utils.chooseLanguage(fileext),
+const { err, fileExt, fileContent } = window.shared.pageOptions;
+
+const options = {
+ lineNumbers: true,
+ mode: Utils.chooseLanguage(fileExt),
extraKeys: {'Ctrl': 'autocomplete'},
theme: 'default',
- autoMatchParens: true,
textWrapping: true,
lineWrapping: true,
- readOnly: 'nocursor',
+ readOnly: true,
+ cursorBlinkRate: -1 // hide the cursor
};
class SharedFileViewText extends React.Component {
-
- constructor(props) {
- super(props);
- this.state = {
- showSaveSharedFileDialog: false,
- };
- }
-
- changeEncode = (e) => {
- let url = new URL(serviceURL) + '/f/' + sharedToken + '/?file_enc=' + e.target.value;
- window.location.href = url.toString();
- }
-
- fileEncode = () => {
- const list = fileEncodingList.substring(1, fileEncodingList.length - 1).replace(/\'*/g,'').replace(/\s*/g,'').split(',');
- return (
-
-
-
-
- );
- }
-
- handleSaveSharedFileDialog = () => {
- this.setState({
- showSaveSharedFileDialog: !this.state.showSaveSharedFileDialog
- });
- }
-
- saveFileSuccess = () => {
- let msg = gettext('Successfully saved {fileName}.');
- msg = msg.replace('{fileName}', fileName);
- toaster.success(msg);
- }
-
render() {
+ return
} />;
+ }
+}
+
+class FileContent extends React.Component {
+ render() {
+ if (err) {
+ return
;
+ }
+
return (
-
-
-
-
-
-
-
- { loginUser &&
}
-
-
-
-
-
{fileName}
-
{gettext('Shared by:')}{' '}{sharedBy}
-
- {download &&
-
- }
-
-
- {this.fileEncode()}
-
- { err ?
{err}
:
-
}
- { this.state.showSaveSharedFileDialog &&
-
- }
-
-
-
+
+
);
}
}
-if (enableWatermark) {
- let watermark_txt;
- if (loginUser) {
- watermark_txt = siteName + ' ' + loginUser;
- } else {
- watermark_txt = gettext('Anonymous User');
- }
- watermark.init({
- watermark_txt: watermark_txt,
- watermark_alpha: 0.075
- });
-}
-
-ReactDOM.render (
+ReactDOM.render(
,
document.getElementById('wrapper')
);
diff --git a/seahub/templates/shared_file_view_react.html b/seahub/templates/shared_file_view_react.html
index e4c93ad27b..98db73858c 100644
--- a/seahub/templates/shared_file_view_react.html
+++ b/seahub/templates/shared_file_view_react.html
@@ -36,7 +36,7 @@
encoding: '{{ encoding }}',
fileContent: '{{ file_content|escapejs }}',
err: '{{ err }}',
- fileext: '{{ fileext }}',
+ fileExt: '{{ fileext }}',
}
};