Skip to content
Snippets Groups Projects
Commit c7342152 authored by Alex ORLUC's avatar Alex ORLUC
Browse files

FEAT #12635 TIME 1:30 fix autcomplete

parent 771da74e
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ import { AppService } from '../../../service/app.service'; ...@@ -8,7 +8,7 @@ import { AppService } from '../../../service/app.service';
import { SortPipe } from '../../../plugins/sorting.pipe'; import { SortPipe } from '../../../plugins/sorting.pipe';
import { FormControl } from '@angular/forms'; import { FormControl } from '@angular/forms';
import { Observable, of } from 'rxjs'; import { Observable, of } from 'rxjs';
import { debounceTime, filter, distinctUntilChanged, tap, switchMap, exhaustMap, catchError } from 'rxjs/operators'; import { debounceTime, filter, distinctUntilChanged, tap, switchMap, exhaustMap, catchError, finalize } from 'rxjs/operators';
import { LatinisePipe } from 'ngx-pipes'; import { LatinisePipe } from 'ngx-pipes';
import { PrivilegeService } from '../../../service/privileges.service'; import { PrivilegeService } from '../../../service/privileges.service';
...@@ -61,7 +61,6 @@ export class ContactAutocompleteComponent implements OnInit { ...@@ -61,7 +61,6 @@ export class ContactAutocompleteComponent implements OnInit {
} }
ngOnInit() { ngOnInit() {
console.log(this.controlAutocomplete);
this.controlAutocomplete.setValue(this.controlAutocomplete.value === null || this.controlAutocomplete.value === '' ? [] : this.controlAutocomplete.value); this.controlAutocomplete.setValue(this.controlAutocomplete.value === null || this.controlAutocomplete.value === '' ? [] : this.controlAutocomplete.value);
this.canAdd = this.privilegeService.hasCurrentUserPrivilege('manage_tags_application'); this.canAdd = this.privilegeService.hasCurrentUserPrivilege('manage_tags_application');
this.initFormValue(); this.initFormValue();
...@@ -104,6 +103,13 @@ export class ContactAutocompleteComponent implements OnInit { ...@@ -104,6 +103,13 @@ export class ContactAutocompleteComponent implements OnInit {
initFormValue() { initFormValue() {
this.controlAutocomplete.value.forEach((contact: any) => { this.controlAutocomplete.value.forEach((contact: any) => {
this.valuesToDisplay[contact.id] = {
type: '',
firstname: '',
lastname: this.lang.undefined,
company: ''
};
if (contact.type === 'contact') { if (contact.type === 'contact') {
this.http.get('../../rest/contacts/' + contact.id).pipe( this.http.get('../../rest/contacts/' + contact.id).pipe(
tap((data: any) => { tap((data: any) => {
...@@ -114,6 +120,11 @@ export class ContactAutocompleteComponent implements OnInit { ...@@ -114,6 +120,11 @@ export class ContactAutocompleteComponent implements OnInit {
company: data.company company: data.company
}; };
}),
finalize(() => this.loadingValues = false),
catchError((err: any) => {
this.notify.error(err.error.errors);
return of(false);
}) })
).subscribe(); ).subscribe();
} else if (contact.type === 'user') { } else if (contact.type === 'user') {
...@@ -124,6 +135,11 @@ export class ContactAutocompleteComponent implements OnInit { ...@@ -124,6 +135,11 @@ export class ContactAutocompleteComponent implements OnInit {
firstname: data.firstname, firstname: data.firstname,
lastname: data.lastname, lastname: data.lastname,
}; };
}),
finalize(() => this.loadingValues = false),
catchError((err: any) => {
this.notify.error(err.error.errors);
return of(false);
}) })
).subscribe(); ).subscribe();
} else if (contact.type === 'entity') { } else if (contact.type === 'entity') {
...@@ -133,12 +149,15 @@ export class ContactAutocompleteComponent implements OnInit { ...@@ -133,12 +149,15 @@ export class ContactAutocompleteComponent implements OnInit {
type: 'entity', type: 'entity',
lastname: data.entity_label, lastname: data.entity_label,
}; };
}),
finalize(() => this.loadingValues = false),
catchError((err: any) => {
this.notify.error(err.error.errors);
return of(false);
}) })
).subscribe(); ).subscribe();
} }
}); });
this.loadingValues = false;
} }
setFormValue(item: any) { setFormValue(item: any) {
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment