app.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. $scope.sourceCategory=1;
  22. var categories = ["PR","News"];
  23. $http.get("/pymnts/sources").then(
  24. function(data){
  25. $scope.sources=data.data.sources.map(
  26. function(e){
  27. e.category=categories[e.category];
  28. return e;
  29. });
  30. },
  31. function(data){
  32. }
  33. );
  34. $scope.parseSource = function(source,name,sel,rss,category, add) {
  35. url="/pymnts/source/test/";
  36. if(add==1)
  37. url="/pymnts/source/add/";
  38. $http.post(url, { "source": source, "selector":sel, "rss":rss, "name":name, "category": category }).then(
  39. function(data) {
  40. if(!add)
  41. $scope.parsed_articles=data.data.links;
  42. },
  43. function(data){
  44. }
  45. );
  46. };
  47. });
  48. app.controller('main', function($scope,$http,$sce) {
  49. $scope.category="-1";
  50. $scope.news=[];
  51. $scope.newsArticle="";
  52. $scope.curPage=1;
  53. $scope.totPages=1;
  54. var lastPage=0;
  55. var itemsPerPage=15;
  56. $scope.keywords=[];
  57. $scope.selected_kw=[];
  58. $scope.filtered = function(q) {
  59. q=q.toLowerCase();
  60. return $scope.keywords.filter(function(e) { return e.toLowerCase().indexOf(q) > -1});
  61. };
  62. $scope.getKeywords = function() {
  63. $http.get("/pymnts/keywords").then(
  64. function(data) {
  65. //$scope.keywords=data.data.keywords.map(function(e) { return {text:e} });
  66. $scope.keywords=data.data.keywords;
  67. },
  68. function(data){
  69. }
  70. );
  71. };
  72. $scope.getKeywords();
  73. $scope.getArticle = function(el) {
  74. $http.get("/pymnts/article/"+el._id).then(
  75. function(data) {
  76. $scope.newsArticle=$sce.trustAsHtml(data.data.articles.html);
  77. },
  78. function(data){
  79. }
  80. );
  81. };
  82. $scope.filter = function(page) {
  83. var kw = $scope.selected_kw.map(function(e){return e.text});
  84. $http.post("/pymnts/articles/",{"mindate":$scope.mindate,
  85. "maxdate":$scope.maxdate,
  86. "site":$scope.site,
  87. "keyword":kw,
  88. "minweight":$scope.minweight,
  89. "title":$scope.title,
  90. "category":$scope.category,
  91. "page":page}).then(
  92. function(data) {
  93. if(page==undefined)
  94. $scope.curPage=1;
  95. $scope.news=data.data.articles.map(
  96. function(el) {
  97. el.kw=el.kw.filter(function(item, pos) {
  98. return el.kw.indexOf(item) == pos;
  99. });
  100. return el;
  101. });
  102. //$scope.news=data.data.articles;
  103. $scope.totPages=Math.ceil(data.data.count/itemsPerPage);
  104. },
  105. function(data) {
  106. }
  107. );
  108. };
  109. $scope.filter();
  110. $scope.changePage = function(newPage) {
  111. if (newPage > $scope.totPages)
  112. newPage=$scope.totPages;
  113. if (newPage < 1)
  114. newPage=1;
  115. if (newPage==lastPage)
  116. return;
  117. lastPage=newPage;
  118. $scope.curPage=newPage; //clamp
  119. $scope.filter(newPage);
  120. };
  121. $scope.delete_article = function(id) {
  122. $http.get("/pymnts/article/delete/"+id).then(
  123. function(data) {
  124. $scope.news=$scope.news.filter(function(el) { return !(el._id == id) } );
  125. },
  126. function(data){
  127. }
  128. );
  129. };
  130. });