mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-16 23:29:49 +00:00
insert file link 2.0 (#3167)
This commit is contained in:
83
frontend/src/components/dialog/insert-file-dialog.js
Normal file
83
frontend/src/components/dialog/insert-file-dialog.js
Normal file
@@ -0,0 +1,83 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Alert } from 'reactstrap';
|
||||
import { gettext } from '../../utils/constants';
|
||||
import { Utils } from '../../utils/utils';
|
||||
import FileChooser from '../file-chooser/file-chooser';
|
||||
import '../../css/dirent-detail.css';
|
||||
|
||||
const propTypes = {
|
||||
repoID: PropTypes.string.isRequired,
|
||||
filePath: PropTypes.string.isRequired,
|
||||
toggleCancel: PropTypes.func.isRequired,
|
||||
dirent: PropTypes.object.isRequired,
|
||||
getInsertLink: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
class InsertFileDialog extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
repo: null,
|
||||
selectedPath: '',
|
||||
};
|
||||
}
|
||||
|
||||
handleInsert = () => {
|
||||
this.props.getInsertLink(this.state.repo.repo_id, this.state.selectedPath);
|
||||
this.props.toggleCancel();
|
||||
}
|
||||
|
||||
onDirentItemClick = (repo, selectedPath, dirent) => {
|
||||
if (dirent.type === 'file') {
|
||||
this.setState({
|
||||
repo: repo,
|
||||
selectedPath: selectedPath,
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.setState({
|
||||
repo: null,
|
||||
selectedPath: '',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onRepoItemClick = () => {
|
||||
this.setState({
|
||||
repo: null,
|
||||
selectedPath: '',
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
let subtitle = gettext('Insert file in {placeholder}');
|
||||
subtitle = subtitle.replace('{placeholder}', '<span class="op-target">' + Utils.HTMLescape(this.props.dirent.name) + '</span>');
|
||||
const toggle = this.props.toggleCancel;
|
||||
return (
|
||||
<Modal isOpen={true} className="sf-add-related-file" toggle={toggle} >
|
||||
<ModalHeader toggle={toggle}>{gettext('Select File')}</ModalHeader>
|
||||
<ModalBody>
|
||||
<div className="related-file-subtitle" dangerouslySetInnerHTML={{__html: subtitle}}></div>
|
||||
<FileChooser
|
||||
isShowFile={true}
|
||||
repoID={this.props.repoID}
|
||||
onDirentItemClick={this.onDirentItemClick}
|
||||
onRepoItemClick={this.onRepoItemClick}
|
||||
mode="current_repo_and_other_repos"
|
||||
/>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="secondary" onClick={toggle}>{gettext('Cancel')}</Button>
|
||||
{this.state.selectedPath ? <Button color="primary" onClick={this.handleInsert}>{gettext('Insert')}</Button>
|
||||
: <Button color="primary" disabled>{gettext('Insert')}</Button>}
|
||||
</ModalFooter>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
InsertFileDialog.propTypes = propTypes;
|
||||
|
||||
export default InsertFileDialog;
|
@@ -13,6 +13,7 @@ import ListRelatedFileDialog from './components/dialog/list-related-file-dialog'
|
||||
import AddRelatedFileDialog from './components/dialog/add-related-file-dialog';
|
||||
import ShareDialog from './components/dialog/share-dialog';
|
||||
import CommentDialog from './components/markdown-view/comment-dialog';
|
||||
import InsertFileDialog from './components/dialog/insert-file-dialog';
|
||||
import MarkdownViewerSlate from '@seafile/seafile-editor/dist/viewer/markdown-viewer-slate';
|
||||
import { serialize, deserialize } from '@seafile/seafile-editor/dist/utils/slate2markdown';
|
||||
import LocalDraftDialog from './components/dialog/local-draft-dialog';
|
||||
@@ -299,6 +300,7 @@ class MarkdownEditor extends React.Component {
|
||||
showMarkdownEditorDialog: false,
|
||||
showShareLinkDialog: false,
|
||||
showCommentDialog: false,
|
||||
showInsertFileDialog: false,
|
||||
showDraftSaved: false,
|
||||
collabUsers: userInfo ?
|
||||
[{user: userInfo, is_editing: false}] : [],
|
||||
@@ -394,6 +396,7 @@ class MarkdownEditor extends React.Component {
|
||||
showMarkdownEditorDialog: false,
|
||||
showShareLinkDialog: false,
|
||||
showCommentDialog: false,
|
||||
showInsertFileDialog: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -514,6 +517,12 @@ class MarkdownEditor extends React.Component {
|
||||
showCommentDialog: true,
|
||||
});
|
||||
break;
|
||||
case 'insert_file':
|
||||
this.setState({
|
||||
showMarkdownEditorDialog: true,
|
||||
showInsertFileDialog: true,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
@@ -945,6 +954,22 @@ class MarkdownEditor extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
getInsertLink = (repoID, filePath) => {
|
||||
seafileAPI.getShareLink(repoID, filePath).then((res) => {
|
||||
if (res.data.length !== 0) {
|
||||
let fileLink = res.data[0];
|
||||
window.richMarkdownEditor.addLink(fileLink.obj_name, fileLink.link);
|
||||
} else {
|
||||
let permissions = { 'can_edit': false, 'can_download': true };
|
||||
permissions = JSON.stringify(permissions);
|
||||
seafileAPI.createShareLink(repoID, filePath, null, null, permissions).then((res) => {
|
||||
let fileLink = res.data;
|
||||
window.richMarkdownEditor.addLink(fileLink.obj_name, fileLink.link);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
let component;
|
||||
let sidePanel = this.state.isShowHistory ? true : false;
|
||||
@@ -1109,6 +1134,17 @@ class MarkdownEditor extends React.Component {
|
||||
/>
|
||||
</ModalPortal>
|
||||
}
|
||||
{this.state.showInsertFileDialog &&
|
||||
<ModalPortal>
|
||||
<InsertFileDialog
|
||||
repoID={repoID}
|
||||
filePath={filePath}
|
||||
toggleCancel={this.toggleCancel}
|
||||
dirent={this.state.fileInfo}
|
||||
getInsertLink={this.getInsertLink}
|
||||
/>
|
||||
</ModalPortal>
|
||||
}
|
||||
{this.state.showShareLinkDialog &&
|
||||
<ModalPortal>
|
||||
<ShareDialog
|
||||
|
Reference in New Issue
Block a user