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

experiement Promise for wait request end

parent 12d8edbe
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http'; ...@@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http';
import { LANG } from '../../translate.component'; import { LANG } from '../../translate.component';
import { NotificationService } from '../../notification.service'; import { NotificationService } from '../../notification.service';
import { tap, finalize, catchError } from 'rxjs/operators'; import { tap, finalize, catchError } from 'rxjs/operators';
import { of, Subject } from 'rxjs'; import { of } from 'rxjs';
import { ContactService } from '../../../service/contact.service'; import { ContactService } from '../../../service/contact.service';
@Component({ @Component({
...@@ -46,25 +46,31 @@ export class ContactsListComponent implements OnInit { ...@@ -46,25 +46,31 @@ export class ContactsListComponent implements OnInit {
private contactService: ContactService, private contactService: ContactService,
) { } ) { }
ngOnInit(): void { async ngOnInit(): Promise<void> {
this.loading = false;
this.http.get("../../rest/contactsCustomFields").pipe( await this.getCustomFields();
tap((data: any) => {
this.customFields = data.customFields.map((custom: any) => { if (this.resId !== null) {
return { this.loadContactsOfResource(this.resId, this.mode);
id: custom.id, } else if (this.contact !== null) {
label: custom.label this.loadContact(this.contact.id, this.contact.type);
} }
}); }
}),
tap(() => { getCustomFields() {
if (this.resId !== null) { return new Promise((resolve, reject) => {
this.loadContactsOfResource(this.resId, this.mode); this.http.get("../../rest/contactsCustomFields").pipe(
} else if (this.contact !== null) { tap((data: any) => {
this.loadContact(this.contact.id, this.contact.type); this.customFields = data.customFields.map((custom: any) => {
} return {
}) id: custom.id,
).subscribe(); label: custom.label
}
});
resolve(true);
})
).subscribe();
});
} }
loadContactsOfResource(resId: number, mode: string) { loadContactsOfResource(resId: number, mode: string) {
...@@ -149,9 +155,6 @@ export class ContactsListComponent implements OnInit { ...@@ -149,9 +155,6 @@ export class ContactsListComponent implements OnInit {
let arrCustomFields: any[] = []; let arrCustomFields: any[] = [];
Object.keys(data).forEach(element => { Object.keys(data).forEach(element => {
console.log(element);
console.log(this.customFields);
arrCustomFields.push({ arrCustomFields.push({
label: this.customFields.filter(custom => custom.id == element)[0].label, label: this.customFields.filter(custom => custom.id == element)[0].label,
value: data[element] value: data[element]
...@@ -174,7 +177,8 @@ export class ContactsListComponent implements OnInit { ...@@ -174,7 +177,8 @@ export class ContactsListComponent implements OnInit {
} }
emptyOtherInfo(contact: any) { emptyOtherInfo(contact: any) {
if (!this.empty(contact.communicationMeans) || !this.empty(contact.customFields)) {
if (contact.type === 'contact' && (!this.empty(contact.communicationMeans) || !this.empty(contact.customFields))) {
return false; return false;
} else { } else {
return true; return true;
......
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