//Importing the libraries import { Component, OnInit, Input } from '@angular/core'; import { DialogService } from 'primeng/api'; import { debug } from 'util'; //Importing the components import { ContactCreateEmailComponent } from '../popups/contact-create-email/contact-create-email.component'; import { ContactCreateProjectComponent } from '../popups/contact-create-project/contact-create-project.component'; //Importing the core classes import { Default } from '../../shared/core/Default.enum'; import { IAssociateRecords } from '../../shared/core/IAssociateRecords '; import { IEmailDetails } from '../../shared/core/IEmailDetails'; import { IEmailAddress } from '../../shared/core/IEmailAddress'; //Importing the service classes import { EmailsService } from '../../shared/service/emails.service'; import { CookieService } from 'ngx-cookie-service'; import { Compiler } from '@angular/core'; import { CompanyService } from '../../shared/service/company.service'; declare var $; @Component({ selector: 'app-contact-email', templateUrl: './contact-email.component.html', styleUrls: ['./contact-email.component.scss'], providers: [DialogService, CompanyService] }) export class ContactEmailComponent implements OnInit { @Input('showShortcut') showShortcut: number; @Input('companyContactId') companyContactId: number; @Input('contactIdParam') contactIdParam: number; @Input('companyId') companyId: number; // Filter Email filter: number; subject: string; // Contact Id this should be contactId: number; // Associate Records IAssociateRecords: IAssociateRecords[]; //Login staff Id loginStaffId: number; // Email Records IEmailDetails: IEmailDetails[]; IEmailThreadDetails: IEmailDetails[] = []; //Snapzing variable showLoading: boolean = false; defualtUserEMail: string; defualtUserName: string; constructor(public dialogService: DialogService, private emailsService: EmailsService, private companyService: CompanyService, private cookieService: CookieService,private _compiler: Compiler) { } ngOnChanges() { this.filter = Default.Email; // Staff Id this.loginStaffId = +this.cookieService.get('LoggedUserId'); this.companyService.GetContactDetailsById(this.contactIdParam).subscribe(details => { //Getting the selected email this.companyService.GetCompanyContactsDetailsById(this.companyId).subscribe( email => { if (email.length > 0) { this.defualtUserEMail = email[0]['Email']; this.defualtUserName = details[0].FirstName + " " + details[0].LastName; } } ); }) } ngOnInit() { this._compiler.clearCache(); // All email this.GetAllEmailsByContactId(); } // show the create email popup showCreateEmail() { const ref = this.dialogService.open(ContactCreateEmailComponent, { header: 'Create new email', width: '70%', contentStyle: {"height":"auto","background":"#fff"}, data: { companyContactId: this.companyContactId, defualtUserEMail: this.defualtUserEMail, defualtUserName: this.defualtUserName } }); ref.onClose.subscribe(() => { this.GetAllEmailsByContactId(); }); } //show the create project popup showCreateProject() { const ref = this.dialogService.open(ContactCreateProjectComponent, { header: 'Create new project', width: '50%' }); } //On click function of the reply replyToEmail(iEmailDetails: IEmailDetails) { //debugger; const ref = this.dialogService.open(ContactCreateEmailComponent, { header: 'Create new email', width: '70%', data: { companyContactId: this.companyContactId, replyEmailId: iEmailDetails.EmailId } }); } // Get Notes Associated Record GetEmailAssociateRecords(emailId) { // console.log(noteId); // Get All notes // debugger; this.emailsService.GetEmailAssociateRecords(emailId).subscribe( result => { if (result != null) { // console.log(result); this.IAssociateRecords = result; //console.log('Email Associate Records'); //console.log(this.IAssociateRecords); } else { //console.log(" Error: GetEmailAssociateRecords "); } } ); } // Email Pin ChangeOrderOfEmails(emailId: any) { this.showLoading = true; // Get All Email this.emailsService.ChangeOrderOfEmails(emailId, this.loginStaffId).subscribe( result => { if (result != null) { // Assing IEmail //this.IEmailDetails = result; this.GetAllEmailsByContactId(); //console.log(' Email Pin Records '); //console.log(this.IEmailDetails); } else { //console.log(" Error: ChangeOrderOfEmails "); } } ); } // Get all emails by contactId GetAllEmailsByContactId() { this.contactId = this.contactIdParam; // Get All notes this.emailsService.GetAllEmailsByContactId(this.contactId).subscribe( result => { if (result != null) { // console.log(result); this.IEmailDetails = result; this.showLoading = false; //console.log(' Get All Emails : ' + this.IEmailDetails); //console.log(this.IEmailDetails); } else { //console.log(" Error: GetAllEmailsByContactId "); } } ); } // Get View Email Threads GetViewEmailThread(ReplyId: any, selectedIEmailDetails: IEmailDetails) { //console.log(' Repley Id '); //console.log(ReplyId); // Get All notes this.emailsService.GetViewEmailThread(ReplyId).subscribe( result => { this.IEmailThreadDetails = []; if (result != null) { // console.log(result); this.IEmailThreadDetails = result; //console.log(' Get All thread Emails : ' + this.IEmailThreadDetails); //console.log(this.IEmailThreadDetails); //Make the thread expandable for (let i = 0; i < this.IEmailDetails.length; i++) { if(this.IEmailDetails[i].EmailId == selectedIEmailDetails.EmailId){ this.IEmailDetails[i].Selected = !this.IEmailDetails[i].Selected; }else{ this.IEmailDetails[i].Selected = false; } } } else { //console.log(" Error: GetAllEmailsByContactId "); } } ); } onChangeEmailDataSet(dataset: IEmailDetails[]) { this.IEmailDetails = dataset; } }