Browse Source

move code to source controller

David 10 years ago
parent
commit
bb85b62902
1 changed files with 19 additions and 16 deletions
  1. 19 16
      front/js/app.js

+ 19 - 16
front/js/app.js

@@ -20,13 +20,28 @@ app.config(function($routeProvider, $locationProvider) {
 
 app.controller('sources', function($scope,$http) {
 	$scope.sources=[];
-		$http.get("/pymnts/sources").then(
-			function(data){
-				$scope.sources=data.data.sources;
+	$scope.parsed_articles=[];
+	$http.get("/pymnts/sources").then(
+		function(data){
+			$scope.sources=data.data.sources;
+		},
+		function(data){
+		}
+	);
+	$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) {
+				if(!add)
+					$scope.parsed_articles=data.data.links;
 			},
 			function(data){
 			}
 		);
+	};
 	
 });
 app.controller('main', function($scope,$http,$sce) {
@@ -77,6 +92,7 @@ app.controller('main', function($scope,$http,$sce) {
 			function(data) {
 				if(page==undefined)
 					$scope.curPage=1;
+				//$scope.news=#data.data.articles.map(function(el) { el.scrap_date=Date(el.scrap_date); return el; });
 				$scope.news=data.data.articles;
 				$scope.totPages=Math.ceil(data.data.count/itemsPerPage);
 			},
@@ -86,19 +102,6 @@ app.controller('main', function($scope,$http,$sce) {
 	};
 
 	$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;