app.js 1.6 KB

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