app.js 1.7 KB

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