From cf8ae790d13f69d15f3d279565abbba3b065fba4 Mon Sep 17 00:00:00 2001
From: Clement Ho <ClemMakesApps@gmail.com>
Date: Mon, 7 Nov 2016 16:18:50 -0600
Subject: [PATCH] Add filter params to search

---
 .../filtered_search_manager.js.es6            | 36 ++++++++++++-------
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/app/assets/javascripts/filtered_search/filtered_search_manager.js.es6 b/app/assets/javascripts/filtered_search/filtered_search_manager.js.es6
index 797473f2044..c26a46a8558 100644
--- a/app/assets/javascripts/filtered_search/filtered_search_manager.js.es6
+++ b/app/assets/javascripts/filtered_search/filtered_search_manager.js.es6
@@ -5,15 +5,19 @@
   const validTokenKeys = [{
     key: 'author',
     type: 'string',
+    param: 'id',
   },{
     key: 'assignee',
-    type: 'string'
+    type: 'string',
+    param: 'id',
   },{
     key: 'milestone',
-    type: 'string'
+    type: 'string',
+    param: 'title',
   },{
     key: 'label',
-    type: 'array'
+    type: 'array',
+    param: 'name%5B%5D',
   },];
 
   class FilteredSearchManager {
@@ -53,14 +57,14 @@
           const tokenValue = i.slice(colonIndex + 1);
 
           const match = validTokenKeys.filter((v) => {
-            return v.name === tokenKey;
+            return v.key === tokenKey;
           })[0];
 
-          if (match) {
-              this.tokens.push = {
-                key: match.key,
-                value: tokenValue,
-              };
+          if (match && tokenValue.length > 0) {
+            this.tokens.push({
+              key: match.key,
+              value: tokenValue,
+            });
           }
         } else {
           searchTerms += i + ' ';
@@ -72,8 +76,11 @@
     }
 
     printTokens() {
-      console.log(this.tokens);
-      console.log(this.searchToken);
+      console.log('tokens:')
+      this.tokens.forEach((token) => {
+        console.log(token);
+      })
+      console.log('search: ' + this.searchToken);
     }
 
     checkForEnter(event) {
@@ -88,8 +95,13 @@
       console.log('search');
       let path = '?scope=all&state=opened&utf8=鉁�';
 
-      this.tokens.foreach((token) => {
 
+      this.tokens.forEach((token) => {
+        const param = validTokenKeys.find((t) => {
+          return t.key === token.key;
+        }).param;
+
+        path += `&${token.key}_${param}=${token.value}`;
       });
 
       if (this.searchToken) {
-- 
2.30.9