瀏覽代碼

keywords+ article filtering

David 10 年之前
父節點
當前提交
d433547b59
共有 2 個文件被更改,包括 30 次插入2 次删除
  1. 8 0
      front/index.html
  2. 22 2
      front/js/app.js

+ 8 - 0
front/index.html

@@ -10,8 +10,11 @@
 
 		<!-- Latest compiled and minified JavaScript -->
 		<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
+		<link rel="stylesheet" type="text/css" href="js/ng-tags-input.min.css">
+		<link rel="stylesheet" type="text/css" href="js/ng-tags-input.bootstrap.min.css">
 
 		<script src="js/angular.min.js"></script>
+		<script src="js/ng-tags-input.min.js"></script>
 		<script src="js/app.js"></script>
 	</head>
 <body>
@@ -32,7 +35,12 @@
 				</div>
 				<div class="row">
 					<div class="col-sm-4 col-md-4 col-lg-4">Keyword:</div>
+					<!--
 					<input class="col-sm-8 col-md-8 col-lg-8" ng-model="keyword" type="text"/>
+					-->
+					<tags-input ng-model="selected_kw" add-on-paste="true" add-from-autocomplete-only="true" replace-spaces-with-dashes="false">
+						<auto-complete source="filtered($query)"></auto-complete>
+					</tags-input>
 				</div>
 				<div class="row">
 					<div class="col-sm-4 col-md-4 col-lg-4">MinWeight:</div>

+ 22 - 2
front/js/app.js

@@ -1,9 +1,12 @@
-app=angular.module('app', []);
+app=angular.module('app', ["ngTagsInput"]);
 
 app.controller('main', function($scope,$http,$sce) {
 	$scope.news=[];
 	$scope.newsArticle="";
 
+	$scope.keywords=[];
+	$scope.selected_kw=[];
+
 	$scope.getNews = function() {
 		$http.get("/pymnts/articles/").then(
 		function(data) {
@@ -21,6 +24,22 @@ app.controller('main', function($scope,$http,$sce) {
 			console.log(data);
 		});
 	};
+	$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) {
@@ -31,7 +50,8 @@ app.controller('main', function($scope,$http,$sce) {
 		);
 	};
 	$scope.filter = function() {
-		$http.post("/pymnts/articles/",{"mindate":$scope.mindate,"maxdate":$scope.maxdate,"site":$scope.site,"keyword":$scope.keywod,"minweight":$scope.minweight}).then(
+		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}).then(
 			function(data) {
 				$scope.news=data.data.articles;
 			},