blob: 50e0063ce674f9afaae69b7021136a26f62a2809 [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 Colee1be1b72015-05-12 16:07:24 -070028 ['$log', '$scope', 'TableBuilderService', 'WebSocketService',
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070029
Bri Prebilic Colee1be1b72015-05-12 16:07:24 -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
Thomas Vachuska530e52a2015-05-06 19:51:32 -070048 document.getElementById('app-form-response').onload = function () {
49 document.getElementById('app-form').reset();
50 $scope.refresh();
Bri Prebilic Colebd0bc772015-05-13 13:02:26 -070051 };
Thomas Vachuska530e52a2015-05-06 19:51:32 -070052
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070053 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 Vachuska619c5382015-04-02 13:41:47 -070072 tbs.buildTable({
Thomas Vachuska619c5382015-04-02 13:41:47 -070073 scope: $scope,
74 tag: 'app',
75 selCb: selCb
76 });
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070077
Thomas Vachuska619c5382015-04-02 13:41:47 -070078 $log.log('OvAppCtrl has been created');
79 }]);
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070080}());