app.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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(function(el) { el.scrap_date=Date(el.scrap_date); return el; });
  88. $scope.news=data.data.articles;
  89. $scope.totPages=Math.ceil(data.data.count/itemsPerPage);
  90. },
  91. function(data) {
  92. }
  93. );
  94. };
  95. $scope.filter();
  96. $scope.changePage = function(newPage) {
  97. if (newPage > $scope.totPages)
  98. newPage=$scope.totPages;
  99. if (newPage < 1)
  100. newPage=1;
  101. if (newPage==lastPage)
  102. return;
  103. lastPage=newPage;
  104. $scope.curPage=newPage; //clamp
  105. $scope.filter(newPage);
  106. };
  107. $scope.delete_article = function(id) {
  108. $http.get("/pymnts/article/delete/"+id).then(
  109. function(data) {
  110. $scope.news=$scope.news.filter(function(el) { return !(el._id == id) } );
  111. },
  112. function(data){
  113. }
  114. );
  115. };
  116. });