app.js 2.8 KB

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