Assign image keyname and pubkey at vnf level
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / ux / mwtnLog / mwtnLog-module / src / main / resources / mwtnLog / mwtnLog.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/mwtnLog/mwtnLog.module',
10         'app/mwtnLog/mwtnLog.services',
11         'app/mwtnCommons/mwtnCommons.module'], 
12         function(mwtnLogApp) {
13     
14   mwtnLogApp.register.controller('mwtnLogCtrl', ['uiGridConstants', '$uibModal', '$scope', '$rootScope', '$mwtnCommons', '$mwtnLogView', '$mwtnLog' ,
15                                                  function(uiGridConstants, $uibModal, $scope, $rootScope,  $mwtnCommons, $mwtnLogView,  $mwtnLog) {
16
17     var COMPONENT = 'mwtnLogCtrl';
18     $mwtnLog.info({component: COMPONENT, message: 'mwtnLogCtrl started!'});
19     // $mwtnLog.error({component: COMPONENT, message: 'Just a test of logging an error.'});
20     // $mwtnLog.warning({component: COMPONENT, message: 'Just a test of logging a warning.'});
21     // $mwtnLog.debug({component: COMPONENT, message: 'Just a test of logging debug information.'});
22     
23     $rootScope.section_logo = 'src/app/mwtnLog/images/mwtnLog.png'; // Add your topbar logo location here such as 'assets/images/logo_topology.gif'
24
25     $scope.highlightFilteredHeader = $mwtnLogView.highlightFilteredHeader;
26  
27     var rowTemplate = '<div ng-click="grid.appScope.fnOne(row)" ng-repeat="col in colContainer.renderedColumns track by col.colDef.name" ng-class="[\'ui-grid-cell\', row.entity.type]" ui-grid-cell></div>';
28     var iconCell = '<div class="ui-grid-cell-contents tooltip-uigrid" title="TOOLTIP"><i ng-class="{\'fa\':true, \'{{COL_FIELD}}\':true}" aria-hidden="true"></i></div>';
29       
30     $scope.gridOptions = JSON.parse(JSON.stringify($mwtnLogView.gridOptions));
31     $scope.gridOptions.rowTemplate = rowTemplate;
32     $scope.gridOptions.columnDefs = [
33        // { field: 'id', type: 'number', displayName: 'No.',  headerCellClass: $scope.highlightFilteredHeader, width : 50, cellClass: 'number', pinnedLeft : true },
34        { field: 'icon',  type: 'string', displayName: '',  headerCellClass: $scope.highlightFilteredHeader, width: 25, enableSorting: false, enableFiltering:false, cellTemplate: iconCell },
35        { field: 'timestamp',  type: 'string', displayName: 'Timestamp',  headerCellClass: $scope.highlightFilteredHeader, width : 200,sort: {
36          direction: uiGridConstants.DESC,
37          priority: 1
38        } },
39        { field: 'type',  type: 'string', displayName: 'Type',  headerCellClass: $scope.highlightFilteredHeader, width: 70 },
40        { field: 'component',  type: 'string', displayName: 'Component',  headerCellClass: $scope.highlightFilteredHeader, width : 200 },
41        { field: 'message',  type: 'string', displayName: 'Message',  headerCellClass: $scope.highlightFilteredHeader, width : 500 }
42      ];
43     
44     $scope.progress = {
45         show: true,
46         max: 200,
47         value: 160
48     };
49     
50     $scope.clearLog = function () {
51
52       var modalInstance = $uibModal.open({
53         animation: true,
54         ariaLabelledBy: 'modal-title',
55         ariaDescribedBy: 'modal-body',
56         templateUrl: 'src/app/mwtnLog/templates/clearLogConfirmation.tpl.html',
57         controller: 'ClearLogCtrl',
58         size: 'lg',
59         resolve: {
60           now: function () {
61             return new Date().toISOString();
62           }
63         }
64       });
65
66       modalInstance.result.then(function () {
67         var spec = {
68             functionId : 'mwtn',
69             docType : 'log',
70             query: {
71               match_all: {}
72             }
73           };
74           $mwtnLogView.deleteDocType(spec).then(function(deleted){
75             $scope.gridOptions.data = [];
76             $mwtnLog.info({component: COMPONENT, message: 'Log cleared!'});
77           }, function(error){
78             $mwtnLog.error({component: COMPONENT, message:JSON.stringify(error)});
79           });
80       }, function () {
81         $mwtnLog.info({component: COMPONENT, message: 'Mount dismissed!'});
82       });
83     };    
84
85     var getIconFromType = function(type) {
86       var mapping = {
87         debug : '',
88         info : 'fa-info-circle',
89         warning : 'fa-exclamation-triangle',
90         error : 'fa-times-circle'
91       };
92       return mapping[type];
93     };
94     
95     var processLogEntries = function(logEntries) {
96       if (logEntries.data.hits.hits) {
97         logEntries.data.hits.hits.map(function(entry){
98           var log = {
99               id: entry._id,
100               icon: getIconFromType(entry._source.type),
101               timestamp: entry._source.timestamp,
102               type: entry._source.type,
103               component: entry._source.component,
104               message: entry._source.message,
105           };
106           $scope.gridOptions.data.push(log);
107         });
108         $scope.progress.max = logEntries.data.hits.total;         
109         $scope.progress.value = $scope.gridOptions.data.length;         
110         $scope.progress.show = $scope.gridOptions.data.length < logEntries.data.hits.total;
111       }
112     };
113     
114     $scope.refreshLog = function() {
115       $scope.gridOptions.data = [];
116       var from = 0;
117       var size = 100;
118       $scope.processing = true;
119       $mwtnLogView.getAllLogEntries(from, size).then(function(logEntries){
120         $scope.processing = false;
121         processLogEntries(logEntries);
122         from = from + size;
123         while (from < $scope.progress.max) {
124           $mwtnLogView.getAllLogEntries(from, size).then(function(logEntries){
125             processLogEntries(logEntries);
126           }, function(error){
127             console.error(JSON.stringify(error));
128           });
129           from = from + size;
130         }
131       }, function(error){
132         console.error(JSON.stringify(error));
133       });      
134     };
135     $scope.refreshLog();
136
137   }]);
138
139   mwtnLogApp.register.controller('ClearLogCtrl', ['$scope', '$uibModalInstance',
140                                                   function ($scope, $uibModalInstance) {
141
142     $scope.ok = function () {
143       $uibModalInstance.close('ok');
144     };
145
146     $scope.cancel = function () {
147       $uibModalInstance.dismiss('cancel');
148     };
149   }]);
150     
151 });