Changeset 8399
- Timestamp:
- 05/02/07 11:06:00 (21 months ago)
- Location:
- dojo/trunk
- Files:
-
- 5 modified
-
data/api/Read.js (modified) (3 diffs)
-
data/JsonItemStore.js (modified) (2 diffs)
-
data/util/filter.js (modified) (3 diffs)
-
tests/data/JsonItemStore.js (modified) (1 diff)
-
tests/data/utils.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
dojo/trunk/data/api/Read.js
r8397 r8399 197 197 // { 198 198 // query: query-string or query-object, 199 // queryIgnoreCase: boolean, 199 200 // onBegin: Function, 200 201 // onItem: Function, … … 220 221 // in some implementations the query might be a Date, or a number, 221 222 // 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). 223 233 // 224 234 // The *onBegin* parameter. … … 326 336 // var request = store.fetch({query:{author:"King"}, sort: [{ attribute: "title", descending: true}, {attribute: "publisher"}], ,start: 0, count:100, onComplete: 'showKing'}); 327 337 // 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 // 328 347 // // Paging: 329 348 // var store = new dojo.data.LargeRdbmsStore({url:"jdbc:odbc:foobar"}); -
dojo/trunk/data/JsonItemStore.js
r8361 r8399 99 99 // summary: 100 100 // 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. 101 123 var values = this.getValues(item, attribute); 102 124 for(var i = 0; i < values.length; ++i){ 103 125 var possibleValue = values[i]; 104 126 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); 106 128 }else{ 107 129 //Non-string matching. … … 165 187 for(var key in requestArgs.query) { 166 188 var value = requestArgs.query[key]; 167 if (!self. containsValue(candidateItem, key, value)){189 if (!self._containsValue(candidateItem, key, value, requestArgs.queryIgnoreCase)){ 168 190 match = false; 169 191 } -
dojo/trunk/data/util/filter.js
r7966 r8399 1 1 dojo.provide("dojo.data.util.filter"); 2 2 3 dojo.data.util.filter.patternToRegExp = function(/*String*/pattern ){3 dojo.data.util.filter.patternToRegExp = function(/*String*/pattern, /*boolean?*/ ignoreCase){ 4 4 // summary: 5 5 // Helper function to convert a simple pattern to a regular expression for matching. … … 20 20 // To use a \ as a character in the string, it must be escaped. So in the pattern it should be 21 21 // 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. 22 26 23 27 var rxp = "^"; … … 53 57 } 54 58 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 56 65 }; -
dojo/trunk/tests/data/JsonItemStore.js
r8386 r8399 560 560 return d; 561 561 }, 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 }, 562 642 function testReadAPI_fetch_sortNumeric(t){ 563 643 // summary: -
dojo/trunk/tests/data/utils.js
r7972 r8399 55 55 t.assertFalse(values[3].match(dojo.data.util.filter.patternToRegExp(pattern))!== null); 56 56 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); 57 67 }, 58 68 function testSingleChar_1(t){