blob: 0185e894037bd1aba53ab1bd1bf9c7f63c00568a [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
Steven Burrowsaf96a212016-12-28 12:57:02 +000026 var panel, gs, flash, ls;
Steven Burrows86af4352016-11-16 18:19:12 -060027
28 // Internal State
29 var subRegionPanel, subRegionData;
30
31 function init() {
Steven Burrowsaf96a212016-12-28 12:57:02 +000032 subRegionPanel = panel();
Steven Burrows86af4352016-11-16 18:19:12 -060033 }
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 }
Steven Burrowsaf96a212016-12-28 12:57:02 +000046 };
47 }
Steven Burrows86af4352016-11-16 18:19:12 -060048
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]);
Steven Burrowsaf96a212016-12-28 12:57:02 +000068 ls.listProps(tbody, subRegionData);
Steven Burrows86af4352016-11-16 18:19:12 -060069 }
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')
Steven Burrowsaf96a212016-12-28 12:57:02 +000090 .factory('Topo2SubRegionPanelService', [
91 'Topo2DetailsPanelService', 'GlyphService', 'FlashService', 'ListService',
92 function (_ps_, _gs_, _flash_, _ls_) {
Steven Burrows86af4352016-11-16 18:19:12 -060093
Steven Burrowsaf96a212016-12-28 12:57:02 +000094 panel = _ps_;
Steven Burrows86af4352016-11-16 18:19:12 -060095 gs = _gs_;
Steven Burrows86af4352016-11-16 18:19:12 -060096 flash = _flash_;
Steven Burrowsaf96a212016-12-28 12:57:02 +000097 ls = _ls_;
Steven Burrows86af4352016-11-16 18:19:12 -060098
99 return {
100 displayPanel: displayPanel,
101 init: init,
102 show: show,
103 hide: hide,
104 toggle: toggle,
105 destroy: destroy,
106 isVisible: function () { return subRegionPanel.isVisible(); }
107 };
108 }
109 ]);
110
111})();