From 1440ea37804a43591be144dfce2a3278dbd88570 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Thu, 6 Aug 2020 08:32:24 +0000
Subject: [PATCH] fix dest mode outgoing

(cherry picked from commit d5d3380ec5f85e5613252c316554998758ced804)
---
 src/frontend/app/diffusions/diffusions-list.component.ts    | 6 +++---
 .../indexation/indexing-form/indexing-form.component.html   | 2 +-
 .../app/indexation/indexing-form/indexing-form.component.ts | 4 ++++
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/frontend/app/diffusions/diffusions-list.component.ts b/src/frontend/app/diffusions/diffusions-list.component.ts
index 790b8f1dbb4..90018e0e992 100644
--- a/src/frontend/app/diffusions/diffusions-list.component.ts
+++ b/src/frontend/app/diffusions/diffusions-list.component.ts
@@ -48,9 +48,9 @@ export class DiffusionsListComponent implements OnInit {
     @Input('entityId') entityId: any = null;
 
     /**
-     * Category identifier to specify the context to load listModel
+     * To specify the context to load listModel
      */
-    @Input() categoryId: any = null;
+    @Input() selfDest: boolean = false;
 
     /**
      * For manage current loaded list
@@ -101,7 +101,7 @@ export class DiffusionsListComponent implements OnInit {
         if (this.resId !== null && this.resId != 0 && this.target !== 'redirect') {
             this.loadListinstance(this.resId);
         } else if ((this.resId === null || this.resId == 0) && !this.functions.empty(this.entityId)) {
-            this.loadListModel(this.entityId, false, this.categoryId === 'outgoing');
+            this.loadListModel(this.entityId, false, this.selfDest);
         }
         this.loading = false;
     }
diff --git a/src/frontend/app/indexation/indexing-form/indexing-form.component.html b/src/frontend/app/indexation/indexing-form/indexing-form.component.html
index bc5f2eae732..f7d1fb1620e 100644
--- a/src/frontend/app/indexation/indexing-form/indexing-form.component.html
+++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.html
@@ -229,7 +229,7 @@
                                     <i class="fas fa-check fieldFull" *ngIf="!adminMode && arrFormControl['diffusionList'].valid && !isEmptyField(field)"></i>
                                 </div>
                             </div>
-                            <app-diffusions-list #appDiffusionsList [resId]="resId" [entityId]="arrFormControl[field.identifier].value" [diffFormControl]="arrFormControl['diffusionList']" [allowedEntities]="field.allowedEntities" [target]="'indexation'" [categoryId]="currentCategory" (triggerEvent)="changeDestination($event,field.allowedEntities)">
+                            <app-diffusions-list #appDiffusionsList [resId]="resId" [entityId]="arrFormControl[field.identifier].value" [diffFormControl]="arrFormControl['diffusionList']" [allowedEntities]="field.allowedEntities" [target]="'indexation'" [selfDest]="selfDest" (triggerEvent)="changeDestination($event,field.allowedEntities)">
                             </app-diffusions-list>
                             <mat-divider></mat-divider>
                         </div>
diff --git a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts
index 20ec038dd89..54ab3330e8f 100755
--- a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts
+++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts
@@ -194,6 +194,8 @@ export class IndexingFormComponent implements OnInit {
 
     currentResourceValues: any = null;
 
+    selfDest: boolean = false;
+
     dialogRef: MatDialogRef<any>;
 
     constructor(
@@ -506,9 +508,11 @@ export class IndexingFormComponent implements OnInit {
                     } else {
                         let title = '';
                         if (elem.default_value === '#myPrimaryEntity') {
+                            this.selfDest = this.currentCategory === 'outgoing';
                             elem.default_value = this.headerService.user.entities[0].id;
                             this.arrFormControl[elem.identifier].setValue(elem.default_value);
                         } else {
+                            this.selfDest = false;
                             const defaultVal = data.entities.filter((entity: any) => entity.enabled === true && entity.id === elem.default_value);
                             elem.default_value = defaultVal.length > 0 ? defaultVal[0].id : null;
                             this.arrFormControl[elem.identifier].setValue(defaultVal.length > 0 ? defaultVal[0].id : '');
-- 
GitLab