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 | |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 24 | var selRow, selection; |
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 | e1be1b7 | 2015-05-12 16:07:24 -0700 | [diff] [blame] | 28 | ['$log', '$scope', 'TableBuilderService', 'WebSocketService', |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 29 | |
Bri Prebilic Cole | e1be1b7 | 2015-05-12 16:07:24 -0700 | [diff] [blame] | 30 | function ($log, $scope, tbs, wss) { |
Bri Prebilic Cole | b699a16 | 2015-04-13 12:01:39 -0700 | [diff] [blame] | 31 | function selCb($event, row) { |
| 32 | selRow = angular.element($event.currentTarget); |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 33 | selection = row; |
Thomas Vachuska | 619c538 | 2015-04-02 13:41:47 -0700 | [diff] [blame] | 34 | $log.debug('Got a click on:', row); |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 35 | // adjust which toolbar buttons are selected |
| 36 | d3.select('#app-activate').classed('active', row && row.state === 'INSTALLED'); |
| 37 | d3.select('#app-deactivate').classed('active', row && row.state === 'ACTIVE'); |
| 38 | d3.select('#app-uninstall').classed('active', row); |
Thomas Vachuska | 619c538 | 2015-04-02 13:41:47 -0700 | [diff] [blame] | 39 | } |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 40 | |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 41 | d3.select('#app-install').on('click', function () { |
| 42 | $log.debug('Initiating install'); |
| 43 | var evt = document.createEvent("HTMLEvents"); |
| 44 | evt.initEvent("click", true, true); |
| 45 | document.getElementById('file').dispatchEvent(evt); |
| 46 | }); |
| 47 | |
Thomas Vachuska | 530e52a | 2015-05-06 19:51:32 -0700 | [diff] [blame] | 48 | document.getElementById('app-form-response').onload = function () { |
| 49 | document.getElementById('app-form').reset(); |
| 50 | $scope.refresh(); |
Bri Prebilic Cole | bd0bc77 | 2015-05-13 13:02:26 -0700 | [diff] [blame] | 51 | }; |
Thomas Vachuska | 530e52a | 2015-05-06 19:51:32 -0700 | [diff] [blame] | 52 | |
Thomas Vachuska | a7a0f56 | 2015-04-14 23:27:44 -0700 | [diff] [blame] | 53 | function appAction(action) { |
| 54 | if (selection) { |
| 55 | $log.debug('Initiating uninstall of', selection); |
| 56 | wss.sendEvent('appManagementRequest', {action: action, name: selection.id}); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | d3.select('#file').on('change', function () { |
| 61 | var file = document.getElementById('file').value.replace('C:\\fakepath\\', ''); |
| 62 | $log.info('Handling file', file); |
| 63 | var evt = document.createEvent("HTMLEvents"); |
| 64 | evt.initEvent("click", true, true); |
| 65 | document.getElementById('app-upload').dispatchEvent(evt); |
| 66 | }); |
| 67 | |
| 68 | d3.select('#app-uninstall').on('click', function () { appAction('uninstall'); }); |
| 69 | d3.select('#app-activate').on('click', function () { appAction('activate'); }); |
| 70 | d3.select('#app-deactivate').on('click', function () { appAction('deactivate'); }); |
| 71 | |
Thomas Vachuska | 619c538 | 2015-04-02 13:41:47 -0700 | [diff] [blame] | 72 | tbs.buildTable({ |
Thomas Vachuska | 619c538 | 2015-04-02 13:41:47 -0700 | [diff] [blame] | 73 | scope: $scope, |
| 74 | tag: 'app', |
| 75 | selCb: selCb |
| 76 | }); |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 77 | |
Thomas Vachuska | 619c538 | 2015-04-02 13:41:47 -0700 | [diff] [blame] | 78 | $log.log('OvAppCtrl has been created'); |
| 79 | }]); |
Thomas Vachuska | 0fa583c | 2015-03-30 23:07:41 -0700 | [diff] [blame] | 80 | }()); |