big_ng.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. angular.module('app', ['app.util','angular-multi-check'])
  2. .config(function($interpolateProvider) {
  3. $interpolateProvider.startSymbol('[[');
  4. $interpolateProvider.endSymbol(']]');
  5. })
  6. .controller('BigCtrl', BigCtrl)
  7. function BigCtrl(FlotServ, $scope, $interval, $timeout, $filter) {
  8. var vm = this;
  9. var urlH = '/chart/h';
  10. var defaultParam = FlotServ.getParam();
  11. var graph_type = defaultParam.graph_type;
  12. if (graph_type === 'k') {
  13. urlH = '/chart/k';
  14. } else if (graph_type === 'a') {
  15. urlH = '/chart/a';
  16. }
  17. vm.chart = {}; // 前端的图, 对应后端的返回
  18. vm.config = []; // 绘图的数据, 会变化
  19. vm.data = []; // 缓存的绘图数据, 不会改变
  20. vm.param = angular.copy(defaultParam);
  21. vm.all = true; // 是否全选
  22. vm.reverse = false; // 是否反选
  23. vm.checkAll = checkAll;
  24. vm.checkReverse = checkReverse;
  25. vm.checkSearch = checkSearch;
  26. vm.reset = reset;
  27. vm.checkFilter = checkFilter;
  28. // watch
  29. $scope.$watch('vm.param', function(newVal, oldVal) {
  30. if (!angular.equals(newVal, oldVal)) {
  31. active(newVal);
  32. }
  33. }, true);
  34. active(vm.param);
  35. // interval
  36. $interval(function() {
  37. var rand = Math.round(Math.random() * 1000 * 120); // 0s ~ 120s
  38. $timeout(function() {
  39. var p = FlotServ.getParam2();
  40. p['-'] = Math.random();
  41. FlotServ.getData(urlH, p).success(function(ret) {
  42. var d = FlotServ.parseData(ret);
  43. if (d.length > 0) {
  44. vm.newdata = FlotServ.parseData(ret);
  45. }
  46. // vm.chart = ret;
  47. // TODO 这里也要重新计算?
  48. // vm.summary = FlotServ.summary(ret.series[0]);
  49. });
  50. }, rand);
  51. }, 60000);
  52. // reset
  53. function reset() {
  54. vm.param = angular.copy(defaultParam);
  55. }
  56. // active
  57. function active(param) {
  58. FlotServ.getData(urlH, param).success(function(ret) {
  59. vm.config = FlotServ.parseData(ret);
  60. vm.data = FlotServ.parseData(ret);
  61. vm.chart = ret;
  62. vm.summary = FlotServ.summary(ret.series[0]);
  63. });
  64. }
  65. function checkFilter() {
  66. _.each(vm.data, function(d) {
  67. d.check = false;
  68. });
  69. var query = vm.query;
  70. var checks = $filter('filter')(vm.data, {label:query});
  71. angular.forEach(checks, function(i) {
  72. i.check = true;
  73. });
  74. }
  75. // 全选
  76. function checkAll() {
  77. if (vm.all) {
  78. _.each(vm.data, function(d) {
  79. d.check = true;
  80. });
  81. } else {
  82. _.each(vm.data, function(d) {
  83. d.check = false;
  84. });
  85. }
  86. }
  87. // 反选
  88. function checkReverse () {
  89. if (vm.reverse) {
  90. vm.all = false;
  91. _.each(vm.data, function(d) {
  92. d.check = !d.check;
  93. });
  94. }
  95. }
  96. // 刷新
  97. function checkSearch() {
  98. var data2 = [];
  99. _.each(vm.data, function(d) {
  100. if (d.check) {
  101. data2.push(d);
  102. }
  103. });
  104. vm.config = data2;
  105. }
  106. }