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-10-26 15:21:15 +01:00
|
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
2021-06-30 16:11:07 +01:00
|
|
|
|
2021-03-24 15:10:46 +01:00
|
|
|
@Component({
|
|
|
|
|
selector: 'app-attendee-modal',
|
|
|
|
|
templateUrl: './attendee-modal.page.html',
|
|
|
|
|
styleUrls: ['./attendee-modal.page.scss'],
|
|
|
|
|
})
|
2021-06-15 15:28:03 +01:00
|
|
|
export class AttendeePage implements OnInit {
|
2021-03-24 15:10:46 +01:00
|
|
|
|
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,
|
2021-10-26 15:21:15 +01:00
|
|
|
private contactsService: ContactsService,
|
|
|
|
|
public ThemeService: ThemeService ) {
|
2021-04-08 13:39:48 +01:00
|
|
|
|
2021-06-30 16:11:07 +01:00
|
|
|
this.LtaskParticipants = removeDuplicate(this.taskParticipants);
|
|
|
|
|
this.LtaskParticipantsCc = removeDuplicate(this.taskParticipantsCc);
|
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(){
|
2021-06-30 16:11:07 +01:00
|
|
|
this.LtaskParticipants = removeDuplicate(this.taskParticipants);
|
|
|
|
|
this.LtaskParticipantsCc = removeDuplicate(this.taskParticipantsCc);
|
2021-04-21 19:59:49 +01:00
|
|
|
}
|
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
|
|
|
|
2021-09-27 16:23:41 +01:00
|
|
|
save() {
|
2021-04-21 19:59:49 +01:00
|
|
|
|
2021-09-27 16:23:41 +01:00
|
|
|
this.setIntervenient.emit(removeDuplicate(this.LtaskParticipants));
|
|
|
|
|
this.setIntervenientCC.emit(removeDuplicate(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') {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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 {
|
2022-04-28 09:32:27 +01:00
|
|
|
//
|
2021-04-12 10:01:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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-06-15 15:45:34 +01:00
|
|
|
const result = this.LtaskParticipants.concat(this.LtaskParticipantsCc).find((contact, index)=>{
|
2021-04-08 13:53:49 +01:00
|
|
|
|
2021-07-14 10:18:35 +01:00
|
|
|
if(contact.Name.toLowerCase() == itm.Name.toLowerCase() && contact.EmailAddress.toLowerCase() == itm.EmailAddress.toLowerCase()){
|
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
|
2021-06-15 15:45:34 +01:00
|
|
|
if(undefined != result){
|
2021-04-08 13:53:49 +01:00
|
|
|
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
|
|
|
|
2021-07-14 10:18:35 +01:00
|
|
|
if(contact.Name.toLowerCase() == itm.Name && contact.EmailAddress.toLowerCase() == itm.EmailAddress.toLowerCase()){
|
2021-04-08 13:53:49 +01:00
|
|
|
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-07-14 10:18:35 +01:00
|
|
|
if(contact.Name.toLocaleLowerCase() != itm.Name.toLocaleLowerCase() && contact.EmailAddress.toLocaleLowerCase() != itm.EmailAddress.toLocaleLowerCase()){
|
2021-04-05 15:10:28 +01:00
|
|
|
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
|
|
|
|
2021-07-14 10:18:35 +01:00
|
|
|
if(contact.Name.toLocaleLowerCase() != itm.Name.toLocaleLowerCase() && contact.EmailAddress.toLocaleLowerCase() != itm.EmailAddress.toLocaleLowerCase()){
|
2021-04-05 15:10:28 +01:00
|
|
|
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) => {
|
2021-07-14 10:18:35 +01:00
|
|
|
return cont.EmailAddress.toLowerCase() == attendee.EmailAddress.toLowerCase()
|
2021-03-24 15:10:46 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
result.splice(index, 1);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.contacts = result;
|
|
|
|
|
this.showLoader = false;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-25 10:50:58 +01:00
|
|
|
}
|