1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-12 13:24:52 +00:00

New draft file (#2465)

This commit is contained in:
C_Q
2018-10-24 14:37:41 +08:00
committed by Daniel Pan
parent 26f9d7d9d7
commit 67e19792aa
10 changed files with 155 additions and 43 deletions

View File

@@ -16,6 +16,7 @@ class CreateFile extends React.Component {
this.state = {
parentPath: '',
childName: props.fileType,
isDraft: false,
};
this.newInput = React.createRef();
}
@@ -28,7 +29,8 @@ class CreateFile extends React.Component {
handleSubmit = () => {
let path = this.state.parentPath + this.state.childName;
this.props.onAddFile(path);
let isDraft = this.state.isDraft;
this.props.onAddFile(path, isDraft);
}
handleKeyPress = (e) => {
@@ -37,6 +39,55 @@ class CreateFile extends React.Component {
}
}
handleCheck = () => {
let pos = this.state.childName.lastIndexOf(".");
if (this.state.isDraft) {
// from draft to not draft
// case 1, normally, the file name is ended with `(draft)`, like `test(draft).md`
// case 2, the file name is not ended with `(draft)`, the user has deleted some characters, like `test(dra.md`
let p = this.state.childName.substring(pos-7, pos);
let fileName = this.state.childName.substring(0, pos-7);
let fileType = this.state.childName.substring(pos);
if (p === '(draft)') {
// remove `(draft)` from file name
this.setState({
childName: fileName + fileType,
isDraft: !this.state.isDraft
})
} else {
// don't change file name
this.setState({
isDraft: !this.state.isDraft
})
}
}
if (!this.state.isDraft) {
// from not draft to draft
// case 1, test.md ===> test(draft).md
// case 2, .md ===> (draft).md
// case 3, no '.' in the file name, don't change the file name
if (pos > 0) {
let fileName = this.state.childName.substring(0, pos);
let fileType = this.state.childName.substring(pos);
this.setState({
childName: fileName + '(draft)' + fileType,
isDraft: !this.state.isDraft
})
} else if (pos === 0 ) {
this.setState({
childName: '(draft)' + this.state.childname,
isDraft: !this.state.isdraft
})
} else {
this.setState({
isDraft: !this.state.isdraft
})
}
}
}
toggle = () => {
this.props.addFileCancel();
}
@@ -67,6 +118,13 @@ class CreateFile extends React.Component {
<Input onKeyPress={this.handleKeyPress} innerRef={input => {this.newInput = input;}} id="fileName" placeholder={gettext('newName')} value={this.state.childName} onChange={this.handleChange}/>
</Col>
</FormGroup>
<FormGroup row>
<Label sm={3} check />
<Col sm={9}>
<Input type="checkbox" onChange={this.handleCheck}/>{' '}{gettext("This is a draft.")}
</Col>
</FormGroup>
</Form>
</ModalBody>
<ModalFooter>

View File

@@ -64,7 +64,8 @@ class DraftContent extends React.Component {
let draft = this.state.currentDraft;
editUtilties.createDraftReview(draft.id).then(res => {
window.open(siteRoot + 'drafts/review/' + res.data.id);
const w = window.open()
w.location = siteRoot + 'drafts/review/' + res.data.id;
}).catch((error) => {
if (error.response.status == '409') {
Toast.error('The draft review is existing.');

View File

@@ -158,9 +158,9 @@ class MainPanel extends Component {
this.setState({showFileDialog: !this.state.showFileDialog});
}
onMainAddFile = (filePath) => {
onMainAddFile = (filePath, isDraft) => {
this.setState({showFileDialog: !this.state.showFileDialog});
this.props.onMainAddFile(filePath);
this.props.onMainAddFile(filePath, isDraft);
}
onMainAddFolder = (dirPath) => {

View File

@@ -127,9 +127,9 @@ class SidePanel extends Component {
this.props.onAddFolderNode(dirPath);
}
onAddFileNode = (filePath) => {
onAddFileNode = (filePath, isDraft) => {
this.setState({showFile: !this.state.showFile});
this.props.onAddFileNode(filePath);
this.props.onAddFileNode(filePath, isDraft);
}
onRenameNode = (newName) => {

View File

@@ -252,8 +252,8 @@ class Wiki extends Component {
});
}
onAddFileNode = (filePath) => {
editorUtilities.createFile(filePath).then(res => {
onAddFileNode = (filePath, isDraft) => {
editorUtilities.createFile(filePath, isDraft).then(res => {
let tree = this.state.tree_data.clone();
let name = this.getFileNameByPath(filePath);
let index = filePath.lastIndexOf('/');

View File

@@ -38,8 +38,8 @@ class EditorUtilities {
});
}
createFile(filePath) {
return seafileAPI.createFile(repoID, filePath);
createFile(filePath, isDraft) {
return seafileAPI.createFile(repoID, filePath, isDraft);
}
deleteFile(filePath) {