blob: d089acbaeb1e2473360d70c3b44a6310222dbd96 [file] [log] [blame]
Steven Burrowsaf3159d2016-08-25 14:54:30 +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 Breadcrumb Module.
19 Module that renders the breadcrumbs for regions
20 */
21
22 (function () {
23 'use strict';
24
25 var $log, wss;
26
27 var breadcrumbContainer,
28 breadcrumbs;
29
30 function init() {
31
32 breadcrumbs = [];
33 breadcrumbContainer = d3.select('#breadcrumbs');
34 render();
35 }
36
37 function addBreadcrumb(crumbs) {
38
39 // If `crumbs` is an array, merge with breadcrumbs;
40 if (crumbs.length) {
41 breadcrumbs = breadcrumbs.concat(crumbs);
42 } else {
43 breadcrumbs.push(crumbs);
44 }
45
46 render();
47 }
48
49 function navigateToRegion(data, index) {
50
51 if (index === breadcrumbs.length - 1) {
52 return;
53 }
54
55 // Remove breadcrumbs after index;
56 breadcrumbs.splice(index + 1);
57
58 wss.sendEvent('topo2navRegion', {
59 dir: 'up',
60 rid: data.id
61 });
62
63 render();
64 }
65
66 function render() {
67
68 var selection = breadcrumbContainer.selectAll('.breadcrumb')
69 .data(breadcrumbs);
70
71 selection.enter()
72 .append('div')
73 .attr('class', 'breadcrumb')
74 .on('click', navigateToRegion)
75 .append('text')
76 .text(function (d) {
77 return d.name;
78 });
79
80 selection.exit()
81 .transition()
82 .duration(200)
83 .style('opacity', 0)
84 .remove();
85 }
86
87 angular.module('ovTopo2')
88 .factory('Topo2BreadcrumbService',
89 ['$log', 'WebSocketService',
90
91 function (_$log_, _wss_) {
92
93 $log = _$log_;
94 wss = _wss_;
95
96 return {
97 init: init,
98 addBreadcrumb: addBreadcrumb
99 };
100 }]);
101
102})();