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