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';
|
2021-04-09 13:43:33 +01:00
|
|
|
import { removeDuplicate } from 'src/plugin/removeDuplicate.js'
|
2021-03-24 15:10:46 +01:00
|
|
|
@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-21 14:27:55 +01:00
|
|
|
|
|
|
|
|
@Output() closeComponent = new EventEmitter<any>();
|
|
|
|
|
|
|
|
|
|
@Output() setIntervenient = new EventEmitter<any>();
|
|
|
|
|
@Output() setIntervenientCC = new EventEmitter<any>();
|
|
|
|
|
@Output() dynamicSetIntervenient = new EventEmitter<any>();
|
|
|
|
|
|
|
|
|
|
|
2021-04-06 11:28:46 +01:00
|
|
|
@Input() taskParticipants:EventPerson[] = [];
|
|
|
|
|
@Input() taskParticipantsCc:EventPerson[] = [];
|
2021-03-29 13:12:35 +01:00
|
|
|
|
2021-05-28 16:39:03 +01:00
|
|
|
@Input() footer: boolean;
|
|
|
|
|
|
2021-04-21 14:27:55 +01:00
|
|
|
LtaskParticipants: EventPerson[] = [];
|
|
|
|
|
LtaskParticipantsCc: EventPerson[] = [];
|
|
|
|
|
|
2021-04-08 13:39:48 +01:00
|
|
|
constructor(
|
|
|
|
|
private modalCtrl: ModalController,
|
|
|
|
|
private contactsService: ContactsService ) {
|
|
|
|
|
|
2021-04-21 14:27:55 +01:00
|
|
|
this.LtaskParticipants = this.taskParticipants;
|
|
|
|
|
this.LtaskParticipantsCc = this.taskParticipantsCc;
|
2021-03-24 15:10:46 +01:00
|
|
|
|
2021-04-21 14:27:55 +01:00
|
|
|
}
|
2021-04-05 15:10:28 +01:00
|
|
|
|
2021-04-21 19:59:49 +01:00
|
|
|
ngOnChanges(){
|
|
|
|
|
this.LtaskParticipants = this.taskParticipants;
|
|
|
|
|
this.LtaskParticipantsCc = this.taskParticipantsCc;
|
|
|
|
|
}
|
|
|
|
|
|
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() {
|
2021-04-08 15:45:45 +01:00
|
|
|
|
2021-03-24 15:10:46 +01:00
|
|
|
this.fetchContacts("");
|
2021-04-05 15:10:28 +01:00
|
|
|
|
2021-04-21 14:27:55 +01:00
|
|
|
if(this.LtaskParticipants == null || this.LtaskParticipants == undefined) {
|
|
|
|
|
this.LtaskParticipants = [];
|
2021-04-06 11:28:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-21 14:27:55 +01:00
|
|
|
if(this.LtaskParticipantsCc == null || this.LtaskParticipantsCc == undefined) {
|
|
|
|
|
this.LtaskParticipantsCc = [];
|
2021-04-06 11:28:46 +01:00
|
|
|
}
|
2021-04-12 10:01:43 +01:00
|
|
|
|
2021-03-24 15:10:46 +01:00
|
|
|
}
|
2021-04-01 15:26:26 +01:00
|
|
|
|
2021-03-24 15:10:46 +01:00
|
|
|
|
|
|
|
|
save(){
|
2021-04-21 19:59:49 +01:00
|
|
|
|
2021-04-21 14:27:55 +01:00
|
|
|
this.setIntervenient.emit(this.LtaskParticipants);
|
|
|
|
|
this.setIntervenientCC.emit(this.LtaskParticipantsCc);
|
2021-04-05 15:10:28 +01:00
|
|
|
|
2021-03-30 10:28:05 +01:00
|
|
|
this.closeComponent.emit();
|
2021-03-24 15:10:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-21 14:27:55 +01:00
|
|
|
setContactWithClose() {
|
|
|
|
|
|
|
|
|
|
if(this.currentPath == '/home/gabinete-digital') {
|
|
|
|
|
console.log('set!!!!! ')
|
|
|
|
|
this.setIntervenient.emit(this.LtaskParticipants);
|
|
|
|
|
this.setIntervenientCC.emit(this.LtaskParticipantsCc);
|
2021-03-30 15:38:57 +01:00
|
|
|
}
|
2021-04-12 10:01:43 +01:00
|
|
|
|
2021-04-21 14:27:55 +01:00
|
|
|
/* console.log('data', this.LtaskParticipants, this.LtaskParticipantsCc ); */
|
2021-04-12 10:01:43 +01:00
|
|
|
this.dynamicSetIntervenient.emit({
|
2021-04-21 19:59:49 +01:00
|
|
|
taskParticipants: this.LtaskParticipants,
|
|
|
|
|
taskParticipantsCc: this.LtaskParticipantsCc
|
2021-04-12 10:01:43 +01:00
|
|
|
})
|
2021-04-21 14:27:55 +01:00
|
|
|
|
2021-04-12 10:01:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async selectContact(itm: EventPerson){
|
|
|
|
|
|
|
|
|
|
if(this.adding == "intervenient") {
|
|
|
|
|
|
|
|
|
|
itm.IsRequired = true;
|
2021-04-21 14:27:55 +01:00
|
|
|
this.LtaskParticipants.push(itm);
|
2021-04-12 10:01:43 +01:00
|
|
|
|
|
|
|
|
} else if (this.adding == "CC") {
|
|
|
|
|
|
|
|
|
|
itm.IsRequired = false;
|
2021-04-21 14:27:55 +01:00
|
|
|
this.LtaskParticipantsCc.push(itm);
|
2021-04-12 10:01:43 +01:00
|
|
|
} else {
|
|
|
|
|
// alert('bug')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// run only in gabinete digital
|
|
|
|
|
|
|
|
|
|
this.setContactWithClose();
|
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
|
|
|
|
2021-04-21 14:27:55 +01:00
|
|
|
const result1 = this.LtaskParticipants.find((contact, index)=>{
|
2021-04-08 13:53:49 +01:00
|
|
|
|
2021-03-29 13:12:35 +01:00
|
|
|
if(contact.Name == itm.Name && contact.EmailAddress == itm.EmailAddress){
|
2021-04-08 13:53:49 +01:00
|
|
|
index = index;
|
|
|
|
|
return contact;
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-04-05 15:10:28 +01:00
|
|
|
|
2021-04-08 13:53:49 +01:00
|
|
|
// if to show
|
|
|
|
|
if(undefined != result1){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-29 13:12:35 +01:00
|
|
|
|
2021-04-21 14:27:55 +01:00
|
|
|
const result2 = this.LtaskParticipantsCc.find((contact, index)=>{
|
2021-04-08 13:53:49 +01:00
|
|
|
|
|
|
|
|
if(contact.Name == itm.Name && contact.EmailAddress == itm.EmailAddress){
|
|
|
|
|
index = index;
|
|
|
|
|
return contact;
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-03-29 13:12:35 +01:00
|
|
|
|
2021-04-08 13:53:49 +01:00
|
|
|
// if to show
|
|
|
|
|
if(undefined != result2){
|
|
|
|
|
return false;
|
2021-04-05 15:10:28 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-08 13:53:49 +01:00
|
|
|
// don't show
|
|
|
|
|
return true;
|
|
|
|
|
|
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-21 14:27:55 +01:00
|
|
|
this.LtaskParticipants = this.LtaskParticipants.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") {
|
|
|
|
|
|
2021-04-21 14:27:55 +01:00
|
|
|
this.LtaskParticipantsCc = this.LtaskParticipantsCc.filter((contact, index) =>{
|
2021-04-05 15:10:28 +01:00
|
|
|
|
|
|
|
|
if(contact.Name != itm.Name && contact.EmailAddress != itm.EmailAddress){
|
|
|
|
|
return contact;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
2021-03-30 15:38:57 +01:00
|
|
|
this.setContactWithClose();
|
2021-03-29 13:12:35 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-30 15:38:57 +01:00
|
|
|
|
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
|
|
|
}
|