blob: bbfd808eb38be63c2d0b78f617f4f94107d4dc79 [file] [log] [blame]
Steven Burrows86af4352016-11-16 18:19:12 -06001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Steven Burrows86af4352016-11-16 18:19:12 -06003 *
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'),
Simon Hunt3d875ec2017-09-07 16:52:59 -070038 propLabels: {
39 '-': '-',
40 'id': 'Id',
41 'nodeType': 'Type',
42 'nDevs': '# Devices',
43 'nHosts': '# Hosts',
Steven Burrows1c2a9682017-07-14 16:52:46 +010044 },
Simon Hunt3d875ec2017-09-07 16:52:59 -070045 propValues: {
46 '-': '-',
47 'id': data.get('id'),
48 'nodeType': data.get('nodeType'),
49 'nDevs': data.get('nDevs'),
50 'nHosts': data.get('nHosts'),
51 },
52 propOrder: [
53 'id',
54 'nodeType',
55 '-',
56 'nDevs',
57 'nHosts',
58 ],
Steven Burrowsaf96a212016-12-28 12:57:02 +000059 };
60 }
Steven Burrows86af4352016-11-16 18:19:12 -060061
62 function displayPanel(data) {
63 init();
64 subRegionData = formatSubRegionData(data);
65 render();
66 }
67
68 function render() {
Steven Burrowsc59481f2017-04-13 10:01:15 -070069 subRegionPanel.show();
Steven Burrows86af4352016-11-16 18:19:12 -060070 subRegionPanel.emptyRegions();
71
72 var svg = subRegionPanel.appendToHeader('div')
73 .classed('icon', true)
74 .append('svg'),
75 title = subRegionPanel.appendToHeader('h2'),
76 table = subRegionPanel.appendToBody('table'),
77 tbody = table.append('tbody');
78
79 title.text(subRegionData.title);
80 gs.addGlyph(svg, 'bird', 24, 0, [1, 1]);
Steven Burrowsaf96a212016-12-28 12:57:02 +000081 ls.listProps(tbody, subRegionData);
Steven Burrows86af4352016-11-16 18:19:12 -060082 }
83
84 function show() {
Steven Burrowsc59481f2017-04-13 10:01:15 -070085 subRegionPanel.show();
Steven Burrows86af4352016-11-16 18:19:12 -060086 }
87
88 function hide() {
89 subRegionPanel.el.hide();
90 }
91
92 function toggle() {
93 var on = subRegionPanel.el.toggle(),
94 verb = on ? 'Show' : 'Hide';
95 flash.flash(verb + ' subRegion Panel');
96 }
97
98 function destroy() {
99 subRegionPanel.destroy();
100 }
101
102 angular.module('ovTopo2')
Steven Burrowsaf96a212016-12-28 12:57:02 +0000103 .factory('Topo2SubRegionPanelService', [
104 'Topo2DetailsPanelService', 'GlyphService', 'FlashService', 'ListService',
105 function (_ps_, _gs_, _flash_, _ls_) {
Steven Burrows86af4352016-11-16 18:19:12 -0600106
Steven Burrowsaf96a212016-12-28 12:57:02 +0000107 panel = _ps_;
Steven Burrows86af4352016-11-16 18:19:12 -0600108 gs = _gs_;
Steven Burrows86af4352016-11-16 18:19:12 -0600109 flash = _flash_;
Steven Burrowsaf96a212016-12-28 12:57:02 +0000110 ls = _ls_;
Steven Burrows86af4352016-11-16 18:19:12 -0600111
112 return {
113 displayPanel: displayPanel,
114 init: init,
115 show: show,
116 hide: hide,
117 toggle: toggle,
118 destroy: destroy,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100119 isVisible: function () { return subRegionPanel.isVisible(); },
Steven Burrows86af4352016-11-16 18:19:12 -0600120 };
Steven Burrows1c2a9682017-07-14 16:52:46 +0100121 },
Steven Burrows86af4352016-11-16 18:19:12 -0600122 ]);
123
124})();