Bri Prebilic Cole | 96f2647 | 2015-03-31 13:07:05 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Bri Prebilic Cole | 96f2647 | 2015-03-31 13:07:05 -0700 | [diff] [blame] | 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 -- Intent View Module |
| 19 | */ |
| 20 | |
| 21 | (function () { |
| 22 | 'use strict'; |
| 23 | |
Viswanath KSP | 0f29770 | 2016-08-13 18:02:43 +0530 | [diff] [blame] | 24 | var dialogId = 'remove-intent-dialog', |
| 25 | dialogOpts = { |
| 26 | edge: 'right' |
| 27 | }; |
| 28 | |
Bri Prebilic Cole | 96f2647 | 2015-03-31 13:07:05 -0700 | [diff] [blame] | 29 | angular.module('ovIntent', []) |
| 30 | .controller('OvIntentCtrl', |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 31 | ['$log', '$scope', 'TableBuilderService', 'NavService', |
Viswanath KSP | 0f29770 | 2016-08-13 18:02:43 +0530 | [diff] [blame] | 32 | 'TopoTrafficService', 'DialogService', |
Bri Prebilic Cole | 96f2647 | 2015-03-31 13:07:05 -0700 | [diff] [blame] | 33 | |
Viswanath KSP | 0f29770 | 2016-08-13 18:02:43 +0530 | [diff] [blame] | 34 | function ($log, $scope, tbs, ns, tts, ds) { |
Kavitha Alagesan | 98c0006 | 2016-08-23 18:20:42 -0700 | [diff] [blame] | 35 | $scope.briefTip = 'Switch to brief view'; |
| 36 | $scope.detailTip = 'Switch to detailed view'; |
| 37 | $scope.brief = true; |
Viswanath KSP | 317f329 | 2016-09-04 14:13:22 +0530 | [diff] [blame] | 38 | $scope.intentState = 'NA'; |
| 39 | $scope.fired = false; |
Bri Prebilic Cole | 96f2647 | 2015-03-31 13:07:05 -0700 | [diff] [blame] | 40 | |
Simon Hunt | 4e41273 | 2015-10-27 15:25:39 -0700 | [diff] [blame] | 41 | function selCb($event, row) { |
| 42 | $log.debug('Got a click on:', row); |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 43 | var m = /(\d+)\s:\s(.*)/.exec(row.appId), |
| 44 | id = m ? m[1] : null, |
| 45 | name = m ? m[2] : null; |
| 46 | |
Simon Hunt | 144bd79 | 2015-10-28 11:46:36 -0700 | [diff] [blame] | 47 | $scope.intentData = ($scope.selId && m) ? { |
Viswanath KSP | 0f29770 | 2016-08-13 18:02:43 +0530 | [diff] [blame] | 48 | appId: id, |
| 49 | appName: name, |
| 50 | key: row.key |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 51 | } : null; |
Viswanath KSP | 317f329 | 2016-09-04 14:13:22 +0530 | [diff] [blame] | 52 | |
| 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 Hunt | 4e41273 | 2015-10-27 15:25:39 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | tbs.buildTable({ |
| 66 | scope: $scope, |
| 67 | tag: 'intent', |
| 68 | selCb: selCb, |
Viswanath KSP | 317f329 | 2016-09-04 14:13:22 +0530 | [diff] [blame] | 69 | respCb: respCb, |
Simon Hunt | 4e41273 | 2015-10-27 15:25:39 -0700 | [diff] [blame] | 70 | idKey: 'key' |
| 71 | }); |
| 72 | |
| 73 | $scope.topoTip = 'Show selected intent on topology view'; |
Viswanath KSP | 14aee09 | 2016-10-02 01:47:40 +0530 | [diff] [blame] | 74 | $scope.resubmitTip = 'Resubmit selected intent'; |
Viswanath KSP | 0f29770 | 2016-08-13 18:02:43 +0530 | [diff] [blame] | 75 | $scope.deactivateTip = 'Remove selected intent'; |
Viswanath KSP | 813a20d | 2016-09-13 04:25:41 +0530 | [diff] [blame] | 76 | $scope.purgeTip = 'Purge selected intent'; |
Simon Hunt | 4e41273 | 2015-10-27 15:25:39 -0700 | [diff] [blame] | 77 | |
| 78 | $scope.showIntent = function () { |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 79 | var d = $scope.intentData; |
Simon Hunt | 144bd79 | 2015-10-28 11:46:36 -0700 | [diff] [blame] | 80 | d && ns.navTo('topo', d); |
Simon Hunt | 4e41273 | 2015-10-27 15:25:39 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
Viswanath KSP | 317f329 | 2016-09-04 14:13:22 +0530 | [diff] [blame] | 83 | $scope.isIntentInstalled = function () { |
| 84 | return $scope.intentState === 'Installed'; |
| 85 | }; |
| 86 | |
Viswanath KSP | 813a20d | 2016-09-13 04:25:41 +0530 | [diff] [blame] | 87 | $scope.isIntentWithdrawn = function () { |
| 88 | return $scope.intentState === 'Withdrawn'; |
| 89 | }; |
Viswanath KSP | 0f29770 | 2016-08-13 18:02:43 +0530 | [diff] [blame] | 90 | |
Viswanath KSP | 14aee09 | 2016-10-02 01:47:40 +0530 | [diff] [blame] | 91 | function executeAction(action) { |
Viswanath KSP | 813a20d | 2016-09-13 04:25:41 +0530 | [diff] [blame] | 92 | var content = ds.createDiv(), |
Viswanath KSP | 14aee09 | 2016-10-02 01:47:40 +0530 | [diff] [blame] | 93 | txt, |
| 94 | bPurge = action === 'purge'; |
Viswanath KSP | 813a20d | 2016-09-13 04:25:41 +0530 | [diff] [blame] | 95 | |
| 96 | $scope.intentData.intentPurge = bPurge; |
| 97 | |
| 98 | content.append('p'). |
Viswanath KSP | 14aee09 | 2016-10-02 01:47:40 +0530 | [diff] [blame] | 99 | text('Are you sure you want to '+ action + |
Viswanath KSP | 813a20d | 2016-09-13 04:25:41 +0530 | [diff] [blame] | 100 | ' the selected intent?'); |
Viswanath KSP | 0f29770 | 2016-08-13 18:02:43 +0530 | [diff] [blame] | 101 | |
| 102 | function dOk() { |
| 103 | var d = $scope.intentData; |
Viswanath KSP | 813a20d | 2016-09-13 04:25:41 +0530 | [diff] [blame] | 104 | $log.debug(d); |
Viswanath KSP | 14aee09 | 2016-10-02 01:47:40 +0530 | [diff] [blame] | 105 | d && (action === 'resubmit' ? tts.resubmitIntent(d) : |
| 106 | tts.removeIntent(d)); |
Viswanath KSP | 317f329 | 2016-09-04 14:13:22 +0530 | [diff] [blame] | 107 | $scope.fired = true; |
Viswanath KSP | 0f29770 | 2016-08-13 18:02:43 +0530 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | function dCancel() { |
| 111 | ds.closeDialog(); |
| 112 | $log.debug('Canceling remove-intent action'); |
| 113 | } |
| 114 | |
| 115 | ds.openDialog(dialogId, dialogOpts) |
| 116 | .setTitle('Confirm Action') |
| 117 | .addContent(content) |
| 118 | .addOk(dOk) |
| 119 | .addCancel(dCancel) |
| 120 | .bindKeys(); |
Viswanath KSP | 813a20d | 2016-09-13 04:25:41 +0530 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | $scope.deactivateIntent = function () { |
Viswanath KSP | 14aee09 | 2016-10-02 01:47:40 +0530 | [diff] [blame] | 124 | executeAction("withdraw"); |
| 125 | }; |
| 126 | |
| 127 | $scope.resubmitIntent = function () { |
| 128 | executeAction("resubmit"); |
Viswanath KSP | 813a20d | 2016-09-13 04:25:41 +0530 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | $scope.purgeIntent = function () { |
Viswanath KSP | 14aee09 | 2016-10-02 01:47:40 +0530 | [diff] [blame] | 132 | executeAction("purge"); |
Viswanath KSP | 0f29770 | 2016-08-13 18:02:43 +0530 | [diff] [blame] | 133 | }; |
| 134 | |
Kavitha Alagesan | 98c0006 | 2016-08-23 18:20:42 -0700 | [diff] [blame] | 135 | $scope.briefToggle = function () { |
| 136 | $scope.brief = !$scope.brief; |
| 137 | }; |
| 138 | |
Viswanath KSP | 0f29770 | 2016-08-13 18:02:43 +0530 | [diff] [blame] | 139 | $scope.$on('$destroy', function () { |
| 140 | ds.closeDialog(); |
| 141 | $log.debug('OvIntentCtrl has been destroyed'); |
| 142 | }); |
| 143 | |
| 144 | $log.debug('OvIntentCtrl has been created'); |
Simon Hunt | 4e41273 | 2015-10-27 15:25:39 -0700 | [diff] [blame] | 145 | }]); |
Bri Prebilic Cole | 96f2647 | 2015-03-31 13:07:05 -0700 | [diff] [blame] | 146 | }()); |