806b1bc28665c79d6d520fc838e7c158c4a46e48
[portal/sdk.git] /
1 appDS2.controller('reportChartController', function ($scope, $rootScope, $timeout, $window, $http, $routeParams,modalService) {
2         //$scope.test="1223";
3         //alert($scope.chartType.value);
4         console.log("reportChartController called");
5     $scope.commonOptionOpen = false;
6     $scope.additionalOptionOpen = false;
7     
8         $scope.selectedChartType = {value:""};
9     $scope.chartTypeOptions = [
10         {value: 'barChart', text: 'Bar Chart'},
11         {value: 'timeSeries', text: 'Time Series/Area Chart'},
12         {value: 'pieChart', text: 'Pie Chart'},         
13         {value: 'annotationChart', text: 'Annotation Chart'},
14         {value: 'flexibleTimeChart', text: 'Flexible Time Chart'}    
15     ];
16     
17     $scope.animateSelected = {value:false};
18     
19         $scope.populateChrtWzdFields = function() {
20                 $scope.reportRunJson = {};
21                 $http.get("raptor.htm?action=chart.json&c_master="+$routeParams.reportId).then(function (response) {
22                         $scope.reportRunJson = response.data;
23                           //Set chart type
24                           if ($scope.reportRunJson.chartTypeJSON) {
25                                   var chrtTypeValue = $scope.reportRunJson.chartTypeJSON.value;
26                                          for(var i = 0; i < $scope.chartTypes.length; i++) {
27                                                     var obj = $scope.chartTypes[i];
28                                                     //console.log(obj.id);
29                                                     if ($scope.chartTypes[i].value==chrtTypeValue) {
30                                                         $scope.reportRunJson.chartTypeJSON.index=$scope.chartTypes[i].index;
31                                                         $scope.reportRunJson.chartTypeJSON.title=$scope.chartTypes[i].title;
32                                                     }
33         
34                                         }
35                           }      
36                                  
37                                 //Set Domain Axis
38                                  if ($scope.reportRunJson.domainAxisJSON) {
39                                           var domaninAxisValue = $scope.reportRunJson.domainAxisJSON.value;
40                                                  for(var i = 0; i < $scope.reportRunJson.chartColumnJSONList.length; i++) {
41                                                            if ($scope.reportRunJson.chartColumnJSONList[i].value==domaninAxisValue) {
42                                                                 $scope.reportRunJson.domainAxisJSON.index=$scope.reportRunJson.chartColumnJSONList[i].index;
43                                                                 $scope.reportRunJson.domainAxisJSON.title=$scope.reportRunJson.chartColumnJSONList[i].title;
44                                                             }
45                 
46                                                 }
47                                   }
48                                  
49                                 //Set Category
50                                  if ($scope.reportRunJson.categoryAxisJSON) {
51                                           var categoryAxisValue = $scope.reportRunJson.categoryAxisJSON.value;
52                                                  for(var i = 0; i < $scope.reportRunJson.chartColumnJSONList.length; i++) {
53                                                            if ($scope.reportRunJson.chartColumnJSONList[i].value==categoryAxisValue) {
54                                                                 $scope.reportRunJson.categoryAxisJSON.index=$scope.reportRunJson.chartColumnJSONList[i].index;
55                                                                 $scope.reportRunJson.categoryAxisJSON.title=$scope.reportRunJson.chartColumnJSONList[i].title;
56                                                             }
57                                                 }
58                                   }
59                                  
60                                 //Set range axis label
61                 if ($scope.reportRunJson.rangeAxisList) {
62                         for(var j = 0; j < $scope.reportRunJson.rangeAxisList.length; j++) { 
63                                  
64                                  if ($scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON) {
65                                           var rangeAxisLabelValue = $scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON.value;
66                                                  for(var i = 0; i < $scope.reportRunJson.chartColumnJSONList.length; i++) {
67                                                            if ($scope.reportRunJson.chartColumnJSONList[i].value==rangeAxisLabelValue) {
68                                                                 $scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON.index=$scope.reportRunJson.chartColumnJSONList[i].index;
69                                                                 $scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON.title=$scope.reportRunJson.chartColumnJSONList[i].title;
70                                                             }
71                                                 }
72                                   }
73                         }
74                 }
75                                 
76                                 
77                                 //set range linetype
78                                 if ($scope.reportRunJson.rangeAxisList) {
79                                         for(var j = 0; j < $scope.reportRunJson.rangeAxisList.length; j++) { 
80                                                  if ($scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON != null && $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.value != ""
81                                                          && $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.value != null) {
82                                                          var lineTypeValue = $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.value;
83                                                          for(var i = 0; i < $scope.lineTypes.length; i++) {
84                                                                     if ($scope.lineTypes[i].value==lineTypeValue) {
85                                                                         $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.index=$scope.lineTypes[i].index;
86                                                                         $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.title=$scope.lineTypes[i].title;
87                                                                     }
88                                                         }
89                                                 } else {
90                                                         $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON = null;
91                                                 }  
92                                         }
93                                 }
94                                 //set range color
95                                 if ($scope.reportRunJson.rangeAxisList) {
96                                         for(var j = 0; j < $scope.reportRunJson.rangeAxisList.length; j++) { 
97                                                  if ($scope.reportRunJson.rangeAxisList[j].rangeColorJSON != null && $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.value != ""
98                                                          && $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.value != null) {
99                                                          var colorValue = $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.value; 
100                                                          for(var i = 0; i < $scope.rangeColors.length; i++) {
101                                                                  if ($scope.rangeColors[i].value==colorValue) {
102                                                                          $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.index=$scope.rangeColors[i].index;
103                                                                          $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.title=$scope.rangeColors[i].title;
104                                                                  }
105                                                          }
106                                                  }else {
107                                                          $scope.reportRunJson.rangeAxisList[j].rangeColorJSON = null; 
108                                                  }
109                                         }
110                                 }
111                   });
112                 
113                 $scope.legend = "true";
114         }
115         
116         $scope.saveChartData = function() {
117                 //Converting string variables to numbers
118                 $scope.reportRunJson.commonChartOptions.rightMargin = Number($scope.reportRunJson.commonChartOptions.rightMargin);
119                 $scope.reportRunJson.commonChartOptions.topMargin = Number($scope.reportRunJson.commonChartOptions.topMargin);
120                 $scope.reportRunJson.commonChartOptions.bottomMargin = Number($scope.reportRunJson.commonChartOptions.bottomMargin);
121                 $scope.reportRunJson.commonChartOptions.leftMargin = Number($scope.reportRunJson.commonChartOptions.leftMargin);
122          
123                 if ($scope.reportRunJson.categoryAxisJSON == "") { 
124                         console.log('Inside categoryAxisJSON value'); 
125                         $scope.reportRunJson.categoryAxisJSON = {}; 
126                         $scope.reportRunJson.categoryAxisJSON.value = -1; 
127                         console.log('$scope.reportRunJson.categoryAxisJSON',$scope.reportRunJson.categoryAxisJSON);  
128                 }
129                 
130                 console.log($scope.reportRunJson);
131                 $http.post("save_chart", JSON.stringify($scope.reportRunJson)).success(function(data, status) {
132                          $scope.successSubmit=true;             
133                         })
134         }
135         
136         
137         $scope.addRangeAxisRow = function (rangeaxisitem) {
138                 $scope.reportRunJson.rangeAxisList.push({
139               });       
140         };
141
142         $scope.removeRangeAxisRow = function (index) {
143                 $scope.reportRunJson.rangeAxisList.splice(index, 1);
144         };
145         
146         
147         $scope.init = function () {
148                 if ($scope) { 
149                         $scope.populateChrtWzdFields();
150                 }
151         };
152         
153         
154         
155         $scope.domainItems = [{title:"Domain Axis1", content:"Test1", open: false},{title:"Domain Axis2", content:"Test2", open: false}];
156         
157         $scope.chartTypes = [        
158                              {index: 0, value: 'BarChart3D', title: 'Bar Chart'},
159                              {index: 1, value: 'TimeSeriesChart', title: 'Time Series/Area Chart'},
160                              {index: 2, value: 'PieChart', title: 'Pie Chart'},
161                              {index: 3, value: 'AnnotationChart', title: 'Annotation Chart'},
162                              {index: 4, value: 'FlexTimeChart', title: 'Flexible Time Chart'}
163          ];
164          
165          $scope.categories = [        
166                                      {index: 0, value: 'scenario_name', title: 'scenario_name'},
167                                      {index: 1, value: 'total_traffic_in_PB', title: 'Total Traffic in PB'},
168                                      {index: 2, value: 'Avg Utilization Day', title: 'Avg Utilization Day'}      
169                  ];
170          
171          $scope.rangeColors = [                                      
172                                      {index: 0, value: "#1f77b4",title: "Dodger Blue"},                                                 
173                                                          {index: 1, value: "#ff7f0e",title: "Vivid orange"},                                                    
174                                                          {index: 2, value: "#2ca02c",title: "Forest Green"},                                                    
175                                                          {index: 3, value: "#8c864b",title: "Greenish Red"},                                                    
176                                                          {index: 4, value: "#9467bd",title: "Desaturated violet"},                                      
177                                                          {index: 5, value: "#8c564b",title: "Dark moderate red"},                                       
178                                                          {index: 6, value: "#e377c2",title: "Soft pink"},                                                       
179                                                          {index: 7, value: "#7f7f7f",title: "Dark gray"},                                                       
180                                                          {index: 8, value: "#bcbd22",title: "Strong yellow"},                                           
181                                                          {index: 9, value: "#17becf",title: "Strong cyan"},                                                     
182                                                          {index: 10, value: "#dc143c",title: "Vivid red"},                                                      
183                                                          {index: 11, value: "#800080",title: "Dark magenta"},                                                   
184                                                          {index: 12, value: "#0000FF",title: "Blue"},                                                                   
185                                                          {index: 13, value: "#008000",title: "Dark lime green"},                                                
186                                                          {index: 14, value: "#D2691E",title: "Reddish Orange"},                                 
187                                                          {index: 15, value: "#FF0000",title: "Red"},                                                            
188                                                          {index: 16, value: "#000000",title: "Black"},                                                          
189                                                          {index: 17, value: "#DB7093",title: "Pink"},                                                           
190                                                          {index: 18, value: "#FF00FF",title: "Pure Magenta"},                                           
191                                                          {index: 19, value: "#7B68EE",title: "Soft blue"},                                                      
192                                                          {index: 20, value: "#1f77b6",title: "Strong blue"},                                            
193                                                          {index: 21, value: "#9edae5",title: "Very soft cyan"},                                         
194                                                          {index: 22, value: "#393b79",title: "Dark Blue"},                                                      
195                                                          {index: 23, value: "#5254a3",title: "Dark moderate Blue"},                                     
196                                                          {index: 24, value: "#6b6ecf",title: "Slightly desaturated blue"},                      
197                                                          {index: 25, value: "#9c9ede",title: "Very soft blue"},                 
198                                                          {index: 26, value: "#637939",title: "Dark Green"},                                                     
199                                                          {index: 27, value: "#8ca252",title: "Dark moderate green"},                            
200                                                          {index: 28, value: "#b5cf6b",title: "Slightly desaturated green"},                     
201                                                          {index: 29, value: "#cedb9c",title: "Desaturated Green"},      
202      
203                                                          /* Old Colors  */
204                                                          {index: 30, value: "#00FFFF",title: "Aqua"},
205                                                          {index: 31, value: "#000000",title: "Black"},
206                                                          {index: 32, value: "#0000FF",title: "Blue"},
207                                                          {index: 33, value: "#FF00FF",title: "Fuchsia"},
208                                                          {index: 34, value: "#808080",title: "Gray"},
209                                                          {index: 35, value: "#008000",title: "Green"},
210                                                          {index: 36, value: "#00FF00",title: "Lime"},
211                                                          {index: 37, value: "#800000",title: "Maroon"},
212                                                          {index: 38, value: "#000080",title: "Navy"},
213                                                          {index: 39, value: "#808000",title: "Olive"},
214                                                          {index: 40, value: "#FF9900",title: "Orange"},
215                                                          {index: 41, value: "#800080",title: "Purple"},
216                                                          {index: 42, value: "#FF0000",title: "Red"},
217                                                          {index: 43, value: "#C0C0C0",title: "Silver"},
218                                                          {index: 44, value: "#008080",title: "Teal"},
219                                                          {index: 45, value: "#FFFFFF",title: "White"},
220                                                          {index: 46, value: "#FFFF00",title: "Yellow"}
221                                                 ];      
222     
223     
224          $scope.lineTypes = [        
225                              {index: 0, value: 'default', title: 'Default'},
226                              {index: 1, value: 'dotted_lines', title: 'Dotted Lines'},
227                              {index: 2, value: 'dashed_lines', title: 'Dashed Lines'}       
228          ]; 
229          
230          $scope.hardCodeReport= {
231                    "reportID":"3356",
232                    "reportName":"Test: Line Chart",
233                    "reportDescr":"",
234                    "reportTitle":"",
235                    "reportSubTitle":"",
236                    "formFieldList":[
237                    ],
238                    "chartColumnJSONList":[
239                       {
240                          "index":0,
241                          "value":"tr0",
242                          "title":"traffic_date",
243                          "$$hashKey":"056"
244                       },
245                       {
246                          "index":1,
247                          "value":"ut1",
248                          "title":"util_perc",
249                          "$$hashKey":"057"
250                       }
251                    ],
252                    "formfield_comments":null,
253                    "totalRows":0,
254                    "chartSqlWhole":"SELECT traffic_date tr0, traffic_date tr0_1,util_perc ut1, 1 FROM portal.demo_util_chart   ORDER BY 1",
255                    "chartAvailable":true,
256                    "chartType":{"index": "", "value": "Bar Chart", "title": ""},
257                    "width":"700",
258                    "height":"420",
259                    "animation":false,
260                    "rotateLabels":"90",
261                    "staggerLabels":false,
262                    "showTitle":"false",
263                    "domainAxis":{
264                               "index":0,
265                               "value":"tr0",
266                               "title":"traffic_date",
267                               "$$hashKey":"11H"
268                            },
269
270                            "categoryAxis":{
271                                       "index":1,
272                                       "value":"ut1",
273                                       "title":"util_perc",
274                                       "$$hashKey":"11I"
275                                    },
276
277                    "hasCategoryAxis":false,
278                    "rangeAxisList":[
279                       {
280                          
281                          "rangeColor":{
282                                 "index":"",
283                             "value":"#bcbd22",
284                             "title":""
285                          },
286                          
287                          "rangeLineType":{
288                             "index":"",
289                             "value":"dotted_lines",
290                             "title":""
291                          },                      
292                          "rangeAxisLabel":{
293                             "index":0,
294                             "value":"tr0",
295                             "title":"traffic_date",
296                             "$$hashKey":"056"
297                          },
298                          "YAxis":"10",
299                          "chartTitle":"test"
300                       },
301                       {      
302                                  "rangeColor":{
303                                         "index":"",
304                                     "value":"#2ca02c",
305                                     "title":""
306                                  },
307                                  
308                                  "rangeLineType":{
309                                     "index":"",
310                                     "value":"dashed_lines",
311                                     "title":""
312                                     
313                                     
314                                  },
315                                  
316                                  "rangeAxisLabel":{
317                                     "index":0,
318                                     "value":"tr0",
319                                     "title":"traffic_date",
320                                     "$$hashKey":"056"
321                                  },
322                                  "YAxis":"10",
323                                  "chartTitle":"test"
324                               }
325                       
326                      
327                    ],
328                   
329                    "primaryAxisLabel":"testlabel",
330                    "secondaryAxisLabel":"testseclabel",
331                    "minRange":"10",
332                    "maxRange":"20",
333                    "topMargin":"6",
334                    "bottomMargin":"5",
335                    "leftMargin":"4",
336                    "rightMargin":"3"
337                 };
338          
339          var colorValue = $scope.hardCodeReport.rangeAxisList[0].rangeColor.value;
340                  
341                 $timeout(function() {
342                         $rootScope.isViewRendering = false;
343                         });
344
345
346 });
347
348 app.directive('onlyDigits', function () {
349
350     return {
351         restrict: 'A',
352         require: '?ngModel',
353         link: function (scope, element, attrs, ngModel) {
354             if (!ngModel) return;
355             ngModel.$parsers.unshift(function (inputValue) {
356                 var digits = inputValue.split('').filter(function (s) { return (!isNaN(s) && s != ' '); }).join('');
357                 ngModel.$viewValue = digits;
358                 ngModel.$render();
359                 return digits;
360             });
361         }
362     };
363 });
364
365 app.directive('onlyCharacters', function () {
366     return {
367         restrict: 'A',
368         require: '?ngModel',
369         link: function (scope, element, attrs, ngModel) {
370             if (!ngModel) return;
371             ngModel.$parsers.unshift(function (inputValue) {
372                 var digits = inputValue.split('').filter(function (s) { return (isNaN(s) && s != ' '); }).join('');
373                 ngModel.$viewValue = digits;
374                 ngModel.$render();
375                 return digits;
376             });
377         }
378     };
379 });
380
381
382