Fixed merge conflicts

chinese-translation
Nishant Arora 8 years ago
commit fb34925251

@ -0,0 +1,52 @@
/*
This file contains the search endpoint.
As of now search is based on the basic LIKE query in SQLite and MySQL.
Further improvements to the search feature should be moved to this file.
Why aren't we using Algolia or ElasticSearch?
Matterwiki wants to keep things simple. Setting up a ES instance or signing up
for Algolia goes against that.
*/
var Articles = require('../models/article.js');
module.exports = function(app) {
app.get('/search',function(req,res){
/*
This is a GET enpoint which takes the search query as a URL param
Runs the search query and returns matching articles in the data key in the
response object.
The endpoint only searches article titles as of now.
*/
var SearchQuery = req.query.query;
SearchQuery = "%"+SearchQuery+"%";
Articles.query(function(qb) {
qb.where('title', 'LIKE', SearchQuery).orWhere('body','LIKE',SearchQuery);
}).fetchAll()
.then(function (collection) {
res.json({
error: {
error: false,
message: ''
},
code: 'B131',
data: collection.toJSON()
});
})
.catch(function (error) {
res.status(500).json({
error: {
error: true,
message: "There was an error performing the search operation. Please try again."
},
code: 'B132',
data: {
}
});
});
});
}

@ -1,5 +1,6 @@
import React from 'react'; import React from 'react';
import Login from './login.jsx'; import Login from './login.jsx';
import SearchForm from './searchform.jsx';
import {Link, hashHistory} from 'react-router'; import {Link, hashHistory} from 'react-router';
import Alert from 'react-s-alert'; import Alert from 'react-s-alert';
@ -61,6 +62,7 @@ class App extends React.Component {
<a href="" onClick={this.handleLogout} >Logout</a> <a href="" onClick={this.handleLogout} >Logout</a>
</li> </li>
</ul> </ul>
<SearchForm />
</div> </div>
: <div/>} : <div/>}
</nav> </nav>

@ -0,0 +1,99 @@
import React from 'react';
import Loader from './loader.jsx';
import {Link, hashHistory} from 'react-router';
import Alert from 'react-s-alert';
class Search extends React.Component {
constructor(props) {
super(props);
this.state = { articles: [], loading: true};
}
componentWillMount() {
var myHeaders = new Headers({
"Content-Type": "application/x-www-form-urlencoded",
"x-access-token": window.localStorage.getItem('userToken')
});
var myInit = { method: 'GET',
headers: myHeaders,
};
var that = this;
fetch('/api/search?query='+this.props.location.query.query,myInit)
.then(function(response) {
return response.json();
})
.then(function(response) {
if(response.error.error)
Alert.error(response.error.message);
else {
that.setState({articles: response.data})
}
that.setState({loading: false});
});
}
componentWillReceiveProps(nextProps) {
var myHeaders = new Headers({
"Content-Type": "application/x-www-form-urlencoded",
"x-access-token": window.localStorage.getItem('userToken')
});
var myInit = { method: 'GET',
headers: myHeaders,
};
var that = this;
fetch('/api/search?query='+nextProps.location.query.query,myInit)
.then(function(response) {
return response.json();
})
.then(function(response) {
if(response.error.error){
Alert.error(response.error.message);
}
else {
that.setState({articles: response.data});
}
that.setState({loading: false});
});
}
componentWillUnmount() {
this.setState({articles: []});
}
render () {
if(this.state.loading)
return <Loader/>;
else
return(<div>
<div className="result-info">
<p className="help-block">
We found {this.state.articles.length} articles for your query
</p>
</div>
{(this.state.articles.length>0) ?
<div className="article-list">
{this.state.articles.map(article => (
<div key={article.id} className="article-item">
<div className="article-item-title">
<Link to={"/article/"+article.id} >{article.title}</Link>
</div>
<div className="article-item-description">
Last updated on {new Date(article.updated_at).toDateString()}
</div>
<hr className="article-separator"></hr>
</div>
))}</div>
:
<div className="no-results">
<i className="fa fa-frown-o"></i>
<p>Please try again with another query</p>
</div>
}
</div>);
}
}
export default Search;

@ -0,0 +1,28 @@
import React from 'react';
import {hashHistory} from 'react-router';
class SearchForm extends React.Component {
constructor(props) {
super(props);
this.searchWiki = this.searchWiki.bind(this);
}
searchWiki() {
var results = '/search?query='+this.refs.search.value;
hashHistory.push(results);
}
render () {
return(
<form className="navbar-form navbar-right" onSubmit={this.searchWiki}>
<div className="form-group">
<input type="text" className="form-control search-input" placeholder="Search" ref="search"/>
</div>
<button type="submit" className="btn search-button"><i className="fa fa-search"></i></button>
</form>
);
}
}
export default SearchForm;

@ -8,6 +8,7 @@ import Article from './components/article.jsx';
import NewArticle from './components/new.jsx'; import NewArticle from './components/new.jsx';
import EditArticle from './components/edit.jsx'; import EditArticle from './components/edit.jsx';
import ArticleHistory from './components/history.jsx'; import ArticleHistory from './components/history.jsx';
import Search from './components/search.jsx';
import Admin from './components/admin.jsx'; import Admin from './components/admin.jsx';
import Setup from './components/setup.jsx'; import Setup from './components/setup.jsx';
import EditTopic from './components/edit_topics.jsx'; import EditTopic from './components/edit_topics.jsx';
@ -27,8 +28,8 @@ export default function () {
<Route path="admin" component={Admin}/> <Route path="admin" component={Admin}/>
<Route path="topic/edit/:topicId" component={EditTopic}/> <Route path="topic/edit/:topicId" component={EditTopic}/>
<Route path="user/edit/:userId" component={EditUser}/> <Route path="user/edit/:userId" component={EditUser}/>
<Route path="search" component={Search}/>
<Route path="setup" component={Setup}/> <Route path="setup" component={Setup}/>
</Route> </Route>
); );
}; };

@ -4244,7 +4244,7 @@ select[multiple].input-group-sm > .input-group-btn > .btn {
.navbar-brand { .navbar-brand {
float: left; float: left;
height: 60px; height: 60px;
padding: 10px 10px; padding: 12px 10px;
font-size: 18px; font-size: 18px;
line-height: 20px; line-height: 20px;
} }

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 434 KiB

@ -464,3 +464,44 @@ font-size: 1.5em;
overflow-y: scroll; overflow-y: scroll;
border: 1px solid #efefef; border: 1px solid #efefef;
} }
.navbar-form {
padding: 10px 15px;
margin-right: 0px;
}
.search-button {
height: 100%;
max-height: 30px;
padding: 5px;
color: #a0a0a0;
background-color: #ccc;
border: 1px solid transparent;
}
.search-button:hover,.search-button:active, .search-button:focus {
color: #ccc;
background-color: #a0a0a0;
}
.search-input {
width: 100%;
min-height: 0px;
height: 30px;
padding: 6px 12px;
font-size: inherit;
}
.result-info {
border-bottom: 1px solid #efefef;
padding: 10px 20px;
margin-bottom: 20px;
}
.no-results {
color: #a0a0a0;
text-align: center;
}
.no-results .fa {
font-size: 200px;
}

@ -9,6 +9,8 @@
<link rel="stylesheet" href="./assets/style.css" /> <link rel="stylesheet" href="./assets/style.css" />
<!-- CSS for the text editor. Basecamp's Trix --> <!-- CSS for the text editor. Basecamp's Trix -->
<link rel="stylesheet" href="./assets/trix.css" /> <link rel="stylesheet" href="./assets/trix.css" />
<!-- CSS for the text editor. Basecamp's Trix -->
<link rel="stylesheet" href="./assets/font-awesome.min.css" />
<script src="./assets/jquery.js" type="text/javascript"></script> <script src="./assets/jquery.js" type="text/javascript"></script>
<!-- JS for the text editor. Basecamp's Trix --> <!-- JS for the text editor. Basecamp's Trix -->
<script src="./assets/trix.js" type="text/javascript"></script> <script src="./assets/trix.js" type="text/javascript"></script>

@ -160,6 +160,9 @@ require('./api/users')(apiRoutesAdmin);
// Importing all endpoints for archives // Importing all endpoints for archives
require('./api/archives')(apiRoutes); require('./api/archives')(apiRoutes);
// Importing the search endpoint
require('./api/search')(apiRoutes);
// Importing all endpoints which are only admin accessible // Importing all endpoints which are only admin accessible
require('./api/admin')(apiRoutesAdmin); require('./api/admin')(apiRoutesAdmin);

Loading…
Cancel
Save