app.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. app=angular.module('app', ["ngTagsInput"]);
  2. app.controller('main', function($scope,$http,$sce) {
  3. $scope.news=[];
  4. $scope.newsArticle="";
  5. $scope.keywords=[];
  6. $scope.selected_kw=[];
  7. $scope.getNews = function() {
  8. $http.get("/pymnts/articles/").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.news=data.data.articles;
  18. },
  19. function(data){
  20. console.log("error");
  21. console.log(data);
  22. });
  23. };
  24. $scope.filtered = function(q) {
  25. q=q.toLowerCase();
  26. return $scope.keywords.filter(function(e) { return e.toLowerCase().indexOf(q) > -1});
  27. };
  28. $scope.getKeywords = function() {
  29. $http.get("/pymnts/keywords").then(
  30. function(data) {
  31. //$scope.keywords=data.data.keywords.map(function(e) { return {text:e} });
  32. $scope.keywords=data.data.keywords;
  33. },
  34. function(data){
  35. }
  36. );
  37. };
  38. $scope.getKeywords();
  39. $scope.getArticle = function(el) {
  40. $http.get("/pymnts/article/"+el._id).then(
  41. function(data) {
  42. $scope.newsArticle=$sce.trustAsHtml(data.data.articles.html);
  43. },
  44. function(data){
  45. }
  46. );
  47. };
  48. $scope.filter = function() {
  49. var kw = $scope.selected_kw.map(function(e){return e.text});
  50. $http.post("/pymnts/articles/",{"mindate":$scope.mindate,"maxdate":$scope.maxdate,"site":$scope.site,"keyword":kw,"minweight":$scope.minweight}).then(
  51. function(data) {
  52. $scope.news=data.data.articles;
  53. },
  54. function(data) {
  55. }
  56. );
  57. };
  58. $scope.getNews();
  59. $scope.parseSource = function(source,name,sel,rss,add) {
  60. url="/pymnts/source/test/";
  61. if(add==1)
  62. url="/pymnts/source/add/";
  63. $http.post(url, { "source": source, "selector":sel, "rss":rss, "name":name }).then(
  64. function(data) {
  65. console.log(data.data);
  66. },
  67. function(data){
  68. }
  69. );
  70. };
  71. /*
  72. $scope.download = function(book) {
  73. $http.post("/test/?adasasd",{"type":"BOOK","book":book}).then(
  74. function(data) {
  75. $scope.getList();
  76. },
  77. function(data){
  78. console.log("error");
  79. console.log(data);
  80. });
  81. };
  82. $scope.searchBook = function(book,extension){
  83. $http.post("/test/?ewqewqewq", {"type":"search","book":book,"extension":extension}).then(
  84. function(data) {
  85. console.log("success");
  86. $scope.getList();
  87. },
  88. function(data){
  89. console.log("err");
  90. });
  91. };
  92. */
  93. });