nexus site path corrected
[portal.git] / ecomp-portal-FE / client / kpi-dashboard / controllers / DCAE-controller.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 //app.controller('DCAE_Ctrl_KPI',
21 (function() {
22         var DCAE_Ctrl_KPI = function($scope, $http, $log, $uibModal, $modal, KpiDashboardService) {
23                                         $scope.Math = window.Math;
24                                         $scope.activeToplevelTabId = 'DCAE';
25                                         $scope.activeTabId = 'KPI';
26                                         var TabIdforState = 'DCAE';
27                                         $scope.toplevelgTabs1 = KpiDashboardService.getToplevelgTabs1();
28                                         $scope.toplevelgTabs2 = KpiDashboardService.getToplevelgTabs2();
29                                         $scope.toplevelgTabs3 = KpiDashboardService.getToplevelgTabs3();
30                                         $scope.gTabs = KpiDashboardService.getGenericTabs(TabIdforState);
31
32                                         $scope.progressReadinessMap = {
33                                                 'C' : 'Complete',
34                                                 'Y' : 'Yellow',
35                                                 'R' : 'Red',
36                                                 'G' : 'Green',
37                                                 'n' : 'N/A'
38                                         }
39
40                                         $scope.progressReadinessColorMap = {
41                                                 'C' : 'black',
42                                                 'Y' : '#FFCC00',
43                                                 'R' : 'red',
44                                                 'G' : '#00FF00',
45                                                 'n' : 'black'
46                                         }
47
48                                         $scope.selectedIST = null;
49                                         $scope.progressReadinessList = [];
50
51                                         $scope.progressReadinessListIndexMap = {};
52                                         var counter = 0;
53                                         for ( var key in $scope.progressReadinessMap) {
54                                                 if ($scope.progressReadinessMap.hasOwnProperty(key)) {
55                                                         $scope.progressReadinessList.push({
56                                                                 'index' : counter,
57                                                                 'value' : key,
58                                                                 'title' : $scope.progressReadinessMap[key]
59                                                         })
60                                                         $scope.progressReadinessListIndexMap[key] = counter
61                                                 }
62                                                 counter = counter + 1;
63                                         }
64                                         $scope.selectedProgressReadiness1 = $scope.progressReadinessList[0];
65
66                                         // restAPI calls to retrieve all user stories
67                                         KpiDashboardService.getKpiUserStoriesStats().then(
68                                                         function(response) {
69                                                                 $scope.userStories = response.data;
70                                                                 $scope.releases = [];
71
72                                                                 if ($scope.userStories) {
73                                                                         $scope.userStories.forEach(function(item,
74                                                                                         index) {
75                                                                                 $scope.releases.push({
76                                                                                         'index' : index,
77                                                                                         'value' : item.releaseKey,
78                                                                                         'title' : item.releaseKey
79                                                                                 });
80                                                                         });
81                                                                         $scope.selectedRelease = $scope.releases[0];
82                                                                 }
83                                                         });
84
85                                                         KpiDashboardService.getKpiLocStats()
86                                                         .then(
87                                                                         function(response) {
88                                                                                 $scope.locStats = response.data;
89                                                                                 var arr = $scope.locStats;
90                                                                                 $scope.totalLOC = 0
91                                                                                 $.each(arr, function() {
92                                                                                         $scope.totalLOC += this;
93                                                                                 });
94                                                                                 var sorted = arr.slice().sort(
95                                                                                                 function(a, b) {
96                                                                                                         return b - a
97                                                                                                 })
98                                                                                 $scope.LOCranks = arr.slice().map(
99                                                                                                 function(v) {
100                                                                                                         return sorted.indexOf(v)
101                                                                                                 });
102                                                                                 $scope.sortedLOC = []
103                                                                                 KpiDashboardService.getKpiLocStatsCat()
104                                                                                                 .then(
105                                                                                                                 function(response) {
106                                                                                                                         $scope.locStatsCat = response.data;
107                                                                                                                         $scope.locStatsCatRanked = [];
108                                                                                                                         var OtherPutLast = false
109                                                                                                                         for (i = 0; i < $scope.LOCranks.length; i++) {
110                                                                                                                                 $scope.locStatsCatRanked[$scope.LOCranks[i]] = $scope.locStatsCat[i];
111                                                                                                                                 $scope.sortedLOC[$scope.LOCranks[i]] = $scope.locStats[i];
112                                                                                                                         }
113
114                                                                                                                         $scope.sortedLocArray = [];
115                                                                                                                         var OthersLoC = null;
116
117                                                                                                                         for (i = 0; i < $scope.sortedLOC.length; i++) {
118                                                                                                                                 if ($scope.locStatsCatRanked[i]
119                                                                                                                                                 .toLowerCase() !== "others") {
120                                                                                                                                         $scope.sortedLocArray
121                                                                                                                                                         .push({
122                                                                                                                                                                 'category' : $scope.locStatsCatRanked[i],
123                                                                                                                                                                 'LOC' : $scope.sortedLOC[i]
124                                                                                                                                                         });
125                                                                                                                                 } else {
126                                                                                                                                         OthersLoC = $scope.sortedLOC[i]
127                                                                                                                                 }
128                                                                                                                         }
129                                                                                                                         $scope.sortedLocArray
130                                                                                                                                         .push({
131                                                                                                                                                 'category' : 'Others',
132                                                                                                                                                 'LOC' : OthersLoC
133                                                                                                                                         })
134                                                                                                                 });
135                                                                         });
136
137                                         KpiDashboardService.getKpiServiceSupported()
138                                         .then(
139                                                         function(response) {
140                                                                 $scope.kpiServiceSupported = response.data;
141                                                         });
142
143                                         KpiDashboardService.getKpiPublishedDelivered()
144                                                         .then(function(response) {
145                                                                 $scope.kpiTrafficStatsArray = response.data;
146                                                                 $scope.kpiTrafficStats = [];
147                                                                 $scope.kpiTrafficStats.push({
148                                                                         'title' : 'Published',
149                                                                         'count' : $scope.kpiTrafficStatsArray[0]
150                                                                 });
151                                                                 $scope.kpiTrafficStats.push({
152                                                                         'title' : 'Delivered',
153                                                                         'count' : $scope.kpiTrafficStatsArray[1]
154                                                                 });
155                                                         });
156
157                                         KpiDashboardService.getKpiFeedStats()
158                                         .then(
159                                                         function(response) {
160                                                                 $scope.kpiFeedStatsArray = response.data;
161                                                                 $scope.kpiFeedStats = [];
162                                                                 $scope.kpiFeedStats.push({
163                                                                         'title' : 'Total Feeds',
164                                                                         'count' : $scope.kpiFeedStatsArray[0]
165                                                                 });
166                                                                 $scope.kpiFeedStats.push({
167                                                                         'title' : 'Active Feeds',
168                                                                         'count' : $scope.kpiFeedStatsArray[1]
169                                                                 });
170                                                                 $scope.kpiFeedStats.push({
171                                                                         'title' : 'Active Subs',
172                                                                         'count' : $scope.kpiFeedStatsArray[2]
173                                                                 });
174                                                         });
175
176                                         KpiDashboardService.getKpiUserApiStats()
177                                                         .then(
178                                                                         function(response) {
179                                                                                 $scope.userApis = response.data;
180                                                                                 $scope.userApiTypes = [];
181                                                                                 if ($scope.userApis) {
182                                                                                         $scope.userApis.forEach(function(
183                                                                                                         item, index) {
184                                                                                                 $scope.userApiTypes.push({
185                                                                                                         'index' : index,
186                                                                                                         'value' : item.apiType,
187                                                                                                         'title' : item.apiType
188                                                                                                 });
189                                                                                         });
190                                                                                         $scope.selectedUserApiType = $scope.userApiTypes[0]
191                                                                                 }
192                                                                         });
193
194                                         $scope.linesOfCode = {
195                                                 "TotalLOC" : "2.068M",
196                                                 "OpenSource" : "63%",
197                                                 "Organic" : "36%",
198                                                 "Generated" : "<1%"
199                                         };
200
201                                         $scope.updateUserStory = function(releases, userStories,
202                                                         progressReadinessList,
203                                                         progressReadinessListIndexMap) {
204                                                 var modalInstance = $uibModal
205                                                                 .open({
206                                                                         animation : $scope.animationsEnabled,
207                                                                         templateUrl : 'kpi-dashboard/app/fusion/scripts/view-models/kpidash-page/userstory-edit.html',
208                                                                         size : 'lg',
209                                                                         controller : [
210                                                                                         '$scope',
211                                                                                         '$uibModalInstance',
212                                                                                         '$http',
213                                                                                         function($scope, $uibModalInstance,
214                                                                                                         $http) {
215
216                                                                                                 $scope.AngChangeCalled = function() {
217                                                                                                         console
218                                                                                                                         .log('change called');
219                                                                                                         console
220                                                                                                                         .log($scope.selectedRelease.releaseKey);
221                                                                                                         $scope.selectedIST = $scope.progressReadinessList[progressReadinessListIndexMap[$scope.userStories[$scope.selectedRelease.index].istprogressReadiness]];
222                                                                                                         $scope.selectedETE = $scope.progressReadinessList[progressReadinessListIndexMap[$scope.userStories[$scope.selectedRelease.index].e2EProgressReadiness]];
223                                                                                                         console
224                                                                                                                         .log("$scope.selectedIST");
225                                                                                                         console
226                                                                                                                         .log($scope.selectedIST);
227                                                                                                         console
228                                                                                                                         .log("$scope.selectedETE");
229                                                                                                         console
230                                                                                                                         .log($scope.selectedETE);
231                                                                                                 };
232                                                                                                 $scope.releases = releases;
233                                                                                                 $scope.userStories = userStories;
234                                                                                                 $scope.progressReadinessList = progressReadinessList;
235                                                                                                 $scope.progressReadinessListIndexMap = progressReadinessListIndexMap;
236                                                                                                 $scope.ok = function() {
237                                                                                                         $scope.userStories[$scope.selectedRelease.index].istprogressReadiness = $scope.selectedIST.value;
238                                                                                                         $scope.userStories[$scope.selectedRelease.index].e2EProgressReadiness = $scope.selectedETE.value;
239                                                                                                         $http
240                                                                                                                         .post(
241                                                                                                                                         'portalApi/update_user_stories_stats',
242                                                                                                                                         $scope.userStories[$scope.selectedRelease.index])
243                                                                                                                         .then(
244                                                                                                                                         function(
245                                                                                                                                                         response) {
246                                                                                                                                                 $scope.userStories = response.data;
247                                                                                                                                                 $scope.releases = [];
248                                                                                                                                                 if ($scope.userStories) {
249                                                                                                                                                         $scope.userStories
250                                                                                                                                                                         .forEach(function(
251                                                                                                                                                                                         item,
252                                                                                                                                                                                         index) {
253                                                                                                                                                                                 $scope.releases
254                                                                                                                                                                                                 .push({
255                                                                                                                                                                                                         'index' : index,
256                                                                                                                                                                                                         'value' : item.releaseKey,
257                                                                                                                                                                                                         'title' : item.releaseKey
258                                                                                                                                                                                                 });
259                                                                                                                                                                         });
260                                                                                                                                                 }
261                                                                                                                                                 $uibModalInstance
262                                                                                                                                                                 .close();
263                                                                                                                                         });
264                                                                                                 };
265
266                                                                                                 $scope.cancel = function() {
267                                                                                                         $uibModalInstance.dismiss();
268                                                                                                 };
269                                                                                         } ],
270                                                                         // End of inner controller
271                                                                         resolve : {}
272                                                                 });
273                                         };
274
275                                         $scope.updateUserApi = function(userApiTypes, userApis) {
276                                                 // workflowToEdit.active='true';
277                                                 var modalInstance = $uibModal
278                                                                 .open({
279                                                                         animation : $scope.animationsEnabled,
280                                                                         templateUrl : 'kpi-dashboard/app/fusion/scripts/view-models/kpidash-page/userapi-edit.html',
281                                                                         size : 'lg',
282                                                                         controller : [
283                                                                                         '$scope',
284                                                                                         '$uibModalInstance',
285                                                                                         '$http',
286                                                                                         function($scope, $uibModalInstance,
287                                                                                                         $http) {
288                                                                                                 $scope.userApiTypes = userApiTypes;
289                                                                                                 $scope.userApis = userApis;
290                                                                                                 $scope.ok = function() {
291                                                                                                         /*
292                                                                                                          * var temp =
293                                                                                                          * {"id":null,"created":null,"modified":null,"createdId":null,"modifiedId":null,"rowNum":null,"auditUserId":null,"auditTrail":null,"apiType":"Physical
294                                                                                                          * APIs","totalApi":2000,"comment":null};
295                                                                                                          */
296                                                                                                         var temp = $scope.userApis[$scope.selectedUserApiType.apiType.index]
297                                                                                                         $http
298                                                                                                                         .post(
299                                                                                                                                         'portalApi/update_user_api_stats',
300                                                                                                                                         temp)
301                                                                                                                         .then(
302                                                                                                                                         function(
303                                                                                                                                                         response) {
304                                                                                                                                                 $uibModalInstance
305                                                                                                                                                                 .close();
306                                                                                                                                                 /*
307                                                                                                                                                  * $http.post('update_user_stories_stats',$scope.userStories[$scope.selectedRelease.releaseKey.index])
308                                                                                                                                                  * .then(function(response){
309                                                                                                                                                  * $scope.userStories =
310                                                                                                                                                  * response.data;
311                                                                                                                                                  * $scope.releases
312                                                                                                                                                  * =[];
313                                                                                                                                                  * if($scope.userStories){
314                                                                                                                                                  * $scope.userStories.forEach(function(item,
315                                                                                                                                                  * index){
316                                                                                                                                                  * $scope.releases.push({'index':
317                                                                                                                                                  * index,
318                                                                                                                                                  * 'value':
319                                                                                                                                                  * item.releaseKey,
320                                                                                                                                                  * 'title':item.releaseKey});
321                                                                                                                                                  * });
322                                                                                                                                                  * $uibModalInstance.close();
323                                                                                                                                                  *  }
324                                                                                                                                                  */
325                                                                                                                                         });
326                                                                                                 };
327
328                                                                                                 $scope.cancel = function() {
329                                                                                                         $uibModalInstance.dismiss();
330                                                                                                 };
331                                                                                         } ],
332                                                                         // End of inner controller
333                                                                         resolve : {}
334                                                                 });
335                                         };
336         };
337
338         DCAE_Ctrl_KPI.$inject = ['$scope','$http', '$log', '$uibModal', '$modal', 'KpiDashboardService'];
339         angular.module('ecompApp').controller('DCAE_Ctrl_KPI',DCAE_Ctrl_KPI);
340
341 }());
342                                 // });
343
344 app.controller('DCAE_Ctrl_UserDefinedKPI', function($scope, $http, $log, KpiDashboardService) {
345         $scope.activeToplevelTabId = 'DCAE';
346         $scope.activeTabId = 'User Defined KPI';
347         var TabIdforState = 'DCAE';
348         $scope.toplevelgTabs1 = KpiDashboardService.getToplevelgTabs1();
349         $scope.toplevelgTabs2 = KpiDashboardService.getToplevelgTabs2();
350         $scope.toplevelgTabs3 = KpiDashboardService.getToplevelgTabs3();
351         $scope.gTabs = KpiDashboardService.getGenericTabs(TabIdforState);
352
353 });
354
355 app.controller('DCAE_Ctrl_Metrics', function($scope, $http, $log, $uibModal,
356                 $modal, KpiDashboardService) {
357         $scope.activeToplevelTabId = 'DCAE';
358         $scope.activeTabId = 'Metrics';
359         var TabIdforState = 'DCAE';
360         $scope.toplevelgTabs1 = KpiDashboardService.getToplevelgTabs1();
361         $scope.toplevelgTabs2 = KpiDashboardService.getToplevelgTabs2();
362         $scope.toplevelgTabs3 = KpiDashboardService.getToplevelgTabs3();
363         $scope.gTabs = KpiDashboardService.getGenericTabs(TabIdforState);
364
365         KpiDashboardService.getKpiGeoMapUrl()
366         .then(function(response) {
367                 $scope.geoMapUrl = response.data;
368         });
369
370         KpiDashboardService.getKpiRCloudAUrl()
371         .then(function(response) {
372                 $scope.rcloudAUrl = response.data;
373         });
374
375 });