Commit 7aba904d authored by Hamza HRAMCHI's avatar Hamza HRAMCHI
Browse files

FIX #17812 TIME 0:10 use headerService + data from the back

parent 15f2a6f8
...@@ -7,6 +7,7 @@ import { NoteEditorComponent } from '../../notes/note-editor.component'; ...@@ -7,6 +7,7 @@ import { NoteEditorComponent } from '../../notes/note-editor.component';
import { tap, finalize, catchError } from 'rxjs/operators'; import { tap, finalize, catchError } from 'rxjs/operators';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { FunctionsService } from '@service/functions.service'; import { FunctionsService } from '@service/functions.service';
import { HeaderService } from '@service/header.service';
@Component({ @Component({
templateUrl: 'give-avis-parallel-action.component.html', templateUrl: 'give-avis-parallel-action.component.html',
...@@ -39,10 +40,11 @@ export class GiveAvisParallelActionComponent implements OnInit { ...@@ -39,10 +40,11 @@ export class GiveAvisParallelActionComponent implements OnInit {
private notify: NotificationService, private notify: NotificationService,
public dialogRef: MatDialogRef<GiveAvisParallelActionComponent>, public dialogRef: MatDialogRef<GiveAvisParallelActionComponent>,
@Inject(MAT_DIALOG_DATA) public data: any, @Inject(MAT_DIALOG_DATA) public data: any,
public functions: FunctionsService) { } public functions: FunctionsService,
public headerService: HeaderService
) { }
async ngOnInit() { ngOnInit() {
await this.isRedirected();
this.checkAvisParallel(); this.checkAvisParallel();
} }
...@@ -68,6 +70,11 @@ export class GiveAvisParallelActionComponent implements OnInit { ...@@ -68,6 +70,11 @@ export class GiveAvisParallelActionComponent implements OnInit {
this.opinionLimitDate = new Date(data.resourcesInformations.success[0].opinionLimitDate); this.opinionLimitDate = new Date(data.resourcesInformations.success[0].opinionLimitDate);
this.opinionLimitDate = this.functions.formatDateObjectToDateString(this.opinionLimitDate); this.opinionLimitDate = this.functions.formatDateObjectToDateString(this.opinionLimitDate);
} }
const userId: number = parseInt(this.data.userId, 10);
this.delegation.isDelegated = userId !== this.headerService.user.id ? true : false;
if (this.delegation.isDelegated && !this.noResourceToProcess) {
this.delegation.userDelegated = data.resourcesInformations.success[0].delegatingUser;
}
}), }),
finalize(() => this.loading = false), finalize(() => this.loading = false),
catchError((err: any) => { catchError((err: any) => {
...@@ -108,28 +115,4 @@ export class GiveAvisParallelActionComponent implements OnInit { ...@@ -108,28 +115,4 @@ export class GiveAvisParallelActionComponent implements OnInit {
isValidAction() { isValidAction() {
return !this.noResourceToProcess && !this.functions.empty(this.noteEditor.getNoteContent()); return !this.noResourceToProcess && !this.functions.empty(this.noteEditor.getNoteContent());
} }
isRedirected() {
return new Promise((resolve) => {
this.http.get('../rest/currentUser/profile').pipe(
tap((data: any) => {
const userId: number = parseInt(this.data.userId, 10);
this.delegation.isDelegated = userId !== data.id ? true : false;
if (this.delegation.isDelegated) {
this.http.get('../rest/users/' + userId).pipe(
tap((user: any) => {
this.delegation.userDelegated = `${user.firstname} ${user.lastname}`;
})
).subscribe();
}
resolve(true);
}),
catchError((err: any) => {
this.notify.handleErrors(err);
return of(false);
})
).subscribe();
});
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment