//Importing the libraries import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; import { formatDate } from '@angular/common'; import { Message } from 'primeng/api'; import { CookieService } from 'ngx-cookie-service'; import { ThirdPartyDraggable } from '@fullcalendar/interaction'; import { defineDirective } from '@angular/core/src/render3'; //Importing the core classes import { INotes } from '../../shared/core/INotes'; import { IStaffs } from '../../shared/core/IStaffs'; import { Default } from '../../shared/core/Default.enum'; import { ITaskDetails } from '../../shared/core/ITaskDetails'; import { IEmailDetails } from '../../shared/core/IEmailDetails'; //Importing the components import { ContactListComponent } from '../contact-list/contact-list.component'; //Importing the service classes import { NotesService } from '../../shared/service/notes.service'; import { TasksService } from '../../shared/service/tasks.service'; import { EmailsService } from '../../shared/service/emails.service'; @Component({ selector: 'app-filter-section', templateUrl: './filter-section.component.html', styleUrls: ['./filter-section.component.scss'] }) export class FilterSectionComponent implements OnInit { // Notes Collection @Input('INotes') INotes: INotes[]; @Output() onChangeDataSet: EventEmitter = new EventEmitter(); // Tasks Colleciton @Input('ITaskDetails') ITaskDetails: ITaskDetails[]; @Output() onChangeTask: EventEmitter = new EventEmitter(); // Email @Input('IEmailDetails') IEmailDetails: IEmailDetails[]; @Input('filter') filter: number; @Output() onChangeEmailDataSet: EventEmitter = new EventEmitter(); // Contact information @Input('contactId') contactId: number; // Hidden hiddenDates: boolean; hiddenOwner: boolean; hiddenSubjectTitle: boolean; //from date fromDate: Date; //to date toDate: Date; //Error Message dateRangeError: Message[] = []; // Staff IStaffs: IStaffs[]; // Owner Id ownerId: number; // Filter Flag flag: number; //Login staff Id loginStaffId: number; // Hidden unused sections hiddenAll: boolean; // filter email by subject subjectTitle: string; searchText: string; constructor(private notesService: NotesService, private cookieService: CookieService, private tasksService: TasksService, private emailsService: EmailsService) { } ngOnInit() { // Default Dates this.fromDate = new Date(); this.toDate = new Date(); // Default Login this.loginStaffId = +this.cookieService.get('LoggedUserId'); // Hidden sections this.hiddenAll = true; this.hiddenDates = true; this.hiddenOwner = true; this.hiddenSubjectTitle = true; // Get Owner List this.notesService.GetOwnerList().subscribe( result => { if (result != null) { this.IStaffs = result; // console.log('Staff List :'); // console.log(this.IStaffs); } else { //console.log(" Error: GetOwnerList "); } } ); } // show date filteration ShowDateRange() { if (this.hiddenDates == true) { this.hiddenDates = false; } else { this.hiddenDates = true; this.fromDate = new Date(); this.toDate = new Date(); } } // show owner filteration ShowOwner() { if (this.hiddenOwner == true) { this.hiddenOwner = false; } else { this.hiddenOwner = true; } } // Filter by subject title ShowSubjectTitile() { if (this.hiddenSubjectTitle == true) { this.hiddenSubjectTitle = false; } else { this.hiddenSubjectTitle = true; this.subjectTitle = ""; } } // Filter by calender FilterByCalender() { if(this.hiddenOwner == true && this.hiddenSubjectTitle == true) { this.flag = Default.DateOnly; } else if(this.hiddenOwner == true) { this.flag = Default.SubjectWithDate; } else if(this.hiddenSubjectTitle == true) { this.flag = Default.OwnerWithDate; } // if (this.ownerId == null && this.ownerId == undefined) { // this.ownerId = this.loginStaffId; // this.flag = Default.DateOnly; // } // check dates if (this.fromDate == null && this.fromDate == undefined) { this.dateRangeError.push({ severity: 'info', summary: 'From date missing', detail: '' }); } if (this.toDate == null && this.toDate == undefined) { this.dateRangeError.push({ severity: 'info', summary: 'To date missing', detail: '' }); } if (this.fromDate != null && this.fromDate != undefined && this.toDate != null && this.toDate != undefined) { var dateFrom = formatDate(this.fromDate, 'yyyy-MM-dd', 'en-US'); var dateTo = formatDate(this.toDate, 'yyyy-MM-dd', 'en-US'); // Date Range Error Message if (dateFrom > dateTo) { this.dateRangeError.push({ severity: 'info', summary: 'From date should be less than To date', detail: '' }); return; } // this is defined from Default.Enum // Notes if (this.filter == 1) { // Get Filtered Records this.notesService.GetAllFilterNotesDetails(dateFrom, dateTo, this.ownerId, this.flag).subscribe( result => { if (result != null) { this.INotes = result; this.onChangeDataSet.emit(this.INotes); // console.log(' Get Filtered by Calender : '); // console.log(this.INotes); } else { //console.log(" Error: Get Filtered Records "); } } ); } // Task else if (this.filter == 2) { // Get Filtered Records this.tasksService.GetAllFilterTasksDetails(dateFrom, dateTo, this.ownerId, this.flag).subscribe( result => { if (result != null) { this.ITaskDetails = result; this.onChangeTask.emit(this.ITaskDetails); } else { //console.log(" Error: Get Filtered Records "); } } ); } // Email else if (this.filter == 3) { // Get Filtered Emails this.emailsService.GetAllFilterEmailsDetails(dateFrom, dateTo, this.ownerId, this.flag, this.subjectTitle, this.contactId).subscribe( result => { if (result != null) { this.IEmailDetails = result; this.onChangeEmailDataSet.emit(this.IEmailDetails); } else { //console.log(" Error: Get Filtered Records "); } } ); } } } // Filter by Owner onChangeType(event) { if(this.hiddenDates == true && this.hiddenSubjectTitle == true) { this.flag = Default.OwnerOnly; } else if(this.hiddenDates == true) { this.flag = Default.SubjectWithOwner; } else if(this.hiddenSubjectTitle == true) { this.flag = Default.OwnerWithDate; } this.ownerId = event.value['StaffId']; // this.flag = Default.OwnerOnly; if (this.fromDate != null && this.fromDate != undefined && this.toDate != null && this.toDate != undefined) { var dateFrom = formatDate(this.fromDate, 'yyyy-MM-dd', 'en-US'); var dateTo = formatDate(this.toDate, 'yyyy-MM-dd', 'en-US'); // Date Range Error Message if (dateFrom > dateTo) { this.dateRangeError.push({ severity: 'info', summary: 'From date should be less than To date', detail: '' }); return; } // this is defined from Default.Enum // Notes funtion if (this.filter == 1) { // Get Filtered Records this.notesService.GetAllFilterNotesDetails(dateFrom, dateTo, this.ownerId, this.flag).subscribe( result => { if (result != null) { this.INotes = result; this.onChangeDataSet.emit(this.INotes); // console.log(' Get Filtered by Calender & Owner : '); // console.log(this.INotes); } else { //console.log(" Error: Get Filtered Records "); } } ); } // Task Funtions else if (this.filter == 2) { // Get Filtered Records this.tasksService.GetAllFilterTasksDetails(dateFrom, dateTo, this.ownerId, this.flag).subscribe( result => { if (result != null) { this.ITaskDetails = result; this.onChangeTask.emit(this.ITaskDetails); } else { //console.log(" Error: Get Filtered Records "); } } ); } // Email else if (this.filter == 3) { // console.log(this.subjectTitle); // Get Filtered Records this.emailsService.GetAllFilterEmailsDetails(dateFrom, dateTo, this.ownerId, this.flag, this.subjectTitle, this.contactId).subscribe( result => { if (result != null) { this.IEmailDetails = result; this.onChangeEmailDataSet.emit(this.IEmailDetails); // console.log(' Get Filtered by Calender : '); // console.log(this.INotes); } else { //console.log(" Error: Get Filtered Records "); } } ); } } else { var dateFrom = formatDate(new Date(), 'yyyy-MM-dd', 'en-US'); var dateTo = formatDate(new Date(), 'yyyy-MM-dd', 'en-US'); // this is defined from Default.Enum // Notes funtion if (this.filter == 1) { this.notesService.GetAllFilterNotesDetails(dateFrom, dateTo, this.ownerId, this.flag).subscribe( result => { if (result != null) { this.INotes = result; this.onChangeDataSet.emit(this.INotes); // console.log(' Get Filtered by Owner : '); // console.log(this.INotes); } else { //console.log(" Error: Get Filtered Records "); } } ); } // Task Funtions else if (this.filter == 2) { // Get Filtered Records this.tasksService.GetAllFilterTasksDetails(dateFrom, dateTo, this.ownerId, this.flag).subscribe( result => { if (result != null) { this.ITaskDetails = result; this.onChangeTask.emit(this.ITaskDetails); } else { //console.log(" Error: Get Filtered Records "); } } ); } // Email else if (this.filter == 3) { //console.log(this.subjectTitle); // Get Filtered Records this.emailsService.GetAllFilterEmailsDetails(dateFrom, dateTo, this.ownerId, this.flag, this.subjectTitle, this.contactId).subscribe( result => { if (result != null) { this.IEmailDetails = result; this.onChangeEmailDataSet.emit(this.IEmailDetails); // console.log(' Get Filtered by Calender : '); // console.log(this.INotes); } else { //console.log(" Error: Get Filtered Records "); } } ); } } } // Email Search by title SearchByTitle() { // console.log(this.subjectTitle); this.searchText = this.subjectTitle; if(this.hiddenDates == true && this.hiddenOwner == true) { this.flag = Default.SubjectOnly; } else if(this.hiddenDates == true) { this.flag = Default.SubjectWithOwner; } else if(this.hiddenOwner == true) { this.flag = Default.SubjectWithDate; } //this.flag = Default.SubjectOnly; var dateFrom = formatDate(this.fromDate, 'yyyy-MM-dd', 'en-US'); var dateTo = formatDate(this.toDate, 'yyyy-MM-dd', 'en-US'); // Get Filtered Records this.emailsService.GetAllFilterEmailsDetails(dateFrom, dateTo, this.ownerId, this.flag, this.subjectTitle, this.contactId).subscribe( result => { if (result != null) { this.IEmailDetails = result; this.onChangeEmailDataSet.emit(this.IEmailDetails); // console.log(' Get Filtered by Calender : '); // console.log(this.INotes); } else { //console.log(" Error: Get Filtered Records "); } } ); } }