mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-13 12:45:46 +00:00
commit
bc32292e45
@ -21,7 +21,7 @@ class CreateFile extends React.Component {
|
|||||||
isMarkdownDraft: false,
|
isMarkdownDraft: false,
|
||||||
isSdocDraft: false,
|
isSdocDraft: false,
|
||||||
errMessage: '',
|
errMessage: '',
|
||||||
isSubmitBtnActive: false,
|
isSubmitBtnActive: props.fileType.slice(0, -5) ? true : false,
|
||||||
};
|
};
|
||||||
this.newInput = React.createRef();
|
this.newInput = React.createRef();
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import { Utils } from '../../../utils/utils';
|
|||||||
import toaster from '../../../components/toast';
|
import toaster from '../../../components/toast';
|
||||||
import InternalLinkDialog from '../../../components/dialog/internal-link-dialog';
|
import InternalLinkDialog from '../../../components/dialog/internal-link-dialog';
|
||||||
import ShareDialog from '../../../components/dialog/share-dialog';
|
import ShareDialog from '../../../components/dialog/share-dialog';
|
||||||
|
import CreateFile from '../../../components/dialog/create-file-dialog';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
repoID: PropTypes.string.isRequired,
|
repoID: PropTypes.string.isRequired,
|
||||||
@ -13,6 +14,8 @@ const propTypes = {
|
|||||||
docName: PropTypes.string.isRequired,
|
docName: PropTypes.string.isRequired,
|
||||||
docPerm: PropTypes.string.isRequired,
|
docPerm: PropTypes.string.isRequired,
|
||||||
isStarred: PropTypes.bool.isRequired,
|
isStarred: PropTypes.bool.isRequired,
|
||||||
|
direntList: PropTypes.array.isRequired,
|
||||||
|
dirPath: PropTypes.string.isRequired,
|
||||||
toggleStar: PropTypes.func.isRequired,
|
toggleStar: PropTypes.func.isRequired,
|
||||||
unmarkDraft: PropTypes.func.isRequired,
|
unmarkDraft: PropTypes.func.isRequired,
|
||||||
onNewNotification: PropTypes.func.isRequired
|
onNewNotification: PropTypes.func.isRequired
|
||||||
@ -26,6 +29,8 @@ class ExternalOperations extends React.Component {
|
|||||||
isShowInternalLinkDialog: false,
|
isShowInternalLinkDialog: false,
|
||||||
isShowShareDialog: false,
|
isShowShareDialog: false,
|
||||||
internalLink: '',
|
internalLink: '',
|
||||||
|
isShowCreateFileDialog: false,
|
||||||
|
fileType: '.sdoc',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,6 +43,7 @@ class ExternalOperations extends React.Component {
|
|||||||
this.unsubscribeFreezeDocument = eventBus.subscribe(EXTERNAL_EVENT.FREEZE_DOCUMENT, this.onFreezeDocument);
|
this.unsubscribeFreezeDocument = eventBus.subscribe(EXTERNAL_EVENT.FREEZE_DOCUMENT, this.onFreezeDocument);
|
||||||
this.unsubscribeUnfreeze = eventBus.subscribe(EXTERNAL_EVENT.UNFREEZE, this.unFreeze);
|
this.unsubscribeUnfreeze = eventBus.subscribe(EXTERNAL_EVENT.UNFREEZE, this.unFreeze);
|
||||||
this.unsubscribeNewNotification = eventBus.subscribe(EXTERNAL_EVENT.NEW_NOTIFICATION, this.onNewNotification);
|
this.unsubscribeNewNotification = eventBus.subscribe(EXTERNAL_EVENT.NEW_NOTIFICATION, this.onNewNotification);
|
||||||
|
this.unsubscribeCreateSdocFile = eventBus.subscribe(EXTERNAL_EVENT.CREATE_SDOC_FILE, this.onCreateSdocFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
@ -48,6 +54,7 @@ class ExternalOperations extends React.Component {
|
|||||||
this.unsubscribeFreezeDocument();
|
this.unsubscribeFreezeDocument();
|
||||||
this.unsubscribeUnfreeze();
|
this.unsubscribeUnfreeze();
|
||||||
this.unsubscribeNewNotification();
|
this.unsubscribeNewNotification();
|
||||||
|
this.unsubscribeCreateSdocFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
onInternalLinkToggle = (options) => {
|
onInternalLinkToggle = (options) => {
|
||||||
@ -116,9 +123,37 @@ class ExternalOperations extends React.Component {
|
|||||||
this.props.onNewNotification();
|
this.props.onNewNotification();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onCreateSdocFile = (params) => {
|
||||||
|
if (params?.newFileName) {
|
||||||
|
this.setState({fileType: `${params.newFileName}.sdoc`});
|
||||||
|
}
|
||||||
|
this.setState({
|
||||||
|
isShowCreateFileDialog: !this.state.isShowCreateFileDialog
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
checkDuplicatedName = (newName) => {
|
||||||
|
let direntList = this.props.direntList;
|
||||||
|
let isDuplicated = direntList.some(object => {
|
||||||
|
return object.name === newName;
|
||||||
|
});
|
||||||
|
return isDuplicated;
|
||||||
|
};
|
||||||
|
|
||||||
|
onAddFile = (filePath, isMarkdownDraft) => {
|
||||||
|
let repoID = this.props.repoID;
|
||||||
|
seafileAPI.createFile(repoID, filePath, isMarkdownDraft).then((res) => {
|
||||||
|
const eventBus = EventBus.getInstance();
|
||||||
|
eventBus.dispatch(EXTERNAL_EVENT.INSERT_LINK, {data: res.data});
|
||||||
|
}).catch((error) => {
|
||||||
|
let errMessage = Utils.getErrorMsg(error);
|
||||||
|
toaster.danger(errMessage);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { repoID, docPath, docName, docPerm } = this.props;
|
const { repoID, docPath, docName, docPerm, dirPath } = this.props;
|
||||||
const { isShowInternalLinkDialog, isShowShareDialog, internalLink } = this.state;
|
const { isShowInternalLinkDialog, isShowShareDialog, internalLink, isShowCreateFileDialog, fileType } = this.state;
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{isShowInternalLinkDialog && (
|
{isShowInternalLinkDialog && (
|
||||||
@ -139,6 +174,15 @@ class ExternalOperations extends React.Component {
|
|||||||
toggleDialog={this.onShareToggle}
|
toggleDialog={this.onShareToggle}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{isShowCreateFileDialog && (
|
||||||
|
<CreateFile
|
||||||
|
parentPath={dirPath}
|
||||||
|
fileType={fileType}
|
||||||
|
onAddFile={this.onAddFile}
|
||||||
|
checkDuplicatedName={this.checkDuplicatedName}
|
||||||
|
toggleDialog={this.onCreateSdocFile}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import React, { Fragment } from 'react';
|
import React, { Fragment } from 'react';
|
||||||
import { SimpleEditor } from '@seafile/sdoc-editor';
|
import { SimpleEditor } from '@seafile/sdoc-editor';
|
||||||
import ExternalOperations from './external-operations';
|
import ExternalOperations from './external-operations';
|
||||||
|
import { seafileAPI } from '../../../utils/seafile-api';
|
||||||
|
import Dirent from '../../../models/dirent';
|
||||||
import { Utils } from '../../../utils/utils';
|
import { Utils } from '../../../utils/utils';
|
||||||
|
|
||||||
export default class SdocEditor extends React.Component {
|
export default class SdocEditor extends React.Component {
|
||||||
@ -10,12 +12,14 @@ export default class SdocEditor extends React.Component {
|
|||||||
const { isStarred, isSdocDraft } = window.app.pageOptions;
|
const { isStarred, isSdocDraft } = window.app.pageOptions;
|
||||||
this.state = {
|
this.state = {
|
||||||
isStarred: isStarred,
|
isStarred: isStarred,
|
||||||
isDraft: isSdocDraft
|
isDraft: isSdocDraft,
|
||||||
|
direntList: []
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.onSetFavicon();
|
this.onSetFavicon();
|
||||||
|
this.getDirentList();
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleStar = (isStarred) => {
|
toggleStar = (isStarred) => {
|
||||||
@ -39,9 +43,36 @@ export default class SdocEditor extends React.Component {
|
|||||||
this.onSetFavicon('_notification');
|
this.onSetFavicon('_notification');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
getDirPath = () => {
|
||||||
|
const { docPath } = window.seafile;
|
||||||
|
const index = docPath.lastIndexOf('/');
|
||||||
|
if (index) {
|
||||||
|
return docPath.slice(0, index);
|
||||||
|
}
|
||||||
|
return '/';
|
||||||
|
};
|
||||||
|
|
||||||
|
getDirentList = () => {
|
||||||
|
const { repoID } = window.seafile;
|
||||||
|
const path = this.getDirPath();
|
||||||
|
seafileAPI.listDir(repoID, path, {'with_thumbnail': true}).then(res => {
|
||||||
|
let direntList = [];
|
||||||
|
res.data.dirent_list.forEach(item => {
|
||||||
|
let dirent = new Dirent(item);
|
||||||
|
direntList.push(dirent);
|
||||||
|
});
|
||||||
|
this.setState({
|
||||||
|
direntList: direntList
|
||||||
|
});
|
||||||
|
}).catch((err) => {
|
||||||
|
Utils.getErrorMsg(err, true);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { repoID, docPath, docName, docPerm } = window.seafile;
|
const { repoID, docPath, docName, docPerm } = window.seafile;
|
||||||
const { isStarred, isDraft } = this.state;
|
const { isStarred, isDraft, direntList } = this.state;
|
||||||
|
const dirPath = this.getDirPath();
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<SimpleEditor isStarred={isStarred} isDraft={isDraft} />
|
<SimpleEditor isStarred={isStarred} isDraft={isDraft} />
|
||||||
@ -51,6 +82,8 @@ export default class SdocEditor extends React.Component {
|
|||||||
docName={docName}
|
docName={docName}
|
||||||
docPerm={docPerm}
|
docPerm={docPerm}
|
||||||
isStarred={isStarred}
|
isStarred={isStarred}
|
||||||
|
direntList={direntList}
|
||||||
|
dirPath={dirPath}
|
||||||
toggleStar={this.toggleStar}
|
toggleStar={this.toggleStar}
|
||||||
unmarkDraft={this.unmarkDraft}
|
unmarkDraft={this.unmarkDraft}
|
||||||
onNewNotification={this.onNewNotification}
|
onNewNotification={this.onNewNotification}
|
||||||
|
Loading…
Reference in New Issue
Block a user