@@ -13,7 +13,7 @@ angular.module('patternfly.card', []);
13
13
* Charts module for patternfly. Must Include d3.js and c3.js to use
14
14
*
15
15
*/
16
- angular . module ( 'patternfly.charts' , [ ] ) ;
16
+ angular . module ( 'patternfly.charts' , [ 'patternfly.utils' ] ) ;
17
17
18
18
; /**
19
19
* @name patternfly card
@@ -672,7 +672,7 @@ angular.module('patternfly.card').directive('pfCard', function () {
672
672
</file>
673
673
</example>
674
674
*/
675
- angular . module ( 'patternfly.charts' ) . directive ( 'pfDonutPctChart' , [ "c3ChartDefaults" , "$timeout" , function ( c3ChartDefaults , $timeout ) {
675
+ angular . module ( 'patternfly.charts' ) . directive ( 'pfDonutPctChart' , [ "c3ChartDefaults" , "pfUtils" , " $timeout", function ( c3ChartDefaults , pfUtils , $timeout ) {
676
676
'use strict' ;
677
677
678
678
return {
@@ -796,7 +796,7 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', ["c3ChartDefaul
796
796
$scope . config . tooltip = donutTooltip ( scope ) ;
797
797
} ;
798
798
799
- $scope . config = angular . merge ( { } , c3ChartDefaults . getDefaultDonutConfig ( ) , $scope . config ) ;
799
+ $scope . config = pfUtils . merge ( c3ChartDefaults . getDefaultDonutConfig ( ) , $scope . config ) ;
800
800
$scope . updateAll ( $scope ) ;
801
801
}
802
802
] ,
@@ -974,7 +974,7 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', ["c3ChartDefaul
974
974
</file>
975
975
</example>
976
976
*/
977
- angular . module ( 'patternfly.charts' ) . directive ( 'pfSparklineChart' , [ "c3ChartDefaults" , function ( c3ChartDefaults ) {
977
+ angular . module ( 'patternfly.charts' ) . directive ( 'pfSparklineChart' , [ "c3ChartDefaults" , "pfUtils" , function ( c3ChartDefaults , pfUtils ) {
978
978
'use strict' ;
979
979
return {
980
980
restrict : 'A' ,
@@ -1131,7 +1131,7 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefau
1131
1131
$scope . defaultConfig . units = '' ;
1132
1132
1133
1133
// Override defaults with callers specifications
1134
- $scope . config = angular . merge ( { } , $scope . defaultConfig , $scope . config ) ;
1134
+ $scope . config = pfUtils . merge ( $scope . defaultConfig , $scope . config ) ;
1135
1135
1136
1136
// Convert the given data to C3 chart format
1137
1137
$scope . config . data = $scope . getSparklineData ( $scope . chartData ) ;
@@ -1140,7 +1140,7 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefau
1140
1140
1141
1141
link : function ( scope ) {
1142
1142
scope . $watch ( 'config' , function ( ) {
1143
- scope . config = angular . merge ( { } , scope . defaultConfig , scope . config ) ;
1143
+ scope . config = pfUtils . merge ( scope . defaultConfig , scope . config ) ;
1144
1144
} , true ) ;
1145
1145
scope . $watch ( 'chartHeight' , function ( ) {
1146
1146
scope . config . size . height = scope . chartHeight ;
@@ -2969,6 +2969,58 @@ angular
2969
2969
}
2970
2970
} ;
2971
2971
} ) ;
2972
+ ; ( function ( ) {
2973
+ 'use strict' ;
2974
+
2975
+ angular . module ( 'patternfly.utils' ) . constant ( 'pfUtils' , {
2976
+ merge : function ( source1 , source2 ) {
2977
+ var retValue ;
2978
+
2979
+ if ( typeof angular . merge === 'function' ) {
2980
+ retValue = this . angularMerge ( source1 , source2 ) ;
2981
+ } else if ( typeof _ . merge === 'function' ) {
2982
+ retValue = this . _merge ( source1 , source2 ) ;
2983
+ } else if ( typeof $ . extend === 'function' ) {
2984
+ retValue = this . $extend ( source1 , source2 ) ;
2985
+ } else {
2986
+ retValue = this . mergeDeep ( source1 , source2 ) ;
2987
+ }
2988
+
2989
+ return retValue ;
2990
+ } ,
2991
+ angularMerge : function ( source1 , source2 ) {
2992
+ return angular . merge ( { } , source1 , source2 ) ;
2993
+ } ,
2994
+ _merge : function ( source1 , source2 ) {
2995
+ return _ . merge ( { } , source1 , source2 ) ;
2996
+ } ,
2997
+ $extend : function ( source1 , source2 ) {
2998
+ return $ . extend ( true , angular . copy ( source1 ) , source2 ) ;
2999
+ } ,
3000
+ mergeDeep : function ( source1 , source2 ) {
3001
+ return mergeDeep ( { } , angular . copy ( source1 ) , angular . copy ( source2 ) ) ;
3002
+ }
3003
+ } ) ;
3004
+ } ) ( ) ;
3005
+
3006
+ /* This function does not merge/concat Arrays.
3007
+ * It replaces the earlier Array with any latter Array.
3008
+ */
3009
+ function mergeDeep ( dst ) {
3010
+ 'use strict' ;
3011
+ angular . forEach ( arguments , function ( obj ) {
3012
+ if ( obj !== dst ) {
3013
+ angular . forEach ( obj , function ( value , key ) {
3014
+ if ( dst [ key ] && dst [ key ] . constructor && dst [ key ] . constructor === Object ) {
3015
+ mergeDeep ( dst [ key ] , value ) ;
3016
+ } else {
3017
+ dst [ key ] = value ;
3018
+ }
3019
+ } ) ;
3020
+ }
3021
+ } ) ;
3022
+ return dst ;
3023
+ }
2972
3024
; /**
2973
3025
* @ngdoc directive
2974
3026
* @name patternfly.validation:pfValidation
@@ -3330,8 +3382,7 @@ angular.module('patternfly.validation', []).directive('pfValidation', ["$timeout
3330
3382
</file>
3331
3383
</example>
3332
3384
*/
3333
- angular . module ( 'patternfly.views' ) . directive ( 'pfDataList' , [
3334
- function ( ) {
3385
+ angular . module ( 'patternfly.views' ) . directive ( 'pfDataList' , [ "pfUtils" , function ( pfUtils ) {
3335
3386
'use strict' ;
3336
3387
return {
3337
3388
restrict : 'A' ,
@@ -3360,7 +3411,7 @@ angular.module('patternfly.views').directive('pfDataList', [
3360
3411
onDblClick : null
3361
3412
} ;
3362
3413
3363
- $scope . config = angular . merge ( { } , $scope . defaultConfig , $scope . config ) ;
3414
+ $scope . config = pfUtils . merge ( $scope . defaultConfig , $scope . config ) ;
3364
3415
if ( $scope . config . selectItems && $scope . config . showSelectBox ) {
3365
3416
throw new Error ( 'pfDataList - ' +
3366
3417
'Illegal use of pfDataList directive! ' +
@@ -3371,7 +3422,7 @@ angular.module('patternfly.views').directive('pfDataList', [
3371
3422
3372
3423
link : function ( scope , element , attrs ) {
3373
3424
attrs . $observe ( 'config' , function ( ) {
3374
- scope . config = angular . merge ( { } , scope . defaultConfig , scope . config ) ;
3425
+ scope . config = pfUtils . merge ( scope . defaultConfig , scope . config ) ;
3375
3426
if ( ! scope . config . selectItems ) {
3376
3427
scope . config . selectedItems = [ ] ;
3377
3428
}
@@ -3463,8 +3514,8 @@ angular.module('patternfly.views').directive('pfDataList', [
3463
3514
} ;
3464
3515
}
3465
3516
} ;
3466
- }
3467
- ] ) ;
3517
+ } ]
3518
+ ) ;
3468
3519
; /**
3469
3520
* @ngdoc directive
3470
3521
* @name patternfly.views.directive:pfDataTiles
@@ -3658,8 +3709,7 @@ angular.module('patternfly.views').directive('pfDataList', [
3658
3709
</file>
3659
3710
</example>
3660
3711
*/
3661
- angular . module ( 'patternfly.views' ) . directive ( 'pfDataTiles' , [
3662
- function ( ) {
3712
+ angular . module ( 'patternfly.views' ) . directive ( 'pfDataTiles' , [ "pfUtils" , function ( pfUtils ) {
3663
3713
'use strict' ;
3664
3714
return {
3665
3715
restrict : 'A' ,
@@ -3686,7 +3736,7 @@ angular.module('patternfly.views').directive('pfDataTiles', [
3686
3736
onDblClick : null
3687
3737
} ;
3688
3738
3689
- $scope . config = angular . merge ( { } , $scope . defaultConfig , $scope . config ) ;
3739
+ $scope . config = pfUtils . merge ( $scope . defaultConfig , $scope . config ) ;
3690
3740
if ( $scope . config . selectItems && $scope . config . showSelectBox ) {
3691
3741
throw new Error ( 'pfDataTiles - ' +
3692
3742
'Illegal use of pfDataTiles directive! ' +
@@ -3695,7 +3745,7 @@ angular.module('patternfly.views').directive('pfDataTiles', [
3695
3745
} ] ,
3696
3746
link : function ( scope , element , attrs ) {
3697
3747
attrs . $observe ( 'config' , function ( ) {
3698
- scope . config = angular . merge ( { } , scope . defaultConfig , scope . config ) ;
3748
+ scope . config = pfUtils . merge ( scope . defaultConfig , scope . config ) ;
3699
3749
if ( ! scope . config . selectItems ) {
3700
3750
scope . config . selectedItems = [ ] ;
3701
3751
}
@@ -3789,8 +3839,8 @@ angular.module('patternfly.views').directive('pfDataTiles', [
3789
3839
} ;
3790
3840
}
3791
3841
} ;
3792
- }
3793
- ] ) ;
3842
+ } ]
3843
+ ) ;
3794
3844
; /**
3795
3845
* @ngdoc directive
3796
3846
* @name patternfly.views.directive:pfDataToolbar
0 commit comments