blob: bb64578c267d60933504f294982d872ebd4a2c06 [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 Burrowsbbe3dda2016-09-26 14:41:59 -070025 var wss;
Steven Burrows9edc7e02016-08-29 11:52:07 +010026 var Collection, Model;
Steven Burrows6deb4ce2016-08-26 16:06:23 +010027
28 var remappedDeviceTypes = {
29 virtual: 'cord'
30 };
31
Steven Burrows57e24e92016-08-04 18:38:24 +010032 function createSubRegionCollection(data, region) {
33
34 var SubRegionCollection = Collection.extend({
35 model: Model
36 });
37
38 return new SubRegionCollection(data);
39 }
40
41 angular.module('ovTopo2')
42 .factory('Topo2SubRegionService',
Steven Burrowsdfa52b02016-09-02 13:50:43 +010043 ['WebSocketService', 'Topo2Collection', 'Topo2NodeModel',
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070044 'ThemeService', 'Topo2ViewService',
Steven Burrows57e24e92016-08-04 18:38:24 +010045
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070046 function (_wss_, _c_, _NodeModel_, _ts_, _t2vs_) {
Steven Burrows57e24e92016-08-04 18:38:24 +010047
Steven Burrows9edc7e02016-08-29 11:52:07 +010048 wss = _wss_;
Steven Burrowsdfa52b02016-09-02 13:50:43 +010049 Collection = _c_;
Steven Burrows6deb4ce2016-08-26 16:06:23 +010050
51 Model = _NodeModel_.extend({
52 initialize: function () {
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070053 this.super = this.constructor.__super__;
54 this.super.initialize.apply(this, arguments);
55 },
56 events: {
57 'dblclick': 'navigateToRegion'
Steven Burrows6deb4ce2016-08-26 16:06:23 +010058 },
59 nodeType: 'sub-region',
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070060 icon: function () {
61 var type = this.get('type');
62 return remappedDeviceTypes[type] || type || 'm_cloud';
63 },
64 navigateToRegion: function () {
Steven Burrowse3a18842016-09-22 15:33:33 +010065
66 if (d3.event.defaultPrevented) return;
67
Steven Burrows9edc7e02016-08-29 11:52:07 +010068 wss.sendEvent('topo2navRegion', {
69 dir: 'down',
70 rid: this.get('id')
71 });
Steven Burrowsbbe3dda2016-09-26 14:41:59 -070072 }
Steven Burrows6deb4ce2016-08-26 16:06:23 +010073 });
Steven Burrows57e24e92016-08-04 18:38:24 +010074
75 return {
76 createSubRegionCollection: createSubRegionCollection
77 };
78 }
79 ]);
80
81})();