David 9 år sedan
förälder
incheckning
33eba85b74
2 ändrade filer med 290 tillägg och 187 borttagningar
  1. 236 182
      front/js/app.js
  2. 54 5
      front/keywords.html

+ 236 - 182
front/js/app.js

@@ -1,196 +1,250 @@
 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("/keywords", {
-			templateUrl: 'keywords.html',
-			controller: 'keywords'
-		})
-		.when("/sources", {
-			templateUrl: 'sources.html',
-			controller: 'sources'
-		})
-		.otherwise({
-			redirectTo: "/"
-		})
+//    $locationProvider.html5Mode(true);
+//    $compileProvider.debugInfoEnabled(false);
+
+    $routeProvider
+        .when("/", {
+            templateUrl: 'main.html',
+            controller: 'main'
+        })
+        .when("/keywords", {
+            templateUrl: 'keywords.html',
+            controller: 'keywords'
+        })
+        .when("/sources", {
+            templateUrl: 'sources.html',
+            controller: 'sources'
+        })
+        .otherwise({
+            redirectTo: "/"
+        })
 });
 
 app.controller('sources', function($scope,$http,$location) {
-	$scope.sources=[];
-	$scope.parsed_articles=[];
-	$scope.sourceCategory=1;
-	$scope.dev=$location.search().dev;
-	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){
-			}
-		);
-	};
-	
+    $scope.sources=[];
+    $scope.parsed_articles=[];
+    $scope.sourceCategory=1;
+    $scope.dev=$location.search().dev;
+    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.selectedArticle = {};
-	$scope.curPage=1;
-	$scope.totPages=1;
-	$scope.pages=[]
-	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) {
-		$scope.selectedArticle = 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);
-				var arr = []
-				var maxPage=Math.min($scope.curPage+2,$scope.totPages);
-				var minPage=Math.max($scope.curPage-2,1);
-				for(var i=minPage; i<=maxPage;i++)
-					arr.push(i);
-				$scope.pages=arr;
-			},
-			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.pages = function() {
-		var arr = [];
-		for(var i=$scope.curPage -2; i<=$scope.curPage+2;i++)
-			if (i>=1 && i<=$scope.totPages)
-				arr.push(i);
-		return arr;
-	};
-	$scope.isCurrent = function(page){
-		return page === $scope.curPage;
-	}
-
-	$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){
-			}
-		);
-	};
+    $scope.category="-1";
+    $scope.news=[];
+    $scope.newsArticle="";
+    $scope.selectedArticle = {};
+    $scope.curPage=1;
+    $scope.totPages=1;
+    $scope.pages=[]
+    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) {
+        $scope.selectedArticle = 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);
+                var arr = []
+                var maxPage=Math.min($scope.curPage+2,$scope.totPages);
+                var minPage=Math.max($scope.curPage-2,1);
+                for(var i=minPage; i<=maxPage;i++)
+                    arr.push(i);
+                $scope.pages=arr;
+            },
+            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.pages = function() {
+        var arr = [];
+        for(var i=$scope.curPage -2; i<=$scope.curPage+2;i++)
+            if (i>=1 && i<=$scope.totPages)
+                arr.push(i);
+        return arr;
+    };
+    $scope.isCurrent = function(page){
+        return page === $scope.curPage;
+    }
+
+    $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){
+            }
+        );
+    };
 });
 
 
 
-app.controller('keywords', function($scope,$http,$location) {
-	$scope.keywords=[];
-	$http.get("/pymnts/keywordsw").then(
-		function(data){
-			$scope.keywords = data.data.keywords;
+app.controller('keywords', function($scope, $http) {
+    $scope.keywords = [];
+    $scope.editing = false;
+    $scope.deleting = false;
+    $scope.creating = false;
+    $http.get("/pymnts/keywordsw").then(
+        function(data){
+            $scope.keywords = data.data.keywords;
         },
-		function(data){
-		}
-	);
+        function(data){
+        }
+    );
+    $scope.edit = function(k) {
+        $scope.oldkw = k.keyword;
+        $scope.newkw = k.keyword;
+        $scope.weight = k.weight;
+        $scope.editing = true;
+        $scope.deleting = false;
+        $scope.creating = false;
+    };
+    $scope.delete = function(k) {
+        $scope.oldkw = k.keyword;
+        $scope.deleting = true;
+        $scope.editing = false;
+        $scope.creating = false;
+    };
+
+    $scope.create = function(){
+        $scope.editing = false;
+        $scope.deleting = false;
+        $scope.creating = true;
+    }
+    $scope.cancel = function(){
+        $scope.editing = false;
+        $scope.deleting = false;
+        $scope.creating = false;
+    }
+
+    $scope.add = function(keyword, weight) {
+        $http.post("/pymnts/keywords/", {'kw': keyword, 'weight': parseInt(weight) }).then(
+            function(data) {
+                $scope.keywords = data.data.keywords;
+            });
+    };
+
+    $scope.update = function(old, newkw, weight){
+        $http.put("/pymnts/keywords/", {'kw': {'oldkw': old, 'newkw': newkw, 'weight': parseInt(weight)}}).then(
+            function(data) {
+                $scope.keywords = data.data.keywords;
+            },
+            function(err){
+            }
+        );
+    }
+
+    $scope.remove = function(kw){
+        var h = { 'Content-type': 'application/json;charset=utf-8' };
+        $http.delete("/pymnts/keywords/", {data: {'kw': kw}, headers: h}).then(
+            function(data){
+                $scope.keywords = data.data.keywords;
+            }
+        );
+    }
 });

+ 54 - 5
front/keywords.html

@@ -1,4 +1,4 @@
-	<div ng-controller="main" class="wrapper">
+	<div ng-controller="keywords" class="wrapper">
 		<aside class="sidebar">
 		<div>
 			<form class="filter">
@@ -6,24 +6,73 @@
 				<li>
 					<h3><i class="fa fa-filter"></i>Keyword panel</h3>
 				</li>
+                </ul>
+
+				<ul ng-if="editing">
 				<li>
 					<label for="title">Keyword</label>
-					<input type="text" ng-model="keyword" class="form-control" placeholder="url">
+					<input type="text" ng-model="oldkw" class="form-control" placeholder="url" disabled>
+				</li>
+				<li>
+					<label for="title">New keyword</label>
+					<input type="text" ng-model="newkw" class="form-control" placeholder="name">
 				</li>
 				<li>
 					<label for="title">Weight</label>
 					<input type="text" ng-model="weight" class="form-control" placeholder="name">
 				</li>
+				<li class="buttons">
+					<button ng-click="cancel()" class="reset">Cancel</button>
+					<button ng-click="update(oldkw, newkw, weight)">Update</button>
+				</li>
+                </ul>
+
+                <ul ng-if="deleting">
+				<li>
+					<label for="title">Keyword</label>
+					<input type="text" ng-model="oldkw" class="form-control" placeholder="url" disabled>
+				</li>
+				<li class="buttons">
+					<button ng-click="cancel()" class="reset">Cancel</button>
+				    <button ng-click="remove(oldkw)">Delete</button>
+                </li>
+                </ul>
+                
+                <ul ng-if="creating">
+				<li>
+					<label for="title">Keyword</label>
+					<input type="text" ng-model="keyword" class="form-control" placeholder="name">
+				</li>
+				<li>
+					<label for="title">Weight</label>
+					<input type="text" ng-model="weight" class="form-control" placeholder="name">
+				</li>
+				<li class="buttons">
+					<button ng-click="cancel()" class="reset">Cancel</button>
+					<button ng-click="add(keyword, weight)">Save</button>
+				</li>
+                </ul>
+
+                <ul ng-if="!editing && !deleting && !creating">
+				<li class="buttons">
+					<button ng-click="create()">New</button>
+				</li>
                 </ul>
+
             </form>
 		</div>
 		</aside>
 		<div class="content-wrapper">
-			<div class="news-wrapper">
-                <div class="">search</div>
+			<div class="news-wrapper" style="margin-bottom:0px">
 				<section ng-repeat="k in keywords" ng-class-odd="'odd-news'" ng-class-even="'even-news'">
 					<div class="title">
-                        <h4>{{k.keyword}}</h4> {{k.weight}} <i class="fa fa-pencil"></i>
+                        <!--
+                        <h4 style="width:auto">{{k.keyword}} ({{k.weight}}) </h4>
+                        -->
+                        <h4 style="width: 50%">{{k.keyword}}</h4>
+                        <h4 style="width: 20%">{{k.weight}}</h4>
+                        <i ng-click="delete(k)" class="pull-right fa fa-times"></i>
+                        <i ng-click="edit(k)"   class="pull-right fa fa-pencil"></i>
 					</div>
 				</section>
 			</div>