From 6f24a63f94fcf47e5c5c86b7c8a7ec7360ccfdbc Mon Sep 17 00:00:00 2001
From: Hamza HRAMCHI <hamza.hramchi@xelians.fr>
Date: Fri, 9 Sep 2022 15:18:29 +0200
Subject: [PATCH] FEAT #21462 TIME 1 reset contact + fix vars

---
 .../contact-autocomplete.component.ts             |  4 +++-
 src/frontend/app/header/header-right.component.ts |  4 ++--
 .../criteria-tool/criteria-tool.component.ts      | 15 +++++++++++++--
 .../result-list/search-result-list.component.ts   |  2 --
 src/lang/lang-en.json                             |  6 +++++-
 5 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/src/frontend/app/contact/autocomplete/contact-autocomplete.component.ts b/src/frontend/app/contact/autocomplete/contact-autocomplete.component.ts
index 5c8bcda5215..6eedda338c9 100755
--- a/src/frontend/app/contact/autocomplete/contact-autocomplete.component.ts
+++ b/src/frontend/app/contact/autocomplete/contact-autocomplete.component.ts
@@ -170,7 +170,9 @@ export class ContactAutocompleteComponent implements OnInit {
     }
 
     selectOpt(ev: any) {
-        this.criteriaSearchService.updateListsPropertiesCriteria({});
+        if (!this.functions.empty(this.controlAutocomplete.value.find((item: any) => this.functions.empty(item.id)))) {
+            this.controlAutocomplete.setValue(this.controlAutocomplete.value.filter((item: any) => !this.functions.empty(item.id)));
+        }
         this.setFormValue(ev.option.value);
         this.afterSelected.emit(ev.option.value);
         this.myControl.setValue('');
diff --git a/src/frontend/app/header/header-right.component.ts b/src/frontend/app/header/header-right.component.ts
index 6c131148994..50238d6f84d 100644
--- a/src/frontend/app/header/header-right.component.ts
+++ b/src/frontend/app/header/header-right.component.ts
@@ -38,13 +38,13 @@ export class HeaderRightComponent implements OnInit {
             icon: 'fas fa-inbox fa-2x',
         },
         {
-            id: 'recipient',
+            id: 'recipients',
             label: this.translate.instant('lang.recipient'),
             desc: this.translate.instant('lang.searchByRecipient'),
             icon: 'fas fa-user fa-2x',
         },
         {
-            id: 'sender',
+            id: 'senders',
             label: this.translate.instant('lang.sender'),
             desc: this.translate.instant('lang.searchBySender'),
             icon: 'fas fa-address-book fa-2x',
diff --git a/src/frontend/app/search/criteria-tool/criteria-tool.component.ts b/src/frontend/app/search/criteria-tool/criteria-tool.component.ts
index db778dd61ab..bb29873d510 100644
--- a/src/frontend/app/search/criteria-tool/criteria-tool.component.ts
+++ b/src/frontend/app/search/criteria-tool/criteria-tool.component.ts
@@ -136,8 +136,8 @@ export class CriteriaToolComponent implements OnInit {
                 this.addCriteria(element, false);
             }
         });
-        if (['sender', 'recipient'].indexOf(this.currentParam?.target) > -1) {
-            if (this.currentParam.target === 'sender') {
+        if (['senders', 'recipients'].indexOf(this.currentParam?.target) > -1) {
+            if (this.currentParam.target === 'senders') {
                 this.criteriaSearchService.updateListsPropertiesCriteria({senders: {type: 'autocomplete', values: [this.currentParam.value]}});
             } else {
                 this.criteriaSearchService.updateListsPropertiesCriteria({recipients: {type: 'autocomplete', values: [this.currentParam.value]}});
@@ -267,6 +267,17 @@ export class CriteriaToolComponent implements OnInit {
                 }
             }
         });
+        if (!this.functions.empty(this.currentParam?.target)) {
+            const contactArray: any = this.appContactAutocomplete.toArray().find((item: any) => item.id === this.currentParam.target);
+            if (!this.functions.empty(contactArray?.myControl) && !this.functions.empty(objCriteria[this.currentParam.target])) {
+                objCriteria[this.currentParam.target]['values'] = contactArray.myControl.value;
+                if (this.currentParam.target === 'senders') {
+                    this.criteriaSearchService.updateListsPropertiesCriteria({senders: {type: 'autocomplete', values: [contactArray.myControl.value]}});
+                } else {
+                    this.criteriaSearchService.updateListsPropertiesCriteria({recipients: {type: 'autocomplete', values: [contactArray.myControl.value]}});
+                }
+            }
+        }
         this.searchUrlGenerated.emit(objCriteria);
     }
 
diff --git a/src/frontend/app/search/result-list/search-result-list.component.ts b/src/frontend/app/search/result-list/search-result-list.component.ts
index 2b9650fa568..7070fe48a33 100644
--- a/src/frontend/app/search/result-list/search-result-list.component.ts
+++ b/src/frontend/app/search/result-list/search-result-list.component.ts
@@ -223,8 +223,6 @@ export class SearchResultListComponent implements OnInit, OnDestroy {
             this.isLoadingResults = false;
             this.hideFilter = true;
         }
-
-
         this.loading = false;
         this.dataResult.emit([]);
     }
diff --git a/src/lang/lang-en.json b/src/lang/lang-en.json
index 8ba8800e67f..8d7d92a2f98 100644
--- a/src/lang/lang-en.json
+++ b/src/lang/lang-en.json
@@ -2598,5 +2598,9 @@
     "canGoToNextResDesc": "Activating this option saves this choice in your session",
     "sortBy": "Sort by",
     "showInformationsBlock": "Show information block",
-    "hideInformationsBlock": "Hide information block"
+    "hideInformationsBlock": "Hide information block",
+    "quickSearchTargets": "Quick search target",
+    "defaultQuickSearch": "Subject, Barcode, GED Number",
+    "searchBySender": "Search by sender",
+    "searchByRecipient": "Search by recipient"
 }
-- 
GitLab