OLD | NEW |
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 YUI.add('juju-notification-controller', function(Y) { | 3 YUI.add('juju-notification-controller', function(Y) { |
4 | 4 |
5 var juju = Y.namespace('juju'); | 5 var juju = Y.namespace('juju'); |
6 | 6 |
7 var _changeNotificationOpToWords = function(op) { | 7 var _changeNotificationOpToWords = function(op) { |
8 if (op === 'add') { | 8 if (op === 'add') { |
9 return 'created'; | 9 return 'created'; |
10 } | 10 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 }, | 139 }, |
140 level: function() { | 140 level: function() { |
141 return 'info'; | 141 return 'info'; |
142 } | 142 } |
143 } | 143 } |
144 }, | 144 }, |
145 /* | 145 /* |
146 * Process new delta stream events and see if we need new notifications | 146 * Process new delta stream events and see if we need new notifications |
147 */ | 147 */ |
148 generate_notices: function(delta_evt) { | 148 generate_notices: function(delta_evt) { |
149 console.log('Generating Notices', this, this.getAttrs()); | |
150 var self = this, | 149 var self = this, |
151 rules = this.ingest_rules, | 150 rules = this.ingest_rules, |
152 app = this.get('app'), | 151 app = this.get('app'), |
153 notifications = this.get('notifications'); | 152 notifications = this.get('notifications'); |
154 | 153 |
155 delta_evt.data.result.forEach(function(change) { | 154 delta_evt.data.result.forEach(function(change) { |
156 var change_type = change[0], | 155 var change_type = change[0], |
157 change_op = change[1], | 156 change_op = change[1], |
158 change_data = change[2], | 157 change_data = change[2], |
159 notify_data = {isDelta: true}, | 158 notify_data = {isDelta: true}, |
160 rule = rules[change_type], | 159 rule = rules[change_type], |
161 model; | 160 model; |
162 | 161 |
163 /* | 162 /* |
164 * Data ingestion rules | 163 * Data ingestion rules |
165 * Create notifications for incoming deltas | 164 * Create notifications for incoming deltas |
166 * Promote some notifications to the 'show me' list | 165 * Promote some notifications to the 'show me' list |
167 * Also: | 166 * Also: |
168 * - for each change event see if there is an notice | 167 * - for each change event see if there is an notice |
169 * relating to that object in the model list | 168 * relating to that object in the model list |
170 * -- see if the current change event invalidates the need | 169 * -- see if the current change event invalidates the need |
171 * to show the existing notices | 170 * to show the existing notices |
172 * -- make the new notice as 'must see' or not ( | 171 * -- make the new notice as 'must see' or not ( |
173 * errors, etc) | 172 * errors, etc) |
174 * - add a notification for the event | 173 * - add a notification for the event |
175 */ | 174 */ |
176 | 175 |
177 // Dispatch ingestion rules (which may mutate either the | 176 // Dispatch ingestion rules (which may mutate either the |
178 // current 'notifications' or models within it (notice status) | 177 // current 'notifications' or models within it (notice status) |
179 | 178 |
180 // 'level' must be called first as 'title' and 'message' may | 179 // 'level' must be called first as 'title' and 'message' may |
181 // depend on it being set. | 180 // depend on it being set. |
182 ['level', 'title', 'message'].forEach(function(attr) { | 181 ['level', 'title', 'message'].forEach(function(attr) { |
183 var active_rule = rule; | 182 var active_rule = rule; |
184 if (!active_rule) { | 183 if (!active_rule) { |
185 return; | 184 return; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 } | 226 } |
228 }); | 227 }); |
229 | 228 |
230 juju.NotificationController = NotificationController; | 229 juju.NotificationController = NotificationController; |
231 juju._changeNotificationOpToWords = _changeNotificationOpToWords; | 230 juju._changeNotificationOpToWords = _changeNotificationOpToWords; |
232 juju._relationNotifications = _relationNotifications; | 231 juju._relationNotifications = _relationNotifications; |
233 | 232 |
234 }, '0.1.0', { | 233 }, '0.1.0', { |
235 requires: ['juju-models'] | 234 requires: ['juju-models'] |
236 }); | 235 }); |
OLD | NEW |