mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-09 02:42:47 +00:00
Revert "Update txt file save mechanism"
This commit is contained in:
@@ -10,9 +10,6 @@ import ShareDialog from '../dialog/share-dialog';
|
|||||||
const propTypes = {
|
const propTypes = {
|
||||||
isLocked: PropTypes.bool.isRequired,
|
isLocked: PropTypes.bool.isRequired,
|
||||||
lockedByMe: PropTypes.bool.isRequired,
|
lockedByMe: PropTypes.bool.isRequired,
|
||||||
onSaveChangedContent: PropTypes.func.isRequired,
|
|
||||||
isSaving: PropTypes.bool.isRequired,
|
|
||||||
isContentChangedButNotSaved: PropTypes.bool.isRequired,
|
|
||||||
toggleLockFile: PropTypes.func.isRequired,
|
toggleLockFile: PropTypes.func.isRequired,
|
||||||
toggleCommentPanel: PropTypes.func.isRequired
|
toggleCommentPanel: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
@@ -48,6 +45,7 @@ class FileToolbar extends React.Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { isLocked, lockedByMe } = this.props;
|
const { isLocked, lockedByMe } = this.props;
|
||||||
|
|
||||||
let showLockUnlockBtn = false;
|
let showLockUnlockBtn = false;
|
||||||
let lockUnlockText, lockUnlockIcon;
|
let lockUnlockText, lockUnlockIcon;
|
||||||
if (canLockUnlockFile) {
|
if (canLockUnlockFile) {
|
||||||
@@ -103,25 +101,15 @@ class FileToolbar extends React.Component {
|
|||||||
href={`${siteRoot}repo/file_revisions/${repoID}/?p=${encodeURIComponent(filePath)}&referer=${encodeURIComponent(location.href)}`}
|
href={`${siteRoot}repo/file_revisions/${repoID}/?p=${encodeURIComponent(filePath)}&referer=${encodeURIComponent(location.href)}`}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{(canEditFile && !err) &&
|
{(canEditFile && !err) && (
|
||||||
( this.props.isSaving ?
|
<IconButton
|
||||||
<button type={'button'} className={'btn btn-icon btn-secondary btn-active'}>
|
id="edit"
|
||||||
<i className={'fa fa-spin fa-spinner'}/></button> :
|
icon="fa fa-edit"
|
||||||
(
|
text={gettext('Edit')}
|
||||||
this.props.isContentChangedButNotSaved ?
|
tag="a"
|
||||||
<IconButton
|
href={`${siteRoot}repo/${repoID}/file/edit/?p=${encodeURIComponent(filePath)}&file_enc=${encodeURIComponent(fileEnc)}`}
|
||||||
text={gettext('Save')}
|
/>
|
||||||
id={'saveButton'}
|
)}
|
||||||
icon={'fa fa-save'}
|
|
||||||
// button imported in this file does not have functionalities of
|
|
||||||
// isActive as button imported in markdowneditor has
|
|
||||||
//isActive={!isContentChanged}
|
|
||||||
onClick={this.props.onSaveChangedContent}
|
|
||||||
/> :
|
|
||||||
<button type={'button'} className={'btn btn-icon btn-secondary btn-active'} disabled>
|
|
||||||
<i className={'fa fa-save'}/></button>
|
|
||||||
)
|
|
||||||
)}
|
|
||||||
{canDownloadFile && (
|
{canDownloadFile && (
|
||||||
<IconButton
|
<IconButton
|
||||||
id="download-file"
|
id="download-file"
|
||||||
|
@@ -10,17 +10,13 @@ import CommentPanel from './comment-panel';
|
|||||||
import '../../css/file-view.css';
|
import '../../css/file-view.css';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
onSaveChangedContent: PropTypes.func.isRequired,
|
content: PropTypes.object.isRequired
|
||||||
content: PropTypes.object.isRequired,
|
|
||||||
isSaving: PropTypes.bool.isRequired,
|
|
||||||
isContentChangedButNotSaved: PropTypes.bool.isRequired,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const { isStarred, isLocked, lockedByMe,
|
const { isStarred, isLocked, lockedByMe,
|
||||||
repoID, filePath, enableWatermark, userNickName
|
repoID, filePath, enableWatermark, userNickName
|
||||||
} = window.app.pageOptions;
|
} = window.app.pageOptions;
|
||||||
|
|
||||||
|
|
||||||
class FileView extends React.Component {
|
class FileView extends React.Component {
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -29,7 +25,7 @@ class FileView extends React.Component {
|
|||||||
isStarred: isStarred,
|
isStarred: isStarred,
|
||||||
isLocked: isLocked,
|
isLocked: isLocked,
|
||||||
lockedByMe: lockedByMe,
|
lockedByMe: lockedByMe,
|
||||||
isCommentPanelOpen: false,
|
isCommentPanelOpen: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,9 +81,6 @@ class FileView extends React.Component {
|
|||||||
<FileToolbar
|
<FileToolbar
|
||||||
isLocked={this.state.isLocked}
|
isLocked={this.state.isLocked}
|
||||||
lockedByMe={this.state.lockedByMe}
|
lockedByMe={this.state.lockedByMe}
|
||||||
onSaveChangedContent={this.props.onSaveChangedContent}
|
|
||||||
isSaving={this.props.isSaving}
|
|
||||||
isContentChangedButNotSaved={this.props.isContentChangedButNotSaved}
|
|
||||||
toggleLockFile={this.toggleLockFile}
|
toggleLockFile={this.toggleLockFile}
|
||||||
toggleCommentPanel={this.toggleCommentPanel}
|
toggleCommentPanel={this.toggleCommentPanel}
|
||||||
/>
|
/>
|
||||||
|
@@ -1,12 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import toaster from './components/toast';
|
|
||||||
import { Utils } from './utils/utils';
|
import { Utils } from './utils/utils';
|
||||||
import { gettext } from './utils/constants';
|
|
||||||
import FileView from './components/file-view/file-view';
|
import FileView from './components/file-view/file-view';
|
||||||
import FileViewTip from './components/file-view/file-view-tip';
|
import FileViewTip from './components/file-view/file-view-tip';
|
||||||
import { seafileAPI } from './utils/seafile-api';
|
|
||||||
|
|
||||||
import CodeMirror from 'react-codemirror';
|
import CodeMirror from 'react-codemirror';
|
||||||
import 'codemirror/mode/javascript/javascript';
|
import 'codemirror/mode/javascript/javascript';
|
||||||
@@ -24,7 +20,7 @@ import 'codemirror/lib/codemirror.css';
|
|||||||
import './css/text-file-view.css';
|
import './css/text-file-view.css';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
err, fileExt, fileContent, repoID, filePath, fileName
|
err, fileExt, fileContent
|
||||||
} = window.app.pageOptions;
|
} = window.app.pageOptions;
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
@@ -34,76 +30,18 @@ const options = {
|
|||||||
theme: 'default',
|
theme: 'default',
|
||||||
textWrapping: true,
|
textWrapping: true,
|
||||||
lineWrapping: true,
|
lineWrapping: true,
|
||||||
readOnly: false, // set false to let user edit directly
|
readOnly: true,
|
||||||
|
cursorBlinkRate: -1 // hide the cursor
|
||||||
};
|
};
|
||||||
|
|
||||||
class ViewFileText extends React.Component {
|
class ViewFileText extends React.Component {
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
this.state = {
|
|
||||||
content: fileContent,
|
|
||||||
isContentChangedButNotSaved: false,
|
|
||||||
isSaving: false,
|
|
||||||
};
|
|
||||||
this.onSaveChangedContent=this.onSaveChangedContent.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
updateContent = (newContent) => {
|
|
||||||
this.setState({
|
|
||||||
isContentChangedButNotSaved: true,
|
|
||||||
content: newContent,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
onSaveChangedContent () {
|
|
||||||
let dirPath = '/';
|
|
||||||
return (
|
|
||||||
seafileAPI.getUpdateLink(repoID, dirPath).then((res) => {
|
|
||||||
const uploadLink = res.data;
|
|
||||||
this.setState({
|
|
||||||
isSaving: true
|
|
||||||
});
|
|
||||||
return seafileAPI.updateFile(
|
|
||||||
uploadLink,
|
|
||||||
filePath,
|
|
||||||
fileName,
|
|
||||||
this.state.content
|
|
||||||
).then(() => {
|
|
||||||
toaster.success(gettext('Successfully saved'), {
|
|
||||||
duration: 3
|
|
||||||
});
|
|
||||||
this.setState({
|
|
||||||
isSaving: false,
|
|
||||||
isContentChangedButNotSaved: false
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<FileView
|
<FileView content={<FileContent />} />
|
||||||
content={
|
|
||||||
<FileContent
|
|
||||||
content={this.state.content}
|
|
||||||
updateContent={this.updateContent}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
isSaving={this.state.isSaving}
|
|
||||||
isContentChangedButNotSaved={this.state.isContentChangedButNotSaved}
|
|
||||||
onSaveChangedContent={this.onSaveChangedContent}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const propTypes = {
|
|
||||||
updateContent: PropTypes.func.isRequired,
|
|
||||||
content: PropTypes.string.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
class FileContent extends React.Component {
|
class FileContent extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -113,17 +51,14 @@ class FileContent extends React.Component {
|
|||||||
<div className="file-view-content flex-1 text-file-view">
|
<div className="file-view-content flex-1 text-file-view">
|
||||||
<CodeMirror
|
<CodeMirror
|
||||||
ref="code-mirror-editor"
|
ref="code-mirror-editor"
|
||||||
value={this.props.content}
|
value={fileContent}
|
||||||
options={options}
|
options={options}
|
||||||
onChange={this.props.updateContent}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileContent.propTypes = propTypes;
|
|
||||||
|
|
||||||
ReactDOM.render (
|
ReactDOM.render (
|
||||||
<ViewFileText />,
|
<ViewFileText />,
|
||||||
document.getElementById('wrapper')
|
document.getElementById('wrapper')
|
||||||
|
Reference in New Issue
Block a user