fe3ee7f7ceedc4240405c13cdb837f7906c0e318
[portal/sdk.git] /
1 /*
2  * Copyright (c) 2014 DataTorrent, Inc. ALL Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 'use strict';
18
19 app
20   .directive('wtTime', function ($interval) {
21     return {
22       restrict: 'A',
23       scope: true,
24       replace: true,
25       template: '<div>Time<div class="alert alert-success">{{time}}</div></div>',
26       link: function (scope) {
27         function update() {
28           scope.time = new Date().toLocaleTimeString();
29         }
30
31         update();
32
33         var promise = $interval(update, 500);
34
35         scope.$on('$destroy', function () {
36           $interval.cancel(promise);
37         });
38       }
39     };
40   })
41   .directive('wtScopeWatch', function () {
42     return {
43       restrict: 'A',
44       replace: true,
45       template: '<div>Value<div class="alert alert-info">{{value}}</div></div>',
46       scope: {
47         value: '=value'
48       }
49     };
50   })
51   .directive('wtFluid', function () {
52     return {
53       restrict: 'A',
54       replace: true,
55       templateUrl: 'app/fusion/scripts/view-models/reportdashboard-page/src/app/template/fluid.html',
56       scope: true,
57       controller: function ($scope) {
58         $scope.$on('widgetResized', function (event, size) {
59           $scope.width = size.width || $scope.width;
60           $scope.height = size.height || $scope.height;
61         });
62       }
63     };
64   })
65   .directive('raptorReportChart', ['widgetDefinitions','defaultWidgets',function (widgetDefinitions, defaultWidgets) {
66     return {
67       restrict: 'A',
68       replace: true,
69       templateUrl: 'app/fusion/scripts/view-models/reportdashboard-page/src/app/template/raptor-report.html',
70       scope: true,
71       controller: function ($scope,$http, $rootScope) {
72 //        console.log('================= Raptor Report scope =================');
73 //                              console.log($scope);
74         $scope.showChart = false;
75                   $scope.url = "report_embedded#/report_run/c_master="+$scope.widget.report_id+ "&refresh=Y&hideGrid=Y&width="+Math.floor($scope.width*13)+"&height=300";
76 //        $scope.url = "report_embedded#/report_run/c_master="+$scope.widget.report_id+ "&refresh=Y&hideGrid="+$scope.hideGrid+"&width=550&height=300";
77           $rootScope.showdataContainer = false;
78                   $rootScope.$watch('showdataContainer', function () {
79                     console.log('change showdataContainer');
80                     console.log($rootScope.showdataContainer);
81                     $scope.gridOptions = $rootScope.gridOptions;
82                     $scope.gridOptions = $rootScope.gridOptions;                    
83                         $scope.uiGridRefresh = function(){
84                                   var columnDefsArray = [];
85                                   var columnFreezeEndColumn = $scope.widget.reportData.colIdxTobeFreezed;
86                                   var doColumnNeedToFreeze = false;
87                                   if(columnFreezeEndColumn && columnFreezeEndColumn.length>0) {
88                                           doColumnNeedToFreeze = true;
89                                   }
90                                   $scope.widget.reportData.reportDataColumns.forEach(function(entry) {
91                                           var tempColumnDef = { displayName: entry.columnTitle, field: entry.colId, enableSorting: entry.sortable,
92                                                           sortingAlgorithm: function(a, b) {
93                                                          return rowSorter.sortAlpha(a.displayValue, b.displayValue);
94                                                           },
95                                                           cellTemplate: '<div  class="ui-grid-cell-contents"  style="text-align:{{COL_FIELD.alignment}};" title="TOOLTIP">   '+
96                                                          '  <div ng-if="!COL_FIELD.drillDownURL || COL_FIELD.drillDownURL==\'\'">{{COL_FIELD.displayValue}}</div>' +
97                                          '  <a ng-if="COL_FIELD.drillDownURL && COL_FIELD.drillDownURL!=\'\'" ng-href="{{COL_FIELD.drillDownURL}}&parent___params==={{grid.appScope.currentReportUrlParams}}" >{{COL_FIELD.displayValue}}</a>' +
98                                                           '</div>'};
99                                   if(entry.columnWidth && entry.columnWidth!='null' && entry.columnWidth!='pxpx' && entry.columnWidth!='nullpx' && entry.columnWidth!='nullpxpx'){
100                                           tempColumnDef['minWidth'] = entry.columnWidth.substring(0, entry.columnWidth.length - 2);
101                                   } else {
102                                           tempColumnDef['minWidth'] = '100';
103                                   }
104                                   if(doColumnNeedToFreeze) {
105                                           tempColumnDef['pinnedLeft']= true;
106                                                   if(columnFreezeEndColumn === entry.colId){
107                                                           doColumnNeedToFreeze = false;
108                                                   }
109                                           }
110                                           columnDefsArray.push(tempColumnDef);
111                                   }); 
112                           
113                                   $scope.gridOptions.paginationPageSizes= [$scope.widget.reportData.pageSize];
114                                   $scope.gridOptions.paginationPageSize= $scope.widget.reportData.pageSize;
115                                   if($scope.widget.reportData.totalRows<14){
116                                           $scope.widget.gridHeight = (widget.reportData.totalRows+5)*30+'px';
117                           }else{
118                                   $scope.gridHeight = '400px';
119                                   }
120                                   $scope.gridOptions.totalItems = $scope.widget.reportData.totalRows;
121                                   $scope.gridOptions.columnDefs= columnDefsArray;
122                                   $scope.gridOptions.data= $scope.widget.reportData.reportDataRows;
123                                   $scope.gridOptions.exporterPdfHeader.text= $scope.widget.reportData.reportName;
124                         };                  
125                         $scope.uiGridRefresh();
126                     
127                     
128                     /*presence.setGlobal({
129                       u: $rootScope.currentUser,
130                       s: 'on'
131                     })*/
132                   })
133           $scope.$on('widgetResized', function (event, size) {
134                   console.log("===$scope===");
135                   console.log($scope);
136                   $scope.width = size.width || $scope.width;
137                   $scope.height = size.height || $scope.height;
138                   $scope.url = "report_embedded#/report_run/c_master="+$scope.widget.report_id+ "&refresh=Y&hideGrid=Y&width="+Math.floor($scope.width*13)+"&height=300";
139           });
140       }
141     };
142   }])
143   .directive('raptorReportData', ['widgetDefinitions','defaultWidgets',function (widgetDefinitions, defaultWidgets) {
144     return {
145       restrict: 'A',
146       replace: true,
147       templateUrl: 'app/fusion/scripts/view-models/reportdashboard-page/src/app/template/raptor-report.html',
148       scope: true,
149       controller: function ($scope,$http, $rootScope) {
150 //        console.log('================= Raptor Report scope =================');
151 //                              console.log($scope);
152         $scope.showChart = false;
153                   $scope.url = "report_embedded#/report_run/c_master="+$scope.widget.report_id+ "&refresh=Y&hideChart=Y&width="+Math.floor($scope.width*13)+"&height=300";
154 //        $scope.url = "report_embedded#/report_run/c_master="+$scope.widget.report_id+ "&refresh=Y&hideGrid="+$scope.hideGrid+"&width=550&height=300";
155           $rootScope.showdataContainer = false;
156                   $rootScope.$watch('showdataContainer', function () {
157                     console.log('change showdataContainer');
158                     console.log($rootScope.showdataContainer);
159                     $scope.gridOptions = $rootScope.gridOptions;
160                     $scope.gridOptions = $rootScope.gridOptions;                    
161                         $scope.uiGridRefresh = function(){
162                                   var columnDefsArray = [];
163                                   var columnFreezeEndColumn = $scope.widget.reportData.colIdxTobeFreezed;
164                                   var doColumnNeedToFreeze = false;
165                                   if(columnFreezeEndColumn && columnFreezeEndColumn.length>0) {
166                                           doColumnNeedToFreeze = true;
167                                   }
168                                   $scope.widget.reportData.reportDataColumns.forEach(function(entry) {
169                                           var tempColumnDef = { displayName: entry.columnTitle, field: entry.colId, enableSorting: entry.sortable,
170                                                           sortingAlgorithm: function(a, b) {
171                                                          return rowSorter.sortAlpha(a.displayValue, b.displayValue);
172                                                           },
173                                                           cellTemplate: '<div  class="ui-grid-cell-contents"  style="text-align:{{COL_FIELD.alignment}};" title="TOOLTIP">   '+
174                                                          '  <div ng-if="!COL_FIELD.drillDownURL || COL_FIELD.drillDownURL==\'\'">{{COL_FIELD.displayValue}}</div>' +
175                                          '  <a ng-if="COL_FIELD.drillDownURL && COL_FIELD.drillDownURL!=\'\'" ng-href="{{COL_FIELD.drillDownURL}}&parent___params==={{grid.appScope.currentReportUrlParams}}" >{{COL_FIELD.displayValue}}</a>' +
176                                                           '</div>'};
177                                   if(entry.columnWidth && entry.columnWidth!='null' && entry.columnWidth!='pxpx' && entry.columnWidth!='nullpx' && entry.columnWidth!='nullpxpx'){
178                                           tempColumnDef['minWidth'] = entry.columnWidth.substring(0, entry.columnWidth.length - 2);
179                                   } else {
180                                           tempColumnDef['minWidth'] = '100';
181                                   }
182                                   if(doColumnNeedToFreeze) {
183                                           tempColumnDef['pinnedLeft']= true;
184                                                   if(columnFreezeEndColumn === entry.colId){
185                                                           doColumnNeedToFreeze = false;
186                                                   }
187                                           }
188                                           columnDefsArray.push(tempColumnDef);
189                                   }); 
190                           
191                                   $scope.gridOptions.paginationPageSizes= [$scope.widget.reportData.pageSize];
192                                   $scope.gridOptions.paginationPageSize= $scope.widget.reportData.pageSize;
193                                   if($scope.widget.reportData.totalRows<14){
194                                           $scope.widget.gridHeight = (widget.reportData.totalRows+5)*30+'px';
195                           }else{
196                                   $scope.gridHeight = '400px';
197                                   }
198                                   $scope.gridOptions.totalItems = $scope.widget.reportData.totalRows;
199                                   $scope.gridOptions.columnDefs= columnDefsArray;
200                                   $scope.gridOptions.data= $scope.widget.reportData.reportDataRows;
201                                   $scope.gridOptions.exporterPdfHeader.text= $scope.widget.reportData.reportName;
202                         };                  
203                         $scope.uiGridRefresh();
204                     
205                     
206                     /*presence.setGlobal({
207                       u: $rootScope.currentUser,
208                       s: 'on'
209                     })*/
210                   })
211       }
212     };
213   }])  
214   .directive('rCloud', function () {
215             return {
216                 restrict: 'A',
217                 replace: true,
218                 templateUrl: 'app/fusion/scripts/view-models/reportdashboard-page/src/app/template/r-cloud.html',
219                 scope: true,
220                 controller: function ($scope,$http) {
221             $scope.showChart = false;
222             $scope.hideGrid = 'true';
223                   $scope.url = $scope.widget.rcloud_url;
224                   $scope.$on('widgetResized', function (event, size) {
225                           $scope.width = size.width || $scope.width;
226                           $scope.height = size.height || $scope.height;
227                   });
228                 }
229               };
230             });