blob: b033dd3df990732b07fbb578c1f73db1a9848de0 [file] [log] [blame]
Bri Prebilic Cole96f26472015-03-31 13:07:05 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Bri Prebilic Cole96f26472015-03-31 13:07:05 -07003 *
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 -- Intent View Module
19 */
20
21(function () {
22 'use strict';
23
Viswanath KSP0f297702016-08-13 18:02:43 +053024 var dialogId = 'remove-intent-dialog',
25 dialogOpts = {
26 edge: 'right'
27 };
28
Bri Prebilic Cole96f26472015-03-31 13:07:05 -070029 angular.module('ovIntent', [])
30 .controller('OvIntentCtrl',
Simon Hunt4a6b54b2015-10-27 22:08:25 -070031 ['$log', '$scope', 'TableBuilderService', 'NavService',
Viswanath KSP0f297702016-08-13 18:02:43 +053032 'TopoTrafficService', 'DialogService',
Bri Prebilic Cole96f26472015-03-31 13:07:05 -070033
Viswanath KSP0f297702016-08-13 18:02:43 +053034 function ($log, $scope, tbs, ns, tts, ds) {
Kavitha Alagesan98c00062016-08-23 18:20:42 -070035 $scope.briefTip = 'Switch to brief view';
36 $scope.detailTip = 'Switch to detailed view';
37 $scope.brief = true;
Bri Prebilic Cole96f26472015-03-31 13:07:05 -070038
Simon Hunt4e412732015-10-27 15:25:39 -070039 function selCb($event, row) {
40 $log.debug('Got a click on:', row);
Simon Hunt4a6b54b2015-10-27 22:08:25 -070041 var m = /(\d+)\s:\s(.*)/.exec(row.appId),
42 id = m ? m[1] : null,
43 name = m ? m[2] : null;
44
Simon Hunt144bd792015-10-28 11:46:36 -070045 $scope.intentData = ($scope.selId && m) ? {
Viswanath KSP0f297702016-08-13 18:02:43 +053046 appId: id,
47 appName: name,
48 key: row.key
Simon Hunt4a6b54b2015-10-27 22:08:25 -070049 } : null;
Simon Hunt4e412732015-10-27 15:25:39 -070050 }
51
52 tbs.buildTable({
53 scope: $scope,
54 tag: 'intent',
55 selCb: selCb,
56 idKey: 'key'
57 });
58
59 $scope.topoTip = 'Show selected intent on topology view';
Viswanath KSP0f297702016-08-13 18:02:43 +053060 $scope.deactivateTip = 'Remove selected intent';
Simon Hunt4e412732015-10-27 15:25:39 -070061
62 $scope.showIntent = function () {
Simon Hunt4a6b54b2015-10-27 22:08:25 -070063 var d = $scope.intentData;
Simon Hunt144bd792015-10-28 11:46:36 -070064 d && ns.navTo('topo', d);
Simon Hunt4e412732015-10-27 15:25:39 -070065 };
66
Viswanath KSP0f297702016-08-13 18:02:43 +053067 $scope.deactivateIntent = function () {
68 var content = ds.createDiv();
69
70 content.append('p')
71 .text('Are you sure you want to remove the selected intent?');
72
73 function dOk() {
74 var d = $scope.intentData;
75 d && tts.removeIntent(d);
76 }
77
78 function dCancel() {
79 ds.closeDialog();
80 $log.debug('Canceling remove-intent action');
81 }
82
83 ds.openDialog(dialogId, dialogOpts)
84 .setTitle('Confirm Action')
85 .addContent(content)
86 .addOk(dOk)
87 .addCancel(dCancel)
88 .bindKeys();
89 };
90
Kavitha Alagesan98c00062016-08-23 18:20:42 -070091 $scope.briefToggle = function () {
92 $scope.brief = !$scope.brief;
93 };
94
Viswanath KSP0f297702016-08-13 18:02:43 +053095 $scope.$on('$destroy', function () {
96 ds.closeDialog();
97 $log.debug('OvIntentCtrl has been destroyed');
98 });
99
100 $log.debug('OvIntentCtrl has been created');
Simon Hunt4e412732015-10-27 15:25:39 -0700101 }]);
Bri Prebilic Cole96f26472015-03-31 13:07:05 -0700102}());