blob: 35712280bffdd2d3b4f3c8cb90c2cc90794402c4 [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) {
Bri Prebilic Cole96f26472015-03-31 13:07:05 -070035
Simon Hunt4e412732015-10-27 15:25:39 -070036 function selCb($event, row) {
37 $log.debug('Got a click on:', row);
Simon Hunt4a6b54b2015-10-27 22:08:25 -070038 var m = /(\d+)\s:\s(.*)/.exec(row.appId),
39 id = m ? m[1] : null,
40 name = m ? m[2] : null;
41
Simon Hunt144bd792015-10-28 11:46:36 -070042 $scope.intentData = ($scope.selId && m) ? {
Viswanath KSP0f297702016-08-13 18:02:43 +053043 appId: id,
44 appName: name,
45 key: row.key
Simon Hunt4a6b54b2015-10-27 22:08:25 -070046 } : null;
Simon Hunt4e412732015-10-27 15:25:39 -070047 }
48
49 tbs.buildTable({
50 scope: $scope,
51 tag: 'intent',
52 selCb: selCb,
53 idKey: 'key'
54 });
55
56 $scope.topoTip = 'Show selected intent on topology view';
Viswanath KSP0f297702016-08-13 18:02:43 +053057 $scope.deactivateTip = 'Remove selected intent';
Simon Hunt4e412732015-10-27 15:25:39 -070058
59 $scope.showIntent = function () {
Simon Hunt4a6b54b2015-10-27 22:08:25 -070060 var d = $scope.intentData;
Simon Hunt144bd792015-10-28 11:46:36 -070061 d && ns.navTo('topo', d);
Simon Hunt4e412732015-10-27 15:25:39 -070062 };
63
Viswanath KSP0f297702016-08-13 18:02:43 +053064 $scope.deactivateIntent = function () {
65 var content = ds.createDiv();
66
67 content.append('p')
68 .text('Are you sure you want to remove the selected intent?');
69
70 function dOk() {
71 var d = $scope.intentData;
72 d && tts.removeIntent(d);
73 }
74
75 function dCancel() {
76 ds.closeDialog();
77 $log.debug('Canceling remove-intent action');
78 }
79
80 ds.openDialog(dialogId, dialogOpts)
81 .setTitle('Confirm Action')
82 .addContent(content)
83 .addOk(dOk)
84 .addCancel(dCancel)
85 .bindKeys();
86 };
87
88 $scope.$on('$destroy', function () {
89 ds.closeDialog();
90 $log.debug('OvIntentCtrl has been destroyed');
91 });
92
93 $log.debug('OvIntentCtrl has been created');
Simon Hunt4e412732015-10-27 15:25:39 -070094 }]);
Bri Prebilic Cole96f26472015-03-31 13:07:05 -070095}());