app.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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.filtered = function(q) {
  8. q=q.toLowerCase();
  9. return $scope.keywords.filter(function(e) { return e.toLowerCase().indexOf(q) > -1});
  10. };
  11. $scope.getKeywords = function() {
  12. $http.get("/pymnts/keywords").then(
  13. function(data) {
  14. //$scope.keywords=data.data.keywords.map(function(e) { return {text:e} });
  15. $scope.keywords=data.data.keywords;
  16. },
  17. function(data){
  18. }
  19. );
  20. };
  21. $scope.getKeywords();
  22. $scope.getArticle = function(el) {
  23. $http.get("/pymnts/article/"+el._id).then(
  24. function(data) {
  25. $scope.newsArticle=$sce.trustAsHtml(data.data.articles.html);
  26. },
  27. function(data){
  28. }
  29. );
  30. };
  31. $scope.filter = function() {
  32. var kw = $scope.selected_kw.map(function(e){return e.text});
  33. $http.post("/pymnts/articles/",{"mindate":$scope.mindate,"maxdate":$scope.maxdate,"site":$scope.site,"keyword":kw,"minweight":$scope.minweight}).then(
  34. function(data) {
  35. $scope.news=data.data.articles;
  36. },
  37. function(data) {
  38. }
  39. );
  40. };
  41. $scope.filter();
  42. $scope.parseSource = function(source,name,sel,rss,add) {
  43. url="/pymnts/source/test/";
  44. if(add==1)
  45. url="/pymnts/source/add/";
  46. $http.post(url, { "source": source, "selector":sel, "rss":rss, "name":name }).then(
  47. function(data) {
  48. console.log(data.data);
  49. },
  50. function(data){
  51. }
  52. );
  53. };
  54. });