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

196 lines
5.4 KiB
TypeScript
Raw Normal View History

2023-08-11 16:14:25 +01:00
import { Component, Input, OnInit } from '@angular/core';
import { EventPerson } from 'src/app/models/eventperson.model';
2021-04-07 11:52:28 +01:00
import { ModalController, NavParams } from '@ionic/angular';
import { ContactsService } from 'src/app/services/contacts.service';
2021-10-26 15:21:15 +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';
@Component({
selector: 'app-attendees',
templateUrl: './attendees.page.html',
styleUrls: ['./attendees.page.scss'],
})
2021-06-15 15:28:03 +01:00
export class AttendeesPageModal implements OnInit {
2021-04-07 11:52:28 +01:00
// Defined by the API
contacts: EventPerson[];
showLoader: boolean = false;
selectedContact: EventPerson[] =[];
eventPersons: EventPerson[];
adding: "intervenient" | "CC";
currentPath = window.location.pathname;
2021-04-07 11:52:28 +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
hideExternalDomain = true;
2023-10-19 16:51:12 +01:00
taskType: any;
2021-04-07 11:52:28 +01:00
constructor(
private modalCtrl: ModalController,
2021-04-07 11:52:28 +01:00
private contactsService: ContactsService,
private navParams: NavParams,
2021-10-26 15:21:15 +01:00
private modalController: ModalController,
2023-10-19 16:51:12 +01:00
public ThemeService: ThemeService,
private router: Router,) {
2021-04-07 11:52:28 +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');
2024-01-06 20:37:49 +01:00
this.hideExternalDomain = this.navParams.get('hideExternalDomain');
2023-08-11 16:14:25 +01:00
this.loggeduser = SessionStore.user;
2021-06-15 14:05:14 +01:00
2021-04-07 11:52:28 +01:00
}
2020-08-26 09:42:16 +01:00
ngOnInit() {
2023-10-19 16:51:12 +01:00
console.log('Pesquisa de contactos current path1',this.router.url)
2021-04-07 11:52:28 +01:00
this.fetchContacts("");
2021-04-07 11:52:28 +01:00
if(this.taskParticipants == null || this.taskParticipants == undefined){
this.taskParticipants = [];
}
if(this.taskParticipantsCc == null || this.taskParticipantsCc == undefined){
this.taskParticipantsCc = [];
}
2020-08-26 14:24:18 +01:00
}
2021-06-15 14:05:14 +01:00
ngOnChanges(event) {}
2020-08-26 14:24:18 +01:00
save(){
2021-04-07 11:52:28 +01:00
this.modalController.dismiss({
'taskParticipants': this.taskParticipants,
'taskParticipantsCc': this.taskParticipantsCc
});
2020-08-26 14:24:18 +01:00
}
2021-06-15 14:05:14 +01:00
close() {
2021-04-07 11:52:28 +01:00
this.modalController.dismiss(false);
2020-08-26 09:42:16 +01:00
}
2020-08-26 16:07:29 +01:00
2021-04-07 11:52:28 +01:00
onChange(evt: any) {
this.fetchContacts(evt.detail.value);
}
filterSearchList(itm: EventPerson): boolean {
2021-06-15 15:45:34 +01:00
const result = this.taskParticipants.concat( this.taskParticipantsCc).find((contact, index)=>{
2021-07-14 10:18:35 +01:00
if(contact.Name.toLocaleLowerCase() == itm.Name.toLocaleLowerCase() && contact.EmailAddress.toLocaleLowerCase() == itm.EmailAddress.toLocaleLowerCase()){
2021-06-15 15:45:34 +01:00
index = index;
return contact;
}
2021-04-07 11:52:28 +01:00
2021-06-15 15:45:34 +01:00
})
2021-06-15 15:45:34 +01:00
return undefined == result;
2020-08-26 16:07:29 +01:00
}
2021-04-07 11:52:28 +01:00
2023-01-24 15:56:47 +01:00
remove(itm: EventPerson) {
2021-04-07 11:52:28 +01:00
2023-01-24 15:56:47 +01:00
if(this.adding == "intervenient") {
2021-04-07 11:52:28 +01:00
this.taskParticipants = this.taskParticipants.filter((contact, index) =>{
2021-07-14 10:18:35 +01:00
if(contact.Name.toLocaleLowerCase() != itm.Name.toLocaleLowerCase() && contact.EmailAddress.toLocaleLowerCase() != itm.EmailAddress.toLocaleLowerCase()){
2021-04-07 11:52:28 +01:00
return contact;
}
return false;
2021-04-07 11:52:28 +01:00
});
} else if (this.adding == "CC") {
this.taskParticipantsCc = this.taskParticipantsCc.filter((contact, index) =>{
2021-07-14 10:18:35 +01:00
if(contact.Name.toLocaleLowerCase() != itm.Name.toLocaleLowerCase() && contact.EmailAddress.toLocaleLowerCase() != itm.EmailAddress.toLocaleLowerCase()){
2021-04-07 11:52:28 +01:00
return contact;
}
return false;
2021-04-07 11:52:28 +01:00
});
}
}
2020-08-26 14:24:18 +01:00
2021-04-07 11:52:28 +01:00
async selectContact(itm: EventPerson){
if(this.adding == "intervenient"){
2021-06-15 13:42:47 +01:00
itm.IsRequired = true;
2021-04-07 11:52:28 +01:00
this.taskParticipants.push(itm);
2021-04-07 11:52:28 +01:00
} else if (this.adding == "CC") {
2021-06-15 13:42:47 +01:00
itm.IsRequired = false;
2021-04-07 11:52:28 +01:00
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 => {
let result
if(this.hideExternalDomain) {
result = _result.filter( e => e.UserType == 'GD')
} else {
result = _result
}
2021-04-07 11:52:28 +01:00
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.toLocaleLowerCase() == attendee.EmailAddress.toLocaleLowerCase()
2021-04-07 11:52:28 +01:00
});
2021-04-07 11:52:28 +01:00
result.splice(index, 1);
2023-08-11 16:14:25 +01:00
2021-04-07 11:52:28 +01:00
});
}
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())
2023-10-19 16:51:12 +01:00
if(this.taskType == 0 || this.taskType == 1){
filterLoggedUserEmail = this.contacts.filter(item => item.IsPR == false)
}
// console.log('Attendes Email', filterLoggedUserEmail)
2023-08-11 16:14:25 +01:00
let filterEmptyEmail = filterLoggedUserEmail.filter(item => item.EmailAddress.toLocaleLowerCase() != "")
2023-08-11 16:14:25 +01:00
this.contacts = filterEmptyEmail;
//console.log('Attendes Email', this.contacts)
2021-04-07 11:52:28 +01:00
this.showLoader = false;
2023-08-11 16:14:25 +01:00
}
2020-08-26 14:24:18 +01:00
}
2021-04-07 11:52:28 +01:00
);
2020-08-25 15:01:29 +01:00
}
2020-08-26 10:18:47 +01:00
2023-01-24 15:56:47 +01:00
sort(data: []) {
return data.sort(function (a: any, b: any) {
if (a.Name > b.Name) {
return -1;
}
if (b.Name > a.Name) {
return 1;
}
return 0;
}).reverse()
}
}