logSicuraSchedulerCtrl.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. app.controller('logSicuraSchedulerCtrl',
  2. function ($scope,$http,$cookies,$window, $location,$timeout, $mdDialog, $q, utilsSvc, LogSicuraScheduler) {
  3. var vm=this;
  4. vm.maxItems = 0;
  5. vm.itemsPerPage = 100;
  6. vm.records=[];
  7. vm.inputFile='';
  8. vm.selectedIndex = -1;
  9. vm.logDetails = "";
  10. vm.columnWidths=[
  11. 150, //0
  12. 350, //1
  13. 250, //2
  14. 380, //3
  15. 380 //4
  16. ];
  17. vm.getListHeight = function() {
  18. containerHeight = (($window.innerHeight - $('#container').position().top - $('#view').position().top))*0.6;
  19. return {'height': containerHeight + 'px'};
  20. };
  21. vm.getGridItemHeight = function() {
  22. return utilsSvc.getGridWithButtonHeight();
  23. }
  24. $window.addEventListener('resize', onResize);
  25. function onResize() {
  26. $scope.$digest();
  27. }
  28. $scope.$on('$destroy', function() {
  29. $window.removeEventListener('resize', onResize);
  30. });
  31. $timeout(function() {
  32. var evt = $window.document.createEvent('UIEvents');
  33. evt.initUIEvent('resize', true, false, $window, 0);
  34. $window.dispatchEvent(evt);
  35. });
  36. vm.onlyFilename = function(filepath) {
  37. if (!filepath || filepath=="")
  38. return "";
  39. var term='\\';
  40. if (filepath.indexOf('/')>0)
  41. term='/';
  42. if (filepath.indexOf(term)>=0)
  43. return filepath.substr(filepath.lastIndexOf(term)+1);
  44. else
  45. return filepath;
  46. }
  47. vm.getColumnWidth = function(idx) {
  48. return {
  49. 'width': vm.columnWidths[idx] + 'px',
  50. 'min-width':vm.columnWidths[idx] + 'px',
  51. 'margin-left':'8px',
  52. 'margin-right':'8px',
  53. 'text-overflow': 'ellipsis',
  54. 'overflow': 'hidden',
  55. 'white-space':'nowrap'
  56. };
  57. }
  58. vm.getLogDetail = function(idx) {
  59. vm.selectedIndex = idx;
  60. LogSicuraScheduler.LogDetail({id:vm.records[idx].id})
  61. .$promise.then(function(data){
  62. vm.logDetails = data;
  63. });
  64. }
  65. vm.getMaxListWidth = function() {
  66. var res=0;
  67. for (var i=0;i<vm.columnWidths.length;i++)
  68. res += vm.columnWidths[i]+6+8+10;
  69. $('#container').css('width',($('#header').width()+10)+'px');
  70. return {'width': res+ 'px!important;'}
  71. }
  72. vm.setOrderField = function(field) {
  73. if (vm.orderField!=field)
  74. vm.orderField = field;
  75. else
  76. vm.orderField = "-" +field;
  77. vm.getLog();
  78. }
  79. vm.infiniteItems = {
  80. numLoaded_: 0,
  81. toLoad_: 0,
  82. loading_:false,
  83. lastStartIdx:-1,
  84. listPromise:null,
  85. canceler: $q.defer(),
  86. // Required.
  87. getItemAtIndex: function(index) {
  88. if (vm.maxItems==0 || index>vm.maxItems)
  89. return null;
  90. if (!vm.infiniteItems.loading_)
  91. if (index > vm.records.length) {
  92. this.fetchMoreItems_(index);
  93. return null;
  94. }
  95. return vm.records [index];
  96. },
  97. getLength: function() {
  98. return vm.maxItems;
  99. },
  100. fetchMoreItems_: function(index) {
  101. if (this.toLoad_ < index) {
  102. this.toLoad_ += vm.itemsPerPage;
  103. utilsSvc.showWaitMessage('Ricerca in corso...');
  104. vm.infiniteItems.loading_ = true;
  105. this.listPromise = LogSicuraScheduler.List({start: vm.records.length,size:Math.max(vm.records.length+index,vm.itemsPerPage), inputFile: vm.inputFile, orderBy:vm.orderField}).$promise;
  106. var mod=this;
  107. this.listPromise.then(
  108. function(data){
  109. vm.infiniteItems.loading_ = false;
  110. vm.infiniteItems.toLoad_=0;
  111. utilsSvc.cancelWaitMessage();
  112. vm.records = vm.records.concat(data);
  113. mod.numLoaded_ = vm.records.length;
  114. mod.lastStartIdx = vm.records.length;
  115. if (vm.selectedIndex==-1) {
  116. vm.selectedIndex = 0;
  117. vm.getLogDetail(0);
  118. }
  119. },
  120. function(error) {
  121. vm.infiniteItems.loading_ = false;
  122. vm.infiniteItems.toLoad_=0;
  123. utilsSvc.handleHttpError(error);
  124. }
  125. );
  126. }
  127. }
  128. }
  129. vm.getLog = function(){
  130. LogSicuraScheduler.Count({inputFile: vm.inputFile},
  131. function(data){
  132. vm.records=[];
  133. vm.maxItems = data.value;
  134. vm.infiniteItems.numLoaded_ = 0;
  135. vm.infiniteItems.toLoad_ = 0;
  136. }
  137. );
  138. }
  139. vm.getLog();
  140. });