javascript debugging

This commit is contained in:
Stephan preeker 2017-12-29 14:52:39 +01:00
parent 04684c5f65
commit 99131374cd
4 changed files with 245 additions and 223 deletions

View File

@ -52,6 +52,25 @@ def search_user():
data = queries.do_user_search(searchword, terms)
# filter sensitive stuff
# we only need. objectID, full_name, username
hits = data.get('hits')
new_hits = []
for hit in hits.get('hits'):
source = hit['_source']
single_hit = {
'_source': {
'objectID': source.get('objectID'),
'username': source.get('username'),
'full_name': source.get('full_name'),
}
}
new_hits.append(single_hit)
# replace search result with safe subset
data['hits']['hits'] = new_hits
return jsonify(data)

View File

@ -42,7 +42,7 @@ $(document).ready(function() {
toggleIconEmptyInput(!query.trim());
// what could be like "/users"
search.setQuery(query, what);
//setURLParams(search);
// setURLParams(search);
search.execute();
}).focus();

View File

@ -125,15 +125,17 @@ var elasticSearch = (function($, url) {
url = '';
}
console.log('searching! '+ url + q);
console.log('searching! '+ url + ' q= ' + q);
$.getJSON("/api/newsearch" + url + "?q=" + q, function( data ) {
let hits = data.hits.hits;
newhits = hits.map(function(hit){
return hit._source;
});
//cb(newhits.slice(0));
cb(newhits.slice(0));
if(async !== undefined){
async(newhits.slice(0));
}
});
};
@ -155,6 +157,7 @@ $(document).ready(function() {
minLength: 0,
templates: {
suggestion: function(hit) {
console.log('hit!');
var hitMedia = (hit.media ? ' · <span class="media">'+hit.media+'</span>' : '');
var hitFree = (hit.is_free ? '<div class="search-hit-ribbon"><span>free</span></div>' : '');
var hitPicture;

View File

@ -7,9 +7,9 @@
{
source: elasticSearch($, '/user'),
displayKey: 'full_name',
async: true,
//async: true,
minLength: 1,
limit: 10,
limit: 9,
templates: {
suggestion: function (hit) {
var suggestion = hit.full_name + ' (' + hit.username + ')';