app.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. app=angular.module('app', []);
  2. app.controller('main', function($scope,$http,$interval) {
  3. var ROOT_PATH="/backend/";
  4. $scope.searchlist=[]
  5. $scope.results = [];
  6. $scope.book="";
  7. $scope.extension="";
  8. $scope.activeTab = 'SEARCH';
  9. $scope.getList = function() {
  10. $http.get(ROOT_PATH+$scope.activeTab).then(
  11. function(data) {
  12. /*
  13. data.data=data.data.map(function(el) {
  14. if (el.STATUS!="DISCONNECTED")
  15. el.STATUS=el.STATUS+" "+el.ELAPSED;
  16. return el;
  17. });
  18. */
  19. if($scope.activeTab === "SEARCH")
  20. $scope.searchlist=data.data;
  21. else
  22. $scope.results=data.data;
  23. },
  24. function(data){
  25. console.log("error");
  26. });
  27. }
  28. $scope.getList();
  29. $scope.download = function(book) {
  30. $http.post(ROOT_PATH+"?adasasd",{"type":"BOOK","book":book}).then(
  31. function(data) {
  32. $scope.newElement(true);
  33. $scope.getList();
  34. },
  35. function(data){
  36. console.log("error");
  37. console.log(data);
  38. });
  39. };
  40. $scope.newElement = function(bool){
  41. $scope.new = bool;
  42. }
  43. $scope.searchBook = function(book,extension){
  44. $http.post(ROOT_PATH+"?ewqewqewq", {"type":"search","book":book,"extension":extension}).then(
  45. function(data) {
  46. console.log("success");
  47. $scope.getList();
  48. },
  49. function(data){
  50. console.log("err");
  51. });
  52. };
  53. $scope.isActiveTab = function(tab){
  54. return $scope.activeTab === tab;
  55. }
  56. $scope.changeTab = function(tab){
  57. $scope.activeTab = tab;
  58. }
  59. $scope.limit = {};
  60. $scope.showMore = function(l){
  61. $scope.limit[l.ID] = $scope.limit[l.ID] ? undefined : l.OUT.length;
  62. }
  63. var promise = $interval($scope.getList, 3500);
  64. $scope.$on('destroy', function() {
  65. $interval.cancel(promise);
  66. });
  67. });
  68. app.directive('progressBar', function(){
  69. return {
  70. template: '<div id="progress-bar"><div id="label">{{progress}}%</div><div id="progress" style="width:{{progress}}%"></div></div>',
  71. restrict: 'E',
  72. scope: {
  73. progress: '='
  74. },
  75. link: function(scope, elem, attrs){
  76. console.log('progress', scope.progress, elem, attrs);
  77. }
  78. }
  79. });