blob: c426d642315a9b5483b992bc3c354f12c1a36e6e [file] [log] [blame]
Steven Burrows57e24e92016-08-04 18:38:24 +01001/*
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 SubRegion Module.
19 Module that holds the sub-regions for a region
20 */
21
22(function () {
23 'use strict';
24
Steven Burrows9edc7e02016-08-29 11:52:07 +010025 var Collection, Model;
Steven Burrows6deb4ce2016-08-26 16:06:23 +010026
27 var remappedDeviceTypes = {
28 virtual: 'cord'
29 };
30
Steven Burrows57e24e92016-08-04 18:38:24 +010031 function createSubRegionCollection(data, region) {
32
33 var SubRegionCollection = Collection.extend({
Steven Burrowsaf96a212016-12-28 12:57:02 +000034 model: Model,
35 region: region
Steven Burrows57e24e92016-08-04 18:38:24 +010036 });
37
38 return new SubRegionCollection(data);
39 }
40
41 angular.module('ovTopo2')
Steven Burrowsaf96a212016-12-28 12:57:02 +000042 .factory('Topo2SubRegionService', [
Simon Hunt9edd1722017-03-10 17:43:26 -080043 '$location', 'WebSocketService', 'Topo2Collection', 'Topo2NodeModel',
Steven Burrows6a4febe2017-04-20 11:45:33 -040044 'Topo2SubRegionPanelService', 'Topo2RegionNavigationService',
Steven Burrows57e24e92016-08-04 18:38:24 +010045
Steven Burrows6a4febe2017-04-20 11:45:33 -040046 function ($loc, wss, _c_, NodeModel, t2srp, t2rns) {
Steven Burrows57e24e92016-08-04 18:38:24 +010047
Steven Burrowsaf96a212016-12-28 12:57:02 +000048 Collection = _c_;
Steven Burrows6deb4ce2016-08-26 16:06:23 +010049
Steven Burrowsaf96a212016-12-28 12:57:02 +000050 Model = NodeModel.extend({
Steven Burrows5fa057e2017-03-15 17:07:56 +000051
52 nodeType: 'sub-region',
Steven Burrowsaf96a212016-12-28 12:57:02 +000053 events: {
54 'dblclick': 'navigateToRegion',
55 'click': 'onClick'
56 },
Steven Burrows5fa057e2017-03-15 17:07:56 +000057
58 initialize: function () {
59 this.super = this.constructor.__super__;
60 this.super.initialize.apply(this, arguments);
61 },
Steven Burrowsaf96a212016-12-28 12:57:02 +000062 onChange: function () {
63 // Update class names when the model changes
64 if (this.el) {
65 this.el.attr('class', this.svgClassName());
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070066 }
Steven Burrowsaf96a212016-12-28 12:57:02 +000067 },
Steven Burrows5fa057e2017-03-15 17:07:56 +000068 showDetails: function () {
69 t2srp.displayPanel(this);
70 },
Steven Burrowsaf96a212016-12-28 12:57:02 +000071 icon: function () {
72 var type = this.get('type');
73 return remappedDeviceTypes[type] || type || 'm_cloud';
74 },
Steven Burrowsaf96a212016-12-28 12:57:02 +000075 navigateToRegion: function () {
Steven Burrowsaf96a212016-12-28 12:57:02 +000076 if (d3.event.defaultPrevented) return;
Steven Burrows6a4febe2017-04-20 11:45:33 -040077 t2rns.navigateToRegion(this.get('id'));
Steven Burrowsaf96a212016-12-28 12:57:02 +000078 t2srp.hide();
79 }
80 });
81
82 return {
83 createSubRegionCollection: createSubRegionCollection
84 };
85 }
86 ]);
Steven Burrows57e24e92016-08-04 18:38:24 +010087
88})();