Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | ONOS GUI -- Topology Region Module. |
| 19 | Module that holds the current region in memory |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame] | 25 | // Injected Services |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 26 | var Model; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 27 | |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 28 | // Internal |
Steven Burrows | b15a394 | 2017-01-17 17:25:04 +0000 | [diff] [blame] | 29 | var instance; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 30 | |
Steven Burrows | 8ea5dea | 2016-12-27 13:28:41 +0000 | [diff] [blame] | 31 | // 'static' vars |
| 32 | var ROOT = '(root)'; |
| 33 | |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 34 | angular.module('ovTopo2') |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 35 | .factory('Topo2RegionService', [ |
| 36 | '$log', 'Topo2Model', 'Topo2SubRegionService', 'Topo2DeviceService', |
Steven Burrows | 1aa4f58 | 2016-12-13 15:05:41 -0500 | [diff] [blame] | 37 | 'Topo2HostService', 'Topo2LinkService', 'Topo2ZoomService', 'Topo2DetailsPanelService', |
Steven Burrows | 86b74fc | 2017-02-22 00:15:16 +0000 | [diff] [blame] | 38 | 'Topo2BreadcrumbService', 'Topo2ViewController', 'Topo2SpriteLayerService', 'Topo2MapService', |
Steven Burrows | 6501de9 | 2017-04-12 15:10:34 -0700 | [diff] [blame] | 39 | 'Topo2MapConfigService', 'Topo2PeerRegionService', 'Topo2NoDevicesConnectedService', |
Steven Burrows | b11a8b8 | 2017-03-10 16:00:31 +0000 | [diff] [blame] | 40 | function ($log, _Model_, t2sr, t2ds, t2hs, t2ls, t2zs, t2dps, t2bcs, ViewController, |
Steven Burrows | 6501de9 | 2017-04-12 15:10:34 -0700 | [diff] [blame] | 41 | t2sls, t2ms, t2mcs, t2pr, t2ndcs) { |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 42 | |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 43 | Model = _Model_; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 44 | |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 45 | var Region = ViewController.extend({ |
| 46 | initialize: function () { |
| 47 | instance = this; |
| 48 | this.model = null; |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 49 | |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 50 | this.bgRendered = false; |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 51 | this.regionData = null; |
| 52 | this.peers = null; |
Steven Burrows | b11a8b8 | 2017-03-10 16:00:31 +0000 | [diff] [blame] | 53 | |
| 54 | var RegionModel = Model.extend({ |
| 55 | findNodeById: this.findNodeById, |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 56 | nodes: this.regionNodes.bind(this) |
Steven Burrows | b11a8b8 | 2017-03-10 16:00:31 +0000 | [diff] [blame] | 57 | }); |
| 58 | |
| 59 | this.model = new RegionModel(); |
Steven Burrows | 6de27f4 | 2017-03-30 16:21:27 +0100 | [diff] [blame] | 60 | this.createEmptyModel(); |
| 61 | |
| 62 | }, |
| 63 | createEmptyModel: function () { |
| 64 | this.model.set({ subregions: t2sr.createSubRegionCollection([], this) }); |
| 65 | this.model.set({ devices: t2ds.createDeviceCollection([], this) }); |
| 66 | this.model.set({ hosts: t2hs.createHostCollection([], this) }); |
| 67 | this.model.set({ peerRegions: t2pr.createCollection([], this) }); |
| 68 | this.model.set({ links: t2ls.createLinkCollection([], this) }); |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 69 | }, |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 70 | isLoadComplete: function() { |
Steven Burrows | 247ab15 | 2017-03-29 13:55:54 +0100 | [diff] [blame] | 71 | return this.bgRendered && this.regionData && this.peers; |
| 72 | }, |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 73 | loaded: function (key, value) { |
| 74 | this[key] = value; |
Steven Burrows | 247ab15 | 2017-03-29 13:55:54 +0100 | [diff] [blame] | 75 | if (this.isLoadComplete()) { |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 76 | this.startRegion(); |
| 77 | } |
| 78 | }, |
| 79 | startRegion: function () { |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 80 | |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 81 | this.model.set({ |
Steven Burrows | b11a8b8 | 2017-03-10 16:00:31 +0000 | [diff] [blame] | 82 | id: this.regionData.id, |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 83 | layerOrder: this.regionData.layerOrder |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 84 | }); |
| 85 | |
Steven Burrows | 32ce1d9 | 2017-04-13 13:18:44 -0700 | [diff] [blame] | 86 | this.sortMultiLinks(); |
Steven Burrows | 4a1b553 | 2017-04-28 11:08:07 -0400 | [diff] [blame] | 87 | this.assignPeerLocations(); |
Steven Burrows | 32ce1d9 | 2017-04-13 13:18:44 -0700 | [diff] [blame] | 88 | |
Steven Burrows | 2b29ca4 | 2017-05-12 10:58:05 -0400 | [diff] [blame] | 89 | // TODO: RegionLinks are dublicated in JSON Payload |
| 90 | |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 91 | this.model.set({ subregions: t2sr.createSubRegionCollection(this.regionData.subregions, this) }); |
| 92 | this.model.set({ devices: t2ds.createDeviceCollection(this.regionData.devices, this) }); |
| 93 | this.model.set({ hosts: t2hs.createHostCollection(this.regionData.hosts, this) }); |
| 94 | this.model.set({ peerRegions: t2pr.createCollection(this.peers, this) }); |
| 95 | this.model.set({ links: t2ls.createLinkCollection(this.regionData.links, this) }); |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 96 | |
| 97 | // Hide Breadcrumbs if there are no subregions configured in the root region |
| 98 | if (this.isRootRegion() && !this.model.get('subregions').models.length) { |
| 99 | t2bcs.hide(); |
| 100 | } |
Steven Burrows | 3cc0c37 | 2017-02-10 15:15:24 +0000 | [diff] [blame] | 101 | |
Steven Burrows | b11a8b8 | 2017-03-10 16:00:31 +0000 | [diff] [blame] | 102 | this.layout.createForceLayout(); |
Steven Burrows | 6501de9 | 2017-04-12 15:10:34 -0700 | [diff] [blame] | 103 | this.displayNoDevs(); |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 104 | }, |
| 105 | clear: function () { |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 106 | this.regionData = null; |
Steven Burrows | 6de27f4 | 2017-03-30 16:21:27 +0100 | [diff] [blame] | 107 | this.createEmptyModel(); |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 108 | }, |
Steven Burrows | 32ce1d9 | 2017-04-13 13:18:44 -0700 | [diff] [blame] | 109 | removePort: function (key) { |
| 110 | var regex = new RegExp('^[^/]*'); |
| 111 | return regex.exec(key)[0]; |
| 112 | }, |
Steven Burrows | 4a1b553 | 2017-04-28 11:08:07 -0400 | [diff] [blame] | 113 | assignPeerLocations: function () { |
| 114 | var _this = this; |
| 115 | _.each(this.regionData.peerLocations, function (location, id) { |
| 116 | _.each(_this.peers, function (peer) { |
| 117 | if (peer.id === id) { |
| 118 | peer.location = location; |
| 119 | } |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 120 | }) |
Steven Burrows | 4a1b553 | 2017-04-28 11:08:07 -0400 | [diff] [blame] | 121 | }); |
| 122 | }, |
Steven Burrows | 32ce1d9 | 2017-04-13 13:18:44 -0700 | [diff] [blame] | 123 | sortMultiLinks: function () { |
| 124 | var _this = this, |
| 125 | deviceConnections = {}; |
| 126 | |
| 127 | _.each(this.regionData.links, function (link) { |
Steven Burrows | 32ce1d9 | 2017-04-13 13:18:44 -0700 | [diff] [blame] | 128 | |
Steven Burrows | 9ce0e40 | 2017-04-20 16:39:17 -0400 | [diff] [blame] | 129 | var epA = _this.removePort(link.epA), |
| 130 | epB = _this.removePort(link.epB), |
| 131 | key = epA + '~' + epB, |
| 132 | collection = deviceConnections[key] || [], |
| 133 | dup = _.find(collection, link); |
Steven Burrows | 32ce1d9 | 2017-04-13 13:18:44 -0700 | [diff] [blame] | 134 | |
Steven Burrows | 0bc6665 | 2017-04-20 13:04:10 -0400 | [diff] [blame] | 135 | // TODO: Investigate why region contains dup links?!?! |
| 136 | // FIXME: This shouldn't be needed - The backend is sending dups |
| 137 | // and this is preventing the client thinking its a multilink |
Steven Burrows | 9ce0e40 | 2017-04-20 16:39:17 -0400 | [diff] [blame] | 138 | if (!dup) { |
| 139 | collection.push(link); |
Steven Burrows | 0bc6665 | 2017-04-20 13:04:10 -0400 | [diff] [blame] | 140 | } |
Steven Burrows | 9ce0e40 | 2017-04-20 16:39:17 -0400 | [diff] [blame] | 141 | |
| 142 | deviceConnections[key] = collection; |
Steven Burrows | 32ce1d9 | 2017-04-13 13:18:44 -0700 | [diff] [blame] | 143 | }); |
| 144 | |
Steven Burrows | 9ce0e40 | 2017-04-20 16:39:17 -0400 | [diff] [blame] | 145 | _.forIn(deviceConnections, function (collection) { |
| 146 | if (collection.length > 1) { |
| 147 | _.each(collection, function (link, index) { |
Steven Burrows | 32ce1d9 | 2017-04-13 13:18:44 -0700 | [diff] [blame] | 148 | link.multiline = { |
Steven Burrows | 9ce0e40 | 2017-04-20 16:39:17 -0400 | [diff] [blame] | 149 | deviceLinks: collection.length, |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 150 | index: index |
| 151 | } |
Steven Burrows | 9ce0e40 | 2017-04-20 16:39:17 -0400 | [diff] [blame] | 152 | }); |
Steven Burrows | 32ce1d9 | 2017-04-13 13:18:44 -0700 | [diff] [blame] | 153 | } |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 154 | }) |
| 155 | |
Steven Burrows | 32ce1d9 | 2017-04-13 13:18:44 -0700 | [diff] [blame] | 156 | }, |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 157 | isRootRegion: function () { |
| 158 | return this.model.get('id') === ROOT; |
| 159 | }, |
| 160 | findNodeById: function (link, id) { |
| 161 | if (link.get('type') !== 'UiEdgeLink') { |
Steven Burrows | 32ce1d9 | 2017-04-13 13:18:44 -0700 | [diff] [blame] | 162 | id = this.removePort(id); |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 163 | } |
| 164 | return this.model.get('devices').get(id) || |
| 165 | this.model.get('hosts').get(id) || |
| 166 | this.model.get('subregions').get(id); |
| 167 | }, |
| 168 | regionNodes: function () { |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 169 | if (this.model) { |
| 170 | return [].concat( |
| 171 | this.model.get('devices').models, |
| 172 | this.model.get('hosts').models, |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 173 | this.model.get('subregions').models, |
| 174 | this.model.get('peerRegions').models |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 175 | ); |
| 176 | } |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 177 | return []; |
| 178 | }, |
| 179 | regionLinks: function () { |
Steven Burrows | b11a8b8 | 2017-03-10 16:00:31 +0000 | [diff] [blame] | 180 | return this.model.get('links').models; |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 181 | }, |
Steven Burrows | b15a394 | 2017-01-17 17:25:04 +0000 | [diff] [blame] | 182 | getLink: function (linkId) { |
| 183 | return this.model.get('links').get(linkId); |
| 184 | }, |
Steven Burrows | 42eb9e2 | 2017-02-06 14:20:24 +0000 | [diff] [blame] | 185 | getDevice: function (deviceId) { |
| 186 | return this.model.get('devices').get(deviceId); |
| 187 | }, |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 188 | filterRegionNodes: function (predicate) { |
| 189 | var nodes = this.regionNodes(); |
| 190 | return _.filter(nodes, predicate); |
| 191 | }, |
| 192 | deselectAllNodes: function () { |
| 193 | var selected = this.filterRegionNodes(function (node) { |
| 194 | return node.get('selected', true); |
| 195 | }); |
| 196 | |
| 197 | if (selected.length) { |
| 198 | |
| 199 | selected.forEach(function (node) { |
| 200 | node.deselect(); |
| 201 | }); |
| 202 | |
| 203 | t2dps().el.hide(); |
| 204 | return true; |
| 205 | } |
| 206 | |
| 207 | return false; |
| 208 | }, |
| 209 | deselectLink: function () { |
| 210 | var selected = _.filter(this.regionLinks(), function (link) { |
| 211 | return link.get('selected', true); |
| 212 | }); |
| 213 | |
| 214 | if (selected.length) { |
| 215 | |
| 216 | selected.forEach(function (link) { |
| 217 | link.deselect(); |
| 218 | }); |
| 219 | |
| 220 | t2dps().el.hide(); |
| 221 | return true; |
| 222 | } |
| 223 | |
| 224 | return false; |
Steven Burrows | b15a394 | 2017-01-17 17:25:04 +0000 | [diff] [blame] | 225 | }, |
Steven Burrows | aea509d | 2017-04-12 14:17:47 -0700 | [diff] [blame] | 226 | toggleHosts: function () { |
| 227 | var state = this.lookupPrefState('hosts'); |
| 228 | this.updatePrefState('hosts', !state); |
Steven Burrows | b15a394 | 2017-01-17 17:25:04 +0000 | [diff] [blame] | 229 | |
Steven Burrows | aea509d | 2017-04-12 14:17:47 -0700 | [diff] [blame] | 230 | _.each(this.model.get('hosts').models, function (host) { |
| 231 | host.setVisibility(); |
| 232 | }); |
| 233 | |
| 234 | _.each(this.model.get('links').models, function (link) { |
| 235 | link.setVisibility(); |
| 236 | }); |
Steven Burrows | 02e67f4 | 2017-04-13 13:59:43 -0700 | [diff] [blame] | 237 | |
| 238 | return !state; |
| 239 | }, |
| 240 | toggleOfflineDevices: function () { |
| 241 | var state = this.lookupPrefState('offline_devices'); |
| 242 | this.updatePrefState('offline_devices', !state); |
| 243 | _.each(this.regionNodes(), function (node) { |
| 244 | node.setOfflineVisibility(); |
| 245 | }); |
| 246 | |
| 247 | return !state; |
Steven Burrows | aea509d | 2017-04-12 14:17:47 -0700 | [diff] [blame] | 248 | }, |
Steven Burrows | b15a394 | 2017-01-17 17:25:04 +0000 | [diff] [blame] | 249 | update: function (event) { |
Steven Burrows | 42eb9e2 | 2017-02-06 14:20:24 +0000 | [diff] [blame] | 250 | |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 251 | if (!this.isLoadComplete()){ |
Steven Burrows | 6de27f4 | 2017-03-30 16:21:27 +0100 | [diff] [blame] | 252 | this.layout.createForceLayout(); |
| 253 | } |
| 254 | |
Steven Burrows | b15a394 | 2017-01-17 17:25:04 +0000 | [diff] [blame] | 255 | if (this[event.type]) { |
| 256 | this[event.type](event); |
Steven Burrows | b15a394 | 2017-01-17 17:25:04 +0000 | [diff] [blame] | 257 | } else { |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 258 | $log.error("Unhanded topology update", event); |
Steven Burrows | b15a394 | 2017-01-17 17:25:04 +0000 | [diff] [blame] | 259 | } |
Steven Burrows | 42eb9e2 | 2017-02-06 14:20:24 +0000 | [diff] [blame] | 260 | |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 261 | this.layout.update() |
Steven Burrows | 6501de9 | 2017-04-12 15:10:34 -0700 | [diff] [blame] | 262 | this.displayNoDevs(); |
| 263 | }, |
| 264 | displayNoDevs: function () { |
| 265 | if (this.regionNodes().length > 0) { |
| 266 | t2ndcs.hide(); |
| 267 | } else { |
| 268 | t2ndcs.show(); |
| 269 | } |
Steven Burrows | b15a394 | 2017-01-17 17:25:04 +0000 | [diff] [blame] | 270 | }, |
| 271 | |
| 272 | // Topology update event handlers |
| 273 | LINK_ADDED_OR_UPDATED: function (event) { |
Steven Burrows | 6de27f4 | 2017-03-30 16:21:27 +0100 | [diff] [blame] | 274 | |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 275 | var regionLinks = this.model.get('links'), |
| 276 | device; |
Steven Burrows | 6de27f4 | 2017-03-30 16:21:27 +0100 | [diff] [blame] | 277 | |
| 278 | if (!regionLinks) { |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 279 | this.model.set({ links: t2ls.createLinkCollection([], this) }) |
Steven Burrows | 6de27f4 | 2017-03-30 16:21:27 +0100 | [diff] [blame] | 280 | } |
| 281 | |
Steven Burrows | b15a394 | 2017-01-17 17:25:04 +0000 | [diff] [blame] | 282 | if (event.memo === 'added') { |
| 283 | var link = this.model.get('links').add(event.data); |
| 284 | link.createLink(); |
Steven Burrows | 6de27f4 | 2017-03-30 16:21:27 +0100 | [diff] [blame] | 285 | $log.debug('Added Link', link); |
Steven Burrows | b15a394 | 2017-01-17 17:25:04 +0000 | [diff] [blame] | 286 | } |
| 287 | }, |
| 288 | LINK_REMOVED: function (event) { |
| 289 | var link = this.getLink(event.subject); |
| 290 | link.remove(); |
Steven Burrows | 42eb9e2 | 2017-02-06 14:20:24 +0000 | [diff] [blame] | 291 | this.model.get('links').remove(link); |
| 292 | }, |
| 293 | DEVICE_ADDED_OR_UPDATED: function (event) { |
| 294 | |
Steven Burrows | 6de27f4 | 2017-03-30 16:21:27 +0100 | [diff] [blame] | 295 | var regionDevices = this.model.get('devices'), |
| 296 | device; |
| 297 | |
| 298 | if (!regionDevices) { |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 299 | this.model.set({ devices: t2ds.createDeviceCollection([], this) }) |
Steven Burrows | 6de27f4 | 2017-03-30 16:21:27 +0100 | [diff] [blame] | 300 | } |
Steven Burrows | 42eb9e2 | 2017-02-06 14:20:24 +0000 | [diff] [blame] | 301 | |
| 302 | if (event.memo === 'added') { |
| 303 | device = this.model.get('devices').add(event.data); |
Simon Hunt | eb3cf54 | 2017-02-10 13:18:41 -0800 | [diff] [blame] | 304 | $log.debug('Added device', device); |
Steven Burrows | 42eb9e2 | 2017-02-06 14:20:24 +0000 | [diff] [blame] | 305 | } else if (event.memo === 'updated') { |
| 306 | device = this.getDevice(event.subject); |
| 307 | device.set(event.data); |
| 308 | } |
| 309 | }, |
| 310 | DEVICE_REMOVED: function (event) { |
| 311 | device.remove(); |
Steven Burrows | 6de27f4 | 2017-03-30 16:21:27 +0100 | [diff] [blame] | 312 | }, |
| 313 | HOST_ADDED_OR_UPDATED: function (event) { |
| 314 | var regionHosts = this.model.get('hosts'), |
| 315 | host; |
| 316 | |
| 317 | if (!regionHosts) { |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 318 | this.model.set({ hosts: t2hs.createHostCollection([], this) }) |
Steven Burrows | 6de27f4 | 2017-03-30 16:21:27 +0100 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | if (event.memo === 'added') { |
| 322 | host = this.model.get('hosts').add(event.data); |
| 323 | $log.debug('Added host', host); |
| 324 | } |
| 325 | }, |
| 326 | REGION_ADDED_OR_UPDATED: function (event) { |
| 327 | var regionSubRegions = this.model.get('subregions'), |
| 328 | region; |
| 329 | |
| 330 | if (!regionSubRegions) { |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 331 | this.model.set({ subregions: t2sr.createSubRegionCollection([], this) }) |
Steven Burrows | 6de27f4 | 2017-03-30 16:21:27 +0100 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | if (event.memo === 'added') { |
| 335 | region = this.model.get('subregions').add(event.data); |
| 336 | $log.debug('Added region', region); |
| 337 | } |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 338 | } |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 339 | }); |
| 340 | |
| 341 | function getInstance() { |
| 342 | return instance || new Region(); |
| 343 | } |
| 344 | |
| 345 | return getInstance(); |
Steven Burrows | b15a394 | 2017-01-17 17:25:04 +0000 | [diff] [blame] | 346 | |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 347 | }]); |
| 348 | |
| 349 | })(); |