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

FEAT #11275 TIME 0:35 add load contacts from contacts group

parent e1b4d9e9
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, finalize } from 'rxjs/operators'; import { debounceTime, filter, distinctUntilChanged, tap, switchMap, exhaustMap, catchError, finalize, map } 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';
import { ContactModalComponent } from '../../administration/contact/modal/contact-modal.component'; import { ContactModalComponent } from '../../administration/contact/modal/contact-modal.component';
...@@ -164,18 +164,49 @@ export class ContactAutocompleteComponent implements OnInit { ...@@ -164,18 +164,49 @@ export class ContactAutocompleteComponent implements OnInit {
} }
setFormValue(item: any) { setFormValue(item: any) {
if (this.controlAutocomplete.value.map((contact: any) => contact.id).indexOf(item['id']) === -1) { if (item.type === 'contactGroup') {
this.http.get('../../rest/contactsGroups/' + item.id).pipe(
map((data: any) => {
const contacts = data.contactsGroup.contacts.map((contact: any) => {
return {
id: contact.id,
type: contact.type,
lastname: contact.contact
}
});
return contacts;
}),
tap((contacts: any) => {
contacts.forEach((contact: any) => {
this.setContact(contact);
});
}),
finalize(() => this.loadingValues = false),
catchError((err: any) => {
console.log(err);
this.notify.error(err.error.errors);
return of(false);
})
).subscribe();
} else {
this.setContact(item);
}
}
setContact(contact: any) {
if (this.controlAutocomplete.value.map((contact: any) => contact.id).indexOf(contact['id']) === -1) {
let arrvalue = []; let arrvalue = [];
if (this.controlAutocomplete.value !== null) { if (this.controlAutocomplete.value !== null) {
arrvalue = this.controlAutocomplete.value; arrvalue = this.controlAutocomplete.value;
} }
arrvalue.push( arrvalue.push(
{ {
type: item['type'], type: contact['type'],
id: item['id'] id: contact['id']
}); });
this.valuesToDisplay[item['id']] = item; this.valuesToDisplay[contact['id']] = contact;
this.controlAutocomplete.setValue(arrvalue); this.controlAutocomplete.setValue(arrvalue);
this.loadingValues = false; this.loadingValues = false;
} }
......
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