1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-16 07:08:55 +00:00

[system admin] search repo: use new api (#4273)

This commit is contained in:
llj
2019-11-20 11:08:35 +08:00
committed by Daniel Pan
parent 1fe0779700
commit 4689380ea2
2 changed files with 15 additions and 24 deletions

View File

@@ -253,7 +253,12 @@ class Item extends Component {
} = this.state; } = this.state;
let iconUrl = Utils.getLibIconUrl(repo); let iconUrl = Utils.getLibIconUrl(repo);
let iconTitle = Utils.getLibIconTitle(repo); let iconTitle = Utils.getLibIconTitle(repo);
let isGroupOwnedRepo = repo.owner.indexOf('@seafile_group') != -1; const index = repo.owner_email.indexOf('@seafile_group');
let isGroupOwnedRepo = index != -1;
let departmentID;
if (isGroupOwnedRepo) {
departmentID = repo.owner_email.substring(0, index);
}
return ( return (
<Fragment> <Fragment>
@@ -264,7 +269,7 @@ class Item extends Component {
<td>{repo.id}</td> <td>{repo.id}</td>
<td> <td>
{isGroupOwnedRepo ? {isGroupOwnedRepo ?
<Link to={`${siteRoot}sys/departments/${repo.owner_name}/`}>{repo.group_name}</Link> : <Link to={`${siteRoot}sys/departments/${departmentID}/`}>{repo.owner_name}</Link> :
<UserLink email={repo.owner_email} name={repo.owner_name} /> <UserLink email={repo.owner_email} name={repo.owner_name} />
} }
</td> </td>

View File

@@ -12,7 +12,6 @@ class SearchRepos extends Component {
super(props); super(props);
this.state = { this.state = {
name: '', name: '',
owner: '',
isSubmitBtnActive: false, isSubmitBtnActive: false,
loading: true, loading: true,
errorMsg: '', errorMsg: '',
@@ -23,17 +22,16 @@ class SearchRepos extends Component {
componentDidMount() { componentDidMount() {
let params = (new URL(document.location)).searchParams; let params = (new URL(document.location)).searchParams;
this.setState({ this.setState({
name: params.get('name') || '', name: params.get('name') || ''
owner: params.get('owner') || ''
}, this.getRepos); }, this.getRepos);
} }
getRepos = () => { getRepos = () => {
const { name, owner } = this.state; const { name } = this.state;
seafileAPI.sysAdminSearchRepos(name, owner).then((res) => { seafileAPI.sysAdminSearchRepos(name).then((res) => {
this.setState({ this.setState({
loading: false, loading: false,
repos: res.data.repos repos: res.data.repo_list
}); });
}).catch((error) => { }).catch((error) => {
if (error.response) { if (error.response) {
@@ -86,21 +84,15 @@ class SearchRepos extends Component {
}, this.checkSubmitBtnActive); }, this.checkSubmitBtnActive);
} }
handleOwnerInputChange = (e) => {
this.setState({
owner: e.target.value
}, this.checkSubmitBtnActive);
}
checkSubmitBtnActive = () => { checkSubmitBtnActive = () => {
const { name, owner } = this.state; const { name } = this.state;
this.setState({ this.setState({
isSubmitBtnActive: name.trim() || owner.trim() isSubmitBtnActive: name.trim()
}); });
} }
render() { render() {
const { name, owner, isSubmitBtnActive } = this.state; const { name, isSubmitBtnActive } = this.state;
return ( return (
<Fragment> <Fragment>
<MainPanelTopbar /> <MainPanelTopbar />
@@ -112,7 +104,7 @@ class SearchRepos extends Component {
<div className="cur-view-content"> <div className="cur-view-content">
<div className="mt-4 mb-6"> <div className="mt-4 mb-6">
<h4 className="border-bottom font-weight-normal mb-2 pb-1">{gettext('Search Libraries')}</h4> <h4 className="border-bottom font-weight-normal mb-2 pb-1">{gettext('Search Libraries')}</h4>
<p className="text-secondary small">{gettext('Tip: you can search by keyword in name or owner or both.')}</p> <p className="text-secondary small">{gettext('Tip: you can search by keyword in name.')}</p>
<Form> <Form>
<FormGroup row> <FormGroup row>
<Label for="name" sm={1}>{gettext('Name')}</Label> <Label for="name" sm={1}>{gettext('Name')}</Label>
@@ -120,12 +112,6 @@ class SearchRepos extends Component {
<Input type="text" name="name" id="name" value={name} onChange={this.handleNameInputChange} /> <Input type="text" name="name" id="name" value={name} onChange={this.handleNameInputChange} />
</Col> </Col>
</FormGroup> </FormGroup>
<FormGroup row>
<Label for="owner" sm={1}>{gettext('Owner')}</Label>
<Col sm={5}>
<Input type="text" name="owner" id="owner" value={owner} onChange={this.handleOwnerInputChange} />
</Col>
</FormGroup>
<FormGroup row> <FormGroup row>
<Col sm={{size: 5, offset: 1}}> <Col sm={{size: 5, offset: 1}}>
<button className="btn btn-outline-primary" disabled={!isSubmitBtnActive} onClick={this.searchRepos}>{gettext('Submit')}</button> <button className="btn btn-outline-primary" disabled={!isSubmitBtnActive} onClick={this.searchRepos}>{gettext('Submit')}</button>