Changeset 8399

Show
Ignore:
Timestamp:
05/02/07 11:06:00 (21 months ago)
Author:
jaredj
Message:

Adding in queryIgnoreCase option into JsonItemStore? (from dojo.data meeting on 2007.05.01 ) refs #2909

Location:
dojo/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • dojo/trunk/data/api/Read.js

    r8397 r8399  
    197197                //              {  
    198198                //                      query: query-string or query-object, 
     199                //                      queryIgnoreCase: boolean, 
    199200                //                      onBegin: Function, 
    200201                //                      onItem: Function, 
     
    220221                //              in some implementations the query might be a Date, or a number, 
    221222                //              or some complex keyword parameter object.  The dojo.data.api.Read 
    222                 //              API is completely agnostic about what the query actually is. 
     223                //              API is completely agnostic about what the query actually is.   
     224                //              In general for query objects that accept strings as attribute value matches,  
     225                //              the store should support basic filtering capability, such as * (match any character) 
     226                //              and ? (match single character).  
     227                // 
     228                //      The *queryIgnoreCase* parameter. 
     229                //              The queryIgnoreCase may be optional in some data store implementations. 
     230                //              If set, this parameter instructs the data store which does filtering 
     231                //              and the like in is query parameter to ignore character casing when doing a  
     232                //              query match.  If this parameter is not included, it is treated as false (case sensitive).  
    223233                // 
    224234                //      The *onBegin* parameter. 
     
    326336                //              var request = store.fetch({query:{author:"King"}, sort: [{ attribute: "title", descending: true}, {attribute: "publisher"}], ,start: 0, count:100, onComplete: 'showKing'}); 
    327337                // 
     338                //              // Fetch the first 100 books by authors starting with the name King, then call showKing when up to 100 items have been located. 
     339                //              var request = store.fetch({query:{author:"King*"}, start: 0, count:100, onComplete: showKing}); 
     340                // 
     341                //              // Fetch the first 100 books by authors ending with 'ing', but only have one character before it (King, Bing, Ling, Sing, etc.), then call showBooks when up to 100 items have been located. 
     342                //              var request = store.fetch({query:{author:"?ing"}, start: 0, count:100, onComplete: showBooks}); 
     343                // 
     344                //              // Fetch the first 100 books by author King, where the name may appear as King, king, KING, kInG, and so on, then call showKing when up to 100 items have been located. 
     345                //              var request = store.fetch({query:{author:"King"}, queryIgnoreCase: true, start: 0, count:100, onComplete: showKing}); 
     346                // 
    328347                //              // Paging: 
    329348                //              var store = new dojo.data.LargeRdbmsStore({url:"jdbc:odbc:foobar"}); 
  • dojo/trunk/data/JsonItemStore.js

    r8361 r8399  
    9999                //      summary:  
    100100                //              See dojo.data.api.Read.containsValue() 
     101                return this._containsValue(item,attribute,value,false); //boolean 
     102        }, 
     103 
     104        _containsValue: function(       /* item */ item,  
     105                                                                /* attribute || attribute-name-string */ attribute,  
     106                                                                /* anything */ value, 
     107                                                                /* boolean */ ignoreCase){ 
     108                //      summary:  
     109                //              Internal function for looking at the values contained by the item. 
     110                //      description:  
     111                //              Internal function for looking at the values contained by the item.  This  
     112                //              function allows for denoting if the comparison should be case sensitive for 
     113                //              strings or not (for handling filtering cases where string case should not matter) 
     114                //       
     115                //      item: 
     116                //              The data item to examine for attribute values. 
     117                //      attribute: 
     118                //              The attribute to inspect. 
     119                //      value:   
     120                //              The value to match, strings may contain wildcard items like * and ?. 
     121                //      ignoreCase: 
     122                //              Flag to denote that if items are a string type, should case be used for comparison or not. 
    101123                var values = this.getValues(item, attribute); 
    102124                for(var i = 0; i < values.length; ++i){ 
    103125                        var possibleValue = values[i]; 
    104126                        if(typeof value === "string" && typeof possibleValue === "string"){ 
    105                                 return (possibleValue.match(dojo.data.util.filter.patternToRegExp(value)) !== null); 
     127                                return (possibleValue.match(dojo.data.util.filter.patternToRegExp(value, ignoreCase)) !== null); 
    106128                        }else{ 
    107129                                //Non-string matching. 
     
    165187                                        for(var key in requestArgs.query) { 
    166188                                                var value = requestArgs.query[key]; 
    167                                                 if (!self.containsValue(candidateItem, key, value)){ 
     189                                                if (!self._containsValue(candidateItem, key, value, requestArgs.queryIgnoreCase)){ 
    168190                                                        match = false; 
    169191                                                } 
  • dojo/trunk/data/util/filter.js

    r7966 r8399  
    11dojo.provide("dojo.data.util.filter"); 
    22 
    3 dojo.data.util.filter.patternToRegExp = function(/*String*/pattern){ 
     3dojo.data.util.filter.patternToRegExp = function(/*String*/pattern, /*boolean?*/ ignoreCase){ 
    44        //      summary:   
    55        //              Helper function to convert a simple pattern to a regular expression for matching. 
     
    2020        //                              To use a \ as a character in the string, it must be escaped.  So in the pattern it should be  
    2121        //                              represented by \\ to be treated as an ordinary \ character instead of an escape. 
     22        // 
     23        //      ignoreCase: 
     24        //              An optional flag to indicate if the pattern matching should be treated as case-sensitive or not when comparing 
     25        //              By default, it is assumed case sensitive. 
    2226 
    2327        var rxp = "^"; 
     
    5357        } 
    5458        rxp += "$"; 
    55         return new RegExp(rxp); //RegExp 
     59        if(ignoreCase){ 
     60                return new RegExp(rxp,"i"); //RegExp 
     61        }else{ 
     62                return new RegExp(rxp); //RegExp 
     63        } 
     64         
    5665}; 
  • dojo/trunk/tests/data/JsonItemStore.js

    r8386 r8399  
    560560                        return d; 
    561561                }, 
     562                function testReadAPI_fetch_patternMatch_caseSensitive(t){ 
     563                        //      summary:  
     564                        //              Function to test pattern matching of a pattern case-sensitively 
     565                        //      description: 
     566                        //              Function to test pattern matching of a pattern case-sensitively 
     567 
     568                        var jsonItemStore = new dojo.data.JsonItemStore({data: { identifier: "uniqueId",  
     569                                                                                          items: [ {uniqueId: 1, value:"foo*bar"}, 
     570                                                                                                   {uniqueId: 2, value:"bar*foo"},  
     571                                                                                                   {uniqueId: 3, value:"BAR*foo"}, 
     572                                                                                                   {uniqueId: 4, value:"BARBananafoo"} 
     573                                                                                                 ] 
     574                                                                                } 
     575                                                                 }); 
     576                         
     577                        var d = new doh.Deferred(); 
     578                        function completed(items, request){ 
     579                                t.assertEqual(1, items.length); 
     580                                var passed = true; 
     581                                for(var i = 0; i < items.length; i++){ 
     582                                        var value = jsonItemStore.getValue(items[i], "value"); 
     583                                        if(!(value === "bar*foo")){ 
     584                                                passed=false; 
     585                                                break; 
     586                                        } 
     587                                } 
     588                                t.assertTrue(passed); 
     589                                if (passed){ 
     590                                        d.callback(true); 
     591                                }else{ 
     592                                        d.errback(new Error("Unexpected pattern matched.  Filter failure.")); 
     593                                } 
     594                        } 
     595                        function error(error, request){ 
     596                                t.assertTrue(false); 
     597                                d.errback(error); 
     598                        } 
     599                        jsonItemStore.fetch({query: {value: "bar\\*foo"}, queryIgnoreCase: false, onComplete: completed, onError: error}); 
     600                        return d; 
     601                }, 
     602                function testReadAPI_fetch_patternMatch_caseInsensitive(t){ 
     603                        //      summary:  
     604                        //              Function to test pattern matching of a pattern case-insensitively 
     605                        //      description: 
     606                        //              Function to test pattern matching of a pattern case-insensitively 
     607 
     608                        var jsonItemStore = new dojo.data.JsonItemStore({data: { identifier: "uniqueId",  
     609                                                                                          items: [ {uniqueId: 1, value:"foo*bar"}, 
     610                                                                                                   {uniqueId: 2, value:"bar*foo"},  
     611                                                                                                   {uniqueId: 3, value:"BAR*foo"}, 
     612                                                                                                   {uniqueId: 4, value:"BARBananafoo"} 
     613                                                                                                 ] 
     614                                                                                } 
     615                                                                 }); 
     616                         
     617                        var d = new doh.Deferred(); 
     618                        function completed(items, request){ 
     619                                t.assertEqual(items.length, 2); 
     620                                var passed = true; 
     621                                for(var i = 0; i < items.length; i++){ 
     622                                        var value = jsonItemStore.getValue(items[i], "value"); 
     623                                        if(!(value === "BAR*foo" || value === "bar*foo")){ 
     624                                                passed=false; 
     625                                                break; 
     626                                        } 
     627                                } 
     628                                t.assertTrue(passed); 
     629                                if (passed){ 
     630                                        d.callback(true); 
     631                                }else{ 
     632                                        d.errback(new Error("Unexpected pattern matched.  Filter failure.")); 
     633                                } 
     634                        } 
     635                        function error(error, request){ 
     636                                t.assertTrue(false); 
     637                                d.errback(error); 
     638                        } 
     639                        jsonItemStore.fetch({query: {value: "bar\\*foo"}, queryIgnoreCase: true, onComplete: completed, onError: error}); 
     640                        return d; 
     641                }, 
    562642                function testReadAPI_fetch_sortNumeric(t){ 
    563643                        //      summary:  
  • dojo/trunk/tests/data/utils.js

    r7972 r8399  
    5555                        t.assertFalse(values[3].match(dojo.data.util.filter.patternToRegExp(pattern))!== null); 
    5656                        t.assertTrue(values[4].match(dojo.data.util.filter.patternToRegExp(pattern))!== null); 
     57                }, 
     58                function testWildcardFilter_caseInsensitive(t){ 
     59                        var pattern = "ca*"; 
     60                        var values = ["CA", "california", "Macca", "Macca*b", "Macca\\b"]; 
     61 
     62                        t.assertTrue(values[0].match(dojo.data.util.filter.patternToRegExp(pattern, true))!== null); 
     63                        t.assertTrue(values[1].match(dojo.data.util.filter.patternToRegExp(pattern, true))!== null); 
     64                        t.assertFalse(values[2].match(dojo.data.util.filter.patternToRegExp(pattern, true))!== null); 
     65                        t.assertFalse(values[3].match(dojo.data.util.filter.patternToRegExp(pattern, true))!== null); 
     66                        t.assertFalse(values[4].match(dojo.data.util.filter.patternToRegExp(pattern, true))!== null); 
    5767                }, 
    5868                function testSingleChar_1(t){