From 4a470c91f2c6388e66ea6bf151133395cde0be8d Mon Sep 17 00:00:00 2001
From: Jean-Laurent <jean-laurent.duzant@xelians.fr>
Date: Tue, 24 May 2022 17:32:25 +0200
Subject: [PATCH] FIX #20391 TIME 0:30 fix 'DLT' if resId exist && code clean
 up

---
 .../indexing-form/indexing-form.component.ts  | 24 ++++++++++++-------
 1 file changed, 16 insertions(+), 8 deletions(-)

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 13fe537406c..8419bfebab8 100755
--- a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts
+++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts
@@ -1000,12 +1000,18 @@ export class IndexingFormComponent implements OnInit {
                 }
 
                 await this.initElemForm(saveResourceState).then(() => {
+                    console.log('initElemForm', 'resId', this.resId);
+                    console.log(this.indexingModelClone);
+                    console.log(this['indexingModels_process']);
+
                     // check if clock is active
                     if (!this.functions.empty(this['indexingModels_process'])) {
                         const processLimitDate = this['indexingModels_process'].find((element: any) => element.identifier === 'processLimitDate');
                         if (!this.functions.empty(processLimitDate.today)) {
                             this.isProcessLimitDateToday = true;
-                            this.calcLimitDateToday();
+                            if (this.functions.empty(this.resId)) {
+                                this.calcLimitDateToday();
+                            }
                         }
                     }
                 });
@@ -1228,7 +1234,7 @@ export class IndexingFormComponent implements OnInit {
      * @description calculate the limit date if the clock is active
      * @returns void
      */
-     calcLimitDateToday() {
+    calcLimitDateToday() {
         let limitDate: any = null;
         const objToSend: any = {
             today: true
@@ -1294,17 +1300,19 @@ export class IndexingFormComponent implements OnInit {
     }
 
     setPriorityColorByLimitDate(field: any, value: any) {
-        const indexingModelCloneProcessLimitDate = this.indexingModelClone.fields.find((element: any) => element.identifier === 'processLimitDate');
-        if (this.isProcessLimitDateToday && this.functions.formatDateObjectToDateString(new Date(this.arrFormControl['processLimitDate'].value), true).toString() === this.functions.formatDateObjectToDateString(new Date(indexingModelCloneProcessLimitDate.default_value), true).toString()) {
-            this.arrFormControl['priority'].disable();
-            return;
-        }
-        this.arrFormControl['priority'].enable();
 
         const limitDate = new Date(value.value);
 
         this.http.get('../rest/indexing/priority', { params: { 'processLimitDate': limitDate.toDateString() } }).pipe(
             tap((data: any) => {
+
+                const indexingModelCloneProcessLimitDate = this.indexingModelClone.fields.find((element: any) => element.identifier === 'processLimitDate');
+                if (this.isProcessLimitDateToday && this.functions.formatDateObjectToDateString(limitDate, true).toString() === this.functions.formatDateObjectToDateString(new Date(indexingModelCloneProcessLimitDate.default_value), true).toString()) {
+                    this.arrFormControl['priority'].disable();
+                } else {
+                    this.arrFormControl['priority'].enable();
+                }
+
                 if (!this.functions.empty(this.arrFormControl['priority'])) {
                     this.arrFormControl['priority'].setValue(data.priority);
                 }
-- 
GitLab