Skip to content

Commit 99780f5

Browse files
Merge pull request #88 from dtaylor113/issue85
This Fixes #85 'angular.merge is not a function .controller'
2 parents 63242a7 + 82127bd commit 99780f5

File tree

9 files changed

+228
-36
lines changed

9 files changed

+228
-36
lines changed

dist/angular-patternfly.js

Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ angular.module('patternfly.card', []);
1313
* Charts module for patternfly. Must Include d3.js and c3.js to use
1414
*
1515
*/
16-
angular.module('patternfly.charts', []);
16+
angular.module('patternfly.charts', ['patternfly.utils']);
1717

1818
;/**
1919
* @name patternfly card
@@ -672,7 +672,7 @@ angular.module('patternfly.card').directive('pfCard', function () {
672672
</file>
673673
</example>
674674
*/
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) {
676676
'use strict';
677677

678678
return {
@@ -796,7 +796,7 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', ["c3ChartDefaul
796796
$scope.config.tooltip = donutTooltip(scope);
797797
};
798798

799-
$scope.config = angular.merge({}, c3ChartDefaults.getDefaultDonutConfig(), $scope.config);
799+
$scope.config = pfUtils.merge(c3ChartDefaults.getDefaultDonutConfig(), $scope.config);
800800
$scope.updateAll($scope);
801801
}
802802
],
@@ -974,7 +974,7 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', ["c3ChartDefaul
974974
</file>
975975
</example>
976976
*/
977-
angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefaults", function (c3ChartDefaults) {
977+
angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefaults", "pfUtils", function (c3ChartDefaults, pfUtils) {
978978
'use strict';
979979
return {
980980
restrict: 'A',
@@ -1131,7 +1131,7 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefau
11311131
$scope.defaultConfig.units = '';
11321132

11331133
// Override defaults with callers specifications
1134-
$scope.config = angular.merge({},$scope.defaultConfig, $scope.config);
1134+
$scope.config = pfUtils.merge($scope.defaultConfig, $scope.config);
11351135

11361136
// Convert the given data to C3 chart format
11371137
$scope.config.data = $scope.getSparklineData($scope.chartData);
@@ -1140,7 +1140,7 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefau
11401140

11411141
link: function (scope) {
11421142
scope.$watch('config', function () {
1143-
scope.config = angular.merge({}, scope.defaultConfig, scope.config);
1143+
scope.config = pfUtils.merge(scope.defaultConfig, scope.config);
11441144
}, true);
11451145
scope.$watch('chartHeight', function () {
11461146
scope.config.size.height = scope.chartHeight;
@@ -2969,6 +2969,58 @@ angular
29692969
}
29702970
};
29712971
});
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+
}
29723024
;/**
29733025
* @ngdoc directive
29743026
* @name patternfly.validation:pfValidation
@@ -3330,8 +3382,7 @@ angular.module('patternfly.validation', []).directive('pfValidation', ["$timeout
33303382
</file>
33313383
</example>
33323384
*/
3333-
angular.module('patternfly.views').directive('pfDataList', [
3334-
function () {
3385+
angular.module('patternfly.views').directive('pfDataList', ["pfUtils", function (pfUtils) {
33353386
'use strict';
33363387
return {
33373388
restrict: 'A',
@@ -3360,7 +3411,7 @@ angular.module('patternfly.views').directive('pfDataList', [
33603411
onDblClick: null
33613412
};
33623413

3363-
$scope.config = angular.merge({}, $scope.defaultConfig, $scope.config);
3414+
$scope.config = pfUtils.merge($scope.defaultConfig, $scope.config);
33643415
if ($scope.config.selectItems && $scope.config.showSelectBox) {
33653416
throw new Error('pfDataList - ' +
33663417
'Illegal use of pfDataList directive! ' +
@@ -3371,7 +3422,7 @@ angular.module('patternfly.views').directive('pfDataList', [
33713422

33723423
link: function (scope, element, attrs) {
33733424
attrs.$observe('config', function () {
3374-
scope.config = angular.merge({}, scope.defaultConfig, scope.config);
3425+
scope.config = pfUtils.merge(scope.defaultConfig, scope.config);
33753426
if (!scope.config.selectItems) {
33763427
scope.config.selectedItems = [];
33773428
}
@@ -3463,8 +3514,8 @@ angular.module('patternfly.views').directive('pfDataList', [
34633514
};
34643515
}
34653516
};
3466-
}
3467-
]);
3517+
}]
3518+
);
34683519
;/**
34693520
* @ngdoc directive
34703521
* @name patternfly.views.directive:pfDataTiles
@@ -3658,8 +3709,7 @@ angular.module('patternfly.views').directive('pfDataList', [
36583709
</file>
36593710
</example>
36603711
*/
3661-
angular.module('patternfly.views').directive('pfDataTiles', [
3662-
function () {
3712+
angular.module('patternfly.views').directive('pfDataTiles', ["pfUtils", function (pfUtils) {
36633713
'use strict';
36643714
return {
36653715
restrict: 'A',
@@ -3686,7 +3736,7 @@ angular.module('patternfly.views').directive('pfDataTiles', [
36863736
onDblClick: null
36873737
};
36883738

3689-
$scope.config = angular.merge({}, $scope.defaultConfig, $scope.config);
3739+
$scope.config = pfUtils.merge($scope.defaultConfig, $scope.config);
36903740
if ($scope.config.selectItems && $scope.config.showSelectBox) {
36913741
throw new Error('pfDataTiles - ' +
36923742
'Illegal use of pfDataTiles directive! ' +
@@ -3695,7 +3745,7 @@ angular.module('patternfly.views').directive('pfDataTiles', [
36953745
}],
36963746
link: function (scope, element, attrs) {
36973747
attrs.$observe('config', function () {
3698-
scope.config = angular.merge({}, scope.defaultConfig, scope.config);
3748+
scope.config = pfUtils.merge(scope.defaultConfig, scope.config);
36993749
if (!scope.config.selectItems) {
37003750
scope.config.selectedItems = [];
37013751
}
@@ -3789,8 +3839,8 @@ angular.module('patternfly.views').directive('pfDataTiles', [
37893839
};
37903840
}
37913841
};
3792-
}
3793-
]);
3842+
}]
3843+
);
37943844
;/**
37953845
* @ngdoc directive
37963846
* @name patternfly.views.directive:pfDataToolbar

dist/angular-patternfly.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/charts/charts.module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
* Charts module for patternfly. Must Include d3.js and c3.js to use
66
*
77
*/
8-
angular.module('patternfly.charts', []);
8+
angular.module('patternfly.charts', ['patternfly.utils']);
99

src/charts/donut/donut-pct-chart-directive.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
</file>
208208
</example>
209209
*/
210-
angular.module('patternfly.charts').directive('pfDonutPctChart', function (c3ChartDefaults, $timeout) {
210+
angular.module('patternfly.charts').directive('pfDonutPctChart', function (c3ChartDefaults, pfUtils, $timeout) {
211211
'use strict';
212212

213213
return {
@@ -331,7 +331,7 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', function (c3Cha
331331
$scope.config.tooltip = donutTooltip(scope);
332332
};
333333

334-
$scope.config = angular.merge({}, c3ChartDefaults.getDefaultDonutConfig(), $scope.config);
334+
$scope.config = pfUtils.merge(c3ChartDefaults.getDefaultDonutConfig(), $scope.config);
335335
$scope.updateAll($scope);
336336
}
337337
],

src/charts/sparkline/sparkline-chart.directive.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
</file>
131131
</example>
132132
*/
133-
angular.module('patternfly.charts').directive('pfSparklineChart', function (c3ChartDefaults) {
133+
angular.module('patternfly.charts').directive('pfSparklineChart', function (c3ChartDefaults, pfUtils) {
134134
'use strict';
135135
return {
136136
restrict: 'A',
@@ -287,7 +287,7 @@ angular.module('patternfly.charts').directive('pfSparklineChart', function (c3Ch
287287
$scope.defaultConfig.units = '';
288288

289289
// Override defaults with callers specifications
290-
$scope.config = angular.merge({},$scope.defaultConfig, $scope.config);
290+
$scope.config = pfUtils.merge($scope.defaultConfig, $scope.config);
291291

292292
// Convert the given data to C3 chart format
293293
$scope.config.data = $scope.getSparklineData($scope.chartData);
@@ -296,7 +296,7 @@ angular.module('patternfly.charts').directive('pfSparklineChart', function (c3Ch
296296

297297
link: function (scope) {
298298
scope.$watch('config', function () {
299-
scope.config = angular.merge({}, scope.defaultConfig, scope.config);
299+
scope.config = pfUtils.merge(scope.defaultConfig, scope.config);
300300
}, true);
301301
scope.$watch('chartHeight', function () {
302302
scope.config.size.height = scope.chartHeight;

src/utils/utils.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
(function () {
2+
'use strict';
3+
4+
angular.module('patternfly.utils').constant('pfUtils', {
5+
merge: function (source1, source2) {
6+
var retValue;
7+
8+
if (typeof angular.merge === 'function') {
9+
retValue = this.angularMerge(source1, source2);
10+
} else if (typeof _.merge === 'function') {
11+
retValue = this._merge(source1, source2);
12+
} else if (typeof $.extend === 'function') {
13+
retValue = this.$extend(source1, source2);
14+
} else {
15+
retValue = this.mergeDeep(source1, source2);
16+
}
17+
18+
return retValue;
19+
},
20+
angularMerge: function (source1, source2) {
21+
return angular.merge({}, source1, source2);
22+
},
23+
_merge: function (source1, source2) {
24+
return _.merge({}, source1, source2);
25+
},
26+
$extend: function (source1, source2) {
27+
return $.extend(true, angular.copy(source1), source2);
28+
},
29+
mergeDeep: function (source1, source2) {
30+
return mergeDeep({}, angular.copy(source1), angular.copy(source2));
31+
}
32+
});
33+
})();
34+
35+
/* This function does not merge/concat Arrays.
36+
* It replaces the earlier Array with any latter Array.
37+
*/
38+
function mergeDeep (dst) {
39+
'use strict';
40+
angular.forEach(arguments, function (obj) {
41+
if (obj !== dst) {
42+
angular.forEach(obj, function (value, key) {
43+
if (dst[key] && dst[key].constructor && dst[key].constructor === Object) {
44+
mergeDeep(dst[key], value);
45+
} else {
46+
dst[key] = value;
47+
}
48+
});
49+
}
50+
});
51+
return dst;
52+
}

src/views/datalist/data-list-directive.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@
192192
</file>
193193
</example>
194194
*/
195-
angular.module('patternfly.views').directive('pfDataList', [
196-
function () {
195+
angular.module('patternfly.views').directive('pfDataList', function (pfUtils) {
197196
'use strict';
198197
return {
199198
restrict: 'A',
@@ -222,7 +221,7 @@ angular.module('patternfly.views').directive('pfDataList', [
222221
onDblClick: null
223222
};
224223

225-
$scope.config = angular.merge({}, $scope.defaultConfig, $scope.config);
224+
$scope.config = pfUtils.merge($scope.defaultConfig, $scope.config);
226225
if ($scope.config.selectItems && $scope.config.showSelectBox) {
227226
throw new Error('pfDataList - ' +
228227
'Illegal use of pfDataList directive! ' +
@@ -233,7 +232,7 @@ angular.module('patternfly.views').directive('pfDataList', [
233232

234233
link: function (scope, element, attrs) {
235234
attrs.$observe('config', function () {
236-
scope.config = angular.merge({}, scope.defaultConfig, scope.config);
235+
scope.config = pfUtils.merge(scope.defaultConfig, scope.config);
237236
if (!scope.config.selectItems) {
238237
scope.config.selectedItems = [];
239238
}
@@ -326,4 +325,4 @@ angular.module('patternfly.views').directive('pfDataList', [
326325
}
327326
};
328327
}
329-
]);
328+
);

src/views/datatiles/data-tiles-directive.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@
191191
</file>
192192
</example>
193193
*/
194-
angular.module('patternfly.views').directive('pfDataTiles', [
195-
function () {
194+
angular.module('patternfly.views').directive('pfDataTiles', function (pfUtils) {
196195
'use strict';
197196
return {
198197
restrict: 'A',
@@ -219,7 +218,7 @@ angular.module('patternfly.views').directive('pfDataTiles', [
219218
onDblClick: null
220219
};
221220

222-
$scope.config = angular.merge({}, $scope.defaultConfig, $scope.config);
221+
$scope.config = pfUtils.merge($scope.defaultConfig, $scope.config);
223222
if ($scope.config.selectItems && $scope.config.showSelectBox) {
224223
throw new Error('pfDataTiles - ' +
225224
'Illegal use of pfDataTiles directive! ' +
@@ -228,7 +227,7 @@ angular.module('patternfly.views').directive('pfDataTiles', [
228227
},
229228
link: function (scope, element, attrs) {
230229
attrs.$observe('config', function () {
231-
scope.config = angular.merge({}, scope.defaultConfig, scope.config);
230+
scope.config = pfUtils.merge(scope.defaultConfig, scope.config);
232231
if (!scope.config.selectItems) {
233232
scope.config.selectedItems = [];
234233
}
@@ -323,4 +322,4 @@ angular.module('patternfly.views').directive('pfDataTiles', [
323322
}
324323
};
325324
}
326-
]);
325+
);

0 commit comments

Comments
 (0)