mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
286 lines
7.6 KiB
TypeScript
286 lines
7.6 KiB
TypeScript
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
|
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'
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
|
import { ViewChild } from '@angular/core';
|
|
import { Searchbar } from 'ionic-angular';
|
|
import { LoginUserRespose } from 'src/app/models/user.model';
|
|
import { SessionStore } from 'src/app/store/session.service';
|
|
import { Router } from '@angular/router';
|
|
|
|
@Component({
|
|
selector: 'app-attendee-modal',
|
|
templateUrl: './attendee-modal.page.html',
|
|
styleUrls: ['./attendee-modal.page.scss'],
|
|
})
|
|
export class AttendeePage implements OnInit {
|
|
|
|
// Defined by the API
|
|
contacts: EventPerson[];
|
|
filterEmptyEmail: EventPerson[];
|
|
showLoader: boolean = false;
|
|
eventPersons: EventPerson[];
|
|
inputFilter = ''
|
|
|
|
|
|
@Output() closeComponent = new EventEmitter<any>();
|
|
|
|
@Output() setIntervenient = new EventEmitter<any>();
|
|
@Output() setIntervenientCC = new EventEmitter<any>();
|
|
@Output() dynamicSetIntervenient = new EventEmitter<any>();
|
|
|
|
|
|
@Input() hideExternalDomain = true;
|
|
|
|
|
|
@Input() taskParticipants: EventPerson[] = [];
|
|
@Input() taskParticipantsCc: EventPerson[] = [];
|
|
@Input() loggedAttendSon: boolean;
|
|
|
|
@Input() footer: boolean;
|
|
|
|
@Input() selectLogUser: boolean = true;
|
|
|
|
@ViewChild('Searchbar') searchbar: Searchbar;
|
|
@Input() taskType: any;
|
|
|
|
LtaskParticipants: EventPerson[] = [];
|
|
LtaskParticipantsCc: EventPerson[] = [];
|
|
loggeduser: LoginUserRespose;
|
|
listOfNotAllowdRoute = ['/home/gabinete-digital/despachos/', ]
|
|
|
|
constructor(
|
|
private modalCtrl: ModalController,
|
|
private contactsService: ContactsService,
|
|
public ThemeService: ThemeService,
|
|
private router: Router,) {
|
|
|
|
|
|
|
|
this.LtaskParticipants = removeDuplicate(this.taskParticipants);
|
|
this.LtaskParticipantsCc = removeDuplicate(this.taskParticipantsCc);
|
|
this.loggeduser = SessionStore.user;
|
|
|
|
}
|
|
|
|
ngOnChanges() {
|
|
this.LtaskParticipants = removeDuplicate(this.taskParticipants);
|
|
this.LtaskParticipantsCc = removeDuplicate(this.taskParticipantsCc);
|
|
console.log('PARTE PARTE', this.loggedAttendSon)
|
|
}
|
|
|
|
currentPath = window.location.pathname;
|
|
@Input() adding: "intervenient" | "CC";
|
|
|
|
ngOnInit() {
|
|
console.log('TASK TYPE',this.taskType);
|
|
console.log('Pesquisa de contactos current path3', this.router.url)
|
|
setTimeout(() => {
|
|
console.log('PARTE PARTE', this.loggedAttendSon)
|
|
});
|
|
|
|
this.fetchContacts("");
|
|
|
|
if (this.LtaskParticipants == null || this.LtaskParticipants == undefined) {
|
|
this.LtaskParticipants = [];
|
|
}
|
|
|
|
if (this.LtaskParticipantsCc == null || this.LtaskParticipantsCc == undefined) {
|
|
this.LtaskParticipantsCc = [];
|
|
}
|
|
|
|
}
|
|
|
|
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.");
|
|
}
|
|
}
|
|
|
|
|
|
save() {
|
|
|
|
this.setIntervenient.emit(removeDuplicate(this.LtaskParticipants));
|
|
this.setIntervenientCC.emit(removeDuplicate(this.LtaskParticipantsCc));
|
|
|
|
this.searchbar.value = null;
|
|
this.closeComponent.emit();
|
|
}
|
|
|
|
setContactWithClose() {
|
|
|
|
if (this.currentPath == '/home/gabinete-digital') {
|
|
this.setIntervenient.emit(this.LtaskParticipants);
|
|
this.setIntervenientCC.emit(this.LtaskParticipantsCc);
|
|
}
|
|
|
|
this.dynamicSetIntervenient.emit({
|
|
taskParticipants: this.LtaskParticipants,
|
|
taskParticipantsCc: this.LtaskParticipantsCc
|
|
})
|
|
|
|
}
|
|
|
|
async selectContact(itm: EventPerson) {
|
|
|
|
if (this.adding == "intervenient") {
|
|
|
|
itm.IsRequired = true;
|
|
this.LtaskParticipants.push(itm);
|
|
|
|
} else if (this.adding == "CC") {
|
|
|
|
itm.IsRequired = false;
|
|
this.LtaskParticipantsCc.push(itm);
|
|
} else {
|
|
//
|
|
}
|
|
|
|
// run only in gabinete digital
|
|
|
|
this.setContactWithClose();
|
|
}
|
|
|
|
close() {
|
|
this.closeComponent.emit();
|
|
}
|
|
|
|
onChange(evt: any) {
|
|
this.fetchContacts(evt.detail.value);
|
|
}
|
|
|
|
filterSearchList(itm: EventPerson): boolean {
|
|
|
|
const result = this.LtaskParticipants.concat(this.LtaskParticipantsCc).find((contact, index) => {
|
|
|
|
if (this.checkStringNull(contact.Name) == this.checkStringNull(itm.Name) && this.checkStringNull(contact.EmailAddress) == this.checkStringNull(itm.EmailAddress)) {
|
|
index = index;
|
|
return contact;
|
|
}
|
|
});
|
|
|
|
// if to show
|
|
if (undefined != result) {
|
|
return false;
|
|
}
|
|
|
|
|
|
const result2 = this.LtaskParticipantsCc.find((contact, index) => {
|
|
|
|
if (this.checkStringNull(contact.Name) == itm.Name && this.checkStringNull(contact.EmailAddress) == this.checkStringNull(itm.EmailAddress)) {
|
|
index = index;
|
|
return contact;
|
|
}
|
|
});
|
|
|
|
// if to show
|
|
if (undefined != result2) {
|
|
return false;
|
|
}
|
|
|
|
// don't show
|
|
return true;
|
|
|
|
}
|
|
|
|
remove(itm: EventPerson) {
|
|
|
|
if (this.adding == "intervenient") {
|
|
|
|
this.LtaskParticipants = this.LtaskParticipants.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.LtaskParticipantsCc = this.LtaskParticipantsCc.filter((contact, index) => {
|
|
|
|
if (contact.Name.toLocaleLowerCase() != itm.Name.toLocaleLowerCase() && contact.EmailAddress.toLocaleLowerCase() != itm.EmailAddress.toLocaleLowerCase()) {
|
|
return contact;
|
|
}
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
this.setContactWithClose();
|
|
|
|
}
|
|
|
|
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()
|
|
}
|
|
|
|
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 this.checkStringNull(cont.EmailAddress) == this.checkStringNull(attendee.EmailAddress)
|
|
});
|
|
|
|
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)
|
|
let filterLoggedUserEmail = this.contacts.filter(item => item.EmailAddress.toLocaleLowerCase() != this.loggeduser.Email.toLocaleLowerCase())
|
|
if(this.taskType == 0 || this.taskType == 1){
|
|
filterLoggedUserEmail = this.contacts.filter(item => item.IsPR == false)
|
|
}
|
|
// 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;
|
|
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
checkStringNull(value: string) {
|
|
if (value) {
|
|
return value.toLowerCase();
|
|
} else {
|
|
return value
|
|
}
|
|
}
|
|
|
|
}
|