mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-12 21:30:39 +00:00
public repo search (#3817)
* public repo search * remove print code * add permission check
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import React, { Component, Fragment } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import MediaQuery from 'react-responsive';
|
||||
import { seafileAPI } from '../../utils/seafile-api';
|
||||
import { gettext, siteRoot } from '../../utils/constants';
|
||||
import SearchResultItem from './search-result-item';
|
||||
import editorUtilities from '../../utils/editor-utilties';
|
||||
import More from '../more';
|
||||
|
||||
const propTypes = {
|
||||
isPublic: PropTypes.bool,
|
||||
repoID: PropTypes.string,
|
||||
placeholder: PropTypes.string,
|
||||
onSearchedClick: PropTypes.func.isRequired,
|
||||
@@ -93,27 +95,53 @@ class Search extends Component {
|
||||
|
||||
sendRequest(queryData, cancelToken) {
|
||||
var _this = this;
|
||||
editorUtilities.searchFiles(queryData,cancelToken).then(res => {
|
||||
if (!res.data.total) {
|
||||
let isPublic = this.props.isPublic;
|
||||
|
||||
if (isPublic) {
|
||||
seafileAPI.searchPublicFiles(queryData.q, queryData.search_repo).then(res => {
|
||||
if (!res.data.total) {
|
||||
_this.setState({
|
||||
resultItems: [],
|
||||
isResultGetted: true
|
||||
});
|
||||
_this.source = null;
|
||||
return;
|
||||
}
|
||||
|
||||
let items = _this.formatResultItems(res.data.results);
|
||||
_this.setState({
|
||||
resultItems: [],
|
||||
resultItems: items,
|
||||
isResultGetted: true
|
||||
});
|
||||
_this.source = null;
|
||||
return;
|
||||
}
|
||||
|
||||
let items = _this.formatResultItems(res.data.results);
|
||||
_this.setState({
|
||||
resultItems: items,
|
||||
isResultGetted: true
|
||||
}).catch(res => {
|
||||
/* eslint-disable */
|
||||
console.log(res);
|
||||
/* eslint-enable */
|
||||
});
|
||||
_this.source = null;
|
||||
}).catch(res => {
|
||||
/* eslint-disable */
|
||||
console.log(res);
|
||||
/* eslint-enable */
|
||||
});
|
||||
} else {
|
||||
editorUtilities.searchFiles(queryData,cancelToken).then(res => {
|
||||
if (!res.data.total) {
|
||||
_this.setState({
|
||||
resultItems: [],
|
||||
isResultGetted: true
|
||||
});
|
||||
_this.source = null;
|
||||
return;
|
||||
}
|
||||
|
||||
let items = _this.formatResultItems(res.data.results);
|
||||
_this.setState({
|
||||
resultItems: items,
|
||||
isResultGetted: true
|
||||
});
|
||||
_this.source = null;
|
||||
}).catch(res => {
|
||||
/* eslint-disable */
|
||||
console.log(res);
|
||||
/* eslint-enable */
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
cancelRequest() {
|
||||
|
@@ -7,6 +7,7 @@ import WikiMarkdownViewer from '../../components/wiki-markdown-viewer';
|
||||
import WikiDirListView from '../../components/wiki-dir-list-view/wiki-dir-list-view';
|
||||
import Loading from '../../components/loading';
|
||||
import { Utils } from '../../utils/utils';
|
||||
import Search from '../../components/search/search';
|
||||
|
||||
const propTypes = {
|
||||
path: PropTypes.string.isRequired,
|
||||
@@ -77,6 +78,21 @@ class MainPanel extends Component {
|
||||
return (
|
||||
<div className="main-panel wiki-main-panel o-hidden">
|
||||
<div className="main-panel-north panel-top border-left-show">
|
||||
{!username &&
|
||||
<Fragment>
|
||||
<div className="cur-view-toolbar">
|
||||
<span className="sf2-icon-menu hidden-md-up d-md-none side-nav-toggle" title="Side Nav Menu" onClick={this.onMenuClick}></span>
|
||||
</div>
|
||||
<div className="common-toolbar">
|
||||
<Search
|
||||
isPublic={true}
|
||||
repoID={repoID}
|
||||
onSearchedClick={this.props.onSearchedClick}
|
||||
placeholder={gettext('Search files in this library')}
|
||||
/>
|
||||
</div>
|
||||
</Fragment>
|
||||
}
|
||||
{username && (
|
||||
<Fragment>
|
||||
<div className="cur-view-toolbar">
|
||||
|
Reference in New Issue
Block a user