blob: 324f389472f74eeddaa537a4aaddd22a2c963875 [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;
Viswanath KSP317f3292016-09-04 14:13:22 +053038 $scope.intentState = 'NA';
39 $scope.fired = false;
Bri Prebilic Cole96f26472015-03-31 13:07:05 -070040
Simon Hunt4e412732015-10-27 15:25:39 -070041 function selCb($event, row) {
42 $log.debug('Got a click on:', row);
Simon Hunt4a6b54b2015-10-27 22:08:25 -070043 var m = /(\d+)\s:\s(.*)/.exec(row.appId),
44 id = m ? m[1] : null,
45 name = m ? m[2] : null;
46
Simon Hunt144bd792015-10-28 11:46:36 -070047 $scope.intentData = ($scope.selId && m) ? {
Viswanath KSP0f297702016-08-13 18:02:43 +053048 appId: id,
49 appName: name,
50 key: row.key
Simon Hunt4a6b54b2015-10-27 22:08:25 -070051 } : null;
Viswanath KSP317f3292016-09-04 14:13:22 +053052
53 $scope.intentState = row.state;
54 }
55
56 function respCb() {
57 if ($scope.fired) {
58 if ($scope.changedData) {
59 $scope.intentState = $scope.changedData.state;
60 }
61 $scope.fired = false;
62 }
Simon Hunt4e412732015-10-27 15:25:39 -070063 }
64
65 tbs.buildTable({
66 scope: $scope,
67 tag: 'intent',
68 selCb: selCb,
Viswanath KSP317f3292016-09-04 14:13:22 +053069 respCb: respCb,
Simon Hunt4e412732015-10-27 15:25:39 -070070 idKey: 'key'
71 });
72
73 $scope.topoTip = 'Show selected intent on topology view';
Viswanath KSP14aee092016-10-02 01:47:40 +053074 $scope.resubmitTip = 'Resubmit selected intent';
Viswanath KSP0f297702016-08-13 18:02:43 +053075 $scope.deactivateTip = 'Remove selected intent';
Viswanath KSP813a20d2016-09-13 04:25:41 +053076 $scope.purgeTip = 'Purge selected intent';
Deepa Vaddireddy63340922017-01-19 08:15:31 +053077 $scope.purgeAllTip = 'Purge withdrawn intents';
Simon Hunt4e412732015-10-27 15:25:39 -070078
79 $scope.showIntent = function () {
Simon Hunt4a6b54b2015-10-27 22:08:25 -070080 var d = $scope.intentData;
Simon Hunt144bd792015-10-28 11:46:36 -070081 d && ns.navTo('topo', d);
Simon Hunt4e412732015-10-27 15:25:39 -070082 };
83
Viswanath KSP317f3292016-09-04 14:13:22 +053084 $scope.isIntentInstalled = function () {
85 return $scope.intentState === 'Installed';
86 };
87
Viswanath KSP813a20d2016-09-13 04:25:41 +053088 $scope.isIntentWithdrawn = function () {
89 return $scope.intentState === 'Withdrawn';
90 };
Viswanath KSP0f297702016-08-13 18:02:43 +053091
Deepa Vaddireddy63340922017-01-19 08:15:31 +053092 $scope.isHavingWithdrawn = function () {
93 var isWithdrawn = false;
94 $scope.tableData.forEach(function (intent) {
95 if (intent.state ==='Withdrawn') {
96 isWithdrawn = true;
97 }
98 });
99 return isWithdrawn;
100 };
101
Viswanath KSP14aee092016-10-02 01:47:40 +0530102 function executeAction(action) {
Viswanath KSP813a20d2016-09-13 04:25:41 +0530103 var content = ds.createDiv(),
Viswanath KSP14aee092016-10-02 01:47:40 +0530104 txt,
105 bPurge = action === 'purge';
Viswanath KSP813a20d2016-09-13 04:25:41 +0530106
107 $scope.intentData.intentPurge = bPurge;
108
109 content.append('p').
Viswanath KSP14aee092016-10-02 01:47:40 +0530110 text('Are you sure you want to '+ action +
Viswanath KSP813a20d2016-09-13 04:25:41 +0530111 ' the selected intent?');
Viswanath KSP0f297702016-08-13 18:02:43 +0530112
113 function dOk() {
114 var d = $scope.intentData;
Viswanath KSP813a20d2016-09-13 04:25:41 +0530115 $log.debug(d);
Viswanath KSP14aee092016-10-02 01:47:40 +0530116 d && (action === 'resubmit' ? tts.resubmitIntent(d) :
117 tts.removeIntent(d));
Viswanath KSP317f3292016-09-04 14:13:22 +0530118 $scope.fired = true;
Viswanath KSP0f297702016-08-13 18:02:43 +0530119 }
120
121 function dCancel() {
122 ds.closeDialog();
123 $log.debug('Canceling remove-intent action');
124 }
125
126 ds.openDialog(dialogId, dialogOpts)
127 .setTitle('Confirm Action')
128 .addContent(content)
129 .addOk(dOk)
130 .addCancel(dCancel)
131 .bindKeys();
Viswanath KSP813a20d2016-09-13 04:25:41 +0530132 }
Deepa Vaddireddy63340922017-01-19 08:15:31 +0530133 function executeActions(action) {
134 var content = ds.createDiv(),
135 txt='purgeIntents';
136 content.append('p').
137 text('Are you sure you want to purge all the withdrawn intents?');
138
139 function dOk() {
140 tts.removeIntents();
141 $scope.fired = true;
142 }
143
144 function dCancel() {
145 ds.closeDialog();
146 $log.debug('Canceling remove-intents action');
147 }
148
149 ds.openDialog(dialogId, dialogOpts)
150 .setTitle('Confirm Action')
151 .addContent(content)
152 .addOk(dOk)
153 .addCancel(dCancel)
154 .bindKeys();
155 }
Viswanath KSP813a20d2016-09-13 04:25:41 +0530156
157 $scope.deactivateIntent = function () {
Viswanath KSP14aee092016-10-02 01:47:40 +0530158 executeAction("withdraw");
159 };
160
161 $scope.resubmitIntent = function () {
162 executeAction("resubmit");
Viswanath KSP813a20d2016-09-13 04:25:41 +0530163 };
164
165 $scope.purgeIntent = function () {
Viswanath KSP14aee092016-10-02 01:47:40 +0530166 executeAction("purge");
Viswanath KSP0f297702016-08-13 18:02:43 +0530167 };
168
Kavitha Alagesan98c00062016-08-23 18:20:42 -0700169 $scope.briefToggle = function () {
170 $scope.brief = !$scope.brief;
171 };
172
Viswanath KSP0f297702016-08-13 18:02:43 +0530173 $scope.$on('$destroy', function () {
174 ds.closeDialog();
175 $log.debug('OvIntentCtrl has been destroyed');
176 });
177
Deepa Vaddireddy63340922017-01-19 08:15:31 +0530178 $scope.purgeIntents = function () {
179 executeActions("purgeIntents");
180 };
Viswanath KSP0f297702016-08-13 18:02:43 +0530181 $log.debug('OvIntentCtrl has been created');
Simon Hunt4e412732015-10-27 15:25:39 -0700182 }]);
Bri Prebilic Cole96f26472015-03-31 13:07:05 -0700183}());