[fix] Fixed search trouble (broadband overload) to search only if no new char in 500ms after

This commit is contained in:
xdrm-brackets 2017-07-29 19:15:00 +02:00
parent e0f20cdd85
commit c9da8708ae
3 changed files with 120 additions and 39 deletions

View File

@ -2,9 +2,13 @@
var section = {
view: {
text: '#CONTAINER > section[data-sublink="view"] ',
element: document.querySelector('#CONTAINER > section[data-sublink="view"]'),
searchbar: document.querySelector('#CONTAINER > section[data-sublink="view"] > .searchbar')
},
element: document.querySelector('#CONTAINER > section[data-sublink="view"]'),
search: {
bar: document.querySelector('#CONTAINER > section[data-sublink="view"] > .searchbar'),
func: null,
time: null // search time manager (interval)
},
},
details: {
text: '#CONTAINER > section[data-sublink="details"] ',
@ -24,18 +28,24 @@ var section = {
*/
if( section.view.element != null ){
/* (0) On gère le zoom sur un log via URL */
if( pageManager.vars.length > 1 && !isNaN(pageManager.vars[1]) ){
document.location = '#'+pageManager.vars[1];
if( document.getElementById(pageManager.vars[1]) != null )
document.getElementById(pageManager.vars[1]).addClass('selected');
}
/* (1) On recupere tous les liens */
section.view.link = {
details: document.querySelectorAll(section.view.text + 'button[data-details]')
details: document.querySelectorAll(section.view.text + 'button[data-details]')
};
/* (2) Gestion de la recherche instantannee */
section.view.searchbar.addEventListener('keyup', function(e){
var search = {
/* (2) Gestion de la recherche instantannee */
section.view.search.func = function(){
var search = {
path: 'historyDefault/search',
keywords: section.view.searchbar.value
keywords: section.view.search.bar.value
};
// On envoie la requete
@ -62,10 +72,29 @@ if( section.view.element != null ){
}
}
});
};
section.view.search.bar.addEventListener('keyup', function(e){
if( section.view.search.time != null )
clearTimeout(section.view.search.time);
section.view.search.time = setTimeout(section.view.search.func, 500);
}, false);
/* (3) On gere la "redirection" vers les détail */
for( var i = 0 ; i < section.view.link.details.length ; i++ ){
section.view.link.details[i].addEventListener('click', function(e){
pageManager.vars = [ 'details', e.target.getData('details') ];
pageManager.refresh();
}, false);
}
}

View File

@ -3,7 +3,11 @@ var section = {
view: {
text: '#CONTAINER > section[data-sublink="view"] ',
element: document.querySelector('#CONTAINER > section[data-sublink="view"]'),
searchbar: document.querySelector('#CONTAINER > section[data-sublink="view"] > .searchbar')
search: {
bar: document.querySelector('#CONTAINER > section[data-sublink="view"] > .searchbar'),
func: null,
time: null
}
},
create: {
@ -24,7 +28,11 @@ var section = {
groups: {
text: '#CONTAINER > section[data-sublink="groups"] ',
element: document.querySelector('#CONTAINER > section[data-sublink="groups"]'),
searchbar: document.querySelector('#CONTAINER > section[data-sublink="groups"] > .searchbar')
search: {
bar: document.querySelector('#CONTAINER > section[data-sublink="groups"] > .searchbar'),
func: null,
time: null
}
}
};
@ -56,11 +64,11 @@ if( section.view.element != null ){
/* (3) Gestion de la recherche instantannee */
section.view.searchbar.addEventListener('keyup', function(e){
section.view.search.func = function(){
var search = {
path: 'machineDefault/search',
keywords: section.view.searchbar.value
keywords: section.view.search.bar.value
};
// On envoie la requete
@ -87,6 +95,15 @@ if( section.view.element != null ){
}
});
};
section.view.search.bar.addEventListener('keyup', function(e){
if( section.view.search.time != null )
clearTimeout(section.view.search.time);
section.view.search.time = setTimeout(section.view.search.func, 500);
}, false);
@ -772,11 +789,11 @@ if( section.groups.element != null ){
/* (3) Gestion de la recherche instantannee */
section.groups.searchbar.addEventListener('keyup', function(e){
section.groups.search.func = function(){
var search = {
path: 'clusterDefault/search',
keywords: section.groups.searchbar.value,
keywords: section.groups.search.bar.value,
class: 1
};
@ -804,6 +821,15 @@ if( section.groups.element != null ){
}
});
};
section.groups.search.bar.addEventListener('keyup', function(e){
if( section.groups.search.time != null )
clearTimeout(section.groups.search.time);
section.groups.search.time = setTimeout(section.groups.search.func, 500);
}, false);
var i;

View File

@ -3,7 +3,11 @@ var section = {
view: {
text: '#CONTAINER > section[data-sublink="view"] ',
element: document.querySelector('#CONTAINER > section[data-sublink="view"]'),
searchbar: document.querySelector('#CONTAINER > section[data-sublink="view"] > .searchbar')
search: {
bar: document.querySelector('#CONTAINER > section[data-sublink="view"] > .searchbar'),
func: null,
time: null
}
},
create: {
@ -24,7 +28,11 @@ var section = {
groups: {
text: '#CONTAINER > section[data-sublink="groups"] ',
element: document.querySelector('#CONTAINER > section[data-sublink="groups"]'),
searchbar: document.querySelector('#CONTAINER > section[data-sublink="groups"] > .searchbar')
search: {
bar: document.querySelector('#CONTAINER > section[data-sublink="groups"] > .searchbar'),
func: null,
time: null
}
}
};
@ -61,11 +69,11 @@ if( section.view.element != null ){
/* (3) Gestion de la recherche instantannee */
section.view.searchbar.addEventListener('keyup', function(e){
section.view.search.func = function(){
var search = {
path: 'userDefault/search',
keywords: section.view.searchbar.value
keywords: section.view.search.bar.value
};
// On envoie la requete
@ -95,6 +103,15 @@ if( section.view.element != null ){
}
});
}
section.view.search.bar.addEventListener('keyup', function(e){
if( section.view.search.time != null )
clearTimeout(section.view.search.time);
section.view.search.time = setTimeout(section.view.search.func, 500);
}, false);
@ -824,11 +841,11 @@ if( section.groups.element != null ){
/* (3) Gestion de la recherche instantannee */
section.groups.searchbar.addEventListener('keyup', function(e){
section.groups.search.func = function(){
var search = {
path: 'clusterDefault/search',
keywords: section.groups.searchbar.value,
keywords: section.groups.search.bar.value,
class: 0
};
@ -856,6 +873,15 @@ if( section.groups.element != null ){
}
});
};
section.groups.search.bar.addEventListener('keyup', function(e){
if( section.groups.search.time != null )
clearTimeout(section.groups.search.time);
section.groups.search.time = setTimeout(section.groups.search.func, 500);
}, false);
var i;