[#180,demos/search][s]: tweak text and refactor js and document it.
This commit is contained in:
@@ -1,37 +1,17 @@
|
|||||||
jQuery(function($) {
|
jQuery(function($) {
|
||||||
window.dataExplorer = null;
|
var $el = $('.search-here');
|
||||||
window.explorerDiv = $('.search-here');
|
|
||||||
|
|
||||||
// var url = 'http://openspending.org/api/search';
|
// var url = 'http://openspending.org/api/search';
|
||||||
// var url = 'http://localhost:9200/tmp/sfpd-last-month';
|
// var url = 'http://localhost:9200/tmp/sfpd-last-month';
|
||||||
|
|
||||||
|
// Crate our Recline Dataset
|
||||||
|
// Here we are just using the local data
|
||||||
var dataset = new recline.Model.Dataset({
|
var dataset = new recline.Model.Dataset({
|
||||||
records: simpleData
|
records: simpleData
|
||||||
});
|
});
|
||||||
createSearch(dataset);
|
|
||||||
});
|
|
||||||
|
|
||||||
var createSearch = function(dataset, state) {
|
|
||||||
// remove existing data explorer view
|
|
||||||
var $el = $('<div />');
|
|
||||||
$el.appendTo(window.explorerDiv);
|
|
||||||
var template = ' \
|
|
||||||
{{#records}} \
|
|
||||||
<div class="record"> \
|
|
||||||
<h3> \
|
|
||||||
{{title}} <em>by {{Author}}</em> \
|
|
||||||
</h3> \
|
|
||||||
<p>{{description}}</p> \
|
|
||||||
<p><code>${{price}}</code></p> \
|
|
||||||
</div> \
|
|
||||||
{{/records}} \
|
|
||||||
';
|
|
||||||
|
|
||||||
window.dataExplorer = new SearchView({
|
|
||||||
el: $el,
|
|
||||||
model: dataset,
|
|
||||||
template: template
|
|
||||||
});
|
|
||||||
|
|
||||||
|
// Optional
|
||||||
|
// Let's configure the initial query a bit and set up facets
|
||||||
dataset.queryState.set({
|
dataset.queryState.set({
|
||||||
size: 10
|
size: 10
|
||||||
},
|
},
|
||||||
@@ -39,13 +19,23 @@ var createSearch = function(dataset, state) {
|
|||||||
);
|
);
|
||||||
dataset.queryState.addFacet('Author');
|
dataset.queryState.addFacet('Author');
|
||||||
dataset.query();
|
dataset.query();
|
||||||
}
|
|
||||||
|
// The search view allows us to customize the template used to render the
|
||||||
|
// list of results
|
||||||
|
var template = getTemplate();
|
||||||
|
var searchView = new SearchView({
|
||||||
|
el: $el,
|
||||||
|
model: dataset,
|
||||||
|
template: template
|
||||||
|
});
|
||||||
|
searchView.render();
|
||||||
|
});
|
||||||
|
|
||||||
// Simple Search View
|
// Simple Search View
|
||||||
//
|
//
|
||||||
// Pulls together various Recline UI components and the central Dataset and Query (state) object
|
// Pulls together various Recline UI components and the central Dataset and Query (state) object
|
||||||
//
|
//
|
||||||
// Plus support for customization e.g. of item template
|
// Plus support for customization e.g. of template for list of results
|
||||||
var SearchView = Backbone.View.extend({
|
var SearchView = Backbone.View.extend({
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
this.el = $(this.el);
|
this.el = $(this.el);
|
||||||
@@ -95,6 +85,24 @@ var SearchView = Backbone.View.extend({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// --------------------------------------------------------
|
||||||
|
// Stuff specific to this demo
|
||||||
|
|
||||||
|
function getTemplate() {
|
||||||
|
template = ' \
|
||||||
|
{{#records}} \
|
||||||
|
<div class="record"> \
|
||||||
|
<h3> \
|
||||||
|
{{title}} <em>by {{Author}}</em> \
|
||||||
|
</h3> \
|
||||||
|
<p>{{description}}</p> \
|
||||||
|
<p><code>${{price}}</code></p> \
|
||||||
|
</div> \
|
||||||
|
{{/records}} \
|
||||||
|
';
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
|
||||||
var simpleData = [
|
var simpleData = [
|
||||||
{
|
{
|
||||||
title: 'War and Peace',
|
title: 'War and Peace',
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ root: ../../
|
|||||||
|
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
.info {
|
.info {
|
||||||
margin-bottom: 40px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************** Search Section ****************/
|
/***************** Search Section ****************/
|
||||||
@@ -80,9 +80,12 @@ ul.facet-items {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<p>This demo shows how Recline can be used to build a search app (<a href="app.js">source JS</a>). The default version uses local example data but you can also connect directly to a SOLR or ElasticSearch endpoint for example.</p>
|
<p>This demo shows how Recline can be used to build a search app. It includes faceting as well as seearch. You can find the <a href="app.js">source javascript here</a> – please feel free to reuse!</p>
|
||||||
|
<p>The default version uses some local example data but you can also connect directly to any other backend supported by Recline, in particular SOLR or ElasticSearch.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
|
||||||
<div class="search-here"></div>
|
<div class="search-here"></div>
|
||||||
|
|
||||||
<div style="clear: both;"></div>
|
<div style="clear: both;"></div>
|
||||||
|
|||||||
Reference in New Issue
Block a user