Skip to content

Commit

Permalink
Linking the search view with the results view.
Browse files Browse the repository at this point in the history
  • Loading branch information
Camilo Morales authored and CamiloMorales committed May 2, 2016
1 parent 1d36620 commit 4622fe1
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
39 changes: 36 additions & 3 deletions app/assets/javascripts/results.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
var Trigger = React.createClass({
loadKeywordFromServer: function () {
$.ajax({
url: this.props.url,
dataType: 'json',
cache: false,
success: function (kw) {
this.setState({keyword: kw["keyword"]});
}.bind(this),
error: function (xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},
getInitialState: function () {
return {keyword: null};
},
componentDidMount: function () {
this.loadKeywordFromServer();
//setInterval(this.loadKeywordFromServer, this.props.pollInterval);
},
render: function () {
if (this.state.keyword) {
return ( <Container keyword={this.state.keyword} pollInterval={200000}/>);
}
return <div>Loading...</div>;
}
});

var Container = React.createClass({
loadCommentsFromServer: function () {

var searchUrl = "/ldw/v1/restApiWrapper/id/twitter/search?query="+this.props.keyword;

$.ajax({
url: this.props.url,
url: searchUrl,
dataType: 'json',
cache: false,
success: function (data) {
Expand Down Expand Up @@ -119,7 +151,8 @@ var ResultsList = React.createClass({
render: function () {
var resultsNodes = this.props.data["@graph"].map(function (result) {
return (
<ResultElement img={result.img} webpage={result.url}
<ResultElement img={result.img}
webpage={result.url}
name={result["http://xmlns.com/foaf/0.1/name"]}
location={result["http://vocab.cs.uni-bonn.de/fuhsen#location"]}
alias={result["http://vocab.cs.uni-bonn.de/fuhsen#alias"]}
Expand Down Expand Up @@ -169,5 +202,5 @@ var ResultElement = React.createClass({
}
});

React.render(<Container url="/ldw/v1/restApiWrapper/id/twitter/search?query=Camilo" pollInterval={200000}/>, document.getElementById('skeleton'));
React.render(<Trigger url="/keyword" pollInterval={200000}/>, document.getElementById('skeleton'));
React.render(<SearchForm id_class="form-search-header"/>, document.getElementById('searchform'));
18 changes: 16 additions & 2 deletions app/controllers/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,22 @@
import views.html.*;

public class Application extends Controller {
public Result index() {return ok(index.render(TokenManager.getFBTokenLifeLength()));}
public Result results() {return ok(results.render());}

private String keyword;

public Result index() {
return ok(index.render(TokenManager.getFBTokenLifeLength()));
}

public Result results(String query) {
this.keyword = query;
return ok(results.render());
}

public Result getKeyword(){
String json_res = "{ \"keyword\" : \""+this.keyword+"\" }";
return ok(json_res);
}
}


4 changes: 1 addition & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,4 @@ enablePlugins(SbtNativePackager)
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator

fork in run := true

fork in run := true
fork in run := true
3 changes: 2 additions & 1 deletion conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

# User Interface routes
GET / controllers.Application.index()
GET /results controllers.Application.results()
GET /results controllers.Application.results(query: String)
GET /keyword controllers.Application.getKeyword()

# Search Engine API routes
GET /engine/v1/search controllers.de.fuhsen.engine.SearchEngine.search(query: String)
Expand Down

0 comments on commit 4622fe1

Please sign in to comment.