[data.ue] added formation list to search bar + fixed proccess time (algo exit first)

This commit is contained in:
xdrm-brackets 2018-03-30 18:07:04 +02:00
parent 9bd58eb460
commit 1ead035f0e
1 changed files with 42 additions and 15 deletions

View File

@ -76,8 +76,7 @@ gstore.add('is_buf', null);
gstore.add('is_handler', function(e){
/* (1) Remove last timeout */
if( gstore.get.is_to != null )
clearTimeout(gstore.get.is_to);
!isNaN(gstore.get.is_to) && clearTimeout(gstore.get.is_to);
/* (2) Store value in buffer */
gstore.get.is_buf = e.target.value.trim().toLowerCase();
@ -86,27 +85,55 @@ gstore.add('is_handler', function(e){
gstore.get.is_to = setTimeout(function(){
// 1. Fetch elements
var local_ptr = gstore.get.ues;
var l = gstore.get.ues.length;
let local_ptr = gstore.get.ues;
let l = gstore.get.ues.length;
let buf = gstore.get.is_buf.replace(/[.?*+^$[\]\\(\){}|-]/g, "\\$&"); // Escape errorful regex characters
// 2. For each element
for( var e = 0 ; e < l ; e++ ){
main_loop: for( let e = 0 ; e < l ; e++ ){
// 2.1. Show by default
var element = document.querySelector('section[data-id=\''+local_ptr[e].code+'\']');
if( !element ) continue;
// 2.1. Set visible by default
let element = document.querySelector('section[data-id=\''+local_ptr[e].code+'\']');
if( !(element instanceof Element) )
continue;
element.remClass('search-hidden');
// 2.2. Extract name components
var code = local_ptr[e].code.trim().toLowerCase();
var label = local_ptr[e].label.trim().toLowerCase();
// 2.2. Empty text -> let visible
if( buf.length == 0 )
continue;
// 2.3. Hide if does not match
var match_offset = gstore.get.is_buf.length == 0 || code.search(gstore.get.is_buf) + label.search(gstore.get.is_buf);
// 2.3. Extract name components
let code = local_ptr[e].code.toLowerCase();
let label = local_ptr[e].label.toLowerCase();
let forms = local_ptr[e].formations;
if( match_offset <= -2 )
element.addClass('search-hidden');
// 2.4-1. Match code -> let visible
if( code.search(buf) >= 0 )
continue;
// 2.4-2. Match label -> let visible
if( label.search(buf) >= 0 )
continue;
// 2.4-3. Check for each formation
for( let f of forms ){
let fetched_form = gstore.get.form_by_id(f);
// if formation not found -> ignore
if( fetched_form == null )
continue;
// if formation LABEL matches -> let visible
if( fetched_form.labelForm.toLowerCase().search(buf) >= 0 )
continue main_loop;
}
// XXXX. Hide all that did not match
element.addClass('search-hidden');
}