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