blob: c56ddf68b0eff5a3ec0f6851e6a7bd8d32a45939 [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
Steven Burrowsdfa52b02016-09-02 13:50:43 +010022(function () {
23
Steven Burrowsaf3159d2016-08-25 14:54:30 +010024 'use strict';
25
26 var $log, wss;
27
Steven Burrowsdfa52b02016-09-02 13:50:43 +010028 // Internal
Steven Burrowsaf3159d2016-08-25 14:54:30 +010029 var breadcrumbContainer,
30 breadcrumbs;
31
32 function init() {
Steven Burrowsdfa52b02016-09-02 13:50:43 +010033 $log.debug("Topo2BreadcrumbService Initiated");
Steven Burrowsaf3159d2016-08-25 14:54:30 +010034 breadcrumbs = [];
35 breadcrumbContainer = d3.select('#breadcrumbs');
36 render();
37 }
38
39 function addBreadcrumb(crumbs) {
40
Steven Burrowsdfa52b02016-09-02 13:50:43 +010041 breadcrumbContainer.selectAll('.breadcrumb').remove();
42 breadcrumbs = crumbs.reverse();
Steven Burrowsaf3159d2016-08-25 14:54:30 +010043 render();
44 }
45
46 function navigateToRegion(data, index) {
47
48 if (index === breadcrumbs.length - 1) {
49 return;
50 }
51
52 // Remove breadcrumbs after index;
53 breadcrumbs.splice(index + 1);
54
55 wss.sendEvent('topo2navRegion', {
56 dir: 'up',
57 rid: data.id
58 });
59
60 render();
61 }
62
63 function render() {
64
65 var selection = breadcrumbContainer.selectAll('.breadcrumb')
66 .data(breadcrumbs);
67
68 selection.enter()
69 .append('div')
70 .attr('class', 'breadcrumb')
71 .on('click', navigateToRegion)
72 .append('text')
73 .text(function (d) {
74 return d.name;
75 });
76
77 selection.exit()
78 .transition()
79 .duration(200)
80 .style('opacity', 0)
81 .remove();
82 }
83
84 angular.module('ovTopo2')
85 .factory('Topo2BreadcrumbService',
86 ['$log', 'WebSocketService',
87
88 function (_$log_, _wss_) {
89
90 $log = _$log_;
91 wss = _wss_;
92
93 return {
94 init: init,
95 addBreadcrumb: addBreadcrumb
96 };
97 }]);
98
99})();