app.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. app=angular.module('app', ["ngTagsInput","ngRoute"]);
  2. app.config(function($routeProvider, $locationProvider) {
  3. // $locationProvider.html5Mode(true);
  4. // $compileProvider.debugInfoEnabled(false);
  5. $routeProvider
  6. .when("/", {
  7. templateUrl: 'main.html',
  8. controller: 'main'
  9. })
  10. .when("/sources", {
  11. templateUrl: 'sources.html',
  12. controller: 'sources'
  13. })
  14. .otherwise({
  15. redirectTo: "/"
  16. })
  17. });
  18. app.controller('sources', function($scope,$http) {
  19. $scope.sources=[];
  20. $scope.parsed_articles=[];
  21. $http.get("/pymnts/sources").then(
  22. function(data){
  23. $scope.sources=data.data.sources;
  24. },
  25. function(data){
  26. }
  27. );
  28. $scope.parseSource = function(source,name,sel,rss,add) {
  29. url="/pymnts/source/test/";
  30. if(add==1)
  31. url="/pymnts/source/add/";
  32. $http.post(url, { "source": source, "selector":sel, "rss":rss, "name":name }).then(
  33. function(data) {
  34. if(!add)
  35. $scope.parsed_articles=data.data.links;
  36. },
  37. function(data){
  38. }
  39. );
  40. };
  41. });
  42. app.controller('main', function($scope,$http,$sce) {
  43. $scope.news=[];
  44. $scope.newsArticle="";
  45. $scope.curPage=1;
  46. $scope.totPages=1;
  47. var lastPage=0;
  48. var itemsPerPage=15;
  49. $scope.keywords=[];
  50. $scope.selected_kw=[];
  51. $scope.filtered = function(q) {
  52. q=q.toLowerCase();
  53. return $scope.keywords.filter(function(e) { return e.toLowerCase().indexOf(q) > -1});
  54. };
  55. $scope.getKeywords = function() {
  56. $http.get("/pymnts/keywords").then(
  57. function(data) {
  58. //$scope.keywords=data.data.keywords.map(function(e) { return {text:e} });
  59. $scope.keywords=data.data.keywords;
  60. },
  61. function(data){
  62. }
  63. );
  64. };
  65. $scope.getKeywords();
  66. $scope.getArticle = function(el) {
  67. $http.get("/pymnts/article/"+el._id).then(
  68. function(data) {
  69. $scope.newsArticle=$sce.trustAsHtml(data.data.articles.html);
  70. },
  71. function(data){
  72. }
  73. );
  74. };
  75. $scope.filter = function(page) {
  76. var kw = $scope.selected_kw.map(function(e){return e.text});
  77. $http.post("/pymnts/articles/",{"mindate":$scope.mindate,
  78. "maxdate":$scope.maxdate,
  79. "site":$scope.site,
  80. "keyword":kw,
  81. "minweight":$scope.minweight,
  82. "title":$scope.title,
  83. "page":page}).then(
  84. function(data) {
  85. if(page==undefined)
  86. $scope.curPage=1;
  87. $scope.news=data.data.articles.map(
  88. function(el) {
  89. el.kw=el.kw.filter(function(item, pos) {
  90. return el.kw.indexOf(item) == pos;
  91. });
  92. return el;
  93. });
  94. //$scope.news=data.data.articles;
  95. $scope.totPages=Math.ceil(data.data.count/itemsPerPage);
  96. },
  97. function(data) {
  98. }
  99. );
  100. };
  101. $scope.filter();
  102. $scope.changePage = function(newPage) {
  103. if (newPage > $scope.totPages)
  104. newPage=$scope.totPages;
  105. if (newPage < 1)
  106. newPage=1;
  107. if (newPage==lastPage)
  108. return;
  109. lastPage=newPage;
  110. $scope.curPage=newPage; //clamp
  111. $scope.filter(newPage);
  112. };
  113. $scope.delete_article = function(id) {
  114. $http.get("/pymnts/article/delete/"+id).then(
  115. function(data) {
  116. $scope.news=$scope.news.filter(function(el) { return !(el._id == id) } );
  117. },
  118. function(data){
  119. }
  120. );
  121. };
  122. });