Files
doneit-web/src/app/services/events/attendees/attendees.page.ts
T
2024-01-06 20:37:49 +01:00

178 lines
5.0 KiB
TypeScript

import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { EventPerson } from 'src/app/models/eventperson.model';
import { ModalController, NavParams } from '@ionic/angular';
import { ContactsService } from 'src/app/services/contacts.service';
import { ThemeService } from 'src/app/services/theme.service'
import { LoginUserRespose } from 'src/app/models/user.model';
import { SessionStore } from 'src/app/store/session.service';
import { Router } from '@angular/router';
@Component({
selector: 'app-attendees',
templateUrl: './attendees.page.html',
styleUrls: ['./attendees.page.scss'],
})
export class AttendeesPageModal implements OnInit {
// Defined by the API
contacts: EventPerson[];
showLoader: boolean = false;
selectedContact: EventPerson[] =[];
eventPersons: EventPerson[];
adding: "intervenient" | "CC";
currentPath = window.location.pathname;
taskParticipants:EventPerson[] = [];
taskParticipantsCc:EventPerson[] = [];
loggeduser: LoginUserRespose;
@Input() loggedAttendSon: boolean;
@Input() hideExternalDomain = true;
taskType: any;
constructor(
private modalCtrl: ModalController,
private contactsService: ContactsService,
private navParams: NavParams,
private modalController: ModalController,
public ThemeService: ThemeService,
private router: Router,) {
this.adding = this.navParams.get('adding');
this.taskParticipants = this.navParams.get('taskParticipants');
this.taskParticipantsCc = this.navParams.get('taskParticipantsCc');
this.taskType = this.navParams.get('taskType');
this.loggeduser = SessionStore.user;
}
ngOnInit() {
console.log('Pesquisa de contactos current path2',this.router.url)
this.fetchContacts("");
if(this.taskParticipants == null || this.taskParticipants == undefined){
this.taskParticipants = [];
}
if(this.taskParticipantsCc == null || this.taskParticipantsCc == undefined){
this.taskParticipantsCc = [];
}
}
ngOnChanges(event) {}
save(){
this.modalController.dismiss({
'taskParticipants': this.taskParticipants,
'taskParticipantsCc': this.taskParticipantsCc
});
}
close() {
this.modalController.dismiss(false);
}
onChange(evt: any) {
this.fetchContacts(evt.detail.value);
}
filterSearchList(itm: EventPerson): boolean {
const result = this.taskParticipants.concat( this.taskParticipantsCc).find((contact, index)=>{
if(contact.Name.toLocaleLowerCase() == itm.Name.toLocaleLowerCase() && contact.EmailAddress.toLocaleLowerCase() == itm.EmailAddress.toLocaleLowerCase()){
index = index;
return contact;
}
})
return undefined == result;
}
remove(itm: EventPerson){
if(this.adding == "intervenient"){
this.taskParticipants = this.taskParticipants.filter((contact, index) =>{
if(contact.Name.toLocaleLowerCase() != itm.Name.toLocaleLowerCase() && contact.EmailAddress.toLocaleLowerCase() != itm.EmailAddress.toLocaleLowerCase()){
return contact;
}
return false;
});
} else if (this.adding == "CC") {
this.taskParticipantsCc = this.taskParticipantsCc.filter((contact, index) =>{
if(contact.Name.toLocaleLowerCase() != itm.Name.toLocaleLowerCase() && contact.EmailAddress.toLocaleLowerCase() != itm.EmailAddress.toLocaleLowerCase()){
return contact;
}
return false;
});
}
}
async selectContact(itm: EventPerson){
if(this.adding == "intervenient"){
itm.IsRequired = true;
this.taskParticipants.push(itm);
} else if (this.adding == "CC") {
itm.IsRequired = false;
this.taskParticipantsCc.push(itm);
}
}
async fetchContacts(filter: string) {
this.showLoader = true;
this.contactsService.getContacts(filter).subscribe(_result =>
{
let result
if(this.hideExternalDomain) {
result = _result.filter( e => e.UserType == 'GD')
} else {
result = _result
}
if (this.eventPersons != null)
{
this.eventPersons.forEach(attendee => {
const index: number = result.findIndex((cont) => {
return cont.EmailAddress.toLocaleLowerCase() == attendee.EmailAddress.toLocaleLowerCase()
});
result.splice(index, 1);
});
}
if(this.loggedAttendSon) {
this.contacts = result;
this.showLoader = false;
} else {
this.contacts = result;
// console.log('Attendes Email',this.loggeduser.Email)
let filterLoggedUserEmail = this.contacts.filter(item => item.EmailAddress.toLocaleLowerCase() != this.loggeduser.Email.toLocaleLowerCase())
// console.log('Attendes Email', filterLoggedUserEmail)
let filterEmptyEmail = filterLoggedUserEmail.filter(item => item.EmailAddress.toLocaleLowerCase() != "")
this.contacts = filterEmptyEmail;
// console.log('Attendes Email', this.contacts)
this.showLoader = false;
}
}
);
}
}