diff options
author | Stefan Parviainen <saparvia@caterva.eu> | 2015-01-08 17:16:08 +0100 |
---|---|---|
committer | Stefan Parviainen <saparvia@caterva.eu> | 2015-01-08 17:16:08 +0100 |
commit | 32c6eab01c820c0ab44aa1b8860bf3173061e4e2 (patch) | |
tree | e9a2415024a0f427e53e63a3e3f334e400bfae06 | |
parent | 4beb78201467f4256424d688b2a55705e333f96a (diff) | |
download | volse-hubzilla-32c6eab01c820c0ab44aa1b8860bf3173061e4e2.tar.gz volse-hubzilla-32c6eab01c820c0ab44aa1b8860bf3173061e4e2.tar.bz2 volse-hubzilla-32c6eab01c820c0ab44aa1b8860bf3173061e4e2.zip |
Fix saved searches on network page, fix caching mith multiple autocompleters
-rw-r--r-- | mod/search_ac.php | 48 | ||||
-rw-r--r-- | view/js/autocomplete.js | 19 | ||||
-rw-r--r-- | view/js/mod_network.js | 2 |
3 files changed, 40 insertions, 29 deletions
diff --git a/mod/search_ac.php b/mod/search_ac.php index 36da21376..b4f5c9600 100644 --- a/mod/search_ac.php +++ b/mod/search_ac.php @@ -1,8 +1,9 @@ <?php +// Autocomplete for saved searches. Should probably be put in the same place as the other autocompletes function search_ac_init(&$a){ if(!local_user()) - return ""; + killme(); $start = (x($_REQUEST,'start')?$_REQUEST['start']:0); @@ -13,17 +14,6 @@ function search_ac_init(&$a){ $search = $_REQUEST['query']; } - - $sql_extra = ''; - - $x = array(); - $x['query'] = $search; - $x['photos'] = array(); - $x['links'] = array(); - $x['suggestions'] = array(); - $x['data'] = array(); - - // Priority to people searches if ($search) { @@ -32,18 +22,23 @@ function search_ac_init(&$a){ } - $r = q("SELECT `abook_id`, `xchan_name`, `xchan_photo_s`, `xchan_url` FROM `abook` left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d + $r = q("SELECT `abook_id`, `xchan_name`, `xchan_photo_s`, `xchan_url`, `xchan_addr` FROM `abook` left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d $people_sql_extra ORDER BY `xchan_name` ASC ", intval(local_user()) ); + $results = array(); if($r) { foreach($r as $g) { - $x['photos'][] = $g['xchan_photo_s']; - $x['links'][] = $g['xchan_url']; - $x['suggestions'][] = '@' . $g['xchan_name']; - $x['data'][] = 'cid=' . intval($g['abook_id']); + $results[] = array( + "photo" => $g['xchan_photo_s'], + "name" => '@'.$g['xchan_name'], + "id" => $g['abook_id'], + "link" => $g['xchan_url'], + "label" => '', + "nick" => '', + ); } } @@ -53,15 +48,24 @@ function search_ac_init(&$a){ if(count($r)) { foreach($r as $g) { - $x['photos'][] = $a->get_baseurl() . '/images/hashtag.png'; - $x['links'][] = $g['url']; - $x['suggestions'][] = '#' . $g['term']; - $x['data'][] = intval($g['tid']); + $results[] = array( + "photo" => $a->get_baseurl() . '/images/hashtag.png', + "name" => '#'.$g['term'], + "id" => $g['tid'], + "link" => $g['url'], + "label" => '', + "nick" => '', + ); } } header("content-type: application/json"); - echo json_encode($x); + $o = array( + 'start' => $start, + 'count' => $count, + 'items' => $results, + ); + echo json_encode($o); logger('search_ac: ' . print_r($x,true)); diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index 63aa7a8f1..40a9cd4c8 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -5,12 +5,15 @@ */ function contact_search(term, callback, backend_url, type, extra_channels) { // Check if there is a cached result that contains the same information we would get with a full server-side search - // Assume type hasn't changed + + var bt = backend_url+type; + if(!(bt in contact_search.cache)) contact_search.cache[bt] = {}; + var lterm = term.toLowerCase(); // Ignore case - for(t in contact_search.cache) { + for(t in contact_search.cache[bt]) { if(lterm.indexOf(t) >= 0) { // A more broad search has been performed already, so use those results // Filter old results locally - var matching = contact_search.cache[t].filter(function (x) { return (x.name.toLowerCase().indexOf(lterm) >= 0 || x.nick.toLowerCase().indexOf(lterm) >= 0); }); + var matching = contact_search.cache[bt][t].filter(function (x) { return (x.name.toLowerCase().indexOf(lterm) >= 0 || x.nick.toLowerCase().indexOf(lterm) >= 0); }); matching.unshift({taggable:false, text: term, replace: term}); callback(matching); return; @@ -36,7 +39,7 @@ function contact_search(term, callback, backend_url, type, extra_channels) { // Cache results if we got them all (more information would not improve results) // data.count represents the maximum number of items if(data.items.length -1 < data.count) { - contact_search.cache[lterm] = data.items; + contact_search.cache[bt][lterm] = data.items; } var items = data.items.slice(0); items.unshift({taggable:false, text: term, replace: term}); @@ -48,8 +51,12 @@ contact_search.cache = {}; function contact_format(item) { - if(typeof item.text === 'undefined') - return "<div class='{0}' title='{4}'><img src='{1}'>{2} ({3})</div>".format(item.taggable, item.photo, item.name, ((item.label) ? item.nick + ' ' + item.label : item.nick), item.link) + // Show contact information if not explicitly told to show something else + if(typeof item.text === 'undefined') { + var desc = ((item.label) ? item.nick + ' ' + item.label : item.nick) + if(desc) desc = ' ('+desc+')'; + return "<div class='{0}' title='{4}'><img src='{1}'>{2}{3}</div>".format(item.taggable, item.photo, item.name, desc, item.link) + } else return "<div>"+item.text+"</div>" } diff --git a/view/js/mod_network.js b/view/js/mod_network.js index 1b7ccdc0a..cbdb82c75 100644 --- a/view/js/mod_network.js +++ b/view/js/mod_network.js @@ -1,5 +1,5 @@ $(document).ready(function() { - $("#search-text").contact_autocomplete(baseurl + '/acl'); + $("#search-text").contact_autocomplete(baseurl + '/search_ac'); $('.jslider-scale ins').addClass('hidden-xs'); }); |