Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / fusion / notebook-integration / scripts / controllers / nbookController.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal SDK
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
21 app.config(function($routeProvider) {
22         $routeProvider
23         
24         //.when('/notebook-frame/:id/:key/:value',{
25         //.when('/notebook-frame/:nid/:qprms',{
26         /*.when('/notebook-frame',{
27                 templateUrl: 'app/fusion/notebook-integration/scripts/view-models/notebook-frame.html',
28                 controller: 'notebookFrameController'
29         })*/
30         
31         .otherwise({
32         //              templateUrl: 'app/fusion/notebook-integration/scripts/view-models/notebook-frame.html',
33                 templateUrl: 'app/fusion/notebook-integration/scripts/view-models/notebookInputs.html', 
34                 controller: 'nbookController'
35                 });
36 }).controller('nbookController', ['$scope', '$location','$window','$http', function ($scope,$location,$window,$http) { 
37         
38         $scope.keyValueList = [{}];
39         console.log('onload nbookController');
40         $scope.submitParameters = function() {
41                 
42                 $scope.iframevisibility = false;
43                 console.log('Inside nbook invoke save');
44                 
45                 $scope.postData = {};
46                 
47                 $scope.additionalqueryParams = {};
48                 
49         //Use this if there is only one 1 query param key value pair 
50                 $scope.additionalqueryParams.paramKey = $scope.qparamKey;
51                 $scope.additionalqueryParams.paramVal = $scope.qparamVal;
52                 
53                 
54         //      console.log('$scope.additionalqueryParams',$scope.additionalqueryParams);
55                 console.log('$scope.notebookvalue',$scope.notebookvalue);
56                 
57                 
58                 //$scope.postData['notebookid'] = 'a06a9cf14211012e221bf842c168849d';
59                 //$scope.postData['param1'] = 'p1';
60                 //$scope.postData['param2'] = 'p2';
61                 
62                 //console.log('Report Schedule object', $scope.reportScheduleObject);
63                 
64         
65                 /* if ($window.location.search.substr($window.location.search.indexOf("=")+1)) {
66                         $scope.queryParams = $window.location.search;
67                         
68                         if ($window.location.search.indexOf("&")!=-1) {
69                                 $scope.notebookparam = $window.location.search.substring($window.location.search.indexOf("?")+1,$window.location.search.indexOf("&"));
70                                 $scope.additionalqueryParams = JSON.parse('{"' + decodeURI($scope.queryParams.substr($scope.queryParams.indexOf("&")+1).replace(/&/g, "\",\"").replace(/=/g,"\":\"")) + '"}');
71                                 console.log('Additional parameters present');
72                         }
73                         else {
74                                 $scope.notebookparam = $window.location.search.substr($window.location.search.indexOf("?")+1);
75                                 console.log('Additional parameters absent');
76                         }
77                         console.log('add parameters',$scope.additionalqueryParams);
78                 //      $scope.notebookid = $scope.notebookparam.substring(0,$scope.notebookparam.indexOf("="));
79                         $scope.notebookvalue = $scope.notebookparam.substr($scope.notebookparam.indexOf("=")+1);
80                         $scope.postData = $window.location.search.substr($window.location.search.indexOf("=")+1);
81                         console.log('Notebook value present ',$scope.notebookvalue);
82                 }
83                 else {
84                         $scope.notebookvalue = '833c0a69ec1433fbb2f8752af733cf0e';
85                         console.log('Notebook value absent ',$scope.notebookvalue);
86                 }*/
87                 
88         //      $http.get("notebook.htm#/notebook-frame", {params : {"a" : "b"}})
89         
90         /*      $http.get("app/fusion/notebook-integration/scripts/view-models/notebook-frame.html", {params : {"a" : "b"}})
91                         .then(function(response) {
92                       console.log("Got response from http get ");
93                      // window.open ('notebook.htm#/notebook-frame','_self',false);
94                   }); */
95                 
96         //      $location.search(1, $scope.additionalqueryParams);
97 //      }
98                 console.log('$scope.additionalqueryParams',$scope.additionalqueryParams);
99 //       $scope.invokeSaveNotebook() = function() { 
100         //      window.open ('notebook.htm#/notebook-frame/1/2/3','_self',false);
101                 
102                 //var testurl = 'nbooktest.htm?nid='+$scope.notebookvalue;
103                 //var testurl = 'nbooktest.htm?nid='+$scope.notebookvalue+'&'+encodeURIComponent(JSON.stringify($scope.additionalqueryParams));
104                 //      var testurl = 'notebook.htm#/notebook-frame/' + $scope.notebookvalue + '/' + encodeURIComponent(JSON.stringify($scope.additionalqueryParams));
105                 
106                 console.log('$scope.keyValueList',$scope.keyValueList);
107                 
108                 /*for (var obj in $scope.keyValueList) {
109                         for (var prop in obj) {
110                                   if (obj.hasOwnProperty(prop)) { 
111                                   // or if (Object.prototype.hasOwnProperty.call(obj,prop)) for safety...
112                                     console.log('property',obj[prop]);
113                                           //console.log("prop: " + prop.qk + " value: " + obj[prop.qk]);
114                                   }
115                                 }
116                 }*/
117                 
118                 console.log('$scope.keyValueList.length',$scope.keyValueList.length);
119                 
120                 var qryStr = '';
121                 for(var i = 0; i < $scope.keyValueList.length; i++) {
122                     var obj = $scope.keyValueList[i];
123                     //console.log('obj.qK',obj.qK);
124                     if (obj.qK != undefined && obj.qV != undefined) { 
125                         //console.log('Inside qk defined');
126                         if (qryStr!='')
127                                 qryStr = qryStr+'&'+obj.qK+'='+obj.qV;
128                             else
129                                 qryStr = obj.qK+'='+obj.qV;
130                             
131                     }
132                     
133                 }
134                 console.log('qryStr',qryStr);
135
136                 
137                 
138                 //var testurl = 'nbooktest.htm?nid='+$scope.notebookvalue+'&k1='+$scope.additionalqueryParams.paramKey+'&v1='+$scope.additionalqueryParams.paramVal;
139                 
140         //      var testurl = 'nbooktest.htm?nid='+$scope.notebookvalue+'&'+$scope.additionalqueryParams.paramKey+'='+$scope.additionalqueryParams.paramVal;
141                 
142                 var queryurl = 'nbooktest.htm?nid='+$scope.notebookvalue+'&'+qryStr;
143                 
144         //      var testurl = 'notebook.htm#/notebook-frame';
145                 
146                 window.open (queryurl,'_self',false);
147
148                 
149         } 
150         
151         $scope.addKeyValuePairs = function (kv) {
152                         
153                         
154                 if ($scope.keyValueList.length < 9) {
155                         $scope.keyValueList.push({  
156                           
157                               });
158                         //      alert($scope.reportRunJson.rangeAxisList.length);
159                         //      console.log('$scope.keyValueList',$scope.keyValueList);
160                         
161                 } else {
162                         //document.getElementById("addbtn").disabled = true;
163                         //      $scope.btnactive = false;
164                         document.getElementById("addbtn")["disabled"]  = true;
165                         //document.getElementById("addbtn")["style.background-color"]  = "#FFFF00";
166                         
167                         //$('#addbtn').btn('type') = "disabled";
168                 }
169         }
170
171         $scope.removeKeyValuePairs = function (index) {
172                 $scope.keyValueList.splice(index, 1);
173                 if ($scope.keyValueList.length == 8) {
174                         document.getElementById("addbtn")["disabled"]  = false;
175                 }
176                 //console.log($scope.hardCodeReport.rangeAxisList)
177         }
178
179 }]);