aboutsummaryrefslogtreecommitdiffstats
path: root/configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-applyConfig-controller.js
blob: faff36338901ed1d06a67f5a234e4245529ad69c (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
myApp.controller('ApplyConfigCtrl', ['$scope','$window', '$http', 'growl', 'deviceConfigService', 'ObjectDiff', function($scope, $http,$window, growl, deviceConfigService, ObjectDiff) {

    $scope.showResult = false;

    //THIS FUNCTION WILL BE CALLED ON PAGE LOAD
    $scope.getAllVNFFromRc = function() {

        deviceConfigService.getAllVNFFromRc().then(function(data) {
            if (data != null) {
                console.log(data);
                $scope.objvnfList = data;
             console.log("CompareConfigCtrl:getAllVNFFromRc called" + $scope.objvnfList);
            } else {
                $scope.warningMessage = "No VNF is eligible for configuration!!!";
                growl.error($scope.warningMessage, {
                    title: 'Warning!',
                    globalDisableCloseButton: false,
                    ttl: 7000,
                    disableCountDown: true  
                });
            }
        });
    };
   $scope.getAllVNFFromRc();
   
   
 
   $scope.selectVnf = function(selectedValueVnf) {

   	var vnfId = selectedValueVnf;
   	
   	 $scope.fileContent = '';
   	    $scope.fileSize = 0;
   	    $scope.fileName = '';
   	  
   	    $scope.submit = function () {
   	      var file = document.getElementById("myFileInput").files[0];
   	    $scope.result1={}; 
   	     
   	      if (file) {
   	        var aReader = new FileReader();
   	        aReader.readAsText(file, "UTF-8");
   	        aReader.onload = function (evt) {
   	           // $scope.fileContent = aReader.result;
   	            $scope.fileName = document.getElementById("myFileInput").files[0].name;
   	            $scope.fileSize = document.getElementById("myFileInput").files[0].size;
   	            var id= vnfId;
   	             result1=JSON.parse(aReader.result);
   	            /*var item = JSON.parse(result1);*/
   	            $scope.fileContent = aReader.result.search(id);
   	            $scope.successMessagebool = false;
   	        if(  $scope.fileContent == -1){
   	        	  $scope.errorMessage = "VNF Id is different!!! Select different file and try again";
   	              growl.error($scope.errorMessage, {
   	                  title: 'Error!',
   	                  globalDisableCloseButton: false,
   	                 ttl: 7000,
   	                 disableCountDown: true  
   	              });
   	            }
   	        else{
   	        	
   	         $scope.apply();
   	     
   	        }
   	           }
   	        aReader.onerror = function (evt) {
   	            $scope.fileContent = "error";
   	        }
   	      }
   	   $scope.successMessagebool1 = false;
   	       $scope.apply = function() {
   	          if (file) {
   	        	  deviceConfigService.runApplyconfig(vnfId,result1);
   	        	$scope.successMessage = "File uploaded successfully";
	              growl.success($scope.successMessage, {
	                  title: 'Success!',
	                  globalDisableCloseButton: false,
	                  ttl: 7000,
	                  disableCountDown: true  
	             }); 
 	            $scope.successMessagebool1 = true;
   	          
   	      
   	          }  };
   	    
   	    }
   	    
   	      }
   
   
}]);