app.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. ws = new WebSocket("ws://192.168.1.12:8099/");
  10. ws.onmessage = function(event) {
  11. var j = JSON.parse(event.data);
  12. console.log(j);
  13. $scope.$apply(function() {
  14. $scope.searchlist=j['SEARCH'];
  15. $scope.results=j['BOOKS'];
  16. });
  17. };
  18. $scope.download = function(book) {
  19. ws.send(JSON.stringify({"type":"BOOK","book":book}));
  20. };
  21. $scope.newElement = function(bool){
  22. $scope.new = bool;
  23. }
  24. $scope.searchBook = function(book,extension){
  25. ws.send(JSON.stringify({"type":"search","book":book,"extension":extension}));
  26. };
  27. $scope.isActiveTab = function(tab){
  28. return $scope.activeTab === tab;
  29. }
  30. $scope.changeTab = function(tab){
  31. $scope.activeTab = tab;
  32. }
  33. $scope.limit = {};
  34. $scope.showMore = function(l){
  35. $scope.limit[l.ID] = $scope.limit[l.ID] ? undefined : l.OUT.length;
  36. }
  37. $scope.clean = function(s) {
  38. s = s.replace(/\(.*?\)/g, '');
  39. s.replace(/\s+/g, " ");
  40. s.replace(/\s+\./g, ".");
  41. return s;
  42. }
  43. });
  44. app.directive('progressBar', function(){
  45. return {
  46. template: '<div id="progress-bar"><div id="label">{{progress}}%</div><div id="progress" style="width:{{progress}}%"></div></div>',
  47. restrict: 'E',
  48. scope: {
  49. progress: '='
  50. },
  51. link: function(scope, elem, attrs){
  52. console.log('progress', scope.progress, elem, attrs);
  53. }
  54. }
  55. });