1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-06 09:21:54 +00:00

insert file link 2.0 (#3167)

This commit is contained in:
Michael An
2019-03-26 11:18:41 +08:00
committed by Daniel Pan
parent ae9bed2446
commit 3c3df8d745
2 changed files with 119 additions and 0 deletions

View File

@@ -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