aboutsummaryrefslogtreecommitdiffstats
path: root/SDNC-GUI-253/webapp/js/sdnc-controller/sdnc-viewreport-controller.js
blob: 7fdc2d56db1519155c23c8fdabc2e80a037025f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* ============LICENSE_START=======================================================
* ONAP : SDNC-FEATURES
* ================================================================================
* Copyright 2018 TechMahindra
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/

myApp.controller('ReportController', ['$scope', '$http', 'viewReportService', 'growl', function($scope, $http, viewReportService, growl) {
    $scope.isDisabled = true;
    $scope.pagination = false;
    $scope.selectedDevice;
    $scope.ShowResult = false;
    $scope.dateValidation = false;
    $scope.NoSearchResult = false;
    $scope.showError = false;
    $scope.errorMessage = "";
    $scope.showSuccess = false;
    $scope.successMessage = "";
    $scope.showWarning = false;
    $scope.warningMessage = "";
    $scope.showExecutionDetails = true;

    //THIS FUNCTION WILL BE CALLED WHEN USER CLICK SUBMIT FROM UI
    $scope.getReports = function(deviceName, startdate, enddate) {

        $scope.ShowResult = false;
        if (new Date(startdate) > new Date(enddate)) {
            $scope.dateValidation = true;
            $scope.showError = true;
            $scope.errorMessage = "Start date cannot be greated than End date";
            growl.error($scope.errorMessage, {
                title: 'Error!'
            });
            return false;
        }
        var date = new Date(startdate);
        if (angular.isDefined(deviceName)) {
            $scope.DeviceName = deviceName;
        }
        if (angular.isDefined(startdate)) {
            $scope.startDate = startdate;
        }
        if (angular.isDefined(enddate)) {
            $scope.endDate = enddate;
        }

        //to generate the dynamic file name while downloading the report
        //var date = new Date();
        // $scope.fileName = $scope.TestName + " " + $scope.TestName + date.csv;
        // console.log("FileName", $scope.fileName);

        if (deviceName != null && startdate != null && enddate != null) {

            //service call to fetch the reports start date,end date,test name
            viewReportService.getData($scope.startDate, $scope.endDate, $scope.DeviceName).then(function(result) {
                    console.log("--ReportController::getdata called from controler--", JSON.stringify(result.data));
                    if (result.status == 200) {
                        if (result.data != null && result.data.length >= 1) {
                            //in case of success, build the model object to store the service output here
                            $scope.createTestReportModel(result.data);
                        } else {
                            $scope.ShowResult = false;
                            $scope.showWarning = true;
                            $scope.warningMessage = "No result found for specified Device name !!";
                            growl.warning($scope.warningMessage, {
                                title: 'Warning!'
                            });
                        }
                    } else {
                        $scope.ShowResult = false;
                        $scope.showWarning = true;
                        $scope.warningMessage = "No result found for specified Device name !!";
                        growl.warning($scope.warningMessage, {
                            title: 'Warning!'
                        });
                    }
                },
                function(response) {
                    console.log("--ReportController::getdata::Error--", response);
                });
        }
    }


    //FUNCTION WILL BE CALLED WHEN USER CLICK DOWNLOAD FROM UI
    $scope.exportToExcel = function(tableId) { // ex: '#my-table'
        var exportHref = Excel.tableToExcel(tableId, 'export');
        $timeout(function() {
            location.href = exportHref;
        }, 100); // trigger download

        console.log("--ReportController::exportToexcel--");
    }

    $scope.createTestReportModel = function(result) {

        $scope.showError = false;
        $scope.showWarning = false;
        $scope.objTestReportModel = result;
        $scope.objTestModel = [];


        if ($scope.objTestReportModel.length > 1) {
            for (var i = 0; i < $scope.objTestReportModel.length; i++) {
                var objTestReport = {};
                objTestReport.testid = $scope.objTestReportModel[i].testid;
                objTestReport.deviceid = $scope.objTestReportModel[i].deviceid;
                objTestReport.deviceName = $scope.objTestReportModel[i].deviceName;
                objTestReport.result = $scope.objTestReportModel[i].result;
                objTestReport.timeStamp = $scope.objTestReportModel[i].timeStamp;
                objTestReport.testname = $scope.objTestReportModel[i].testName;

                var executionDetails = {};
                $scope.tmp = angular.fromJson($scope.objTestReportModel[i].execuationDetails); 
                executionDetails = $scope.tmp.output;

                if ($scope.objTestReportModel[i].testName === "Network Layer") {
                    //fetching the statistics to show in progress bar
                    var statistics = executionDetails.statistics;
                    objTestReport.status = executionDetails.status;
                    objTestReport.statistics = executionDetails.statistics;
                    statistics = statistics.split("%");
                    executionDetails.statistics = statistics[0];
                    if (executionDetails.statistics == 0) {
                        executionDetails.statisticPer = parseInt(executionDetails.statistics) + 50;
                    } else
                        executionDetails.statisticPer = executionDetails.statistics;

                    console.log("--ReportController::CreateTestReportModel--", executionDetails.statistics);

                    //fetching the avg time to show in progress bar
                    var avgTime = executionDetails.avgTime;
                    objTestReport.avgTime = executionDetails.avgTime;
                    avgTime = avgTime.split("=");
                    var Testtime = avgTime[1];
                    executionDetails.avgTime = Testtime.slice(0, -2).trim();
                    console.log("--ReportController::CreateTestReportModel--", executionDetails.avgTime);
                    if (executionDetails.avgTime < 50) {
                        executionDetails.avgTimePer = parseInt(executionDetails.avgTime) + 10;
                    } else
                        executionDetails.avgTimePer = executionDetails.avgTime;

                }


                objTestReport.executionDetails = executionDetails;
                $scope.objTestModel.push(objTestReport);
                console.log("--ReportController::CreateTestReportModel--", JSON.stringify($scope.objTestModel));

            }
            $scope.ShowResult = true;
            $scope.pagination = true;
        }
        console.log("--ReportController::createTestReportModel::final TestReportModel--" + JSON.stringify($scope.objTestModel));
        $scope.csvOrder = ['testname', 'deviceName', 'timeStamp', 'status', 'statistics', 'avgTime', 'result'];

    }
}]);