summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorMichael Wood <michael.g.wood@intel.com>2015-08-04 22:46:39 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-08-06 16:04:47 -0500
commitaad380028fb1eec0defbeced39926f4626e02855 (patch)
treef6255408ac3a90ee281e238a7dcaa7d4ff0a267d /bitbake
parent0494a2769b72c3aa47461cf66c475c7677d1636c (diff)
downloadpoky-aad380028fb1eec0defbeced39926f4626e02855.tar.gz
bitbake: toastergui: libtoaster: typeahead resiliency for slow server
When we have a slow request we don't want to see the typeahead results changing in the middle of typing the item. To do this we make sure that requests to the typeahead can only happen sequentially and that if results have been retrieved but the input is now empty we don't bother showing the results. (Bitbake rev: 0b508e8b4a9e25c223c6c11ecd6d0e1aab727e8c) Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/libtoaster.js18
1 files changed, 17 insertions, 1 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js
index 587f51fff9..34a3fbb1fb 100644
--- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js
+++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js
@@ -18,15 +18,24 @@ var libtoaster = (function (){
18 if (!xhrUrl || xhrUrl.length === 0) 18 if (!xhrUrl || xhrUrl.length === 0)
19 throw("No url to typeahead supplied"); 19 throw("No url to typeahead supplied");
20 20
21 var xhrReq;
22
21 jQElement.typeahead({ 23 jQElement.typeahead({
22 source: function(query, process){ 24 source: function(query, process){
23 xhrParams.search = query; 25 xhrParams.search = query;
24 $.getJSON(xhrUrl, this.options.xhrParams, function(data){ 26
27 /* If we have a request in progress don't fire off another one*/
28 if (xhrReq)
29 xhrReq.abort();
30
31 xhrReq = $.getJSON(xhrUrl, this.options.xhrParams, function(data){
25 if (data.error !== "ok") { 32 if (data.error !== "ok") {
26 console.log("Error getting data from server "+data.error); 33 console.log("Error getting data from server "+data.error);
27 return; 34 return;
28 } 35 }
29 36
37 xhrReq = null;
38
30 return process(data.results); 39 return process(data.results);
31 }); 40 });
32 }, 41 },
@@ -41,6 +50,9 @@ var libtoaster = (function (){
41 return 0; 50 return 0;
42 } 51 }
43 52
53 if (this.$element.val().length === 0)
54 return 0;
55
44 return 1; 56 return 1;
45 }, 57 },
46 highlighter: function (item) { 58 highlighter: function (item) {
@@ -52,6 +64,7 @@ var libtoaster = (function (){
52 sorter: function (items) { return items; }, 64 sorter: function (items) { return items; },
53 xhrUrl: xhrUrl, 65 xhrUrl: xhrUrl,
54 xhrParams: xhrParams, 66 xhrParams: xhrParams,
67 xhrReq: xhrReq,
55 }); 68 });
56 69
57 70
@@ -528,6 +541,9 @@ $(document).ready(function() {
528 }); 541 });
529 542
530 $(document).ajaxError(function(event, jqxhr, settings, errMsg){ 543 $(document).ajaxError(function(event, jqxhr, settings, errMsg){
544 if (errMsg === 'abort')
545 return;
546
531 console.warn("Problem with xhr call"); 547 console.warn("Problem with xhr call");
532 console.warn(errMsg); 548 console.warn(errMsg);
533 console.warn(jqxhr.responseText); 549 console.warn(jqxhr.responseText);