blob: 236099dcd196cb4d6c06fa93d36ca647979e5e1d [file] [log] [blame]
Thomas Vachuska0fa583c2015-03-30 23:07:41 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -07004 * Licensed under the Apache License, Version 2.0 (the 'License');
Thomas Vachuska0fa583c2015-03-30 23:07:41 -07005 * 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 Vachuskaa7a0f562015-04-14 23:27:44 -070011 * distributed under the License is distributed on an 'AS IS' BASIS,
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070012 * 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 Vachuskaa7a0f562015-04-14 23:27:44 -070024 var selRow, selection;
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070025
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070026 angular.module('ovApp', [])
27 .controller('OvAppCtrl',
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070028 ['$log', '$scope', 'TableBuilderService', 'WebSocketService',
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070029
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070030 function ($log, $scope, tbs, wss) {
Bri Prebilic Coleb699a162015-04-13 12:01:39 -070031 function selCb($event, row) {
32 selRow = angular.element($event.currentTarget);
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070033 selection = row;
Thomas Vachuska619c5382015-04-02 13:41:47 -070034 $log.debug('Got a click on:', row);
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070035 // 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 Vachuska619c5382015-04-02 13:41:47 -070039 }
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070040
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070041 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
48 function appAction(action) {
49 if (selection) {
50 $log.debug('Initiating uninstall of', selection);
51 wss.sendEvent('appManagementRequest', {action: action, name: selection.id});
52 }
53 }
54
55 d3.select('#file').on('change', function () {
56 var file = document.getElementById('file').value.replace('C:\\fakepath\\', '');
57 $log.info('Handling file', file);
58 var evt = document.createEvent("HTMLEvents");
59 evt.initEvent("click", true, true);
60 document.getElementById('app-upload').dispatchEvent(evt);
61 });
62
63 d3.select('#app-uninstall').on('click', function () { appAction('uninstall'); });
64 d3.select('#app-activate').on('click', function () { appAction('activate'); });
65 d3.select('#app-deactivate').on('click', function () { appAction('deactivate'); });
66
Thomas Vachuska619c5382015-04-02 13:41:47 -070067 tbs.buildTable({
68 self: this,
69 scope: $scope,
70 tag: 'app',
71 selCb: selCb
72 });
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070073
Thomas Vachuska619c5382015-04-02 13:41:47 -070074 $log.log('OvAppCtrl has been created');
75 }]);
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070076}());