| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- app=angular.module('app', ["ngTagsInput","ngRoute"]);
- app.config(function($routeProvider, $locationProvider) {
- // $locationProvider.html5Mode(true);
- // $compileProvider.debugInfoEnabled(false);
- $routeProvider
- .when("/", {
- templateUrl: 'main.html',
- controller: 'main'
- })
- .when("/sources", {
- templateUrl: 'sources.html',
- controller: 'sources'
- })
- .otherwise({
- redirectTo: "/"
- })
- });
- app.controller('sources', function($scope,$http) {
- $scope.sources=[];
- $scope.parsed_articles=[];
- $scope.sourceCategory=1;
- var categories = ["PR","News"];
- $http.get("/pymnts/sources").then(
- function(data){
- $scope.sources=data.data.sources.map(
- function(e){
- e.category=categories[e.category];
- return e;
- });
- },
- function(data){
- }
- );
- $scope.parseSource = function(source,name,sel,rss,category, add) {
- url="/pymnts/source/test/";
- if(add==1)
- url="/pymnts/source/add/";
- $http.post(url, { "source": source, "selector":sel, "rss":rss, "name":name, "category": category }).then(
- function(data) {
- if(!add)
- $scope.parsed_articles=data.data.links;
- },
- function(data){
- }
- );
- };
-
- });
- app.controller('main', function($scope,$http,$sce) {
- $scope.category="-1";
- $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.addKeyword = function(k) {
- c=$scope.selected_kw.filter(function(el) { return el.text==k; }).length;
- if (c>0)
- return;
- $scope.selected_kw.push({text:k});
- $scope.filter();
- };
- $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.reset = function() {
- $scope.mindate=undefined;
- $scope.maxdate=undefined;
- $scope.site=undefined;
- $scope.selected_kw=[];
- $scope.minweight="1";
- $scope.title=undefined;
- $scope.category="-1";
- $scope.filter();
- };
- $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,
- "category":$scope.category,
- "page":page}).then(
- function(data) {
- if(page==undefined)
- $scope.curPage=1;
- $scope.news=data.data.articles.map(
- function(el) {
- el.kw=el.kw.filter(function(item, pos) {
- return el.kw.indexOf(item) == pos;
- });
- return el;
- });
- //$scope.news=data.data.articles;
- $scope.totPages=Math.ceil(data.data.count/itemsPerPage);
- },
- function(data) {
- }
- );
- };
- $scope.filter();
- $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){
- }
- );
- };
- });
|