瀏覽代碼

Provided a minimalistic way to handle duplicate query attributes, and added handling for when a query string is passed in. Basically, if a query string is passed in, simple and advanced search all get reset.

jalbr74 6 年之前
父節點
當前提交
00e4f7b4ea

+ 31 - 7
client/src/modules/helpdesk/helpdesk-search-base.component.ts

@@ -89,11 +89,21 @@ export default abstract class HelpDeskSearchBaseComponent {
                 })
             ]
         ).then(result => {
-            this.query = this.getSearchText();
-            this.advancedSearch = this.commonSearchService.isHdAdvancedSearchActive();
-            this.queries = this.commonSearchService.getHdAdvSearchQueries();
-            if (this.queries.length === 0) {
-                this.addSearchTag();
+            const searchQuery = this.getSearchQuery();
+            if (searchQuery) {
+                // A search query has been passed in, disregard the current search state
+                this.query = searchQuery;
+                this.advancedSearch = false;
+                this.storeSearchText();
+                this.commonSearchService.setHdAdvancedSearchActive(this.advancedSearch);
+                this.commonSearchService.setHdAdvSearchQueries([]);
+            } else {
+                this.query = this.getSearchText();
+                this.advancedSearch = this.commonSearchService.isHdAdvancedSearchActive();
+                this.queries = this.commonSearchService.getHdAdvSearchQueries();
+                if (this.queries.length === 0) {
+                    this.addSearchTag();
+                }
             }
 
             // Once <ias-search-box> from ng-ias allows the autofocus attribute, we can remove this code
@@ -111,7 +121,7 @@ export default abstract class HelpDeskSearchBaseComponent {
         return this.errorMessage || this.searchMessage;
     }
 
-    private getSearchText(): string {
+    private getSearchQuery(): string {
         let param: string = this.$stateParams['query'];
         // If multiple query parameters are defined, use the first one
         if (isArray(param)) {
@@ -121,7 +131,11 @@ export default abstract class HelpDeskSearchBaseComponent {
             param = param.trim();
         }
 
-        return param || this.localStorageService.getItem(this.searchTextLocalStorageKey);
+        return param;
+    }
+
+    private getSearchText(): string {
+        return this.localStorageService.getItem(this.searchTextLocalStorageKey);
     }
 
     abstract fetchData(): void;
@@ -146,6 +160,16 @@ export default abstract class HelpDeskSearchBaseComponent {
                 return null;
             }
 
+            const keys = new Set();
+            for (let searchQuery of this.queries) {
+                keys.add(searchQuery.key);
+            }
+
+            if (keys.size < this.queries.length) {
+                this.searchMessage = 'Search attributes must be unique';
+                return null;
+            }
+
             promise = this.helpDeskService.advancedSearch(this.queries);
         }
         else {

+ 31 - 7
client/src/modules/peoplesearch/peoplesearch-base.component.ts

@@ -217,6 +217,16 @@ abstract class PeopleSearchBaseComponent {
                 return null;
             }
 
+            const keys = new Set();
+            for (let searchQuery of this.queries) {
+                keys.add(searchQuery.key);
+            }
+
+            if (keys.size < this.queries.length) {
+                this.searchMessage = 'Search attributes must be unique';
+                return null;
+            }
+
             promise = this.peopleService.advancedSearch(this.queries);
         }
         else {
@@ -279,11 +289,21 @@ abstract class PeopleSearchBaseComponent {
                 })
             ]
         ).then(result => {
-            this.query = this.getSearchText();
-            this.advancedSearch = this.commonSearchService.isPsAdvancedSearchActive();
-            this.queries = this.commonSearchService.getPsAdvSearchQueries();
-            if (this.queries.length === 0) {
-                this.addSearchTag();
+            const searchQuery = this.getSearchQuery();
+            if (searchQuery) {
+                // A search query has been passed in, disregard the current search state
+                this.query = searchQuery;
+                this.advancedSearch = false;
+                this.storeSearchText();
+                this.commonSearchService.setPsAdvancedSearchActive(this.advancedSearch);
+                this.commonSearchService.setPsAdvSearchQueries([]);
+            } else {
+                this.query = this.getSearchText();
+                this.advancedSearch = this.commonSearchService.isPsAdvancedSearchActive();
+                this.queries = this.commonSearchService.getPsAdvSearchQueries();
+                if (this.queries.length === 0) {
+                    this.addSearchTag();
+                }
             }
 
             // Once <ias-search-box> from ng-ias allows the autofocus attribute, we can remove this code
@@ -297,7 +317,7 @@ abstract class PeopleSearchBaseComponent {
         });
     }
 
-    private getSearchText(): string {
+    private getSearchQuery(): string {
         let param: string = this.$stateParams['query'];
         // If multiple query parameters are defined, use the first one
         if (isArray(param)) {
@@ -307,7 +327,11 @@ abstract class PeopleSearchBaseComponent {
             param = param.trim();
         }
 
-        return param || this.localStorageService.getItem(this.searchTextLocalStorageKey);
+        return param;
+    }
+
+    private getSearchText(): string {
+        return this.localStorageService.getItem(this.searchTextLocalStorageKey);
     }
 
     protected storeSearchText(): void {