//Importing the libraries import { Component, OnInit } from '@angular/core'; import { DialogService, MenuItem, SelectItem } from 'primeng/api'; import { ActivatedRoute } from '@angular/router'; import { ENTER_SELECTOR } from '@angular/animations/browser/src/util'; import { trigger, state, style, transition, animate } from '@angular/animations'; import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop'; import { CookieService } from 'ngx-cookie-service'; import { DomSanitizer, SafeResourceUrl, SafeUrl } from '@angular/platform-browser'; //Importing the core classes import { ICompanyDetails } from '../../shared/core/ICompanyDetails'; import { IContactDetails } from '../../shared/core/IContactDetails'; import { ICompanyContacts } from '../../shared/core/ICompanyContacts'; import { IOptions } from '../../shared/core/IOptions'; import { ContactHistory } from '../../shared/core/contactHistory'; //Importing the components import { ContactAvatarUploadComponent } from '../popups/contact-avatar-upload/contact-avatar-upload.component'; import { ContactPotisionComponent } from '../popups/contact-potision/contact-potision.component'; //Importing the service classes import { CompanyService } from '../../shared/service/company.service'; import { DashboardService } from '../../shared/service/dashboard.service'; import { ContactService } from '../../shared/service/contact.service'; @Component({ selector: 'app-contact', templateUrl: './contact.component.html', styleUrls: ['./contact.component.scss'], providers: [DialogService, ContactService], animations: [ trigger('slideInOut', [ state('in', style({ transform: 'translate3d(0, 0, 0)' })), state('out', style({ transform: 'translate3d(104%, 0, 0)' })), transition('in => out', animate('400ms ease-in-out')), transition('out => in', animate('400ms ease-in-out')) ]), ] }) export class ContactComponent implements OnInit { items: MenuItem[]; selectedMenuitem:MenuItem; public showSideMenu: boolean = true; selectedMenu: number; //History list historyList: ContactHistory[] = []; // Need to pass contact Id form Start management contactId: number; // company iCompanyDetails: ICompanyDetails[]; companyId: number; // contacts iContactDetails: any[]; // Company contacts iCompanyContacts: ICompanyContacts[]; // Number of company companyCount: number; // Contact Defalt Value companyContactId: number firstName: string; lastName: string; email: string; phone: string; contactOwner: string; address: string; contactStatus_selected: number = null leadStatus_Selected: boolean = null last_contacted: string; last_activity: string; newSelectedLastContactedDate: Date; newSelectedLastActivityDate: Date; /** For Contact status dropdown */ contactStatus: SelectItem[] /** For Lead status dropdown */ leadStatus: SelectItem[] // show companay contact details showCompanyContact: boolean; // Company model company: ICompanyDetails; /** For contact positions */ contactPositions: any[] /** To customize company details of a contact*/ companyContactDetails: ICompanyContacts; /** To customize contact details */ contactDetails: IContactDetails; // Show notes showCreateNotes: boolean; // Show Tasks showCreateTasks: boolean; // Show emails showCreateEmails: boolean; //Image url imageUrl: any; showShortcut: boolean = false; //Variables for company detail slide in companyDetailPageState: string = 'out'; createNotePageState: string = 'out'; createTaskPageState: string = 'out'; tables: string[] /** For drag and drop */ comDetails: any[] = [] comContactDetails: any[] /** For contact options */ contactOptions: IOptions //Active tab item variable activeTabItem: string; // set default company defaultCompanyContactId: number; defaultCompanyId: number; //Variable to display the new company input newCompanyInputState: boolean = false; //Variable to hole the new company name newCompanyName: string; // company history iCompanyDetailsHistory: ICompanyDetails[]; // Company history contacts iCompanyContactsHistory: ICompanyContacts[]; //Variables to display the firstname histories displayFirstNameHistory: boolean = false; displayLastNameHistory: boolean = false; displayEmailHistory: boolean = false; displayPhoneHistory: boolean = false; displayAddressHistory: boolean = false; displayExpertential: boolean = false; showAutomation: boolean = false; autoNewNote:boolean constructor( public dialogService: DialogService, private companyService: CompanyService, private dashboardService: DashboardService, private route: ActivatedRoute, private cookieService: CookieService, private contactService: ContactService, private _sanitizer: DomSanitizer ) { } //Closing the toggle menu closeToggelMenu() { this.companyDetailPageState = 'out'; } ngOnChange() { // console.log("Tab item changed"); //console.log(this.activeTabItem); } /** ngOnInit() starts*/ ngOnInit() { this.showCreateNotes = false; this.showCreateTasks = false; this.showCreateEmails = false; /** get parameter contactId */ this.route.paramMap.subscribe(params => { this.contactId = +params.get("contactId") }) this.firstName = ""; this.lastName = ""; this.showCompanyContact = true; // Need to pass contact Id form Start management // Need to remove // When you are remove pls delete comment line from ReadmeFutureDelete // Get All contact details by Id this.companyService.GetContactDetailsById(this.contactId).subscribe( result => { if (result != null) { this.iContactDetails = result; this.imageUrl = this.iContactDetails[0]['Avatar']; this.companyCount = result.length; this.firstName = this.iContactDetails[0].FirstName; this.lastName = this.iContactDetails[0].LastName; // console.log("this.iContactDetails"); // console.log(this.iContactDetails); // default company id this.companyId = this.iContactDetails[0].CompanyDetailsList[0].CompanyId; this.DisplayCompanyContactData(this.companyId); } else { //console.log("Error: GetContactDetailsById "); } } ); // Get All contact details by Id this.companyService.GetContactDetailsByContactId(this.contactId).subscribe( result => { if (result != null) { this.comContactDetails = result; //console.log("--------------"); //console.log(this.comContactDetails); let cDtailsFirst = [] let cDtailsSecond = [] //filter deafault company to another array this.comContactDetails.forEach(element => { if (element.IsDefaultCompany == 1) { cDtailsFirst.push({ CompanyContactsId: element.CompanyContactsId, comName: element.CompanyDetails.CompanyName, comId: element.CompanyDetails.CompanyId, IsDefaultCompany: element.IsDefaultCompany }) } else { cDtailsSecond.push({ CompanyContactsId: element.CompanyContactsId, comName: element.CompanyDetails.CompanyName, comId: element.CompanyDetails.CompanyId, IsDefaultCompany: element.IsDefaultCompany }) } }); //To combine two arrays, and default company to first cDtailsFirst.forEach(element => { this.comDetails.push({ CompanyContactsId: element.CompanyContactsId, comName: element.comName, comId: element.comId, IsDefaultCompany: element.IsDefaultCompany }); }); cDtailsSecond.forEach(element => { this.comDetails.push({ CompanyContactsId: element.CompanyContactsId, comName: element.comName, comId: element.comId, IsDefaultCompany: element.IsDefaultCompany }); }); } else { //console.log("Error: GetContactDetailsById "); } } ); /** Get CompanyContacts By Contact Id */ this.contactOptions = { Params: [ { 'key': 'id', 'value': +this.cookieService.get('LoggedUserId') }, { 'key': 'contactopt', 'value': null }, { 'key': 'contactid', 'value': 1 } ], FilterValue: [{ 'key': '', 'value': null }], SearchValue: "", RecordCount: 10, CurrentPage: 0 } this.dashboardService.getContactList(this.contactOptions, +this.cookieService.get('CompanyId')).subscribe( (data: any[]) => { this.comContactDetails = data; //console.log("@@@@@@@@@@@@@@@"); //console.log(this.comContactDetails); }); this.contactStatus = [ { label: 'Contact Status', value: null }, { label: 'Lead', value: 1 }, { label: 'Customer', value: 2 }, { label: 'Affiliate', value: 3 }, { label: 'Partner', value: 4 }, ] this.leadStatus = [ { label: 'Lead Status', value: null }, { label: 'True', value: true }, { label: 'False', value: false } ] // show page tab list this.items = [ { label: 'History', command: (event) => { this.onTabChange("HISTORY"); } }, { label: 'Email', command: (event) => { this.onTabChange("EMAIL"); } }, { label: 'Notes', command: (event) => { this.onTabChange("NOTES"); } }, { label: 'Tasks', command: (event) => { this.onTabChange("TASKS"); } }, { label: 'expertential', command: (event) => { this.onTabChange("EXPERTENTIAL"); } }, { label: 'Deals', command: (event) => { this.onTabChange("DEALS"); } }, { label: 'Collection', command: (event) => { this.onTabChange("COLLECTION"); } }, { label: 'Projects', command: (event) => { this.onTabChange("PROJECTS"); } }, { label: 'Orders', command: (event) => { this.onTabChange("ORDERS"); } }, { label: 'Services', command: (event) => { this.onTabChange("SERVICES"); } }, { label: 'Marketing', command: (event) => { this.onTabChange("MARKETING"); } }, { label: 'Automation', command: (event) => { this.onTabChange("AUTOMATION"); } } ]; this.selectedMenuitem = this.items[0]; /** for test drag and drop */ this.tables = ['table1', 'table2', 'table3']; } /** Ends - ngOnInit() */ onTabChange(tabName: string) { this.showAutomation = false; switch (tabName) { case "TASKS": this.showCreateTasks = false; this.showCreateNotes = true; this.showCreateEmails = true; this.displayExpertential = true; //Enabaling the short cut button this.showShortcut = true; break; case "NOTES": this.showCreateNotes = false; this.showCreateTasks = true; this.showCreateEmails = true; this.displayExpertential = true; //Enabaling the short cut button this.showShortcut = true; break; case "HISTORY": this.showCreateTasks = false; this.showCreateNotes = false; this.showCreateEmails = false; this.displayExpertential = true; //Enabaling the short cut button this.showShortcut = false; break; case "EMAIL": this.showCreateTasks = true; this.showCreateNotes = true; this.showCreateEmails = false; this.displayExpertential = true; //Enabaling the short cut button this.showShortcut = true; break; case "AUTOMATION": this.displayExpertential = false; this.showCreateTasks = true; this.showCreateNotes = true; this.showCreateEmails = true; //Enabaling the short cut button this.showShortcut = false; this.showAutomation = false; break; default: this.displayExpertential = false; this.showCreateTasks = true; this.showCreateNotes = true; this.showCreateEmails = true; break; } } // Show the user avatar upload position popup showAvatarUploadPopup() { const ref = this.dialogService.open(ContactAvatarUploadComponent, { width: '30%', data: { imageUrl: this.imageUrl, contactId: this.contactId } }); ref.onClose.subscribe(() => { this.imageUrl = this.dialogService.dialogComponentRef.instance.componentRef.instance.imageUrl; }); } // Show the contact position popup showContactPosition() { const ref = this.dialogService.open(ContactPotisionComponent, { data: { contactDetails: this.iContactDetails }, header: 'Contact position', width: '40%' }); ref.onClose.subscribe(() => { this.iContactDetails = this.dialogService.dialogComponentRef.instance.componentRef.instance.contactDetails; //Getting the company details this.companyService.GetCompanyDetailsById(this.companyId).subscribe( result => { if (result != null) { this.iCompanyDetails = result; // console.log(this.iCompanyDetails); // assign company model to company object this.company = this.iCompanyDetails[0]; //console.log("Compnay details in contact comp"); //console.log(this.company); } else { //console.log(" Error: viewCompanyDetails "); } } ); }); } // Display company Right Side viewCompany() { this.showSideMenu = false; } //View on click function from slide in component viewOnClick() { this.companyDetailPageState = "out"; // Get All company details by Id this.companyService.GetCompanyDetailsById(this.companyId).subscribe( result => { if (result != null) { this.showSideMenu = false; this.iCompanyDetails = result; //console.log("Company details"); //console.log(this.iCompanyDetails); // assign company model to company object this.company = this.iCompanyDetails[0]; // console.log(this.company); } else { //console.log(" Error: viewCompanyDetails "); } } ); } // show company details by button click viewCompanyDetails(companyId) { //Slide in the comapny component if (this.companyDetailPageState == "in") { this.companyDetailPageState = "out"; } else { this.companyDetailPageState = "in"; } // console.log(companyId); this.companyId = companyId; // Get All company details by Id this.companyService.GetCompanyDetailsById(this.companyId).subscribe( result => { if (result != null) { // debugger; this.showSideMenu = true; this.iCompanyDetails = result; // console.log(this.iCompanyDetails); // assign company model to company object this.company = this.iCompanyDetails[0]; // console.log(this.company); } else { //console.log(" Error: viewCompanyDetails "); } } ); } // Display Company Information DisplayCompanyContactData(companyId) { this.companyId = companyId; this.selectedMenu = companyId; // Get All company contact details by Id this.companyService.GetCompanyContactsDetailsById(this.companyId).subscribe( result => { if (result != null) { this.showCompanyContact = false; this.iCompanyContacts = result; this.companyContactId = this.iCompanyContacts[0]['CompanyContactsId']; this.email = this.iCompanyContacts[0]['Email']; this.phone = this.iCompanyContacts[0]['Phone']; this.contactOwner = this.iCompanyContacts[0]['Owner']; this.address = this.iCompanyContacts[0]['Address'] this.contactStatus_selected = this.iCompanyContacts[0]['ContactStatusId']; this.leadStatus_Selected = this.iCompanyContacts[0]['LeadStatus']; this.last_contacted = this.iCompanyContacts[0]['Lastcontacted']; this.last_activity = this.iCompanyContacts[0]['LastActivity']; //Setting the date variables this.newSelectedLastActivityDate = new Date(this.last_activity); this.newSelectedLastContactedDate = new Date(this.last_contacted); //console.log("iCompanyContacts"); //console.log(this.iCompanyContacts); } else { //console.log(" Error: DisplayCompanyData "); } //Getting the company details this.companyService.GetCompanyDetailsById(this.companyId).subscribe( result => { if (result != null) { this.iCompanyDetails = result; this.company = this.iCompanyDetails[0]; } else { } } ); } ); // Get All company History details by Id this.companyService.GetCompanyHistoryDetailsById(this.companyId).subscribe( result => { if (result != null) { this.iCompanyDetailsHistory = result; // console.log(' Company Details History '); // console.log(this.iCompanyDetailsHistory); // assign company model to company object // this.company = this.iCompanyDetailsHistory[0]; // console.log(this.company); } else { //console.log(" Error: GetCompanyHistoryDetailsById "); } } ); // Get All company contact History details by Id this.companyService.GetCompanyContactsHistoryDetailsById(this.companyId).subscribe( result => { if (result != null) { this.iCompanyContactsHistory = result; // console.log(' Company Contact History '); // console.log(this.iCompanyContactsHistory); // assign company model to company object // this.company = this.iCompanyDetailsHistory[0]; // console.log(this.company); } else { //console.log(" Error: GetCompanyContactsHistoryDetailsById "); } } ); } /** To save contact details */ SaveCompanyContact(): void { this.contactDetails = { ContactDetailsId: this.contactId, FirstName: this.firstName, LastName: this.lastName, Avatar: this.imageUrl, IsDisable: false } //Setting the new selected last contacted date if (this.newSelectedLastContactedDate) { this.last_contacted = this.newSelectedLastContactedDate.toString(); } //Setting the new selected last activity date if (this.newSelectedLastActivityDate) { this.last_activity = this.newSelectedLastActivityDate.toString(); } this.companyContactDetails = { CompanyContactsId: this.companyContactId, ContactDetailsId: this.contactId, CompanyDetailsId: this.companyId, ContactStatusId: this.contactStatus_selected, ContactPositionsId: 0, Email: this.email, Address: this.address, Phone: this.phone, Owner: this.contactOwner, LeadStatus: this.leadStatus_Selected, IsDefaultCompany: false, IsMainContact: false, CreatedDate: new Date(), IsDisable: false, ContactDetails: this.contactDetails, CompanyDetails: null, ContactStatus: null, Lastcontacted: this.last_contacted, LastActivity: this.last_activity, StatusName: "" } // debugger; //console.log(this.companyContactDetails); /** Save company contact details */ this.companyService.SaveCompanyContactDetails(this.companyContactDetails, +this.cookieService.get('LoggedUserId')).subscribe( result => { //console.log("Focus out"); //console.log(result); if (result != null) { } else { //console.log(" Error: Save In Contacts "); } } ); } // Save company details Save(): void { //console.log(this.company); // Save All company details by Id this.companyService.SaveCompanyDetails(this.company).subscribe( result => { if (result != null) { } else { //console.log(" Error: Save "); } } ); } // Show Notes CreateNotes() { //this.showCreateNotes = !this.showCreateNotes; // if (this.createNotePageState == 'in') { // this.createNotePageState = 'out' // } else { // this.createNotePageState = 'in' // } this.selectedMenuitem = this.items[2]; this.showCreateTasks = true; this.showCreateNotes = false; this.showCreateEmails = true; //Enabaling the short cut button this.showShortcut = true; } // Show Tasks CreateTasks() { // this.showCreateTasks = true; // if (this.createTaskPageState == 'in') { // this.createTaskPageState = 'out' // } else { // this.createTaskPageState = 'in' // } this.selectedMenuitem = this.items[3]; this.showCreateTasks = false; this.showCreateNotes = true; this.showCreateEmails = true; //Enabaling the short cut button this.showShortcut = true; } //Show Emails CreateEmails() { this.selectedMenuitem = this.items[1]; this.showCreateTasks = true; this.showCreateNotes = true; this.showCreateEmails = false; //Enabaling the short cut button this.showShortcut = true; } drop(event: CdkDragDrop) { moveItemInArray(this.comDetails, event.previousIndex, event.currentIndex); // Set Default Company /** Save company contact details */ // console.log("Company Contact Id :" + this.comDetails[0].CompanyContactsId); // console.log("Company Id :" + this.comDetails[0].comId); this.defaultCompanyContactId = this.comDetails[0].CompanyContactsId; this.defaultCompanyId = this.comDetails[0].comId; this.companyService.UpdateDefaultCompany(this.defaultCompanyContactId, this.defaultCompanyId).subscribe( result => { if (result != null) { } else { //console.log(" Error: UpdateDefaultCompany "); } }); } //Adding a new company addCompanyOnClick() { //Setting the visibility this.newCompanyInputState = true; } //Closing the add new company onCancelOnClick() { //Cloasing the new company this.newCompanyInputState = false; } //adding a new company on click function onCreateOnClick() { //Checking if the new company is empty if (this.newCompanyName) { //Calling the service to add the new company this.companyService.AddNewCompany(this.newCompanyName, this.contactId, +this.cookieService.get('LoggedUserId')).subscribe( data => { //refresh the company details //Emptying the new company value box this.newCompanyName = ""; //Cloasing the new company this.newCompanyInputState = false; // Get All contact details by Id this.companyService.GetContactDetailsByContactId(this.contactId).subscribe( result => { if (result != null) { this.comContactDetails = []; this.comDetails = []; this.comContactDetails = result; //console.log("--------------"); //console.log(this.comContactDetails); let cDtailsFirst = [] let cDtailsSecond = [] //filter deafault company to another array this.comContactDetails.forEach(element => { if (element.IsDefaultCompany == 1) { cDtailsFirst.push({ CompanyContactsId: element.CompanyContactsId, comName: element.CompanyDetails.CompanyName, comId: element.CompanyDetails.CompanyId, IsDefaultCompany: element.IsDefaultCompany }) } else { cDtailsSecond.push({ CompanyContactsId: element.CompanyContactsId, comName: element.CompanyDetails.CompanyName, comId: element.CompanyDetails.CompanyId, IsDefaultCompany: element.IsDefaultCompany }) } }); //To combine two arrays, and default company to first cDtailsFirst.forEach(element => { this.comDetails.push({ CompanyContactsId: element.CompanyContactsId, comName: element.comName, comId: element.comId, IsDefaultCompany: element.IsDefaultCompany }); }); cDtailsSecond.forEach(element => { this.comDetails.push({ CompanyContactsId: element.CompanyContactsId, comName: element.comName, comId: element.comId, IsDefaultCompany: element.IsDefaultCompany }); }); } else { //console.log("Error: GetContactDetailsById "); } } ); } ); } else { //console.log("New Company name is empty"); } } //On click function for histories onclickHistoryFunction(contactVariableType: string) { switch (contactVariableType) { case 'CONTACTFIRSTNAME': this.contactService.GetHistoryRecords(this.contactId, contactVariableType).subscribe( data => { this.historyList = data; this.displayFirstNameHistory = !this.displayFirstNameHistory; this.displayLastNameHistory = false; this.displayEmailHistory = false; this.displayPhoneHistory = false; this.displayAddressHistory = false; } ); break; case 'CONTACTLASTNAME': this.contactService.GetHistoryRecords(this.contactId, contactVariableType).subscribe( data => { this.historyList = data; this.displayLastNameHistory = !this.displayLastNameHistory; this.displayFirstNameHistory = false; this.displayEmailHistory = false; this.displayPhoneHistory = false; this.displayAddressHistory = false; } ); break; case 'CONTACTEMAIL': this.contactService.GetHistoryRecords(this.contactId, contactVariableType).subscribe( data => { this.historyList = data; this.displayEmailHistory = !this.displayEmailHistory; this.displayFirstNameHistory = false; this.displayLastNameHistory = false; this.displayPhoneHistory = false; this.displayAddressHistory = false; } ); break; case 'CONTACTPHONE': this.contactService.GetHistoryRecords(this.contactId, contactVariableType).subscribe( data => { this.historyList = data; this.displayPhoneHistory = !this.displayPhoneHistory; this.displayFirstNameHistory = false; this.displayLastNameHistory = false; this.displayEmailHistory = false; this.displayAddressHistory = false; } ); break; case 'CONTACTADDRESS': this.contactService.GetHistoryRecords(this.contactId, contactVariableType).subscribe( data => { this.historyList = data; this.displayAddressHistory = !this.displayAddressHistory; this.displayFirstNameHistory = false; this.displayLastNameHistory = false; this.displayEmailHistory = false; this.displayPhoneHistory = false; } ); break; } } noteWithNewNote(){ this.autoNewNote = true; this.CreateNotes(); } }