1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-09 02:42:47 +00:00

add libraryType to choose different create repo method

This commit is contained in:
shanshuirenjia
2018-12-07 13:21:43 +08:00
parent a51bc8cea5
commit 6420c7fcdb
4 changed files with 36 additions and 23 deletions

View File

@@ -35,8 +35,8 @@ class CreateRepoDialog extends React.Component {
}
handleSubmit = () => {
let isValidate = this.validateInputParams();
if (isValidate) {
let isValid= this.validateInputParams();
if (isValid) {
let repoName = this.state.repoName.trim();
let password = this.state.encrypt ? this.state.password1 : '';
let repo = this.createRepo(repoName, password);
@@ -65,12 +65,11 @@ class CreateRepoDialog extends React.Component {
errMessage = 'Name is required';
this.setState({errMessage: errMessage});
return false;
}
if (repoName.indexOf('/') > -1) {
errMessage = 'Name should not include \'/\'.';
this.setState({errMessage: errMessage});
return;
return false;
}
if (this.state.encrypt) {
let password1 = this.state.password1.trim();
@@ -108,8 +107,11 @@ class CreateRepoDialog extends React.Component {
}
createRepo = (repoName, password) => {
let libraryType = this.props.libraryType;
let encrypt = password ? true : false;
let repo = {
let repo = null;
if (libraryType === 'mine' || libraryType === 'public') {
repo = {
id: null,
name: repoName,
desc: '',
@@ -124,6 +126,14 @@ class CreateRepoDialog extends React.Component {
permission: 'rw',
storage_name: '-',
};
}
if (libraryType === 'group') {
repo = {
repo_name: repoName,
password: password,
permission: 'rw',
};
}
return repo;
}

View File

@@ -6,7 +6,7 @@ import CreateRepoDialog from '../dialog/create-repo-dialog';
const propTypes = {
// isOwnLibrary: PropTypes.bool.isRequired,
// libraryType: PropTypes.string.isRequired,
libraryType: PropTypes.string.isRequired,
onCreateRepo: PropTypes.func.isRequired,
};
@@ -38,12 +38,15 @@ class RepoViewToolbar extends React.Component {
<i className="fas fa-plus-square op-icon"></i>
{gettext('New Library')}
</button>
{this.props.libraryType !== 'group' && (
<button className="btn btn-secondary operation-item" title={gettext('More')} onClick={this.onShareClick}>{gettext('More')}</button>
)}
</div>
</div>
{this.state.isCreateRepoDialogShow && (
<ModalPortal>
<CreateRepoDialog
libraryType={this.props.libraryType}
onCreateRepo={this.onCreateRepo}
onCreateToggle={this.onCreateToggle}
/>

View File

@@ -284,7 +284,7 @@ class Group extends Component {
return (
<Fragment>
<div className="main-panel-north">
<RepoViewToolbar onShowSidePanel={this.props.onShowSidePanel} onCreateRepo={this.onCreateRepo} />
<RepoViewToolbar onShowSidePanel={this.props.onShowSidePanel} onCreateRepo={this.onCreateRepo} libraryType={'group'}/>
<CommonToolbar onSearchedClick={this.props.onSearchedClick} />
</div>
<div className="main-panel-center">

View File

@@ -403,7 +403,7 @@ class MyLibraries extends Component {
return (
<Fragment>
<div className="main-panel-north">
<RepoViewToolbar onShowSidePanel={this.props.onShowSidePanel} onCreateRepo={this.onCreateRepo} />
<RepoViewToolbar onShowSidePanel={this.props.onShowSidePanel} onCreateRepo={this.onCreateRepo} libraryType={'mine'}/>
<CommonToolbar onSearchedClick={this.props.onSearchedClick} />
</div>
<div className="main-panel-center">