From 1ead035f0e1c9057f6b78e27327f7f2592bdaa8f Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Fri, 30 Mar 2018 18:07:04 +0200 Subject: [PATCH] [data.ue] added formation list to search bar + fixed proccess time (algo exit first) --- webpack/data/ue.js | 57 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/webpack/data/ue.js b/webpack/data/ue.js index c1d5909..238efe3 100644 --- a/webpack/data/ue.js +++ b/webpack/data/ue.js @@ -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'); }