Files
doneit-web/src/app/shared/event/attendee-modal/attendee-modal.page.ts
T

286 lines
7.6 KiB
TypeScript
Raw Normal View History

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';
import { removeDuplicate } from 'src/plugin/removeDuplicate.js'
2021-10-26 15:21:15 +01:00
import { ThemeService } from 'src/app/services/theme.service'
2023-01-24 15:56:47 +01:00
import { ViewChild } from '@angular/core';
import { Searchbar } from 'ionic-angular';
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-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[];
2023-08-11 16:14:25 +01:00
filterEmptyEmail: EventPerson[];
2021-03-24 15:10:46 +01:00
showLoader: boolean = false;
eventPersons: EventPerson[];
2022-12-17 15:18:47 +01:00
inputFilter = ''
2021-03-24 15:10:46 +01:00
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>();
2024-01-06 20:37:49 +01:00
@Input() hideExternalDomain = true;
2023-10-19 16:51:12 +01:00
@Input() taskParticipants: EventPerson[] = [];
@Input() taskParticipantsCc: EventPerson[] = [];
2023-08-11 16:14:25 +01:00
@Input() loggedAttendSon: boolean;
2021-03-29 13:12:35 +01:00
2021-05-28 16:39:03 +01:00
@Input() footer: boolean;
2023-08-10 16:46:55 +01:00
@Input() selectLogUser: boolean = true;
2023-01-24 15:56:47 +01:00
@ViewChild('Searchbar') searchbar: Searchbar;
2023-10-19 16:51:12 +01:00
@Input() taskType: any;
2023-01-24 15:56:47 +01:00
2021-04-21 14:27:55 +01:00
LtaskParticipants: EventPerson[] = [];
LtaskParticipantsCc: EventPerson[] = [];
2023-08-11 16:14:25 +01:00
loggeduser: LoginUserRespose;
2023-10-19 16:51:12 +01:00
listOfNotAllowdRoute = ['/home/gabinete-digital/despachos/', ]
2021-04-21 14:27:55 +01:00
2021-04-08 13:39:48 +01:00
constructor(
2023-10-19 16:51:12 +01:00
private modalCtrl: ModalController,
2021-10-26 15:21:15 +01:00
private contactsService: ContactsService,
2023-10-19 16:51:12 +01:00
public ThemeService: ThemeService,
private router: Router,) {
2021-04-08 13:39:48 +01:00
2023-08-11 16:14:25 +01:00
2023-10-19 16:51:12 +01:00
this.LtaskParticipants = removeDuplicate(this.taskParticipants);
this.LtaskParticipantsCc = removeDuplicate(this.taskParticipantsCc);
this.loggeduser = SessionStore.user;
2022-12-17 15:18:47 +01:00
}
2021-04-05 15:10:28 +01:00
2022-12-17 15:18:47 +01:00
ngOnChanges() {
2023-10-19 16:51:12 +01:00
this.LtaskParticipants = removeDuplicate(this.taskParticipants);
2021-06-30 16:11:07 +01:00
this.LtaskParticipantsCc = removeDuplicate(this.taskParticipantsCc);
2023-10-19 16:51:12 +01:00
console.log('PARTE PARTE', this.loggedAttendSon)
2021-04-21 19:59:49 +01:00
}
2023-10-19 16:51:12 +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() {
2023-10-19 16:51:12 +01:00
console.log('TASK TYPE',this.taskType);
console.log('Pesquisa de contactos current path3', this.router.url)
2023-08-11 16:14:25 +01:00
setTimeout(() => {
2023-10-19 16:51:12 +01:00
console.log('PARTE PARTE', this.loggedAttendSon)
});
2021-03-24 15:10:46 +01:00
this.fetchContacts("");
2023-10-19 16:51:12 +01:00
if (this.LtaskParticipants == null || this.LtaskParticipants == undefined) {
2021-04-21 14:27:55 +01:00
this.LtaskParticipants = [];
2021-04-06 11:28:46 +01:00
}
2023-10-19 16:51:12 +01:00
if (this.LtaskParticipantsCc == null || this.LtaskParticipantsCc == undefined) {
2021-04-21 14:27:55 +01:00
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
}
2023-10-19 16:51:12 +01:00
removeIdfromRoute(route: string) {
let lastIndex: number = route.lastIndexOf('/');
if (lastIndex !== -1) {
let modifiedString: string = route.slice(0, lastIndex + 1);
console.log(modifiedString);
} else {
console.log("No '/' found in the string.");
}
}
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
2023-01-24 15:56:47 +01:00
this.searchbar.value = null;
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() {
2023-10-19 16:51:12 +01:00
if (this.currentPath == '/home/gabinete-digital') {
2021-04-21 14:27:55 +01:00
this.setIntervenient.emit(this.LtaskParticipants);
this.setIntervenientCC.emit(this.LtaskParticipantsCc);
2023-10-19 16:51:12 +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
}
2023-01-24 15:56:47 +01:00
async selectContact(itm: EventPerson) {
2021-04-12 10:01:43 +01:00
2023-10-19 16:51:12 +01:00
if (this.adding == "intervenient") {
2021-04-12 10:01:43 +01:00
itm.IsRequired = true;
2021-04-21 14:27:55 +01:00
this.LtaskParticipants.push(itm);
2023-10-19 16:51:12 +01:00
2021-04-12 10:01:43 +01:00
} else if (this.adding == "CC") {
2023-10-19 16:51:12 +01:00
2021-04-12 10:01:43 +01:00
itm.IsRequired = false;
2021-04-21 14:27:55 +01:00
this.LtaskParticipantsCc.push(itm);
2021-04-12 10:01:43 +01:00
} else {
//
2021-04-12 10:01:43 +01:00
}
2023-10-19 16:51:12 +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
}
2022-12-17 15:18:47 +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
2023-10-19 16:51:12 +01:00
const result = this.LtaskParticipants.concat(this.LtaskParticipantsCc).find((contact, index) => {
2023-10-19 16:51:12 +01:00
if (this.checkStringNull(contact.Name) == this.checkStringNull(itm.Name) && this.checkStringNull(contact.EmailAddress) == this.checkStringNull(itm.EmailAddress)) {
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
2023-10-19 16:51:12 +01:00
if (undefined != result) {
2021-04-08 13:53:49 +01:00
return false;
}
2021-03-29 13:12:35 +01:00
2023-10-19 16:51:12 +01:00
const result2 = this.LtaskParticipantsCc.find((contact, index) => {
if (this.checkStringNull(contact.Name) == itm.Name && this.checkStringNull(contact.EmailAddress) == this.checkStringNull(itm.EmailAddress)) {
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
2023-10-19 16:51:12 +01:00
if (undefined != result2) {
2021-04-08 13:53:49 +01:00
return false;
2021-04-05 15:10:28 +01:00
}
2023-10-19 16:51:12 +01:00
2021-04-08 13:53:49 +01:00
// don't show
return true;
2023-10-19 16:51:12 +01:00
2021-03-29 13:12:35 +01:00
}
2022-12-17 15:18:47 +01:00
remove(itm: EventPerson) {
2021-03-29 13:12:35 +01:00
2023-10-19 16:51:12 +01:00
if (this.adding == "intervenient") {
2021-03-29 13:12:35 +01:00
2023-10-19 16:51:12 +01:00
this.LtaskParticipants = this.LtaskParticipants.filter((contact, index) => {
2021-03-29 13:12:35 +01:00
2023-10-19 16:51:12 +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;
2023-10-19 16:51:12 +01:00
2021-04-05 15:10:28 +01:00
});
} else if (this.adding == "CC") {
2023-10-19 16:51:12 +01:00
this.LtaskParticipantsCc = this.LtaskParticipantsCc.filter((contact, index) => {
2021-04-05 15:10:28 +01:00
2023-10-19 16:51:12 +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;
2023-10-19 16:51:12 +01:00
2021-04-05 15:10:28 +01:00
});
}
2021-03-30 15:38:57 +01:00
this.setContactWithClose();
2023-10-19 16:51:12 +01:00
2021-03-29 13:12:35 +01:00
}
2022-12-17 15:18:47 +01:00
sort(data: []) {
return data.sort(function (a: any, b: any) {
if (a.Name > b.Name) {
2023-10-19 16:51:12 +01:00
return -1;
2022-12-17 15:18:47 +01:00
}
if (b.Name > a.Name) {
2023-10-19 16:51:12 +01:00
return 1;
2022-12-17 15:18:47 +01:00
}
return 0;
2023-10-19 16:51:12 +01:00
}).reverse()
2022-12-17 15:18:47 +01:00
}
2021-03-24 15:10:46 +01:00
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
}
2023-10-19 16:51:12 +01:00
if (this.eventPersons != null) {
this.eventPersons.forEach(attendee => {
const index: number = result.findIndex((cont) => {
return this.checkStringNull(cont.EmailAddress) == this.checkStringNull(attendee.EmailAddress)
2021-03-24 15:10:46 +01:00
});
2023-10-19 16:51:12 +01:00
result.splice(index, 1);
});
}
if (this.loggedAttendSon) {
this.contacts = this.sort(result as any);
this.showLoader = false;
} else {
this.contacts = this.sort(result as any);
// 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() != "")
this.contacts = filterEmptyEmail;
// console.log('Attendes Email', this.contacts)
2021-03-24 15:10:46 +01:00
this.showLoader = false;
2023-08-11 16:14:25 +01:00
2021-03-24 15:10:46 +01:00
}
2023-10-19 16:51:12 +01:00
}
2021-03-24 15:10:46 +01:00
);
}
checkStringNull(value: string) {
2023-10-19 16:51:12 +01:00
if (value) {
return value.toLowerCase();
} else {
return value
}
}
}