[Pcsclite-git-commit] [website] 02/03: Reader selection: add support of "any" filter

Ludovic Rousseau rousseau at moszumanska.debian.org
Sun Jun 26 09:05:36 UTC 2016


This is an automated email from the git hooks/post-receive script.

rousseau pushed a commit to branch master
in repository website.

commit 9a769b4725616b6095688f41f16dfc7b567a4dd7
Author: Ludovic Rousseau <ludovic.rousseau at free.fr>
Date:   Thu Jun 23 00:19:32 2016 +0200

    Reader selection: add support of "any" filter
    
    The "filter" any will filter any field.
    It can be used to easily find a reader by product name, vendor name,
    product ID, etc.
---
 select_readers/index.html |   1 +
 select_readers/js/main.js | 140 ++++++++++++++++++++++++++++++----------------
 2 files changed, 94 insertions(+), 47 deletions(-)

diff --git a/select_readers/index.html b/select_readers/index.html
index 2d00635..de19b88 100644
--- a/select_readers/index.html
+++ b/select_readers/index.html
@@ -40,6 +40,7 @@
             <form id="target">
                 <select id="selector">
                     <option value="Add" disabled>Add a match on...</option>
+                    <option value="any">any</option>
                     <option value="bClassEnvelope">bClassEnvelope</option>
                     <option value="bClassGetResponse">bClassGetResponse</option>
                     <option value="bMaxCCIDBusySlots">bMaxCCIDBusySlots</option>
diff --git a/select_readers/js/main.js b/select_readers/js/main.js
index 8f57c60..88d492c 100644
--- a/select_readers/js/main.js
+++ b/select_readers/js/main.js
@@ -120,59 +120,96 @@ function update_list() {
 function match(filters, reader) {
     "use strict";
 
-    var a, b, i, l, f, field, value, relation, v, m;
+    var a, b, i, l, f, field, value, field2, value2, relation, v, m, found;
 
     for (f = 0; f < filters.length; f += 1) {
         field = filters[f][0];
         relation = filters[f][1];
         value = filters[f][2];
 
-        /* may happen with iInterface field */
-        if (reader[field] === undefined) {
-            return false;
-        }
-
-        switch (relation[0]) {
-        case "=":
-            if ('features' === field) {
-                // feature not present?
-                if (reader[field].indexOf(value) === -1) {
-                    return false;
-                }
-            } else if ('dwFeatures' === field) {
-                v = Readers_dwFeatures[value][1];   /* value */
-                m = Readers_dwFeatures[value][2];   /* mask */
-                /*jslint bitwise: true */
-                if ((reader[field] & m) !== v) {
-                    return false;
-                }
-                /*jslint bitwise: false */
+        /* special filter 'any' */
+        if (field === 'any') {
+            /* convert from hex to decimal if needed */
+            if (value.indexOf("0x") === 0) {
+                value2 = parseInt(value, 16);
             } else {
-                if (reader[field] !== value) {
-                    return false;
-                }
+                value2 = parseInt(value, 10);
             }
-            break;
-        case '~':
-            a = reader[field].toLocaleUpperCase();
-            b = value.toLocaleUpperCase();
-            l = Math.min(a.length, b.length);
-            for (i = 0; i < l; i += 1) {
-                if (a[i] !== b[i]) {
-                    return false;
+            if (isNaN(value2)) {
+                value2 = value;
+            }
+
+            found = false;
+            for (field2 in reader) {
+                if (reader.hasOwnProperty(field2)) {
+                    if (typeof reader[field2] === 'number') {
+                        if (reader[field2] === value2) {
+                            found = true;
+                            break;
+                        }
+                    } else {
+                        if (typeof reader[field2] === 'string') {
+                            a = reader[field2].toLocaleUpperCase();
+                            b = value2.toLocaleUpperCase();
+                            if (a.indexOf(b) > -1) {
+                                found = true;
+                                break;
+                            }
+                        }
+                    }
                 }
             }
-            break;
-        case '≤':
-            if (reader[field] > value) {
+            if (!found) {
                 return false;
             }
-            break;
-        case '≥':
-            if (reader[field] < value) {
+        } else {
+            /* may happen with iInterface field */
+            if (reader[field] === undefined) {
                 return false;
             }
-            break;
+
+            switch (relation[0]) {
+            case "=":
+                if ('features' === field) {
+                    // feature not present?
+                    if (reader[field].indexOf(value) === -1) {
+                        return false;
+                    }
+                } else if ('dwFeatures' === field) {
+                    v = Readers_dwFeatures[value][1];   /* value */
+                    m = Readers_dwFeatures[value][2];   /* mask */
+                    /*jslint bitwise: true */
+                    if ((reader[field] & m) !== v) {
+                        return false;
+                    }
+                    /*jslint bitwise: false */
+                } else {
+                    if (reader[field] !== value) {
+                        return false;
+                    }
+                }
+                break;
+            case '~':
+                a = reader[field].toLocaleUpperCase();
+                b = value.toLocaleUpperCase();
+                l = Math.min(a.length, b.length);
+                for (i = 0; i < l; i += 1) {
+                    if (a[i] !== b[i]) {
+                        return false;
+                    }
+                }
+                break;
+            case '≤':
+                if (reader[field] > value) {
+                    return false;
+                }
+                break;
+            case '≥':
+                if (reader[field] < value) {
+                    return false;
+                }
+                break;
+            }
         }
     }
     return true;
@@ -196,7 +233,7 @@ function function_filter() {
 
         Filter[f][1] = $("#relation_" + f).html().split(' ')[0];
 
-        /* if the reader value is an integer then we convert the user value */
+        /* special case for dwFeatures */
         if (field === 'dwFeatures') {
             for (feature in Readers_dwFeatures) {
                 if (Readers_dwFeatures.hasOwnProperty(feature)) {
@@ -205,7 +242,8 @@ function function_filter() {
                     }
                 }
             }
-        } else if (typeof reader[field] === 'number') {
+        /* if the reader value is an integer then we convert the user value */
+        } else if (typeof reader[field] === 'number') {
             if (value.indexOf("0x") === 0) {
                 value = parseInt(value, 16);
             } else {
@@ -333,13 +371,17 @@ function update_filters_ihm() {
             html += '<div class="input-group-btn">';
             html += '<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false" id="relation_' + f + '">AAA</button>';
             html += '<ul class="dropdown-menu" role="menu">';
-            if (Filter[f][0] === 'iManufacturer' || Filter[f][0] === 'iProduct' || Filter[f][0] === 'iInterface') {
-                // iFoo: approximative match
+            if (Filter[f][0] === 'any') {
                 html += ' <li><a href="#">~ </a></li>';
+            } else {
+                if (Filter[f][0] === 'iManufacturer' || Filter[f][0] === 'iProduct' || Filter[f][0] === 'iInterface') {
+                    // iFoo: approximative match
+                    html += ' <li><a href="#">~ </a></li>';
+                }
+                html += ' <li><a href="#">= </a></li>';
+                html += ' <li><a href="#">≤ </a></li>';
+                html += ' <li><a href="#">≥ </a></li>';
             }
-            html += ' <li><a href="#">= </a></li>';
-            html += ' <li><a href="#">≤ </a></li>';
-            html += ' <li><a href="#">≥ </a></li>';
             html += ' <li class="divider"></li>';
             html += ' <li><a href="#">disabled</a></li>';
             html += '</ul></div>';
@@ -372,7 +414,11 @@ function add_filter() {
 
     field = $("#selector").val();
 //    console.log("add filter: " + field);
-    Filter[Filter.length] = [field, "=", ""];
+    if (['any', 'iManufacturer', 'iInterface', 'iProduct'].indexOf(field) > -1) {
+        Filter[Filter.length] = [field, "~", ""];
+    } else {
+        Filter[Filter.length] = [field, "=", ""];
+    }
 //    console.log(Filter);
 
     update_filters_ihm();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pcsclite/website.git



More information about the Pcsclite-cvs-commit mailing list