[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){ gstore.add('is_handler', function(e){
/* (1) Remove last timeout */ /* (1) Remove last timeout */
if( gstore.get.is_to != null ) !isNaN(gstore.get.is_to) && clearTimeout(gstore.get.is_to);
clearTimeout(gstore.get.is_to);
/* (2) Store value in buffer */ /* (2) Store value in buffer */
gstore.get.is_buf = e.target.value.trim().toLowerCase(); gstore.get.is_buf = e.target.value.trim().toLowerCase();
@ -86,26 +85,54 @@ gstore.add('is_handler', function(e){
gstore.get.is_to = setTimeout(function(){ gstore.get.is_to = setTimeout(function(){
// 1. Fetch elements // 1. Fetch elements
var local_ptr = gstore.get.ues; let local_ptr = gstore.get.ues;
var l = gstore.get.ues.length; let l = gstore.get.ues.length;
let buf = gstore.get.is_buf.replace(/[.?*+^$[\]\\(\){}|-]/g, "\\$&"); // Escape errorful regex characters
// 2. For each element // 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 // 2.1. Set visible by default
var element = document.querySelector('section[data-id=\''+local_ptr[e].code+'\']'); let element = document.querySelector('section[data-id=\''+local_ptr[e].code+'\']');
if( !element ) continue;
if( !(element instanceof Element) )
continue;
element.remClass('search-hidden'); element.remClass('search-hidden');
// 2.2. Extract name components // 2.2. Empty text -> let visible
var code = local_ptr[e].code.trim().toLowerCase(); if( buf.length == 0 )
var label = local_ptr[e].label.trim().toLowerCase(); continue;
// 2.3. Hide if does not match // 2.3. Extract name components
var match_offset = gstore.get.is_buf.length == 0 || code.search(gstore.get.is_buf) + label.search(gstore.get.is_buf); let code = local_ptr[e].code.toLowerCase();
let label = local_ptr[e].label.toLowerCase();
let forms = local_ptr[e].formations;
if( match_offset <= -2 ) // 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'); element.addClass('search-hidden');
} }