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