Simon Hunt
Committed by Gerrit Code Review

ONOS-2850 : Beginnings of Topology Programmable Dialog box --- WIP.

Change-Id: I7e08b3c5d97f409c470eeb97b0f988a14b6d495f
...@@ -96,6 +96,24 @@ html[data-platform='iPad'] #topo-p-detail { ...@@ -96,6 +96,24 @@ html[data-platform='iPad'] #topo-p-detail {
96 height: 30px; 96 height: 30px;
97 } 97 }
98 98
99 +/* --- Topo Dialog Panel --- */
100 +
101 +#topo-p-dialog .dialog-button {
102 + display: inline-block;
103 + cursor: pointer;
104 + height: 20px;
105 + padding: 2px 6px;
106 + margin: 4px;
107 + float: right;
108 +}
109 +
110 +.light #topo-p-dialog .dialog-button {
111 + background-color: #fec;
112 +}
113 +.dark #topo-p-dialog .dialog-button {
114 + background-color: #369;
115 +}
116 +
99 /* --- general topo-panel styling --- */ 117 /* --- general topo-panel styling --- */
100 118
101 .topo-p div.header div.icon { 119 .topo-p div.header div.icon {
......
1 +/*
2 + * Copyright 2015 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 Dialog Module.
19 + Defines functions for manipulating a dialog box.
20 + */
21 +
22 +(function () {
23 + 'use strict';
24 +
25 + // injected refs
26 + var $log, $window, $rootScope, fs, ps, bns;
27 +
28 + // constants
29 + var pCls = 'topo-p',
30 + idDialog = 'topo-p-dialog',
31 + panelOpts = {
32 + width: 300
33 + };
34 +
35 + // internal state
36 + var pApi, panel, dApi;
37 +
38 + // TODO: ESC key invokes Cancel callback
39 + // TODO: Enter invokes OK callback
40 +
41 + // create the dialog; return its API
42 + function createDialog() {
43 + var header, body, footer,
44 + p = ps.createPanel(idDialog, panelOpts);
45 + p.classed(pCls, true);
46 + panel = p;
47 +
48 + function reset() {
49 + p.empty();
50 + p.append('div').classed('header', true);
51 + p.append('div').classed('body', true);
52 + p.append('div').classed('footer', true);
53 +
54 + header = p.el().select('.header');
55 + body = p.el().select('.body');
56 + footer = p.el().select('.footer');
57 + }
58 +
59 + function hAppend(x) {
60 + if (typeof x === 'string') {
61 + return header.append(x);
62 + }
63 + header.node().appendChild(x.node());
64 + return header;
65 + }
66 +
67 + function bAppend(x) {
68 + if (typeof x === 'string') {
69 + return body.append(x);
70 + }
71 + body.node().appendChild(x.node());
72 + return body;
73 + }
74 +
75 + function fAppend(x) {
76 + if (typeof x === 'string') {
77 + return footer.append(x);
78 + }
79 + footer.node().appendChild(x.node());
80 + return footer;
81 + }
82 +
83 + function destroy() {
84 + ps.destroyPanel(idDialog);
85 + }
86 +
87 + return {
88 + reset: reset,
89 + appendHeader: hAppend,
90 + appendBody: bAppend,
91 + appendFooter: fAppend,
92 + destroy: destroy
93 + };
94 + }
95 +
96 + function makeButton(text, callback) {
97 + var cb = fs.isF(callback);
98 +
99 + function invoke() {
100 + cb && cb();
101 + panel.hide();
102 + }
103 + return createDiv('dialog-button')
104 + .text(text)
105 + .on('click', invoke);
106 + }
107 +
108 + function addContent(content) {
109 + if (pApi) {
110 + pApi.appendBody(content);
111 + }
112 + return dApi;
113 + }
114 +
115 + function addButton(text, cb) {
116 + if (pApi) {
117 + pApi.appendFooter(makeButton(text, cb));
118 + }
119 + return dApi;
120 + }
121 +
122 + // opens the dialog (creates if necessary)
123 + function openDialog() {
124 + $log.debug('Open DIALOG');
125 + if (!pApi) {
126 + pApi = createDialog();
127 + }
128 + pApi.reset();
129 + pApi.appendHeader('h2').text('=dialog=');
130 + panel.show();
131 +
132 + // return the dialog object API
133 + dApi = {
134 + addContent: addContent,
135 + addButton: addButton
136 + };
137 + return dApi;
138 + }
139 +
140 + // closes the dialog (destroying panel)
141 + function closeDialog() {
142 + $log.debug('Close DIALOG');
143 + if (pApi) {
144 + panel.hide();
145 + pApi.destroy();
146 + pApi = null;
147 + dApi = null;
148 + }
149 + }
150 +
151 + // creates a detached div, returning D3 selection
152 + // optional CSS class may be provided
153 + function createDiv(cls) {
154 + var div = d3.select(document.createElement('div'));
155 + if (cls) {
156 + div.classed(cls, true);
157 + }
158 + return div;
159 + }
160 +
161 + // ==========================
162 +
163 + angular.module('ovTopo')
164 + .factory('TopoDialogService',
165 + ['$log', '$window', '$rootScope', 'FnService', 'PanelService', 'ButtonService',
166 +
167 + function (_$log_, _$window_, _$rootScope_,
168 + _fs_, _ps_, _bns_) {
169 + $log = _$log_;
170 + $window = _$window_;
171 + $rootScope = _$rootScope_;
172 + fs = _fs_;
173 + ps = _ps_;
174 + bns = _bns_;
175 +
176 + return {
177 + openDialog: openDialog,
178 + closeDialog: closeDialog,
179 + createDiv: createDiv
180 + };
181 + }]);
182 +}());
...@@ -240,6 +240,33 @@ ...@@ -240,6 +240,33 @@
240 return cc; 240 return cc;
241 } 241 }
242 242
243 + // returns a selection context, providing info about what is selected
244 + function selectionContext() {
245 + var devices = [],
246 + hosts = [],
247 + types = {};
248 +
249 + angular.forEach(selections, function (d) {
250 + var o = d.obj,
251 + c = o.class;
252 +
253 + if (c === 'device') {
254 + devices.push(o.id);
255 + types[o.id] = o.type;
256 + }
257 + if (c === 'host') {
258 + hosts.push(o.id);
259 + types[o.id] = o.type;
260 + }
261 + });
262 +
263 + return {
264 + devices: devices,
265 + hosts: hosts,
266 + types: types
267 + };
268 + }
269 +
243 // === ----------------------------------------------------- 270 // === -----------------------------------------------------
244 // === MODULE DEFINITION === 271 // === MODULE DEFINITION ===
245 272
...@@ -280,7 +307,8 @@ ...@@ -280,7 +307,8 @@
280 selectOrder: function () { return selectOrder; }, 307 selectOrder: function () { return selectOrder; },
281 somethingSelected: somethingSelected, 308 somethingSelected: somethingSelected,
282 309
283 - clickConsumed: clickConsumed 310 + clickConsumed: clickConsumed,
311 + selectionContext: selectionContext
284 }; 312 };
285 }]); 313 }]);
286 }()); 314 }());
......
...@@ -98,6 +98,7 @@ ...@@ -98,6 +98,7 @@
98 <script src="app/view/topo/topo.js"></script> 98 <script src="app/view/topo/topo.js"></script>
99 <script src="app/view/topo/topoD3.js"></script> 99 <script src="app/view/topo/topoD3.js"></script>
100 <script src="app/view/topo/topoEvent.js"></script> 100 <script src="app/view/topo/topoEvent.js"></script>
101 + <script src="app/view/topo/topoDialog.js"></script>
101 <script src="app/view/topo/topoFilter.js"></script> 102 <script src="app/view/topo/topoFilter.js"></script>
102 <script src="app/view/topo/topoForce.js"></script> 103 <script src="app/view/topo/topoForce.js"></script>
103 <script src="app/view/topo/topoInst.js"></script> 104 <script src="app/view/topo/topoInst.js"></script>
......