//Importing the libraries import { Component, OnInit, ElementRef, EventEmitter, Output, ViewChild } from '@angular/core'; import { SelectItem, MenuItem, DialogService } from 'primeng/api'; import dayGridPlugin from '@fullcalendar/daygrid'; import timeGridPlugin from '@fullcalendar/timegrid'; import interactionPlugin from '@fullcalendar/interaction'; import { fromEvent } from 'rxjs'; import { map, filter, debounceTime, tap, switchAll } from 'rxjs/operators'; import { parse } from 'url'; import { CookieService } from 'ngx-cookie-service'; //Importing the core classes import { IOptions } from '../../shared/core/IOptions'; import { ISelectOptionList } from '../../shared/core/ISelectOptionList'; //Importing the service classes import { DashboardService } from '../../shared/service/dashboard.service'; import { ImportService } from '../../shared/service/import.service'; //Importing the components import { ContactListComponent } from '../contact-list/contact-list.component'; import { CompanyListComponent } from '../company-list/company-list.component'; import { LeadsListComponent } from '../leads-list/leads-list.component'; import { IFilterType } from '../../shared/core/IFilterType'; import { IfStmt } from '@angular/compiler'; import { IFilterOption } from '../../shared/core/IFilterOption'; import { IFilterKey } from '../../shared/core/IFilterKey'; import { DatePipe } from '@angular/common'; import * as globals from '../../shared/core/common'; import { HubConnection, HubConnectionBuilder } from '@aspnet/signalr'; import { ContactCreateComponent } from '../../components/popups/contact-create/contact-create.component'; import { ContactImportComponent } from '../../components/popups/contact-import/contact-import.component'; import { ContactExportComponent } from '../../components/popups/contact-export/contact-export.component'; import { IContactImports } from '../../shared/core/IContactImports'; import { IContactSearch } from '../../shared/core/IContactSearch'; @Component({ selector: 'app-contact-home', templateUrl: './contact-home.component.html', styleUrls: ['./contact-home.component.scss'], providers: [DatePipe] }) export class ContactHomeComponent implements OnInit { //this var is for staff social component @ViewChild(ContactListComponent) ContactListComponent: ContactListComponent; @ViewChild(CompanyListComponent) CompanyListComponent: CompanyListComponent; @ViewChild(LeadsListComponent) LeadsListComponent: LeadsListComponent; showbar: boolean = true; //logged person id LoggedId: number = 14; cols: { field: string; header: string; width: string; }[] documents: any activity: SelectItem[] items: MenuItem[] events: any = [] options: any startDate = "2016-01-01" display: boolean = false /** For contact options */ contactOptions: IOptions /** For me and myteam dropdown options */ drpdwn_contactOptions: any /** To keep me and myteam contact options values*/ drpdwn_contactOptions_selected: any /** For filter dropdown options */ filterOptionsContacts: ISelectOptionList[] = []; filterOptionsCompany: ISelectOptionList[] = []; filterOptionsLeads: ISelectOptionList[] = []; /** To keep filter options values*/ filterOptions_selected: any /** For no of records per page dropdown*/ noOfRecordsPerPage: SelectItem[] /** To keep no of records per page values*/ noOfRecordsPerPage_selected: number //flag for contact list isContactsOn: boolean = false; //flag for companies list isCompaniesOn: boolean = false; //flag for leads list isLeadsOn: boolean = false; //curent page number currentPage: number = 1; //this will hold search value searchQuery: string; searchQueryCompany: string; searchQueryLeads: string; //these are the date range values filterKey: string = ""; filterValue: string = ""; //thse will containg custom calendar values fromDate: Date; toDate: Date; //this will hide and show custom calendars showCalendar: boolean = false; //this will hold custom date range type Eg:last activity or date joined dateRangeType: string = ""; //Filter variables filterTypes: IFilterType[] = []; filterKeys: IFilterKey[]; daysWeeksMonthsList: any; filterTypeIsDisabled: boolean = false; filterType: string = ''; dateRangeSelection: any; dwmSelection; dwmEnteredText; dateFromAndTo: Date[] = [new Date, new Date]; contactOptionList: any[] = [{ label: 'My Team', value: "MYTEAM" }, { label: 'Me', value: "ME" }]; ContactOption: any = {}; //Disable filter variables disableWithTasks: boolean = false; disableWithOutTasks: boolean = false; disableWithNotes: boolean = false; disableWithOutNotes: boolean = false; selectedAddOption: number = 0; xeroAuthUrl: string; displayXeroAuth: boolean; myobAuthUrl: string = ""; displayMyOBAuth: boolean = false; hubConnection: HubConnection; displayMyOBAuthFrame:boolean = false; contactCount:string = '0'; displayMyOBSuccess:boolean = false; displayXeroAuthFrame:boolean = false; displayXeroSuccess:boolean = false; displayXeroSearchAuthFrame:boolean = false; displayXeroSearchResult:boolean = false; xeroSearchAuthUrl:string; xeroText:string=""; token:string=""; searchList:string[]=[]; contactSearchList:IContactSearch[]=[]; // contactValues: IContactImports[]; contactValues: SelectItem[] = []; selectedcontactValues: IContactImports; /** for search */ @Output() loading = new EventEmitter(); @Output() results = new EventEmitter(); constructor( private importService: ImportService, private el: ElementRef, private dashboardService: DashboardService, private cookieService: CookieService, public dialogService: DialogService, private datePipe: DatePipe) { } /** ngOnInit() starts */ ngOnInit() { // this.cookieService.set('LoggedUserId', '14'); this.LoggedId = +this.cookieService.get('LoggedUserId'); //this will reset tab to initial state Eg: when tab change this.resetTab(); //turn on the contact list this.isContactsOn = true; //this will prepare items for tab menu this.prepareMenuItems(); /** For Me and MyTeam */ this.drpdwn_contactOptions = [ { label: 'Me', value: "ME" }, { label: 'My team', value: "MYTEAM" }, ]; /** For filter options*/ this.filterOptionsContacts = [ { label: 'Select', value: null } //for contacts ]; this.filterOptionsCompany = [ { label: 'Select', value: null } //for companies ]; this.filterOptionsLeads = [ { label: 'Select', value: null } //for leads ] /** Filter option - days, weeks, months */ this.daysWeeksMonthsList = [ { label: '#days', value: "DAYS" }, { label: '#weeks', value: "WEEKS" }, { label: '#months', value: "MONTHS" } ]; this.dwmSelection = this.daysWeeksMonthsList[0]; //no of records dropdown option list this.noOfRecordsPerPage = [ { label: "1 record per page", value: 1 }, { label: "3 record per page", value: 3 }, { label: "20 records per page", value: 20 } ]; // Add contacts this.contactValues = [ {label:'+ Add contact',value:0, disabled:true}, { label: '+ Add a new contact', value: 1 }, { label: 'Import from CSV', value: 2 }, { label: 'Import from Xero', value: 3 }, { label: 'Import from MYOB', value: 4 }, { label: 'Export contacts to CSV', value: 5 } ]; //initializing dropdown default values this.drpdwn_contactOptions_selected = this.drpdwn_contactOptions[0].value; this.noOfRecordsPerPage_selected = this.noOfRecordsPerPage[2].value; /** preparing parameters and options to retrieve contact list, this collection is the one accepts as the parameter in API */ this.contactOptions = { Params: [ { 'key': 'id', 'value': this.LoggedId }, { 'key': 'contactopt', 'value': this.drpdwn_contactOptions_selected } ], FilterValue: [{ 'key': '', 'value': null }], SearchValue: this.searchQuery, RecordCount: this.noOfRecordsPerPage_selected, CurrentPage: this.currentPage } /** Get contacts */ //this.dashboardService.getContactList(this.contactOptions).subscribe(res => { //this.contactList = res; //this.dashboardService.emitSearchResults(this.contactList); //}); //console.log("init: " + JSON.stringify(this.contactOptions)); //loading the calendar this.prepareCalendar(); //Getting all the filter options this.dashboardService.getFilterTypes("DASHBOARD", +this.cookieService.get('CompanyId')).subscribe( data => { this.filterTypes = data; console.log(this.filterTypes); } ); } /** Ends - ngOnInit() */ RefreshReports() { console.log(this.ContactOption); } //filtering by ME and MYTEAM option filterResultsByContactOption() { var searchTerm = ""; if (this.isContactsOn) { searchTerm = this.searchQuery; } else if (this.isCompaniesOn) { searchTerm = this.searchQueryCompany; } else if (this.isLeadsOn) { searchTerm = this.searchQueryLeads; } //preparing options before operation this.contactOptions = { Params: [ { 'key': 'id', 'value': this.LoggedId }, { 'key': 'contactopt', 'value': this.drpdwn_contactOptions_selected } //{ 'Key': ''} ], FilterValue: [{ 'key': this.filterKey.toUpperCase(), 'value': this.filterValue }], SearchValue: searchTerm, RecordCount: this.noOfRecordsPerPage_selected, CurrentPage: this.currentPage } //running the method if (this.isContactsOn) { this.ContactListComponent.getContactList(this.contactOptions); } else if (this.isCompaniesOn) { this.CompanyListComponent.getCompanies(this.contactOptions); } else if (this.isLeadsOn) { this.LeadsListComponent.getLeadList(this.contactOptions); } } filterResultsByContactOptionFromParent(drpdwn_contactOptions_selected: string) { var searchTerm = ""; if (this.isContactsOn) { searchTerm = this.searchQuery; } else if (this.isCompaniesOn) { searchTerm = this.searchQueryCompany; } else if (this.isLeadsOn) { searchTerm = this.searchQueryLeads; } //preparing options before operation this.contactOptions = { Params: [ { 'key': 'id', 'value': this.LoggedId }, { 'key': 'contactopt', 'value': drpdwn_contactOptions_selected } //{ 'Key': ''} ], FilterValue: [{ 'key': this.filterKey.toUpperCase(), 'value': this.filterValue }], SearchValue: searchTerm, RecordCount: this.noOfRecordsPerPage_selected, CurrentPage: this.currentPage } //running the method if (this.isContactsOn) { this.ContactListComponent.getContactList(this.contactOptions); } else if (this.isCompaniesOn) { this.CompanyListComponent.getCompanies(this.contactOptions); } else if (this.isLeadsOn) { this.LeadsListComponent.getLeadList(this.contactOptions); } } //limiting contacts record count to be display in dashboard filterResultsByNoOfRecords() { //preparing options before operation this.contactOptions = { Params: [ { 'key': 'id', 'value': this.LoggedId }, { 'key': 'contactopt', 'value': this.drpdwn_contactOptions_selected } ], FilterValue: [{ 'key': this.filterKey.toUpperCase(), 'value': this.filterValue }], SearchValue: this.searchQuery, RecordCount: this.noOfRecordsPerPage_selected, CurrentPage: this.currentPage } /** Get Number of records per page */ this.dashboardService.emitCurrentNoOfRecords(this.drpdwn_contactOptions_selected); //running the method this.ContactListComponent.getContactList(this.contactOptions); } //limiting company record count to be display in dashboard filterCompanyResultsByNoOfRecords() { //preparing options before operation //console.log("searching") this.contactOptions = { Params: [ { 'key': 'id', 'value': this.LoggedId }, { 'key': 'contactopt', 'value': this.drpdwn_contactOptions_selected } ], FilterValue: [{ 'key': this.filterKey.toUpperCase(), 'value': this.filterValue }], SearchValue: this.searchQueryCompany, RecordCount: this.noOfRecordsPerPage_selected, CurrentPage: this.currentPage } //running the method this.CompanyListComponent.getCompanies(this.contactOptions); } //limiting company record count to be display in dashboard filterLeadsResultsByNoOfRecords() { //preparing options before operation //console.log("searching") this.contactOptions = { Params: [ { 'key': 'id', 'value': this.LoggedId }, { 'key': 'contactopt', 'value': this.drpdwn_contactOptions_selected } ], FilterValue: [{ 'key': this.filterKey.toUpperCase(), 'value': this.filterValue }], SearchValue: this.searchQueryLeads, RecordCount: this.noOfRecordsPerPage_selected, CurrentPage: this.currentPage } //running the method this.LeadsListComponent.getLeadList(this.contactOptions); } //Calling the pagination results filterResultsByNoOfRecordsInPaginator(pageNumber: any) { //preparing options before operation this.contactOptions = { Params: [ { 'key': 'id', 'value': this.LoggedId }, { 'key': 'contactopt', 'value': this.drpdwn_contactOptions_selected } ], FilterValue: [{ 'key': this.filterKey.toUpperCase(), 'value': this.filterValue }], SearchValue: this.searchQuery, RecordCount: this.noOfRecordsPerPage_selected, CurrentPage: parseInt(pageNumber) } /** Get Number of records per page */ this.dashboardService.emitCurrentNoOfRecords(this.drpdwn_contactOptions_selected); //running the method this.ContactListComponent.getContactList(this.contactOptions); } //Calling the pagination results filterCompanyResultsByNoOfRecordsInPaginator(pageNumber: any) { //preparing options before operation this.contactOptions = { Params: [ { 'key': 'id', 'value': this.LoggedId }, { 'key': 'contactopt', 'value': this.drpdwn_contactOptions_selected } ], FilterValue: [{ 'key': this.filterKey.toUpperCase(), 'value': this.filterValue }], SearchValue: this.searchQueryCompany, RecordCount: this.noOfRecordsPerPage_selected, CurrentPage: parseInt(pageNumber) } /** Get Number of records per page */ this.dashboardService.emitCurrentNoOfRecords(this.drpdwn_contactOptions_selected); //running the method this.ContactListComponent.getContactList(this.contactOptions); } //Calling the pagination results filterLeadsResultsByNoOfRecordsInPaginator(pageNumber: any) { //preparing options before operation this.contactOptions = { Params: [ { 'key': 'id', 'value': this.LoggedId }, { 'key': 'contactopt', 'value': this.drpdwn_contactOptions_selected } ], FilterValue: [{ 'key': this.filterKey.toUpperCase(), 'value': this.filterValue }], SearchValue: this.searchQueryLeads, RecordCount: this.noOfRecordsPerPage_selected, CurrentPage: parseInt(pageNumber) } /** Get Number of records per page */ this.dashboardService.emitCurrentNoOfRecords(this.drpdwn_contactOptions_selected); //running the method this.ContactListComponent.getContactList(this.contactOptions); } searchContacts() { //preparing options before operation //console.log("searching") this.contactOptions = { Params: [ { 'key': 'id', 'value': this.LoggedId }, { 'key': 'contactopt', 'value': this.drpdwn_contactOptions_selected } ], FilterValue: [{ 'key': this.filterKey.toUpperCase(), 'value': this.filterValue }], SearchValue: this.searchQuery, RecordCount: this.noOfRecordsPerPage_selected, CurrentPage: this.currentPage } //running the method this.ContactListComponent.getContactList(this.contactOptions); } searchCompanies() { // debugger; //preparing options before operation //console.log("searching") this.contactOptions = { Params: [ { 'key': 'id', 'value': this.LoggedId }, { 'key': 'contactopt', 'value': this.drpdwn_contactOptions_selected } ], FilterValue: [{ 'key': this.filterKey.toUpperCase(), 'value': this.filterValue }], SearchValue: this.searchQueryCompany, RecordCount: this.noOfRecordsPerPage_selected, CurrentPage: this.currentPage } //running the method this.CompanyListComponent.getCompanies(this.contactOptions); } searchLeads() { //preparing options before operation //console.log("searching") this.contactOptions = { Params: [ { 'key': 'id', 'value': this.LoggedId }, { 'key': 'contactopt', 'value': this.drpdwn_contactOptions_selected } ], FilterValue: [{ 'key': this.filterKey.toUpperCase(), 'value': this.filterValue }], SearchValue: this.searchQueryLeads, RecordCount: this.noOfRecordsPerPage_selected, CurrentPage: this.currentPage } //running the method this.LeadsListComponent.getLeadList(this.contactOptions); } filterResultByDateRange() { //preparing options before operation this.contactOptions = { Params: [ { 'key': 'id', 'value': this.LoggedId }, { 'key': 'contactopt', 'value': this.drpdwn_contactOptions_selected } ], FilterValue: [{ 'key': this.filterKey.toUpperCase(), 'value': this.filterValue }], SearchValue: this.searchQuery, RecordCount: this.noOfRecordsPerPage_selected, CurrentPage: this.currentPage } //running the method this.ContactListComponent.getContactList(this.contactOptions); } //data range selection method for contacts selectDateRange(event) { // debugger; this.showCalendar = false; this.filterValue = ""; this.filterKey = ""; if (event.value == "" || event.value == null) { this.filterResultByDateRange(); return; } else if (event.value == "CustomLastActivity") { this.showCalendar = true; this.dateRangeType = "CustomLastActivity"; } else if (event.value == "CustomDateJoined") { this.showCalendar = true; this.dateRangeType = "CustomDateJoined"; } else { this.showCalendar = false; var filter = event.value.split(':', 2); this.filterKey = filter[0]; this.filterValue = filter[1]; this.filterResultByDateRange(); } //Clearing the values this.fromDate = null; this.toDate = null; } //selected date picking method for contacts dateSelected(event) { if (this.fromDate.toString() != "" && this.toDate.toString() != "") { this.filterKey = this.dateRangeType; this.filterValue = this.fromDate + "," + this.toDate; this.filterResultByDateRange(); } } //getting emiting filters list from contact list component getContactFilters(event) { this.filterOptionsContacts = []; this.filterOptionsContacts = event; this.filterOptionsContacts.unshift({ label: 'Select', value: null }); } //getting emiting filters list from company list component getCompanyFilters(event) { this.filterOptionsCompany = []; this.filterOptionsCompany = event; this.filterOptionsCompany.unshift({ label: 'Select', value: null }); } //getting emiting filters list from leads list component getLeadsFilters(event) { this.filterOptionsLeads = []; this.filterOptionsLeads = event; this.filterOptionsLeads.unshift({ label: 'Select', value: null }); } // show page tab list prepareMenuItems() { this.items = [ { id: "1", label: 'Contacts', }, { id: "2", label: 'Companies', }, { id: "3", label: 'Leads', } ]; } //this method hide and show depend on the link clicked showContent(id: any) { //first hide all sections by this method //Reset the filters this.getGlobalFilters(); //depend on the id, relavant section will display and style class will be added switch (id) { case "1": this.isContactsOn = true; this.isLeadsOn = false; this.isCompaniesOn = false; document.getElementById("link1").className = "ui-g-4 tab-container myclass"; document.getElementById("link2").className = "ui-g-4 tab-container "; document.getElementById("link3").className = "ui-g-4 tab-container "; break; case "2": this.isCompaniesOn = true; this.isContactsOn = false; this.isLeadsOn = false; document.getElementById("link2").className = "ui-g-4 tab-container myclass"; document.getElementById("link1").className = "ui-g-4 tab-container "; document.getElementById("link3").className = "ui-g-4 tab-container "; break; case "3": this.isLeadsOn = true; this.isContactsOn = false; this.isCompaniesOn = false; document.getElementById("link3").className = "ui-g-4 tab-container myclass"; document.getElementById("link1").className = "ui-g-4 tab-container "; document.getElementById("link2").className = "ui-g-4 tab-container "; break; } } //this method turn off all right side contents before turn on any content turnOffAll() { this.isContactsOn = false; this.isCompaniesOn = false; this.isLeadsOn = false; document.getElementById("link1").className = ""; document.getElementById("link2").className = ""; document.getElementById("link3").className = ""; this.resetTab(); } //method to reset tab initial selections and values resetTab() { this.currentPage = 1; this.searchQuery = ""; this.searchQueryCompany = ""; this.searchQueryLeads = ""; } //hide and show calendar showDialog() { this.display = true; } //make calendar options and display prepareCalendar() { this.events = [ { "title": "All Day Event", "start": "2017-08-15" }, { "title": "Long Event", "start": "2016-01-07", "end": "2016-01-10" }, { "title": "Repeating Event", "start": "2016-01-09T16:00:00" }, { "title": "Repeating Event", "start": "2016-01-16T16:00:00" }, { "title": "Conference", "start": "2016-01-11", "end": "2016-01-13" } ]; //options needed for calnedar this.options = { themeSystem: 'bootstrap', plugins: [dayGridPlugin, timeGridPlugin, interactionPlugin], defaultDate: this.startDate, header: { left: 'prev,next', center: 'title', right: 'month,week,day,today' }, titleFormat: { year: 'numeric', month: 'long', day: 'numeric' }, buttonText: { today: 'Today', month: 'Month', week: 'Week', } }; // /** convert the `keyup` event into an observable stream for search*/ // fromEvent(this.el.nativeElement, 'keyup').pipe( // map((e: any) => e.target.value), // extract the value of the input // debounceTime(500), // only once every 500ms // tap(() => this.loading.emit(true)), // enable loading // map((query: string) => this.dashboardService.search(this.contactOptions, query)), // search, discarding old events if new input comes in // switchAll()) // produces values only from the most recent inner sequence ignoring previous streams. // .subscribe( // act on the return of the search // (_postResults: any) => { // this.results.emit(_postResults); // //---------- // this.dashboardService.emitSearchResults(_postResults); // console.log("search results: " + JSON.stringify(_postResults)); // }, // err => { // console.log(err); // }, // () => { // } // ); } /** Ends - ngOnInit() */ // filterResultsByDrp1() { // this.contactOptions.Params[0].value = this.drpdwn_contactOptions_selected; // this.dashboardService.getContactList(this.contactOptions).subscribe( // (data: any[]) => { this.contactList = data }); // /** behavior subject */ // console.log("second: " + JSON.stringify(this.contactOptions)); // } // filterResultsByNoOfRecords(){ // this.contactOptions.RecordCount= this.noOfRecordsPerPage_selected; // this.dashboardService.getContactList(this.contactOptions).subscribe( // (data: any[]) => {this.contactList = data}); // /** behavior subject */ // console.log("third: " + JSON.stringify(this.contactOptions)); // } // Call wehen check the filter type checkboxes onChangeFilterType(filter: IFilterType) { filter.IsChecked = !filter.IsChecked; filter.selectedFilterOption = filter.FilterOptions[0]; let allFilterValues = []; switch (filter.Code) { case 'COMPANY': case 'FNAME': case 'LNAME': case 'MOBILE': case 'CSTATUS': case 'LSTATUS': case 'COUNTRY': case 'STATE': case 'TITLE': // Getting all the companies this.dashboardService.GetFilterValues(filter.Code).subscribe( allValues => { allFilterValues = allValues; filter.multiSelectList = allFilterValues.map(x => ({ label: x.Value, value: x.Id })); // remove empty filter.multiSelectList = filter.multiSelectList.filter(x => x.label != ""); //remove duplicates filter.multiSelectList = filter.multiSelectList.filter((test, index, array) => index === array.findIndex((findTest) => findTest.label === test.label )); } ); this.onChangeFilterOption(filter); break; case 'EMAIL': case 'PHONE': case 'ONUMBER': case 'CITY': // Getting all the companies this.dashboardService.GetFilterValues(filter.Code).subscribe( allValues => { allFilterValues = allValues; filter.multiSelectList = allFilterValues.map(x => ({ label: x.Value, value: x.Value })); // remove empty filter.multiSelectList = filter.multiSelectList.filter(x => x.label != ""); //remove duplicates filter.multiSelectList = filter.multiSelectList.filter((test, index, array) => index === array.findIndex((findTest) => findTest.label === test.label )); } ); this.onChangeFilterOption(filter); break; case 'LCONTACTED': break; case 'LACTIVITY': break; case 'WONOTES': if (filter.IsChecked == true) { this.disableWithNotes = true; } else { this.disableWithNotes = false; } break; case 'WNOTES': if (filter.IsChecked == true) { this.disableWithOutNotes = true; } else { this.disableWithOutNotes = false; } break; case 'WOTASKS': if (filter.IsChecked == true) { this.disableWithTasks = true; } else { this.disableWithTasks = false; } break; case 'WTASKS': if (filter.IsChecked == true) { this.disableWithOutTasks = true; } else { this.disableWithOutTasks = false; } break; case 'ESTATUS': case 'WOACTIVITIES': case 'AOVERDUE': case 'ADUE': case 'ACOMPLETED': //Remove disable values this.disableWithTasks = false; this.disableWithOutTasks = false; break; default: //Remove disable values this.disableWithTasks = false; this.disableWithOutTasks = false; } } uncheckTheFilter(filterCode) { for (let i = 0; i < this.filterTypes.length; i++) { if (this.filterTypes[i].Code == filterCode) { this.filterTypes[i].IsChecked = false; break; } } } // Call when select a filter option onChangeFilterOption(filter: IFilterType) { if (filter.selectedFilterOption.Code == 'IS' || filter.selectedFilterOption.Code == 'IS$NOT') { filter.textFieldValue = ''; } else if (filter.selectedFilterOption.Code == 'CONTAINS' || filter.selectedFilterOption.Code == 'NOT$CONTAINS' || filter.selectedFilterOption.Code == 'START' || filter.selectedFilterOption.Code == 'END') { filter.selectedMultiSelectList = []; } else if (filter.selectedFilterOption.Code == 'EMPTY' || filter.selectedFilterOption.Code == 'NOT$EMPTY') { filter.selectedMultiSelectList = []; filter.textFieldValue = 'null'; } } // filter button click filterList() { var filterKeys: IFilterKey[] = []; // set filter keys this.filterTypes.forEach(filterType => { if (filterType.IsChecked) { var filterKey: IFilterKey = { Code: '', Option: '', Values: [] }; // for multi select conditions if (filterType.selectedFilterOption && (filterType.selectedFilterOption.Code == 'IS' || filterType.selectedFilterOption.Code == 'IS$NOT')) { if (filterType.selectedMultiSelectList != undefined && filterType.selectedMultiSelectList != null && filterType.selectedMultiSelectList.length > 0) { filterKey.Code = filterType.Code; filterKey.Option = filterType.selectedFilterOption.Code; // bind selected values to the 'Values' array list filterType.selectedMultiSelectList.forEach(element => { var value = encodeURIComponent(element.value) filterKey.Values.push(value) }); filterKeys.push(filterKey); } } // for single value conditions else { if (filterType.selectedFilterOption) { filterKey.Code = filterType.Code; filterKey.Option = filterType.selectedFilterOption.Code; filterKey.Values.push(filterType.textFieldValue); } else { filterKey.Code = filterType.Code; filterKey.Option = " " filterKey.Values.push(" "); } filterKeys.push(filterKey); } } }); //Check the selected tab if (this.isContactsOn && this.contactOptions) { // Contacts list this.ContactListComponent.filterContactListByParent(filterKeys); } else if (this.isCompaniesOn && this.contactOptions) { // Company List this.CompanyListComponent.filterCompanyListByParent(filterKeys); } else if (this.isLeadsOn && this.contactOptions) { this.LeadsListComponent.filterContactListByParent(filterKeys); // Leads list } } getGlobalFilters() { //Getting all the filter options this.dashboardService.getFilterTypes("DASHBOARD", +this.cookieService.get('CompanyId')).subscribe( data => { this.filterTypes = data; console.log(this.filterTypes); } ); } clearFilter() { this.getGlobalFilters(); //Check the selected tab if (this.isContactsOn && this.contactOptions) { // Contacts list this.showContent("1"); this.ContactListComponent.getContactList(this.contactOptions); } else if (this.isCompaniesOn && this.contactOptions) { // Company List this.showContent("2"); this.CompanyListComponent.getCompanies(this.contactOptions); } else if (this.isLeadsOn && this.contactOptions) { this.showContent("3"); this.LeadsListComponent.getLeadList(this.contactOptions); // Leads list } } onSelectFollowUpDate(IFilterType: IFilterType) { console.log(this.dateRangeSelection); let date1 = this.datePipe.transform((this.dateRangeSelection[0] == null) ? Date() : this.dateRangeSelection[0].toString(), "MM-dd-yyyy"); let date2 = this.datePipe.transform((this.dateRangeSelection[1] == null) ? Date() : this.dateRangeSelection[1].toString(), "MM-dd-yyyy"); for (let i = 0; i < this.filterTypes.length; i++) { if (this.filterTypes[i].Id == IFilterType.Id) { this.filterTypes[i].textFieldValue = date1 + "&" + date2; break; } } } dwmFocusOutEvent(filterType: IFilterType) { debugger; for (let i = 0; i < this.filterTypes.length; i++) { if (this.filterTypes[i].Id == filterType.Id) { this.filterTypes[i].textFieldValue = this.dwmSelection['value'] + "&" + this.dwmEnteredText; break; } } } onSinenavToggle() { this.showbar = !this.showbar; } onSinenavToggled() { this.showbar = !this.showbar; // $(".card").removeClass("width1785"); } ngAfterViewInit() { document.getElementById("link1").className = "ui-g-4 tab-container myclass"; } // Implement + Add New Contact button functions ShowContact(event) { console.log(event.value); switch (event.value) { case 1: // console.log('+ Add a new contact'); this.selectedAddOption = 0; const contactCreateComponent = this.dialogService.open(ContactCreateComponent, { header: 'Add New Contact', width: '40%' }); break; case 2: console.log('Import from CSV'); this.selectedAddOption = 0; const contactImportComponent = this.dialogService.open(ContactImportComponent, { header: 'Import contacts', width: '40%' }); break; case 3: console.log('Import from Xero'); this.selectedAddOption = 0; this.displayXeroAuth = true; this.displayXeroAuthFrame = false; this.displayXeroSuccess = false; this.displayXeroSearchResult = false; this.contactCount = '0'; //this.getXeroAuthentication(); break; case 4: console.log('Import from MYOB'); this.selectedAddOption = 0; this.displayMyOBAuth = true; this.displayMyOBAuthFrame = false; this.displayMyOBSuccess = false; this.contactCount = '0'; //this.getMYOBAuthentication(); break; case 5: this.selectedAddOption = 0; // console.log('Export contacts to CSV'); const contactExportComponent = this.dialogService.open(ContactExportComponent, { header: 'Export contacts', width: '40%' }); // this.router.navigate(['/contactExport']); break; default: break; } } // xero authentication for import all function getXeroAuthentication() { this.importService.getXeroAuth().subscribe(link => { this.xeroAuthUrl = link; //this.displayXeroAuthFrame = true; this.hubConnection = new HubConnectionBuilder() .withUrl(globals.serverBase + '/notify') .build(); this.hubConnection .start() .then(() => console.log('Connection started!')) .catch(err => console.log('Error while establishing connection :(')); var xeroWindow = window.open(link, "something", "width=1000,height=500"); this.hubConnection.on('BroadcastMessage', (type: string, payload: string) => { if (type == "XERO") { this.displayXeroAuthFrame = false; xeroWindow.close(); this.displayXeroSuccess = true; this.contactCount = payload; } this.selectedAddOption = 0; }); }) } // myob authentication for import all function getMYOBAuthentication() { this.importService.getMYOBAuth().subscribe(link => { this.myobAuthUrl = link; //this.displayMyOBAuthFrame = true; this.hubConnection = new HubConnectionBuilder() .withUrl(globals.serverBase + '/notify') .build(); this.hubConnection .start() .then(() => console.log('Connection started!')) .catch(err => console.log('Error while establishing connection :(')); var myobWindow = window.open(link, "something", "width=1000,height=500"); this.hubConnection.on('BroadcastMessage', (type: string, payload: string) => { if (type == "MYOB") { this.displayMyOBAuthFrame = false; myobWindow.close(); this.displayMyOBSuccess = true; this.contactCount = payload; this.selectedAddOption = 0; } this.selectedAddOption = 0; }); }) } // xero authentication for search function getXeroSearchAuthentication(){ this.contactSearchList = []; this.searchList = []; if(this.xeroText!==null && this.xeroText!==""){ this.importService.getXeroSearchAuth().subscribe(link => { this.xeroSearchAuthUrl = link; //this.displayXeroSearchAuthFrame = true; this.hubConnection = new HubConnectionBuilder() .withUrl(globals.serverBase + '/notify') .build(); this.hubConnection .start() .then(() => console.log('Connection started!')) .catch(err => console.log('Error while establishing connection :(')); var xeroWindow = window.open(link, "something", "width=1000,height=500"); this.hubConnection.on('BroadcastMessage', (type: string, payload: string) => { if (type == "XERO Search") { this.token = payload this.displayXeroSearchAuthFrame = false; xeroWindow.close(); if(this.token!="" && this.token!="Invalid"){ this.importService.searchXero(this.xeroText,this.token).subscribe(list=>{ this.displayXeroSearchResult = true; this.searchList = list; if(this.searchList.length>0){ this.searchList.forEach(element => { this.contactSearchList.push({Title:element,IsImported:false}) }); } }) } } this.selectedAddOption = 0; }); }); } } // import the search item importSearch(searchTitle:string){ this.importService.importXero(searchTitle,this.token).subscribe(data=>{ var index = this.contactSearchList.findIndex(x=>x.Title==searchTitle); this.contactSearchList[index].Title = "Total of " + data + " contacts imported"; this.contactSearchList[index].IsImported = true; }); } }