Files
doneit-web/src/app/services/events/attendees/attendees.page.ts
T

178 lines
5.0 KiB
TypeScript
Raw Normal View History

2021-09-24 08:56:43 +01:00
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';
2021-10-26 17:22:21 +01:00
import { ThemeService } from 'src/app/services/theme.service'
2023-08-11 16:14:25 +01:00
import { LoginUserRespose } from 'src/app/models/user.model';
import { SessionStore } from 'src/app/store/session.service';
2023-10-19 16:51:12 +01:00
import { Router } from '@angular/router';
2021-09-24 08:56:43 +01:00
@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;
2021-09-24 08:56:43 +01:00
taskParticipants:EventPerson[] = [];
taskParticipantsCc:EventPerson[] = [];
2023-08-11 16:14:25 +01:00
loggeduser: LoginUserRespose;
@Input() loggedAttendSon: boolean;
2024-01-06 20:37:49 +01:00
@Input() hideExternalDomain = true;
2023-10-19 16:51:12 +01:00
taskType: any;
2021-09-24 08:56:43 +01:00
constructor(
private modalCtrl: ModalController,
2021-09-24 08:56:43 +01:00
private contactsService: ContactsService,
private navParams: NavParams,
2021-10-26 17:22:21 +01:00
private modalController: ModalController,
2023-10-19 16:51:12 +01:00
public ThemeService: ThemeService,
private router: Router,) {
2021-09-24 08:56:43 +01:00
this.adding = this.navParams.get('adding');
this.taskParticipants = this.navParams.get('taskParticipants');
this.taskParticipantsCc = this.navParams.get('taskParticipantsCc');
2023-10-19 16:51:12 +01:00
this.taskType = this.navParams.get('taskType');
2023-08-11 16:14:25 +01:00
this.loggeduser = SessionStore.user;
2021-09-24 08:56:43 +01:00
}
ngOnInit() {
2023-10-19 16:51:12 +01:00
console.log('Pesquisa de contactos current path2',this.router.url)
2021-09-24 08:56:43 +01:00
this.fetchContacts("");
2021-09-24 08:56:43 +01:00
if(this.taskParticipants == null || this.taskParticipants == undefined){
this.taskParticipants = [];
}
if(this.taskParticipantsCc == null || this.taskParticipantsCc == undefined){
this.taskParticipantsCc = [];
}
2021-09-24 08:56:43 +01:00
}
2021-09-24 08:56:43 +01:00
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)=>{
2021-09-24 08:56:43 +01:00
if(contact.Name.toLocaleLowerCase() == itm.Name.toLocaleLowerCase() && contact.EmailAddress.toLocaleLowerCase() == itm.EmailAddress.toLocaleLowerCase()){
index = index;
return contact;
}
})
2021-09-24 08:56:43 +01:00
return undefined == result;
2021-09-24 08:56:43 +01:00
}
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;
2021-09-24 08:56:43 +01:00
});
} 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;
2021-09-24 08:56:43 +01:00
});
}
}
async selectContact(itm: EventPerson){
if(this.adding == "intervenient"){
itm.IsRequired = true;
this.taskParticipants.push(itm);
2021-09-24 08:56:43 +01:00
} else if (this.adding == "CC") {
itm.IsRequired = false;
this.taskParticipantsCc.push(itm);
}
}
async fetchContacts(filter: string) {
this.showLoader = true;
2024-01-06 20:37:49 +01:00
this.contactsService.getContacts(filter).subscribe(_result =>
2021-09-24 08:56:43 +01:00
{
2024-01-06 20:37:49 +01:00
let result
if(this.hideExternalDomain) {
result = _result.filter( e => e.UserType == 'GD')
} else {
result = _result
}
2021-09-24 08:56:43 +01:00
if (this.eventPersons != null)
{
this.eventPersons.forEach(attendee => {
const index: number = result.findIndex((cont) => {
return cont.EmailAddress.toLocaleLowerCase() == attendee.EmailAddress.toLocaleLowerCase()
});
2021-09-24 08:56:43 +01:00
result.splice(index, 1);
});
}
2023-08-11 16:14:25 +01:00
if(this.loggedAttendSon) {
this.contacts = result;
this.showLoader = false;
} else {
this.contacts = result;
// console.log('Attendes Email',this.loggeduser.Email)
2023-08-11 16:14:25 +01:00
let filterLoggedUserEmail = this.contacts.filter(item => item.EmailAddress.toLocaleLowerCase() != this.loggeduser.Email.toLocaleLowerCase())
// console.log('Attendes Email', filterLoggedUserEmail)
2023-08-11 16:14:25 +01:00
let filterEmptyEmail = filterLoggedUserEmail.filter(item => item.EmailAddress.toLocaleLowerCase() != "")
this.contacts = filterEmptyEmail;
// console.log('Attendes Email', this.contacts)
2021-09-24 08:56:43 +01:00
this.showLoader = false;
2023-08-11 16:14:25 +01:00
}
2021-09-24 08:56:43 +01:00
}
);
}
}