2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright 2018 TechMahindra
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ============LICENSE_END=========================================================
21 myApp.controller('ReportController', ['$scope', '$http', 'viewReportService', 'growl', function($scope, $http, viewReportService, growl) {
22 $scope.isDisabled = true;
23 $scope.pagination = false;
24 $scope.selectedDevice;
25 $scope.ShowResult = false;
26 $scope.dateValidation = false;
27 $scope.NoSearchResult = false;
28 $scope.showError = false;
29 $scope.errorMessage = "";
30 $scope.showSuccess = false;
31 $scope.successMessage = "";
32 $scope.showWarning = false;
33 $scope.warningMessage = "";
34 $scope.showExecutionDetails = true;
36 //THIS FUNCTION WILL BE CALLED WHEN USER CLICK SUBMIT FROM UI
37 $scope.getReports = function(deviceIP, startdate, enddate) {
39 $scope.ShowResult = false;
40 if (new Date(startdate) > new Date(enddate)) {
41 $scope.dateValidation = true;
42 $scope.showError = true;
43 $scope.errorMessage = "Start date cannot be greated than End date";
44 growl.error($scope.errorMessage, {
49 var date = new Date(startdate);
50 if (angular.isDefined(deviceIP)) {
51 $scope.DeviceIP = deviceIP;
53 if (angular.isDefined(startdate)) {
54 $scope.startDate = startdate;
56 if (angular.isDefined(enddate)) {
57 $scope.endDate = enddate;
60 if (deviceIP != null && startdate != null && enddate != null) {
62 //service call to fetch the reports start date,end date,test name
63 viewReportService.getData($scope.startDate, $scope.endDate, $scope.DeviceIP).then(function(result) {
64 console.log("--ReportController::getdata called from controler--", JSON.stringify(result.data));
65 if (result.status == 200) {
66 if (result.data != null && result.data.length >= 1) {
68 //in case of success, build the model object to store the service output here
69 $scope.createTestReportModel(result.data);
71 $scope.ShowResult = false;
72 $scope.showWarning = true;
73 $scope.warningMessage = "No result found for specified Device name !!";
74 growl.warning($scope.warningMessage, {
79 $scope.ShowResult = false;
80 $scope.showWarning = true;
81 $scope.warningMessage = "No result found for specified Device name !!";
82 growl.warning($scope.warningMessage, {
88 console.log("--ReportController::getdata::Error--", response);
94 //FUNCTION WILL BE CALLED WHEN USER CLICK DOWNLOAD FROM UI
95 $scope.exportToExcel = function(tableId) { // ex: '#my-table'
96 var exportHref = Excel.tableToExcel(tableId, 'export');
98 location.href = exportHref;
99 }, 100); // trigger download
101 console.log("--ReportController::exportToexcel--");
104 $scope.createTestReportModel = function(result) {
106 $scope.showError = false;
107 $scope.showWarning = false;
108 $scope.objTestReportModel = result;
109 $scope.objTestModel = [];
112 if ($scope.objTestReportModel.length >= 1) {
113 for (var i = 0; i < $scope.objTestReportModel.length; i++) {
114 var objTestReport = {};
115 objTestReport.testid = $scope.objTestReportModel[i].testid;
116 objTestReport.deviceid = $scope.objTestReportModel[i].deviceid;
117 objTestReport.deviceIP = $scope.objTestReportModel[i].deviceIP;
118 objTestReport.result = $scope.objTestReportModel[i].result;
119 objTestReport.timeStamp = $scope.objTestReportModel[i].timeStamp;
120 objTestReport.testname = $scope.objTestReportModel[i].testName;
122 var executionDetails = {};
123 $scope.tmp = angular.fromJson($scope.objTestReportModel[i].execuationDetails);
124 executionDetails = $scope.tmp.output;
126 if ($scope.objTestReportModel[i].testName === "Network Layer") {
128 //fetching the statistics to show in progress bar
129 var statistics = executionDetails.statistics;
130 objTestReport.status = executionDetails.status;
131 objTestReport.statistics = executionDetails.statistics;
132 statistics = statistics.split("%");
133 executionDetails.statistics = statistics[0];
134 if (executionDetails.statistics == 0) {
135 executionDetails.statisticPer = parseInt(executionDetails.statistics) + 50;
137 executionDetails.statisticPer = executionDetails.statistics;
139 console.log("--ReportController::CreateTestReportModel--", executionDetails.statistics);
141 //fetching the avg time to show in progress bar
143 var avgTime = executionDetails.avgTime;
144 objTestReport.avgTime = executionDetails.avgTime;
145 avgTime = avgTime.split("=");
146 var Testtime = avgTime[1];
147 executionDetails.avgTime = Testtime.slice(0, -2).trim();
148 console.log("--ReportController::CreateTestReportModel--", executionDetails.avgTime);
149 if (executionDetails.avgTime < 50) {
150 executionDetails.avgTimePer = parseInt(executionDetails.avgTime) + 10;
152 executionDetails.avgTimePer = executionDetails.avgTime;
157 objTestReport.executionDetails = executionDetails;
158 $scope.objTestModel.push(objTestReport);
159 console.log("--ReportController::CreateTestReportModel--", JSON.stringify($scope.objTestModel));
162 $scope.ShowResult = true;
163 $scope.pagination = true;
165 console.log("--ReportController::createTestReportModel::final TestReportModel--" + JSON.stringify($scope.objTestModel));
166 $scope.csvOrder = ['testname', 'deviceIP', 'timeStamp', 'status', 'statistics', 'avgTime', 'result'];