Assign image keyname and pubkey at vnf level
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / ux / mwtnClosedLoop / mwtnClosedLoop-module / src / main / resources / mwtnClosedLoop / mwtnClosedLoop.controller.js
1 /*
2  * Copyright (c) 2016 highstreet technologies GmbH and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 define(['app/mwtnClosedLoop/mwtnClosedLoop.module','app/mwtnClosedLoop/mwtnClosedLoop.services','app/mwtnCommons/mwtnCommons.services'], function(mwtnClosedLoopApp) {
10
11   mwtnClosedLoopApp.register.controller('mwtnClosedLoopCtrl', ['$scope', '$rootScope', 'uiGridConstants',  '$mwtnClosedLoop', '$mwtnCommons', '$mwtnLog', 'OnfNetworkElement', 'MicrowavePhysicalSection',
12                                                                function($scope, $rootScope, uiGridConstants, $mwtnClosedLoop, $mwtnCommons, $mwtnLog, OnfNetworkElement, MicrowavePhysicalSection) {
13
14     var COMPONENT = 'mwtnClosedLoopCtrl';
15     $mwtnLog.info({component: COMPONENT, message: 'Started!'});
16
17     $rootScope.section_logo = 'src/app/mwtnClosedLoop/images/mwtnClosedLoop.png'; // Add your topbar logo location here such as 'assets/images/logo_topology.gif'
18
19     $scope.timerOptionList = [
20         {id : '5seconds', name : "5 seconds"},
21         {id : '30seconds', name : "30 seconds"},
22         {id : '1minute', name : "One minute"},
23         {id : '2minutes', name : "Two minutes"},
24         {id : '30minutes', name : "30 minutes"},
25         {id : '1hour', name : "One hour"}];
26
27     var clearMessages = function() {
28       $scope.info = undefined;
29       $scope.error = undefined;
30     };
31     
32     $scope.executeNow = function() {
33         clearMessages();
34         $mwtnCommons.executeClosedLoopAutomation().then(function(message){
35           $mwtnLog.info({component: 'mwtnClosedLoopCtrl', message: 'Closed loop automation was started'});
36           $scope.info = 'Closed loop automation was executed: ' + new Date().toISOString().toHumanReadableTimeFormat();
37           $scope.refresh();
38         }, function(error){
39           $mwtnLog.error({component: 'mwtnClosedLoopCtrl', message: 'Cannot execute Closed Loop Automation'});
40           $scope.error = 'Cannot execute Closed Loop Automation';
41           $scope.refresh();
42         });
43     };
44
45     $scope.save = function() {
46         clearMessages();
47         $mwtnCommons.saveClosedLoopAutomation($scope.timerEnabled, $scope.timerOption).then(function(message){
48           $mwtnLog.info({component: 'mwtnClosedLoopCtrl', message: 'Timer was changed'});
49           $scope.info = 'Timer was changed';
50           $scope.refresh();
51         }, function(error){
52           $mwtnLog.error({component: 'mwtnClosedLoopCtrl', message: 'Cannot save timer'});
53           $scope.error = 'Cannot save timer';
54           $scope.refresh();
55         });
56     };
57
58     $scope.read = function() {
59         clearMessages();
60         $mwtnCommons.readClosedLoopAutomation().then(function(message){
61            $scope.timerEnabled = message.data.output.enabled;
62            $scope.timerOption = message.data.output.option;
63            $scope.refresh();
64         }, function(error){
65           $mwtnLog.error({component: 'mwtnClosedLoopCtrl', message: 'Cannot read configuration data from the server'});
66           $scope.error = 'Cannot read configuration data from the server';
67           $scope.refresh();
68         });
69      };
70
71      $scope.read();
72
73      var updateAirInterface = function(spec, data) {
74        if (data) {
75          var radioSignalID = data.airInterfaceConfiguration.radioSignalID;      
76          $scope.gridOptions.data.map(function(row){
77            if (row.name === spec.nodeId && row.radioSignalID === radioSignalID) {
78              row.actualAirInterfaceName = data.airInterfaceConfiguration.airInterfaceName;
79            }
80          });
81        } else {
82          $scope.gridOptions.data.map(function(row){
83            if (row.nodeId === spec.nodeId) {
84              row.actualAirInterfaceName = '?';
85            }
86          });
87        }
88      };
89
90      $scope.processing = false;
91      $scope.refresh = function() {
92        $scope.processing = true;
93        $mwtnClosedLoop.refresh().then(function(success){
94          $scope.processing = false;
95          $scope.gridOptions.data = success.airInterfaces;
96          success.actualNodes.map(function(actualNode){
97            if (actualNode.connectionStatus !== 'connected') {
98              return;
99            }
100            var revision = '2016-09-01';
101            $mwtnClosedLoop.getActualNetworkElement(actualNode.id, revision).then(function(onfNe){
102              var aOnfNe = new OnfNetworkElement(onfNe.NetworkElement);
103              aOnfNe.getLTPMwpsList().map(function(ltp){
104                var spec = {
105                  nodeId: actualNode.id,
106                  revision: revision,
107                  pacId: 'airinterface',
108                  layerProtocolId: ltp._lpList[0].uuid,
109                  partId: 'Configuration'
110                };
111                $mwtnClosedLoop.getPacParts(spec).then(function(success){
112                  updateAirInterface(spec, success);
113                }, function(error){
114                  updateAirInterface(spec, error);
115                });
116              });
117            }, function(error){
118              // do nothing
119            });
120          });
121        }, function(error){
122          $scope.processing = false;
123          $scope.gridOptions.data = [];
124        });
125      };
126
127      $scope.highlightFilteredHeader = $mwtnClosedLoop.highlightFilteredHeader;
128
129      var requiredNesConnectionStatusCellTemplate = [
130         '<div class="ui-grid-cell-contents" ng-class="{ \'green\': grid.getCellValue(row, col) === \'connected\'}"}>',
131         '  <i ng-show="grid.getCellValue(row, col) === \'connected\'" class="fa fa-link" aria-hidden="true"></i>',
132         '  <span>{{grid.getCellValue(row, col)}}</span>',
133         '</div>'].join('');
134
135      // ng-class="{\'mismatch\': {{row.entity.plannedAirInterfaceName}}      !== grid.getCellValue(row, col) }"
136      var actualAirinterfaceNameTemplate = [
137       '<div class="ui-grid-cell-contents">',
138       '  <span>{{grid.getCellValue(row, col)}}</span>',
139       '</div>'].join('');
140    
141      $scope.gridOptions = JSON.parse(JSON.stringify($mwtnClosedLoop.gridOptions));
142      $scope.gridOptions.columnDefs = [
143       { field: 'id', type: 'number', displayName: 'Id',  headerCellClass: $scope.highlightFilteredHeader, width : 50, cellClass: 'number', pinnedLeft : true , sort: {
144         direction: uiGridConstants.ASC,
145         ignoreSort: false,
146         priority: 0
147        }},
148       { field: 'name', type: 'string', displayName: 'Name',  headerCellClass: $scope.highlightFilteredHeader, width : 140 },
149       { field: 'connectionStatus', type: 'string', displayName: 'Connection status',  headerCellClass: $scope.highlightFilteredHeader, width : 150, cellTemplate: requiredNesConnectionStatusCellTemplate },
150       { field: 'radioSignalID', type: 'string', displayName: 'Radio signal id',  headerCellClass: $scope.highlightFilteredHeader, width : 130 },
151       { field: 'plannedAirInterfaceName', type: 'string', displayName: 'Planned airinterface name',  headerCellClass: $scope.highlightFilteredHeader, width : 200 },
152       { field: 'actualAirInterfaceName',  type: 'string', displayName: 'Actual airinterface name',  headerCellClass: $scope.highlightFilteredHeader, width : 250, cellTemplate: actualAirinterfaceNameTemplate},
153       ];
154
155      $scope.refresh();
156
157   }]);
158
159
160 });