Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the 'License'); |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 11 | * distributed under the License is distributed on an 'AS IS' BASIS, |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 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 -- App View Module |
| 19 | */ |
| 20 | |
| 21 | (function () { |
| 22 | 'use strict'; |
| 23 | |
Bri Prebilic Cole | 6b95a3f | 2015-06-04 09:15:00 -0700 | [diff] [blame^] | 24 | var selectionObj; |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 25 | |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 26 | angular.module('ovApp', []) |
| 27 | .controller('OvAppCtrl', |
Bri Prebilic Cole | 6b95a3f | 2015-06-04 09:15:00 -0700 | [diff] [blame^] | 28 | ['$log', '$scope', 'FnService', 'TableBuilderService', 'WebSocketService', |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 29 | |
Bri Prebilic Cole | 6b95a3f | 2015-06-04 09:15:00 -0700 | [diff] [blame^] | 30 | function ($log, $scope, fs, tbs, wss) { |
| 31 | $scope.ctrlBtnState = {}; |
| 32 | // TODO: clean up view |
| 33 | // all DOM manipulation (adding styles, getting elements and doing stuff |
| 34 | // with them) should be done in directives |
| 35 | |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 36 | function selCb($event, row) { |
Bri Prebilic Cole | 6b95a3f | 2015-06-04 09:15:00 -0700 | [diff] [blame^] | 37 | $scope.ctrlBtnState.selection = !!$scope.selId; |
| 38 | selectionObj = row; |
Thomas Vachuska | 619c538 | 2015-04-02 13:41:47 -0700 | [diff] [blame] | 39 | $log.debug('Got a click on:', row); |
Bri Prebilic Cole | 6b95a3f | 2015-06-04 09:15:00 -0700 | [diff] [blame^] | 40 | |
| 41 | if ($scope.ctrlBtnState.selection) { |
| 42 | $scope.ctrlBtnState.installed = row.state === 'INSTALLED'; |
| 43 | $scope.ctrlBtnState.active = row.state === 'ACTIVE'; |
| 44 | } else { |
| 45 | $scope.ctrlBtnState.installed = false; |
| 46 | $scope.ctrlBtnState.active = false; |
| 47 | } |
Thomas Vachuska | 619c538 | 2015-04-02 13:41:47 -0700 | [diff] [blame] | 48 | } |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 49 | |
Bri Prebilic Cole | 6b95a3f | 2015-06-04 09:15:00 -0700 | [diff] [blame^] | 50 | tbs.buildTable({ |
| 51 | scope: $scope, |
| 52 | tag: 'app', |
| 53 | selCb: selCb |
| 54 | }); |
| 55 | |
| 56 | // TODO: use d3 click events -- move to directive |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 57 | d3.select('#app-install').on('click', function () { |
| 58 | $log.debug('Initiating install'); |
| 59 | var evt = document.createEvent("HTMLEvents"); |
| 60 | evt.initEvent("click", true, true); |
| 61 | document.getElementById('file').dispatchEvent(evt); |
| 62 | }); |
| 63 | |
Bri Prebilic Cole | 6b95a3f | 2015-06-04 09:15:00 -0700 | [diff] [blame^] | 64 | // TODO: use d3 to select elements -- move to directive |
Thomas Vachuska | 530e52a | 2015-05-06 19:51:32 -0700 | [diff] [blame] | 65 | document.getElementById('app-form-response').onload = function () { |
| 66 | document.getElementById('app-form').reset(); |
Bri Prebilic Cole | 6b95a3f | 2015-06-04 09:15:00 -0700 | [diff] [blame^] | 67 | $scope.$apply(); |
| 68 | //$scope.sortCallback($scope.sortParams); |
Bri Prebilic Cole | bd0bc77 | 2015-05-13 13:02:26 -0700 | [diff] [blame] | 69 | }; |
Thomas Vachuska | 530e52a | 2015-05-06 19:51:32 -0700 | [diff] [blame] | 70 | |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 71 | function appAction(action) { |
Bri Prebilic Cole | 6b95a3f | 2015-06-04 09:15:00 -0700 | [diff] [blame^] | 72 | if ($scope.ctrlBtnState.selection) { |
| 73 | $log.debug('Initiating ' + action + ' of', selectionObj); |
| 74 | wss.sendEvent('appManagementRequest', {action: action, name: selectionObj.id}); |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
Bri Prebilic Cole | 6b95a3f | 2015-06-04 09:15:00 -0700 | [diff] [blame^] | 78 | // TODO: use d3 to select elements -- move to directive |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 79 | d3.select('#file').on('change', function () { |
| 80 | var file = document.getElementById('file').value.replace('C:\\fakepath\\', ''); |
| 81 | $log.info('Handling file', file); |
| 82 | var evt = document.createEvent("HTMLEvents"); |
| 83 | evt.initEvent("click", true, true); |
| 84 | document.getElementById('app-upload').dispatchEvent(evt); |
| 85 | }); |
| 86 | |
Bri Prebilic Cole | 6b95a3f | 2015-06-04 09:15:00 -0700 | [diff] [blame^] | 87 | // TODO: move to directive |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 88 | d3.select('#app-uninstall').on('click', function () { appAction('uninstall'); }); |
| 89 | d3.select('#app-activate').on('click', function () { appAction('activate'); }); |
| 90 | d3.select('#app-deactivate').on('click', function () { appAction('deactivate'); }); |
| 91 | |
Thomas Vachuska | 619c538 | 2015-04-02 13:41:47 -0700 | [diff] [blame] | 92 | $log.log('OvAppCtrl has been created'); |
| 93 | }]); |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 94 | }()); |