blob: b5e49b78cd9dd8bf92fa83952881b642baabe534 [file] [log] [blame]
Steven Burrows86af4352016-11-16 18:19:12 -06001/*
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 Layout Module.
19 Module that contains the d3.force.layout logic
20 */
21
22(function () {
23 'use strict';
24
25 // Injected Services
26 var Panel, gs, wss, flash, listProps;
27
28 // Internal State
29 var subRegionPanel, subRegionData;
30
31 function init() {
32 subRegionPanel = Panel();
33 }
34
35 function formatSubRegionData(data) {
36 return {
37 title: data.get('name'),
38 propOrder: ['Id', 'Type', '-', 'Number of Devices', 'Number of Hosts'],
39 props: {
40 '-': '',
41 'Id': data.get('id'),
42 'Type': data.get('nodeType'),
43 'Number of Devices': data.get('nDevs'),
44 'Number of Hosts': data.get('nHosts')
45 }
46 }
47 };
48
49 function displayPanel(data) {
50 init();
51 subRegionData = formatSubRegionData(data);
52 render();
53 }
54
55 function render() {
56 subRegionPanel.el.show();
57 subRegionPanel.emptyRegions();
58
59 var svg = subRegionPanel.appendToHeader('div')
60 .classed('icon', true)
61 .append('svg'),
62 title = subRegionPanel.appendToHeader('h2'),
63 table = subRegionPanel.appendToBody('table'),
64 tbody = table.append('tbody');
65
66 title.text(subRegionData.title);
67 gs.addGlyph(svg, 'bird', 24, 0, [1, 1]);
68 listProps(tbody, subRegionData);
69 }
70
71 function show() {
72 subRegionPanel.el.show();
73 }
74
75 function hide() {
76 subRegionPanel.el.hide();
77 }
78
79 function toggle() {
80 var on = subRegionPanel.el.toggle(),
81 verb = on ? 'Show' : 'Hide';
82 flash.flash(verb + ' subRegion Panel');
83 }
84
85 function destroy() {
86 subRegionPanel.destroy();
87 }
88
89 angular.module('ovTopo2')
90 .factory('Topo2SubRegionPanelService',
91 ['Topo2DetailsPanelService', 'GlyphService', 'WebSocketService', 'FlashService', 'ListService',
92 function (_ps_, _gs_, _wss_, _flash_, _listService_) {
93
94 Panel = _ps_;
95 gs = _gs_;
96 wss = _wss_;
97 flash = _flash_;
98 listProps = _listService_;
99
100 return {
101 displayPanel: displayPanel,
102 init: init,
103 show: show,
104 hide: hide,
105 toggle: toggle,
106 destroy: destroy,
107 isVisible: function () { return subRegionPanel.isVisible(); }
108 };
109 }
110 ]);
111
112})();