blob: cacd5e07fa3baafa8bdcd5ceba819cdfd05f4c16 [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',
Bri Prebilic Cole3d4d01c2015-04-30 13:48:36 -070028 ['$log', '$scope', 'TableService', 'TableBuilderService', 'WebSocketService',
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070029
Bri Prebilic Cole3d4d01c2015-04-30 13:48:36 -070030 function ($log, $scope, ts, 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
Bri Prebilic Cole3d4d01c2015-04-30 13:48:36 -070048 $scope.refresh = function () {
49 $log.debug('Refreshing application page');
50 ts.resetSortIcons();
51 $scope.sortCallback();
52 };
53
Thomas Vachuska530e52a2015-05-06 19:51:32 -070054 document.getElementById('app-form-response').onload = function () {
55 document.getElementById('app-form').reset();
56 $scope.refresh();
57 }
58
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070059 function appAction(action) {
60 if (selection) {
61 $log.debug('Initiating uninstall of', selection);
62 wss.sendEvent('appManagementRequest', {action: action, name: selection.id});
63 }
64 }
65
66 d3.select('#file').on('change', function () {
67 var file = document.getElementById('file').value.replace('C:\\fakepath\\', '');
68 $log.info('Handling file', file);
69 var evt = document.createEvent("HTMLEvents");
70 evt.initEvent("click", true, true);
71 document.getElementById('app-upload').dispatchEvent(evt);
72 });
73
74 d3.select('#app-uninstall').on('click', function () { appAction('uninstall'); });
75 d3.select('#app-activate').on('click', function () { appAction('activate'); });
76 d3.select('#app-deactivate').on('click', function () { appAction('deactivate'); });
77
Thomas Vachuska619c5382015-04-02 13:41:47 -070078 tbs.buildTable({
Thomas Vachuska619c5382015-04-02 13:41:47 -070079 scope: $scope,
80 tag: 'app',
81 selCb: selCb
82 });
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070083
Thomas Vachuska619c5382015-04-02 13:41:47 -070084 $log.log('OvAppCtrl has been created');
85 }]);
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070086}());