@@ -21,21 +21,39 @@ uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinE
21
21
self . parse = function ( expression ) {
22
22
23
23
24
- //0000000000000000000000000000000000011111111100000000000000022222222222222003333333333333333333333000044444444444444444400000000000000005555500000666666666666600000000000000000000007777777770000000
25
- var 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 * $ / ) ;
24
+ var match ;
25
+ var isObjectCollection = / \( \s * ( [ \$ \w ] [ \$ \w ] * ) \s * , \s * ( [ \$ \w ] [ \$ \w ] * ) \s * \) / . test ( expression ) ;
26
+ // If an array is used as collection
27
+
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 * $ / ) ;
31
+
32
+ // 1 Alias
33
+ // 2 Item
34
+ // 3 Key on (key,value)
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
26
40
27
41
if ( ! match ) {
28
42
throw uiSelectMinErr ( 'iexp' , "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'." ,
29
43
expression ) ;
30
44
}
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 ) ;
48
+ }
31
49
32
50
return {
33
51
itemName : match [ 4 ] || match [ 2 ] , // (lhs) Left-hand side,
34
52
keyName : match [ 3 ] , //for (key, value) syntax
35
- source : $parse ( ! match [ 3 ] ? match [ 5 ] + ( match [ 6 ] || '' ) : match [ 5 ] ) , //concat source with filters if its an array
36
- sourceName : match [ 5 ] ,
37
- filters : match [ 6 ] ,
38
- trackByExp : match [ 7 ] ,
53
+ source : $parse ( ! match [ 3 ] ? match [ 5 ] : match [ 6 ] ) ,
54
+ sourceName : match [ 6 ] ,
55
+ filters : match [ 7 ] ,
56
+ trackByExp : match [ 8 ] ,
39
57
modelMapper : $parse ( match [ 1 ] || match [ 4 ] || match [ 2 ] ) ,
40
58
repeatExpression : function ( grouped ) {
41
59
var expression = this . itemName + ' in ' + ( grouped ? '$group.items' : '$select.items' ) ;
0 commit comments