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

157 lines
4.0 KiB
TypeScript
Raw Normal View History

2022-04-26 16:14:55 +01:00
import { Component, 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'
@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;
taskParticipants:EventPerson[] = [];
taskParticipantsCc:EventPerson[] = [];
2021-04-07 11:52:28 +01:00
constructor(
private modalCtrl: ModalController,
private contactsService: ContactsService,
private navParams: NavParams,
2021-10-26 15:21:15 +01:00
private modalController: ModalController,
public ThemeService: ThemeService) {
2021-06-15 14:05:14 +01:00
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');
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() {
2021-04-07 11:52:28 +01:00
this.fetchContacts("");
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-04-07 11:52:28 +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
})
return undefined == result;
2021-04-07 11:52:28 +01:00
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;
2020-08-26 10:18:47 +01:00
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;
});
}
}
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);
} 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;
this.contactsService.getContacts(filter).subscribe(result =>
2020-08-26 14:24:18 +01:00
{
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
});
result.splice(index, 1);
});
}
2023-01-24 15:56:47 +01:00
this.contacts = this.sort(result as any);
2021-04-07 11:52:28 +01:00
this.showLoader = false;
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()
}
2020-08-26 10:18:47 +01:00
}