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

174 lines
4.2 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 {
2021-04-01 15:26:26 +01:00
// Defined by the API
2021-03-24 15:10:46 +01:00
contacts: EventPerson[];
showLoader: boolean = false;
eventPersons: EventPerson[];
2021-04-06 11:28:46 +01:00
@Input() taskParticipants:EventPerson[] = [];
@Input() taskParticipantsCc:EventPerson[] = [];
2021-03-29 13:12:35 +01:00
2021-04-08 13:39:48 +01:00
constructor(
private modalCtrl: ModalController,
private contactsService: ContactsService ) {
}
2021-03-24 15:10:46 +01:00
2021-03-30 10:28:05 +01:00
@Output() closeComponent = new EventEmitter<any>();
2021-04-05 15:10:28 +01:00
@Output() setIntervenient = new EventEmitter<any>();
@Output() setIntervenientCC = new EventEmitter<any>();
2021-04-06 13:55:17 +01:00
@Output() dynamicSetIntervenient = new EventEmitter<any>();
2021-03-24 15:10:46 +01:00
2021-03-30 15:38:57 +01:00
currentPath = window.location.pathname;
2021-04-05 15:10:28 +01:00
@Input() adding: "intervenient" | "CC";
2021-03-30 15:38:57 +01:00
2021-03-24 15:10:46 +01:00
ngOnInit() {
this.fetchContacts("");
2021-04-05 15:10:28 +01:00
2021-04-06 11:28:46 +01:00
if(this.taskParticipants == null || this.taskParticipants == undefined){
this.taskParticipants = [];
}
if(this.taskParticipantsCc == null || this.taskParticipantsCc == undefined){
this.taskParticipantsCc = [];
}
2021-03-24 15:10:46 +01:00
}
2021-04-01 15:26:26 +01:00
2021-04-05 15:10:28 +01:00
ngOnChanges(event){}
2021-03-24 15:10:46 +01:00
save(){
2021-04-05 15:10:28 +01:00
this.setIntervenient.emit(this.taskParticipants);
this.setIntervenientCC.emit(this.taskParticipantsCc);
2021-03-30 10:28:05 +01:00
this.closeComponent.emit();
2021-03-24 15:10:46 +01:00
}
2021-03-30 15:38:57 +01:00
setContactWithClose(){
if(this.currentPath == '/home/gabinete-digital'){
2021-04-05 15:10:28 +01:00
this.setIntervenient.emit(this.taskParticipants);
this.setIntervenientCC.emit(this.taskParticipantsCc);
2021-03-30 15:38:57 +01:00
}
}
2021-03-24 15:10:46 +01:00
close(){
2021-03-30 10:28:05 +01:00
this.closeComponent.emit();
2021-03-24 15:10:46 +01:00
}
onChange(evt: any) {
this.fetchContacts(evt.detail.value);
}
2021-03-30 10:28:05 +01:00
filterSearchList(itm: EventPerson): boolean {
2021-04-05 15:10:28 +01:00
if(this.adding == "intervenient"){
const result = this.taskParticipants.find((contact, index)=>{
if(contact.Name == itm.Name && contact.EmailAddress == itm.EmailAddress){
index = index;
return contact;
}
});
return undefined == result;
} else if (this.adding == "CC") {
const result = this.taskParticipantsCc.find((contact, index)=>{
2021-03-29 13:12:35 +01:00
if(contact.Name == itm.Name && contact.EmailAddress == itm.EmailAddress){
2021-04-05 15:10:28 +01:00
index = index;
return contact;
}
});
2021-03-29 13:12:35 +01:00
2021-04-05 15:10:28 +01:00
return undefined == result;
}
2021-03-29 13:12:35 +01:00
}
remove(itm: EventPerson){
2021-04-05 15:10:28 +01:00
if(this.adding == "intervenient"){
2021-03-29 13:12:35 +01:00
2021-04-05 15:10:28 +01:00
this.taskParticipants = this.taskParticipants.filter((contact, index) =>{
2021-03-29 13:12:35 +01:00
2021-04-05 15:10:28 +01:00
if(contact.Name != itm.Name && contact.EmailAddress != itm.EmailAddress){
return contact;
}
return false;
});
} else if (this.adding == "CC") {
this.taskParticipantsCc = this.taskParticipantsCc.filter((contact, index) =>{
if(contact.Name != itm.Name && contact.EmailAddress != itm.EmailAddress){
return contact;
}
return false;
});
}
2021-03-30 15:38:57 +01:00
2021-04-06 13:55:17 +01:00
this.dynamicSetIntervenient.emit({
taskParticipants: this.taskParticipants,
taskParticipantsCc: this.taskParticipantsCc
})
2021-03-30 15:38:57 +01:00
this.setContactWithClose();
2021-03-29 13:12:35 +01:00
}
async selectContact(itm: EventPerson){
2021-04-05 15:10:28 +01:00
if(this.adding == "intervenient"){
2021-03-30 15:38:57 +01:00
2021-04-08 13:39:48 +01:00
itm.IsRequired = true;
2021-04-05 15:10:28 +01:00
this.taskParticipants.push(itm);
} else if (this.adding == "CC") {
2021-04-08 13:39:48 +01:00
itm.IsRequired = false;
2021-04-05 15:10:28 +01:00
this.taskParticipantsCc.push(itm);
}
2021-03-30 15:38:57 +01:00
// run only in gabinete digital
this.setContactWithClose();
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
}