@@ -22,38 +22,48 @@ uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinE
22
22
23
23
24
24
var match ;
25
- var isObjectCollection = / \( \s * ( [ \$ \w ] [ \$ \w ] * ) \s * , \s * ( [ \$ \w ] [ \$ \w ] * ) \s * \) / . test ( expression ) ;
25
+ // var isObjectCollection = /\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)/.test(expression);
26
26
// If an array is used as collection
27
27
28
28
// if (isObjectCollection){
29
- //00000000000000000000000000000111111111000000000000000222222222222220033333333333333333333330000444444444444444444000000000000000556666660000077777777777755000000000000000000000088888880000000
30
- match = expression . match ( / ^ \s * (?: ( [ \s \S ] + ?) \s + a s \s + ) ? (?: ( [ \$ \w ] [ \$ \w ] * ) | (?: \( \s * ( [ \$ \w ] [ \$ \w ] * ) \s * , \s * ( [ \$ \w ] [ \$ \w ] * ) \s * \) ) ) \s + i n \s + ( ( [ \w \. ] + ) ? \s * ( | \s * [ \s \S ] + ?) ) ? (?: \s + t r a c k \s + b y \s + ( [ \s \S ] + ?) ) ? \s * $ / ) ;
29
+ // 000000000000000000000000000000111111111000000000000000222222222222220033333333333333333333330000444444444444444444000000000000000055555555555000000000000000000000066666666600000000
30
+ match = expression . match ( / ^ \s * (?: ( [ \s \S ] + ?) \s + a s \s + ) ? (?: ( [ \$ \w ] [ \$ \w ] * ) | (?: \( \s * ( [ \$ \w ] [ \$ \w ] * ) \s * , \s * ( [ \$ \w ] [ \$ \w ] * ) \s * \) ) ) \s + i n \s + ( \s * [ \s \S ] + ?) ? (?: \s + t r a c k \s + b y \s + ( [ \s \S ] + ?) ) ? \s * $ / ) ;
31
31
32
32
// 1 Alias
33
33
// 2 Item
34
34
// 3 Key on (key,value)
35
35
// 4 Value on (key,value)
36
- // 5 Collection expresion (only used when using an array collection)
37
- // 6 Object that will be converted to Array when using (key,value) syntax
38
- // 7 Filters that will be applied to #6 when using (key,value) syntax
39
- // 8 Track by
36
+ // 5 Source expression (including filters)
37
+ // 6 Track by
40
38
41
39
if ( ! match ) {
42
40
throw uiSelectMinErr ( 'iexp' , "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'." ,
43
41
expression ) ;
44
42
}
45
- if ( ! match [ 6 ] && isObjectCollection ) {
46
- throw uiSelectMinErr ( 'iexp' , "Expected expression in form of '_item_ as (_key_, _item_) in _ObjCollection_ [ track by _id_]' but got '{0}'." ,
47
- expression ) ;
43
+
44
+ var source = match [ 5 ] ,
45
+ filters = '' ;
46
+
47
+ // When using (key,value) ui-select requires filters to be extracted, since the object
48
+ // is converted to an array for $select.items
49
+ // (in which case the filters need to be reapplied)
50
+ if ( match [ 3 ] ) {
51
+ // Remove any enclosing parenthesis
52
+ source = match [ 5 ] . replace ( / ( ^ \( ) | ( \) $ ) / g, '' ) ;
53
+ // match all after | but not after ||
54
+ var filterMatch = match [ 5 ] . match ( / ^ \s * (?: [ \s \S ] + ?) (?: [ ^ \| ] | \| \| ) + ( [ \s \S ] * ) \s * $ / ) ;
55
+ if ( filterMatch && filterMatch [ 1 ] . trim ( ) ) {
56
+ filters = filterMatch [ 1 ] ;
57
+ source = source . replace ( filters , '' ) ;
58
+ }
48
59
}
49
60
50
61
return {
51
62
itemName : match [ 4 ] || match [ 2 ] , // (lhs) Left-hand side,
52
63
keyName : match [ 3 ] , //for (key, value) syntax
53
- source : $parse ( ! match [ 3 ] ? match [ 5 ] : match [ 6 ] ) ,
54
- sourceName : match [ 6 ] ,
55
- filters : match [ 7 ] ,
56
- trackByExp : match [ 8 ] ,
64
+ source : $parse ( source ) ,
65
+ filters : filters ,
66
+ trackByExp : match [ 6 ] ,
57
67
modelMapper : $parse ( match [ 1 ] || match [ 4 ] || match [ 2 ] ) ,
58
68
repeatExpression : function ( grouped ) {
59
69
var expression = this . itemName + ' in ' + ( grouped ? '$group.items' : '$select.items' ) ;
0 commit comments