| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- app=angular.module('app', ["ngTagsInput"]);
- app.controller('main', function($scope,$http,$sce) {
- $scope.news=[];
- $scope.newsArticle="";
- $scope.curPage=1;
- $scope.totPages=1;
- var lastPage=0;
- var itemsPerPage=15;
- $scope.keywords=[];
- $scope.selected_kw=[];
- $scope.filtered = function(q) {
- q=q.toLowerCase();
- return $scope.keywords.filter(function(e) { return e.toLowerCase().indexOf(q) > -1});
- };
- $scope.getKeywords = function() {
- $http.get("/pymnts/keywords").then(
- function(data) {
- //$scope.keywords=data.data.keywords.map(function(e) { return {text:e} });
- $scope.keywords=data.data.keywords;
- },
- function(data){
- }
- );
- };
- $scope.getKeywords();
- $scope.getArticle = function(el) {
- $http.get("/pymnts/article/"+el._id).then(
- function(data) {
- $scope.newsArticle=$sce.trustAsHtml(data.data.articles.html);
- },
- function(data){
- }
- );
- };
- $scope.filter = function(page) {
- var kw = $scope.selected_kw.map(function(e){return e.text});
- $http.post("/pymnts/articles/",{"mindate":$scope.mindate,
- "maxdate":$scope.maxdate,
- "site":$scope.site,
- "keyword":kw,
- "minweight":$scope.minweight,
- "title":$scope.title,
- "page":page}).then(
- function(data) {
- if(page==undefined)
- $scope.curPage=1;
- $scope.news=data.data.articles;
- $scope.totPages=Math.ceil(data.data.count/itemsPerPage);
- },
- function(data) {
- }
- );
- };
- $scope.filter();
- $scope.parseSource = function(source,name,sel,rss,add) {
- url="/pymnts/source/test/";
- if(add==1)
- url="/pymnts/source/add/";
- $http.post(url, { "source": source, "selector":sel, "rss":rss, "name":name }).then(
- function(data) {
- console.log(data.data);
- },
- function(data){
- }
- );
- };
- $scope.changePage = function(newPage) {
- if (newPage > $scope.totPages)
- newPage=$scope.totPages;
- if (newPage < 1)
- newPage=1;
- if (newPage==lastPage)
- return;
- lastPage=newPage;
- $scope.curPage=newPage; //clamp
- $scope.filter(newPage);
- };
- $scope.delete_article = function(id) {
- $http.get("/pymnts/article/delete/"+id).then(
- function(data) {
- $scope.news=$scope.news.filter(function(el) { return !(el._id == id) } );
- },
- function(data){
- }
- );
- };
- });
|