Improve Attendees component for agenda

This commit is contained in:
Peter Maquiran
2021-03-29 13:12:35 +01:00
parent 2606235a09
commit 28dc0f3e22
6 changed files with 126 additions and 36 deletions
@@ -1,4 +1,4 @@
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { ContactsService } from 'src/app/services/contacts.service';
import { EventPerson } from 'src/app/models/eventperson.model';
@@ -12,22 +12,27 @@ export class AttendeeModalPage implements OnInit {
contacts: EventPerson[];
showLoader: boolean = false;
selectedContact: EventPerson[] =[];
eventPersons: EventPerson[];
@Input() eventAttendees: EventPerson[];
constructor(private modalCtrl: ModalController, private contactsService: ContactsService) { }
@Output() openAttendeesComponent = new EventEmitter<any>();
@Output() GoBackEditOrAdd = new EventEmitter<any>();
ngOnInit() {
this.fetchContacts("");
this.selectedContact = this.eventAttendees;
}
save(){
this.openAttendeesComponent.emit(this.contacts.filter(function(contact) {
return contact.IsRequired == true;
}));
// set data to agenda component
this.openAttendeesComponent.emit(this.selectedContact);
// got back
this.GoBackEditOrAdd.emit();
}
close(){
@@ -39,8 +44,45 @@ export class AttendeeModalPage implements OnInit {
this.fetchContacts(evt.detail.value);
}
selectContact(itm: EventPerson){
itm.IsRequired = !itm.IsRequired;
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;
const findIndex = this.selectedContact.find((contact, index)=>{
if(contact.Name == itm.Name && contact.EmailAddress == itm.EmailAddress){
index = index;
return contact;
}
});
this.selectedContact.push(itm);
}
async fetchContacts(filter: string) {