Files
doneit-web/src/app/shared/event/attendee-modal/attendee-modal.page.ts
T

111 lines
2.7 KiB
TypeScript
Raw Normal View History

2021-03-29 13:12:35 +01:00
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2021-03-24 15:10:46 +01:00
import { ModalController } from '@ionic/angular';
import { ContactsService } from 'src/app/services/contacts.service';
import { EventPerson } from 'src/app/models/eventperson.model';
@Component({
selector: 'app-attendee-modal',
templateUrl: './attendee-modal.page.html',
styleUrls: ['./attendee-modal.page.scss'],
})
export class AttendeeModalPage implements OnInit {
contacts: EventPerson[];
showLoader: boolean = false;
2021-03-29 13:12:35 +01:00
selectedContact: EventPerson[] =[];
2021-03-24 15:10:46 +01:00
eventPersons: EventPerson[];
2021-03-29 13:12:35 +01:00
@Input() eventAttendees: EventPerson[];
2021-03-24 15:10:46 +01:00
constructor(private modalCtrl: ModalController, private contactsService: ContactsService) { }
@Output() openAttendeesComponent = new EventEmitter<any>();
2021-03-29 13:12:35 +01:00
@Output() GoBackEditOrAdd = new EventEmitter<any>();
2021-03-29 13:44:48 +01:00
@Output() setContact = new EventEmitter<any>();
2021-03-24 15:10:46 +01:00
ngOnInit() {
this.fetchContacts("");
2021-03-29 13:12:35 +01:00
this.selectedContact = this.eventAttendees;
2021-03-24 15:10:46 +01:00
}
save(){
2021-03-25 10:50:58 +01:00
2021-03-29 13:12:35 +01:00
// set data to agenda component
2021-03-29 13:44:48 +01:00
this.setContact.emit(this.selectedContact);
2021-03-29 13:12:35 +01:00
this.GoBackEditOrAdd.emit();
2021-03-24 15:10:46 +01:00
}
close(){
// this.modalCtrl.dismiss(null);
2021-03-29 13:44:48 +01:00
this.selectedContact = [];
this.GoBackEditOrAdd.emit();
2021-03-24 15:10:46 +01:00
}
onChange(evt: any) {
this.fetchContacts(evt.detail.value);
}
2021-03-29 13:12:35 +01:00
checkbox(itm: EventPerson): boolean {
const result = this.selectedContact.find((contact, index)=>{
if(contact.Name == itm.Name && contact.EmailAddress == itm.EmailAddress){
index = index;
return contact;
}
});
return undefined == result;
}
remove(itm: EventPerson){
this.selectedContact = this.selectedContact.filter((contact, index) =>{
if(contact.Name != itm.Name && contact.EmailAddress != itm.EmailAddress){
return contact;
}
return false;
});
}
async selectContact(itm: EventPerson){
const index = 0;
2021-03-29 17:00:21 +01:00
const findIndex = this.selectedContact.find((contact, index)=>{
2021-03-29 13:12:35 +01:00
if(contact.Name == itm.Name && contact.EmailAddress == itm.EmailAddress){
index = index;
return contact;
}
});
this.selectedContact.push(itm);
2021-03-24 15:10:46 +01:00
}
async fetchContacts(filter: string) {
this.showLoader = true;
this.contactsService.getContacts(filter).subscribe(result =>
{
if (this.eventPersons != null)
{
this.eventPersons.forEach(attendee => {
const index: number = result.findIndex((cont) => {
return cont.EmailAddress == attendee.EmailAddress
});
result.splice(index, 1);
});
}
this.contacts = result;
this.showLoader = false;
}
);
}
2021-03-25 10:50:58 +01:00
}