1 appDS2.requires.push('ui.grid');
2 appDS2.requires.push('ui.grid.pagination');
3 appDS2.requires.push('ui.grid.resizeColumns');
4 appDS2.controller("reportSearchController", ['$scope','$rootScope','$http','$timeout','uiGridConstants','$modal','$q','$log','raptorReportFactory',function ($scope,$rootScope,$http,$timeout,uiGridConstants,$modal,$q,$log,raptorReportFactory) {
5 $scope.showLoader=false;
6 $scope.getSearchData = function(){
7 $scope.showLoader=true;
9 raptorReportFactory.getSearchData().then(function(data){
10 $scope.searchdData = data;
12 $log.error("raptorReportFactory: getSearchData failed.");
13 }).finally(function() {
14 $scope.showLoader=false;// Always execute this on both error and success
18 $scope.getSearchData();
20 $scope.runReport = function(){
21 var searchParams = '';
22 if($scope.reportId && $scope.reportId!=''){
23 searchParams = '&rep_id='+$scope.reportId+'&rep_id_options='+$scope.operatorRepId.index;
25 if($scope.reportName && $scope.reportName!=''){
26 searchParams = searchParams+'&rep_name='+$scope.reportName+'&rep_name_options='+$scope.operatorRepName.index;
28 $scope.showLoader=true;
29 var pageSearchParameter = ($scope.paginationOptions.pageNumber-1)+searchParams
30 raptorReportFactory.getSearchDataAtPage(pageSearchParameter).then(function(data){
31 $scope.searchdData = data
33 $log.error("raptorReportFactory: getSearchDataAtPage failed.");
34 }).finally(function() {
35 $scope.showLoader=false;// Always execute this on both error and success
41 $scope.paginationOptions = {
47 function convertValue(v){
48 return parseInt(v.displayValue);
51 $scope.getSortingAlgorithm= function (columnName) {
52 return function(a, b, rowA, rowB, direction) {
53 console.log("sorting by column " + columnName,a,b);
54 if(columnName=='rep_id'){
55 if(a && b && a.displayValue && b.displayValue){
56 if (convertValue(a) == convertValue(b)) return 0;
57 if (convertValue(a) < convertValue(b)) return -1;
58 if (convertValue(a) > convertValue(b)) return 1;
62 }else if(columnName=='rep_name'){
63 if(a && b && a.displayValue && b.displayValue){
64 if (a.displayValue == b.displayValue) return 0;
65 if (a.displayValue < b.displayValue) return -1;
66 if (a.displayValue > b.displayValue) return 1;
70 }else if(columnName=='descr'){
71 if(a && b && a.displayValue && b.displayValue){
72 if (a.displayValue == b.displayValue) return 0;
73 if (a.displayValue < b.displayValue) return -1;
74 if (a.displayValue > b.displayValue) return 1;
78 }else if(columnName=='owner'){
79 if(a && b && a.displayValue && b.displayValue){
80 if (a.displayValue == b.displayValue) return 0;
81 if (a.displayValue < b.displayValue) return -1;
82 if (a.displayValue > b.displayValue) return 1;
86 }else if(columnName=='create_date'){
87 if(a && b && a.displayValue && b.displayValue){
88 if (a.displayValue == b.displayValue) return 0;
89 if (a.displayValue < b.displayValue) return -1;
90 if (a.displayValue > b.displayValue) return 1;
98 var correctTotalPaginationTemplate =
99 //same as normal template, but fixed totals: {{(((grid.options.paginationCurrentPage-1)*grid.options.paginationPageSize)+1)}} {{(grid.options.paginationCurrentPage*grid.options.paginationPageSize>grid.options.totalItems?grid.options.totalItems:grid.options.paginationCurrentPage*grid.options.paginationPageSize)}}
100 "<div role=\"contentinfo\" class=\"ui-grid-pager-panel\" ui-grid-pager ng-show=\"grid.options.enablePaginationControls\"><div role=\"navigation\" class=\"ui-grid-pager-container\"><div role=\"menubar\" class=\"ui-grid-pager-control\"><button type=\"button\" role=\"menuitem\" class=\"ui-grid-pager-first\" ui-grid-one-bind-title=\"aria.pageToFirst\" ui-grid-one-bind-aria-label=\"aria.pageToFirst\" ng-click=\"pageFirstPageClick()\" ng-disabled=\"cantPageBackward()\"><div class=\"first-triangle\"><div class=\"first-bar\"></div></div></button> <button type=\"button\" role=\"menuitem\" class=\"ui-grid-pager-previous\" ui-grid-one-bind-title=\"aria.pageBack\" ui-grid-one-bind-aria-label=\"aria.pageBack\" ng-click=\"pagePreviousPageClick()\" ng-disabled=\"cantPageBackward()\"><div class=\"first-triangle prev-triangle\"></div></button> <input type=\"number\" ui-grid-one-bind-title=\"aria.pageSelected\" ui-grid-one-bind-aria-label=\"aria.pageSelected\" class=\"ui-grid-pager-control-input\" ng-model=\"grid.options.paginationCurrentPage\" min=\"1\" max=\"{{ paginationApi.getTotalPages() }}\" required> <span class=\"ui-grid-pager-max-pages-number\" ng-show=\"paginationApi.getTotalPages() > 0\"><abbr ui-grid-one-bind-title=\"paginationOf\">/</abbr> {{ paginationApi.getTotalPages() }}</span> <button type=\"button\" role=\"menuitem\" class=\"ui-grid-pager-next\" ui-grid-one-bind-title=\"aria.pageForward\" ui-grid-one-bind-aria-label=\"aria.pageForward\" ng-click=\"pageNextPageClick()\" ng-disabled=\"cantPageForward()\"><div class=\"last-triangle next-triangle\"></div></button> <button type=\"button\" role=\"menuitem\" class=\"ui-grid-pager-last\" ui-grid-one-bind-title=\"aria.pageToLast\" ui-grid-one-bind-aria-label=\"aria.pageToLast\" ng-click=\"pageLastPageClick()\" ng-disabled=\"cantPageToLast()\"><div class=\"last-triangle\"><div class=\"last-bar\"></div></div></button></div><div class=\"ui-grid-pager-row-count-picker\" ng-if=\"grid.options.paginationPageSizes.length > 1\"><select ui-grid-one-bind-aria-labelledby-grid=\"'items-per-page-label'\" ng-model=\"grid.options.paginationPageSize\" ng-options=\"o as o for o in grid.options.paginationPageSizes\"></select><span ui-grid-one-bind-id-grid=\"'items-per-page-label'\" class=\"ui-grid-pager-row-count-label\"> {{sizesLabel}}</span></div><span ng-if=\"grid.options.paginationPageSizes.length <= 1\" class=\"ui-grid-pager-row-count-label\">{{grid.options.paginationPageSize}} {{sizesLabel}}</span></div><div class=\"ui-grid-pager-count-container\"><div class=\"ui-grid-pager-count\"><span ng-show=\"grid.options.totalItems > 0\">{{(((grid.options.paginationCurrentPage-1)*grid.options.paginationPageSize)+1)}} <abbr ui-grid-one-bind-title=\"paginationThrough\">-</abbr> {{(grid.options.paginationCurrentPage*grid.options.paginationPageSize>grid.options.totalItems?grid.options.totalItems:grid.options.paginationCurrentPage*grid.options.paginationPageSize)}} {{paginationOf}} {{grid.options.totalItems}} {{totalItemsLabel}}</span></div></div></div>";
102 $scope.gridOptions = {
103 paginationPageSizes: [5],
104 paginationPageSize: 5,
105 paginationTemplate: correctTotalPaginationTemplate,
107 enableColumnResizing: true,
109 enableGridMenu: true,
110 enableSelectAll: true,
111 exporterMenuPdf: false,
112 exporterMenuCsv: false,
113 exporterCsvFilename: 'myFile.csv',
114 exporterPdfDefaultStyle: {fontSize: 9},
115 exporterPdfTableStyle: {margin: [30, 30, 30, 30]},
116 exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
117 exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
118 exporterPdfFooter: function ( currentPage, pageCount ) {
119 return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
121 exporterPdfCustomFormatter: function ( docDefinition ) {
122 docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
123 docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
124 return docDefinition;
126 exporterPdfOrientation: 'portrait',
127 exporterPdfPageSize: 'LETTER',
128 exporterPdfMaxGridWidth: 500,
129 exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
130 onRegisterApi: function(gridApi) {
131 gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
132 $scope.paginationOptions.pageNumber = newPage;
133 $scope.paginationOptions.pageSize = pageSize;
140 var getPage = function() {
141 $scope.gridOptions.columnDefs = [];
142 $scope.searchdData.columns[0].forEach(function(entry) {
143 if(entry.columnTitle=='Run'){
144 $scope.gridOptions.columnDefs.push({ displayName: entry.columnTitle, field: entry.columnId, enableSorting: false,
145 cellTemplate: '<div class="ui-grid-cell-contents"><a ng-href="#/report_run/{{COL_FIELD.drillDownLink.substr(39)}}" class="icon-controls-pointer" style="font-size:20px;"></a></div>'
147 } else if(entry.columnTitle=='Edit'){
148 $scope.gridOptions.columnDefs.push({ displayName: entry.columnTitle, field: entry.columnId, enableSorting: false,
149 cellTemplate: '<div class="ui-grid-cell-contents"><a ng-href="{{COL_FIELD.drillDownLink}}" class="icon-misc-pen" style="font-size:20px;"></a></div>'
151 } else if(entry.columnTitle=='Delete'){
152 $scope.gridOptions.columnDefs.push({ displayName: entry.columnTitle, field: entry.columnId, enableSorting: false,
153 cellTemplate: '<div class="ui-grid-cell-contents"><a ng-click="grid.appScope.removeReport(COL_FIELD.drillDownLink,row)" class="icon-misc-trash" style="font-size:20px;"></a></div>'
155 } else if(entry.columnTitle=='Copy'){
156 $scope.gridOptions.columnDefs.push({ displayName: entry.columnTitle, field: entry.columnId, enableSorting: false,
157 cellTemplate: '<div class="ui-grid-cell-contents"><a ng-href="{{COL_FIELD.drillDownLink}}" class="icon-documents-copy" style="font-size:20px;"></a></div>'
159 } else if(entry.columnTitle=='Schedule'){
160 } else if(entry.columnTitle=='No'){
162 $scope.gridOptions.columnDefs.push({ displayName: entry.columnTitle, field: entry.columnId,
164 sortingAlgorithm: $scope.getSortingAlgorithm(entry.columnId),
165 cellTemplate: '<div class="ui-grid-cell-contents" style="text-align:{{COL_FIELD.alignment}};" title="TOOLTIP"> <div>{{COL_FIELD.displayValue}}</div> </div>'
169 $scope.gridOptions.useExternalPagination=true;
170 $scope.gridOptions.paginationPageSizes= [$scope.searchdData.metaReport.pageSize];
171 $scope.gridOptions.paginationPageSize= 50;//$scope.searchdData.metaReport.pageSize;
172 $scope.gridOptions.totalItems = $scope.searchdData.metaReport.totalSize;
173 $scope.gridOptions.data = [];
174 $scope.searchdData.rows[0].forEach(function(entry) {
176 entry.forEach(function(rowData){
177 localData[rowData["columnId"]]= rowData["searchresultField"];
179 $scope.gridOptions.data.push(localData);
183 $scope.$watch("searchdData",function(newValue,oldValue) {
184 if($scope.searchdData){
189 $scope.operatorsRepId = [
190 {index: 0, value: 'Equal To', text: 'Equal To', alias:'Equal To'},
191 {index: 1, value: 'Less Than', text: 'Less Than', alias:'Less Than'},
192 {index: 2, value: 'Greater Than', text: 'Greater Than', alias:'Greater Than'}];
193 $scope.operatorRepId = {};
194 $scope.operatorRepId.value = $scope.operatorsRepId[0].value;
195 $scope.operatorRepId.index = $scope.operatorsRepId[0].index;
197 $scope.operatorsRepName = [
198 {index: 0, value: 'Starts With', text: 'Starts With', alias:'Starts With'},
199 {index:1, value: 'Ends With', text: 'Ends With', alias:'Ends With'},
200 {index: 2, value: 'Contains', text: 'Contains', alias:'Contains'}];
202 $scope.operatorRepName = {};
203 $scope.operatorRepName.value = $scope.operatorsRepName[0].value;
204 $scope.operatorRepName.index = $scope.operatorsRepName[0].index;
206 $scope.removeReport = function(reportDeleteUrl,row) {
207 var modalInstance = $modal.open({
208 animation: $scope.animationsEnabled,
209 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-del-confirm.html',
210 sizeClass: 'modal-small',
211 controller: ['$scope', '$modalInstance', '$http', '$log','raptorReportFactory', function ($scope, $modalInstance, $http, $log, raptorReportFactory) {
212 $scope.ok = function() {
213 raptorReportFactory.getReportDeleteStatus(reportDeleteUrl).then(function(data){
214 if (!(data.deleted)) {
215 $log.error("raptorReportFactory: report removal failed.")
217 $modalInstance.close();
219 $log.error("report removal error.")
223 $scope.cancel = function() {
224 $modalInstance.dismiss();
229 modalInstance.result.then(function () {
230 $scope.$emit('RefreshGridOptions');
235 $scope.$on('RefreshGridOptions', function(event) {
236 $scope.getSearchData();
239 $timeout(function() {
240 $rootScope.isViewRendering = false;