mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-07 09:51:26 +00:00
fix
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import React, { Fragment } from 'react';
|
import React, { Fragment } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { ButtonGroup, Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap';
|
import { ButtonGroup } from 'reactstrap';
|
||||||
import IconButton from '../icon-button';
|
import IconButton from '../icon-button';
|
||||||
import { gettext, siteRoot } from '../../utils/constants';
|
import { gettext, siteRoot } from '../../utils/constants';
|
||||||
import { Utils } from '../../utils/utils';
|
import { Utils } from '../../utils/utils';
|
||||||
@@ -31,7 +31,6 @@ class FileToolbar extends React.Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
dropdownOpen: false,
|
|
||||||
isShareDialogOpen: false
|
isShareDialogOpen: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -40,15 +39,8 @@ class FileToolbar extends React.Component {
|
|||||||
this.setState({isShareDialogOpen: !this.state.isShareDialogOpen});
|
this.setState({isShareDialogOpen: !this.state.isShareDialogOpen});
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle = () => {
|
|
||||||
this.setState({
|
|
||||||
dropdownOpen: !this.state.dropdownOpen
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
||||||
@@ -71,7 +63,7 @@ class FileToolbar extends React.Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<ButtonGroup className="d-none d-md-block">
|
<ButtonGroup className="align-self-center">
|
||||||
<IconButton
|
<IconButton
|
||||||
id="open-parent-folder"
|
id="open-parent-folder"
|
||||||
icon="fa fa-folder-open"
|
icon="fa fa-folder-open"
|
||||||
@@ -104,15 +96,25 @@ 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) &&
|
||||||
<IconButton
|
( this.props.isSaving ?
|
||||||
id="edit"
|
<button type={'button'} className={'btn btn-icon btn-secondary btn-active'}>
|
||||||
icon="fa fa-edit"
|
<i className={'fa fa-spin fa-spinner'}/></button> :
|
||||||
text={gettext('Edit')}
|
(
|
||||||
tag="a"
|
this.props.isContentChangedButNotSaved ?
|
||||||
href={`${siteRoot}repo/${repoID}/file/edit/?p=${encodeURIComponent(filePath)}&file_enc=${encodeURIComponent(fileEnc)}`}
|
<IconButton
|
||||||
/>
|
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"
|
||||||
@@ -132,54 +134,6 @@ class FileToolbar extends React.Component {
|
|||||||
)}
|
)}
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
|
|
||||||
<Dropdown isOpen={this.state.dropdownOpen} toggle={this.toggle} className="d-block d-md-none">
|
|
||||||
<DropdownToggle className="sf2-icon-more">
|
|
||||||
</DropdownToggle>
|
|
||||||
<DropdownMenu right={true}>
|
|
||||||
<DropdownItem>
|
|
||||||
<a href={`${siteRoot}library/${repoID}/${Utils.encodePath(repoName + parentDir)}`} className="text-inherit">
|
|
||||||
{gettext('Open parent folder')}
|
|
||||||
</a>
|
|
||||||
</DropdownItem>
|
|
||||||
{showLockUnlockBtn && (
|
|
||||||
<DropdownItem onClick={this.props.toggleLockFile}>
|
|
||||||
{lockUnlockText}
|
|
||||||
</DropdownItem>
|
|
||||||
)}
|
|
||||||
{showShareBtn && (
|
|
||||||
<DropdownItem onClick={this.toggleShareDialog}>
|
|
||||||
{gettext('Share')}
|
|
||||||
</DropdownItem>
|
|
||||||
)}
|
|
||||||
{filePerm == 'rw' && (
|
|
||||||
<DropdownItem>
|
|
||||||
<a href={`${siteRoot}repo/file_revisions/${repoID}/?p=${encodeURIComponent(filePath)}&referer=${encodeURIComponent(location.href)}`} className="text-inherit">
|
|
||||||
{gettext('History')}
|
|
||||||
</a>
|
|
||||||
</DropdownItem>
|
|
||||||
)}
|
|
||||||
{(canEditFile && !err) && (
|
|
||||||
<DropdownItem>
|
|
||||||
<a href={`${siteRoot}repo/${repoID}/file/edit/?p=${encodeURIComponent(filePath)}&file_enc=${encodeURIComponent(fileEnc)}`} className="text-inherit">
|
|
||||||
{gettext('Edit')}
|
|
||||||
</a>
|
|
||||||
</DropdownItem>
|
|
||||||
)}
|
|
||||||
{canDownloadFile && (
|
|
||||||
<DropdownItem>
|
|
||||||
<a href="?dl=1" className="text-inherit">
|
|
||||||
{gettext('Download')}
|
|
||||||
</a>
|
|
||||||
</DropdownItem>
|
|
||||||
)}
|
|
||||||
{enableComment && (
|
|
||||||
<DropdownItem onClick={this.props.toggleCommentPanel}>
|
|
||||||
{gettext('Comment')}
|
|
||||||
</DropdownItem>
|
|
||||||
)}
|
|
||||||
</DropdownMenu>
|
|
||||||
</Dropdown>
|
|
||||||
|
|
||||||
{this.state.isShareDialogOpen &&
|
{this.state.isShareDialogOpen &&
|
||||||
<ModalPortal>
|
<ModalPortal>
|
||||||
<ShareDialog
|
<ShareDialog
|
||||||
|
@@ -20,6 +20,7 @@ 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) {
|
||||||
@@ -28,7 +29,7 @@ class FileView extends React.Component {
|
|||||||
isStarred: isStarred,
|
isStarred: isStarred,
|
||||||
isLocked: isLocked,
|
isLocked: isLocked,
|
||||||
lockedByMe: lockedByMe,
|
lockedByMe: lockedByMe,
|
||||||
isCommentPanelOpen: false
|
isCommentPanelOpen: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +76,7 @@ class FileView extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="h-100 d-flex flex-column">
|
<div className="h-100 d-flex flex-column">
|
||||||
<div className="file-view-header d-flex justify-content-between align-items-center">
|
<div className="file-view-header d-flex justify-content-between">
|
||||||
<FileInfo
|
<FileInfo
|
||||||
isStarred={this.state.isStarred}
|
isStarred={this.state.isStarred}
|
||||||
isLocked={this.state.isLocked}
|
isLocked={this.state.isLocked}
|
||||||
@@ -84,6 +85,9 @@ 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,8 +1,12 @@
|
|||||||
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';
|
||||||
@@ -20,7 +24,7 @@ import 'codemirror/lib/codemirror.css';
|
|||||||
import './css/text-file-view.css';
|
import './css/text-file-view.css';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
err, fileExt, fileContent
|
err, fileExt, fileContent, repoID, filePath, fileName
|
||||||
} = window.app.pageOptions;
|
} = window.app.pageOptions;
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
@@ -30,18 +34,76 @@ const options = {
|
|||||||
theme: 'default',
|
theme: 'default',
|
||||||
textWrapping: true,
|
textWrapping: true,
|
||||||
lineWrapping: true,
|
lineWrapping: true,
|
||||||
readOnly: true,
|
readOnly: false, // set false to let user edit directly
|
||||||
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 content={<FileContent />} />
|
<FileView
|
||||||
|
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) {
|
||||||
@@ -51,14 +113,17 @@ 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={fileContent}
|
value={this.props.content}
|
||||||
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