mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-02 07:27:04 +00:00
optimized repo create code (#2697)
This commit is contained in:
@@ -103,10 +103,6 @@ class App extends Component {
|
||||
this.setState({currentTab: '', pathPrefix: []});
|
||||
let url = siteRoot + 'library/' + selectedItem.repo_id + '/' + selectedItem.repo_name + selectedItem.path;
|
||||
navigate(url, {repalce: true});
|
||||
} else if (Utils.isMarkdownFile(selectedItem.path)) {
|
||||
let url = siteRoot + 'wiki/lib/' + selectedItem.repo_id + selectedItem.path;
|
||||
let newWindow = window.open('markdown-editor');
|
||||
newWindow.location.href = url;
|
||||
} else {
|
||||
let url = siteRoot + 'lib/' + selectedItem.repo_id + '/file' + Utils.encodePath(selectedItem.path);
|
||||
let newWindow = window.open('about:blank');
|
||||
|
@@ -167,8 +167,8 @@ class CopyDirent extends React.Component {
|
||||
{this.state.errMessage && <Alert color="danger" style={{margin: '0.5rem'}}>{this.state.errMessage}</Alert>}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="primary" onClick={this.handleSubmit}>{gettext('Submit')}</Button>
|
||||
<Button color="secondary" onClick={this.toggle}>{gettext('Cancel')}</Button>
|
||||
<Button color="primary" onClick={this.handleSubmit}>{gettext('Submit')}</Button>
|
||||
</ModalFooter>
|
||||
</Modal>
|
||||
);
|
||||
|
@@ -167,8 +167,8 @@ class MoveDirent extends React.Component {
|
||||
{this.state.errMessage && <Alert color="danger" style={{margin: '0.5rem'}}>{this.state.errMessage}</Alert>}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="primary" onClick={this.handleSubmit}>{gettext('Submit')}</Button>
|
||||
<Button color="secondary" onClick={this.toggle}>{gettext('Cancel')}</Button>
|
||||
<Button color="primary" onClick={this.handleSubmit}>{gettext('Submit')}</Button>
|
||||
</ModalFooter>
|
||||
</Modal>
|
||||
);
|
||||
|
@@ -17,6 +17,7 @@ const propTypes = {
|
||||
currentRepoInfo: PropTypes.object,
|
||||
pathPrefix: PropTypes.array.isRequired,
|
||||
path: PropTypes.string.isRequired,
|
||||
errorMsg: PropTypes.string.isRequired,
|
||||
repoID: PropTypes.string.isRequired,
|
||||
repoName: PropTypes.string.isRequired,
|
||||
pathExist: PropTypes.bool.isRequired,
|
||||
@@ -104,7 +105,7 @@ class DirPanel extends React.Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const ErrMessage = (<div className="message empty-tip err-message"><h2>{gettext('Folder does not exist.')}</h2></div>);
|
||||
const errMessage = (<div className="message empty-tip err-message"><h2>{gettext('Folder does not exist.')}</h2></div>);
|
||||
|
||||
return (
|
||||
<div className="main-panel wiki-main-panel o-hidden">
|
||||
@@ -161,8 +162,11 @@ class DirPanel extends React.Component {
|
||||
/>
|
||||
</div>
|
||||
<div className="cur-view-content">
|
||||
{this.props.errorMsg ?
|
||||
<p className="error text-center">{this.props.errorMsg}</p> :
|
||||
<Fragment>
|
||||
{!this.props.pathExist ?
|
||||
ErrMessage :
|
||||
errMessage :
|
||||
<Fragment>
|
||||
<DirentListView
|
||||
path={this.props.path}
|
||||
@@ -193,6 +197,8 @@ class DirPanel extends React.Component {
|
||||
/>
|
||||
</Fragment>
|
||||
}
|
||||
</Fragment>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, { Fragment } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { siteRoot } from '../../utils/constants';
|
||||
import { seafileAPI } from '../../utils/seafile-api';
|
||||
@@ -24,7 +24,7 @@ class DirView extends React.Component {
|
||||
|
||||
this.state = {
|
||||
path: '/',
|
||||
pathExit: true,
|
||||
pathExist: true,
|
||||
repoName: '',
|
||||
repoID: '',
|
||||
permission: true,
|
||||
@@ -36,6 +36,7 @@ class DirView extends React.Component {
|
||||
direntList: [],
|
||||
selectedDirentList: [],
|
||||
dirID: '',
|
||||
errorMsg: '',
|
||||
};
|
||||
window.onpopstate = this.onpopstate;
|
||||
}
|
||||
@@ -69,6 +70,25 @@ class DirView extends React.Component {
|
||||
if (!res.data.lib_need_decrypt) {
|
||||
this.updateDirentList(path);
|
||||
}
|
||||
}).catch(error => {
|
||||
if (error.response) {
|
||||
if (error.response.status == 403) {
|
||||
this.setState({
|
||||
isDirentListLoading: false,
|
||||
errorMsg: gettext('Permission denied')
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
isDirentListLoading: false,
|
||||
errorMsg: gettext('Error')
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.setState({
|
||||
isDirentListLoading: false,
|
||||
errorMsg: gettext('Please check the network.')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -101,11 +121,15 @@ class DirView extends React.Component {
|
||||
});
|
||||
this.setState({
|
||||
isDirentListLoading: false,
|
||||
pathExist: true,
|
||||
direntList: direntList,
|
||||
dirID: res.headers.oid,
|
||||
});
|
||||
}).catch(() => {
|
||||
this.setState({pathExist: false});
|
||||
this.setState({
|
||||
isDirentListLoading: false,
|
||||
pathExist: false
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -365,10 +389,6 @@ class DirView extends React.Component {
|
||||
onSearchedClick = (selectedItem) => {
|
||||
if (selectedItem.is_dir === true) {
|
||||
this.setState({path: selectedItem.path});
|
||||
} else if (Utils.isMarkdownFile(selectedItem.path)) {
|
||||
let url = siteRoot + 'wiki/lib/' + selectedItem.repo_id + selectedItem.path;
|
||||
let newWindow = window.open('markdown-editor');
|
||||
newWindow.location.href = url;
|
||||
} else {
|
||||
let url = siteRoot + 'lib/' + selectedItem.repo_id + '/file' + selectedItem.path;
|
||||
let newWindow = window.open('about:blank');
|
||||
@@ -487,7 +507,8 @@ class DirView extends React.Component {
|
||||
pathPrefix={this.props.pathPrefix}
|
||||
currentRepoInfo={this.state.currentRepoInfo}
|
||||
path={this.state.path}
|
||||
pathExist={this.state.pathExit}
|
||||
pathExist={this.state.pathExist}
|
||||
errorMsg={this.state.errorMsg}
|
||||
repoID={this.state.repoID}
|
||||
repoName={this.state.repoName}
|
||||
permission={this.state.permission}
|
||||
|
@@ -95,7 +95,7 @@ class MutipleDirOperationToolbar extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<Fragment>
|
||||
<div className="operation mutiple-dirents-operation">
|
||||
<div className="operation multiple-dirents-operation">
|
||||
<button className="btn btn-secondary operation-item op-icon sf2-icon-move" title={gettext('Move')} onClick={this.onMoveToggle}></button>
|
||||
<button className="btn btn-secondary operation-item op-icon sf2-icon-copy" title={gettext('Copy')} onClick={this.onCopyToggle}></button>
|
||||
<button className="btn btn-secondary operation-item op-icon sf2-icon-delete" title={gettext('Delete')} onClick={this.props.onItemsDelete}></button>
|
||||
|
@@ -30,6 +30,9 @@
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.multiple-dirents-operation .operation-item {
|
||||
font-size: 1.125rem;
|
||||
}
|
||||
/* end file-operation toolbar */
|
||||
|
||||
/* begin view-mode toolbar */
|
||||
|
@@ -207,7 +207,7 @@ class GroupView extends React.Component {
|
||||
|
||||
addRepoItem = (repo) => {
|
||||
let newRepoList = this.state.repoList.map(item => {return item;});
|
||||
newRepoList.push(repo);
|
||||
newRepoList.unshift(repo);
|
||||
return newRepoList;
|
||||
}
|
||||
|
||||
|
@@ -59,7 +59,7 @@ class MyLibraries extends Component {
|
||||
encrypted: res.data.encrypted,
|
||||
permission: permission,
|
||||
};
|
||||
this.state.items.push(repo);
|
||||
this.state.items.unshift(repo);
|
||||
this.setState({items: this.state.items});
|
||||
});
|
||||
}
|
||||
|
@@ -114,19 +114,21 @@ class PublicSharedView extends React.Component {
|
||||
|
||||
addRepoItem = (repo) => {
|
||||
let isExist = false;
|
||||
let repoIndex = 0;
|
||||
let repoList = this.state.repoList;
|
||||
for (let i = 0; i < repoList.length; i ++) {
|
||||
if (repo.repo_id === repoList[i].repo_id) {
|
||||
isExist = true;
|
||||
repoIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isExist) {
|
||||
return this.state.repoList;
|
||||
this.state.repoList.splice(repoIndex, 1);
|
||||
}
|
||||
|
||||
let newRepoList = this.state.repoList.map(item => {return item;});
|
||||
newRepoList.push(repo);
|
||||
newRepoList.unshift(repo);
|
||||
return newRepoList;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user