2014-07-08 04:35:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-07-28 07:38:03 +00:00
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
(function(hscd) {
|
|
|
|
var ctx = {};
|
2014-07-28 07:48:24 +00:00
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
function onAdjust(name, value) {
|
|
|
|
ctx.searchParams[name] = value;
|
2014-07-08 04:35:52 +00:00
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
var params = {
|
|
|
|
searchParams: ctx.searchParams,
|
|
|
|
searchRange: ctx.searchRange,
|
|
|
|
minScore: ctx.minScore,
|
|
|
|
hintSteps: ctx.hintSteps,
|
|
|
|
maxResults: ctx.maxResults
|
|
|
|
};
|
2014-07-08 04:35:52 +00:00
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
$.getJSON('/node/search', params, function(results) {
|
|
|
|
var hintData = {};
|
|
|
|
for (var feature in results.columns) {
|
|
|
|
hintData[feature] = results.columns[feature].hints;
|
|
|
|
}
|
2014-07-08 04:35:52 +00:00
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
ctx.grapher.setColumnHints(hintData);
|
|
|
|
outputResults(results.items, params.maxResults);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function onSearch() {
|
|
|
|
var params = {
|
|
|
|
keyword: $('#keyword').val(),
|
|
|
|
searchRange: { min: -1.0, max: 1.0 },
|
|
|
|
minScore: parseInt($('#minScore').val()),
|
|
|
|
hintSteps: parseInt($('#hintSteps').val()),
|
|
|
|
maxResults: parseInt($('#maxResults').val())
|
|
|
|
};
|
|
|
|
|
|
|
|
$.getJSON('/node/search', params, function(results) {
|
|
|
|
ctx.searchParams = results.params;
|
|
|
|
ctx.searchRange = params.searchRange;
|
|
|
|
ctx.minScore = params.minScore;
|
|
|
|
ctx.hintSteps = params.hintSteps;
|
|
|
|
ctx.maxResults = params.maxResults;
|
|
|
|
|
|
|
|
ctx.grapher = new Grapher('grapher', ctx.searchRange, true, true);
|
|
|
|
ctx.grapher.setColumns(results.columns);
|
|
|
|
ctx.grapher.setValueChangedListener(onAdjust);
|
|
|
|
|
|
|
|
outputResults(results.items, params.maxResults);
|
|
|
|
|
|
|
|
$('#query').text(params.keyword);
|
|
|
|
$('#useLocalScale').click(function() {
|
|
|
|
var useLocalScale = $('#useLocalScale').is(':checked');
|
|
|
|
ctx.grapher.setUseLocalScale(useLocalScale);
|
|
|
|
});
|
|
|
|
$('#useRelativeScale').click(function() {
|
|
|
|
var useRelativeScale = $('#useRelativeScale').is(':checked');
|
|
|
|
ctx.grapher.setUseRelativeScale(useRelativeScale);
|
|
|
|
});
|
|
|
|
$('#input').fadeOut(function() {
|
|
|
|
$('#output').fadeIn();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2014-07-28 07:21:08 +00:00
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
function outputResults(results, maxResults) {
|
|
|
|
$('#results').empty();
|
|
|
|
$('#count').text(results.length);
|
2014-07-28 07:21:08 +00:00
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
results = results.splice(0, maxResults);
|
2014-07-28 07:21:08 +00:00
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
var template = Handlebars.compile($('#template').html());
|
|
|
|
$('#results').append(template({'results': results}));
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
2014-07-28 22:36:12 +00:00
|
|
|
$(document).on({
|
|
|
|
ajaxStart: function() {
|
|
|
|
$('#spinner').show();
|
|
|
|
},
|
|
|
|
ajaxStop: function() {
|
|
|
|
$('#spinner').hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
$.getJSON('/node/keywords', function(keywords) {
|
|
|
|
for (var i = 0; i < keywords.length; ++i) {
|
|
|
|
var properties = { value: keywords[i], text: keywords[i] };
|
|
|
|
$('#keyword').append($('<option></option>', properties));
|
2014-07-28 09:18:54 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 13:12:44 +00:00
|
|
|
$('#search').prop('disabled', false);
|
|
|
|
$('#search').click(onSearch);
|
|
|
|
});
|
2014-07-26 06:02:42 +00:00
|
|
|
});
|
2014-07-28 13:12:44 +00:00
|
|
|
}(window.hscd = window.hscd || {}));
|