blob: 29cc9b626d069d3d5d71fc4e7cf06657078eea35 [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
Bri Prebilic Cole6b95a3f2015-06-04 09:15:00 -070024 var selectionObj;
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 Cole6b95a3f2015-06-04 09:15:00 -070028 ['$log', '$scope', 'FnService', 'TableBuilderService', 'WebSocketService',
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070029
Bri Prebilic Cole6b95a3f2015-06-04 09:15:00 -070030 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 Coleb699a162015-04-13 12:01:39 -070036 function selCb($event, row) {
Bri Prebilic Cole6b95a3f2015-06-04 09:15:00 -070037 $scope.ctrlBtnState.selection = !!$scope.selId;
38 selectionObj = row;
Thomas Vachuska619c5382015-04-02 13:41:47 -070039 $log.debug('Got a click on:', row);
Bri Prebilic Cole6b95a3f2015-06-04 09:15:00 -070040
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 Vachuska619c5382015-04-02 13:41:47 -070048 }
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070049
Bri Prebilic Cole6b95a3f2015-06-04 09:15:00 -070050 tbs.buildTable({
51 scope: $scope,
52 tag: 'app',
53 selCb: selCb
54 });
55
56 // TODO: use d3 click events -- move to directive
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070057 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 Cole6b95a3f2015-06-04 09:15:00 -070064 // TODO: use d3 to select elements -- move to directive
Thomas Vachuska530e52a2015-05-06 19:51:32 -070065 document.getElementById('app-form-response').onload = function () {
66 document.getElementById('app-form').reset();
Bri Prebilic Cole6b95a3f2015-06-04 09:15:00 -070067 $scope.$apply();
68 //$scope.sortCallback($scope.sortParams);
Bri Prebilic Colebd0bc772015-05-13 13:02:26 -070069 };
Thomas Vachuska530e52a2015-05-06 19:51:32 -070070
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070071 function appAction(action) {
Bri Prebilic Cole6b95a3f2015-06-04 09:15:00 -070072 if ($scope.ctrlBtnState.selection) {
73 $log.debug('Initiating ' + action + ' of', selectionObj);
74 wss.sendEvent('appManagementRequest', {action: action, name: selectionObj.id});
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070075 }
76 }
77
Bri Prebilic Cole6b95a3f2015-06-04 09:15:00 -070078 // TODO: use d3 to select elements -- move to directive
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070079 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 Cole6b95a3f2015-06-04 09:15:00 -070087 // TODO: move to directive
Thomas Vachuskaa7a0f562015-04-14 23:27:44 -070088 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 Vachuska619c5382015-04-02 13:41:47 -070092 $log.log('OvAppCtrl has been created');
93 }]);
Thomas Vachuska0fa583c2015-03-30 23:07:41 -070094}());