app.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.getNews = function() {
  8. $http.get("/pymnts/articles/").then(
  9. function(data) {
  10. /*
  11. data.data=data.data.map(function(el) {
  12. if (el.STATUS!="DISCONNECTED")
  13. el.STATUS=el.STATUS+" "+el.ELAPSED;
  14. return el;
  15. });
  16. */
  17. $scope.news=data.data.articles;
  18. },
  19. function(data){
  20. console.log("error");
  21. console.log(data);
  22. });
  23. };
  24. $scope.filtered = function(q) {
  25. q=q.toLowerCase();
  26. return $scope.keywords.filter(function(e) { return e.toLowerCase().indexOf(q) > -1});
  27. };
  28. $scope.getKeywords = function() {
  29. $http.get("/pymnts/keywords").then(
  30. function(data) {
  31. //$scope.keywords=data.data.keywords.map(function(e) { return {text:e} });
  32. $scope.keywords=data.data.keywords;
  33. },
  34. function(data){
  35. }
  36. );
  37. };
  38. $scope.getKeywords();
  39. $scope.getArticle = function(el) {
  40. $http.get("/pymnts/article/"+el._id).then(
  41. function(data) {
  42. $scope.newsArticle=$sce.trustAsHtml(data.data.articles.html);
  43. },
  44. function(data){
  45. }
  46. );
  47. };
  48. $scope.filter = function() {
  49. var kw = $scope.selected_kw.map(function(e){return e.text});
  50. $http.post("/pymnts/articles/",{"mindate":$scope.mindate,"maxdate":$scope.maxdate,"site":$scope.site,"keyword":kw,"minweight":$scope.minweight}).then(
  51. function(data) {
  52. $scope.news=data.data.articles;
  53. },
  54. function(data) {
  55. }
  56. );
  57. };
  58. $scope.getNews();
  59. /*
  60. $scope.download = function(book) {
  61. $http.post("/test/?adasasd",{"type":"BOOK","book":book}).then(
  62. function(data) {
  63. $scope.getList();
  64. },
  65. function(data){
  66. console.log("error");
  67. console.log(data);
  68. });
  69. };
  70. $scope.searchBook = function(book,extension){
  71. $http.post("/test/?ewqewqewq", {"type":"search","book":book,"extension":extension}).then(
  72. function(data) {
  73. console.log("success");
  74. $scope.getList();
  75. },
  76. function(data){
  77. console.log("err");
  78. });
  79. };
  80. */
  81. });