|
57 | 57 | /* @ngInject */ |
58 | 58 | function ConfigurationProvider() { |
59 | 59 | this.mergedConfiguration = {}; |
60 | | - this.addObject(window.webConfig, true); |
61 | | - this.addObject(window.configuration, true); |
| 60 | + this.addConfiguration(window.webConfig, true); |
| 61 | + this.addConfiguration(window.configuration, true); |
62 | 62 | } |
| 63 | + /* @ngInject */ |
63 | 64 | ConfigurationProvider.prototype.$get = function ($q) { |
64 | | - return this.mergedConfiguration; |
| 65 | + return this.getConfiguration(); |
65 | 66 | }; |
66 | | - ConfigurationProvider.prototype.get = function () { |
67 | | - return this.mergedConfiguration; |
68 | | - }; |
69 | | - ConfigurationProvider.prototype.addObject = function (obj, optional) { |
| 67 | + ConfigurationProvider.prototype.$get.$inject = ["$q"]; |
| 68 | + ConfigurationProvider.prototype.addConfiguration = function (obj, optional) { |
70 | 69 | if (obj) { |
71 | 70 | this.mergedConfiguration = merge(this.mergedConfiguration, obj); |
72 | 71 | } |
|
76 | 75 | } |
77 | 76 | } |
78 | 77 | }; |
| 78 | + /** |
| 79 | + * Add a default object that will only add params that aren't already specified |
| 80 | + * @param obj |
| 81 | + */ |
| 82 | + ConfigurationProvider.prototype.addDefaultConfiguration = function (obj) { |
| 83 | + if (obj) { |
| 84 | + this.mergedConfiguration = merge(obj, this.mergedConfiguration); |
| 85 | + } |
| 86 | + }; |
| 87 | + ConfigurationProvider.prototype.getConfiguration = function () { |
| 88 | + return this.mergedConfiguration; |
| 89 | + }; |
79 | 90 | return ConfigurationProvider; |
80 | 91 | }()); |
81 | 92 | exports.ConfigurationProvider = ConfigurationProvider; |
|
84 | 95 | xobj.overrideMimeType("application/json"); |
85 | 96 | xobj.open('GET', 'configuration.json', true); // Replace 'my_data' with the path to your file |
86 | 97 | xobj.onreadystatechange = function () { |
87 | | - if (xobj.readyState == 4 && xobj.status == 200) { |
88 | | - // Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode |
89 | | - window.configuration = JSON.parse(xobj.responseText); |
| 98 | + if (xobj.readyState == 4) { |
| 99 | + if (xobj.status == 200) { |
| 100 | + window.configuration = JSON.parse(xobj.responseText); |
| 101 | + } |
90 | 102 | callback(); |
91 | 103 | } |
92 | 104 | }; |
|
0 commit comments