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 821350e65b8a9f070b8c45e42f2c9d4dadec54bf..957fecd5f3200d7dae32c7cc0af79e89a8988854 100755 --- a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts +++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts @@ -1161,7 +1161,7 @@ export class IndexingFormComponent implements OnInit { } } - toggleTodayDate(field: any) { + async toggleTodayDate(field: any) { field.today = !field.today; if (field.today) { this.arrFormControl[field.identifier].disable(); @@ -1175,8 +1175,10 @@ export class IndexingFormComponent implements OnInit { if (field.identifier === 'processLimitDate' && !this.functions.empty(this.arrFormControl['priority'])) { const clonePriority = this.indexingModelClone.fields.find((element: any) => element.identifier === 'priority'); if (!this.functions.empty(clonePriority.default_value)) { - this.arrFormControl['priority'].setValue(clonePriority.default_value); - this.calcLimitDateByPriority(clonePriority, clonePriority.default_value); + const newProcessLimitDate = await this.calcLimitDateByPriority(clonePriority, clonePriority.default_value); + console.log('JL newProcessLimitDate', newProcessLimitDate); + this.setPriorityColorByLimitDate(null, { value: newProcessLimitDate}); + } else { this.arrFormControl['priority'].setValue(''); this.setPriorityColor(null, null); @@ -1256,7 +1258,6 @@ export class IndexingFormComponent implements OnInit { exhaustMap(() => this.http.get('../rest/indexing/priority', { params: { 'processLimitDate': limitDate.toDateString() } })), tap((data: any) => { if (!this.functions.empty(this.arrFormControl['priority'])) { - this.arrFormControl['priority'].disable(); this.arrFormControl['priority'].setValue(data.priority); } this.setPriorityColor(null, data.priority); @@ -1269,30 +1270,34 @@ export class IndexingFormComponent implements OnInit { } } - calcLimitDateByPriority(field: any, value: any) { - let limitDate: any = null; - const objToSend: any = { - priority: value, - doctype: this.arrFormControl['doctype']?.value, - }; - if (this.functions.empty(this.arrFormControl['doctype']?.value)) { - delete objToSend.doctype; - } - if (this.arrFormControl['processLimitDate'] !== undefined) { - this.http.get('../rest/indexing/processLimitDate', { params: objToSend }).pipe( - tap((data: any) => { - limitDate = data.processLimitDate !== null ? new Date(data.processLimitDate) : ''; - this.arrFormControl['processLimitDate'].setValue(limitDate); - this.setPriorityColor(field, value); - }), - catchError((err: any) => { - this.notify.handleErrors(err); - return of(false); - }) - ).subscribe(); - } else { - this.setPriorityColor(field, value); - } + async calcLimitDateByPriority(field: any, value: any) { + return await new Promise(async (resolve, reject) => { + let limitDate: any = null; + const objToSend: any = { + priority: value, + doctype: this.arrFormControl['doctype']?.value, + }; + if (this.functions.empty(this.arrFormControl['doctype']?.value)) { + delete objToSend.doctype; + } + if (this.arrFormControl['processLimitDate'] !== undefined) { + await this.http.get('../rest/indexing/processLimitDate', { params: objToSend }).pipe( + tap((data: any) => { + limitDate = data.processLimitDate !== null ? new Date(data.processLimitDate) : ''; + this.arrFormControl['processLimitDate'].setValue(limitDate); + this.setPriorityColor(field, value); + resolve(limitDate); + }), + catchError((err: any) => { + this.notify.handleErrors(err); + return of(false); + }) + ).subscribe(); + } else { + this.setPriorityColor(field, value); + resolve(limitDate); + } + }); } setPriorityColor(field: any, value: any) { @@ -1316,15 +1321,15 @@ export class IndexingFormComponent implements OnInit { tap((data: any) => { if (!this.functions.empty(this.arrFormControl['priority']) ) { this.arrFormControl['priority'].setValue(data.priority); - const indexingModelCloneProcessLimitDate = this.indexingModelClone.fields.find((element: any) => element.identifier === 'processLimitDate'); - - if (!this.functions.empty(indexingModelCloneProcessLimitDate)) { - 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(); - } - } + // const indexingModelCloneProcessLimitDate = this.indexingModelClone.fields.find((element: any) => element.identifier === 'processLimitDate'); + + // if (!this.functions.empty(indexingModelCloneProcessLimitDate)) { + // 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(); + // } + // } } this.setPriorityColor(null, data.priority); }),