import { Component, OnInit, ViewChild } from '@angular/core'; import { MenuItem, DialogService } from 'primeng/api'; import { AddJobPlanComponent } from '../popups/add-job-plan/add-job-plan.component'; import { ActivatedRoute } from '@angular/router'; import { AddMessageComponent } from '../popups/add-message/add-message.component'; import { JobPlanDetailComponent } from '../job-plan-detail/job-plan-detail.component'; import { AddDocumentComponent } from '../popups/add-document/add-document.component'; import { JobMessagesComponent } from '../job-messages/job-messages.component'; import { JobDocumentsComponent } from '../job-documents/job-documents.component'; import * as moment_ from 'moment'; import { CookieService } from 'ngx-cookie-service'; import { ClientDetails } from '../../shared/core/IClientDetails'; import { ActivityServicesService } from '../../shared/services/activity-services.service'; import { DashboardServicesService } from '../../shared/services/dashboard-services.service'; const moment = moment_; @Component({ selector: 'app-client-detail', templateUrl: './client-detail.component.html', styleUrls: ['./client-detail.component.scss'], }) export class ClientDetailComponent implements OnInit { @ViewChild(JobDocumentsComponent) JobDocumentsComponent: JobDocumentsComponent; @ViewChild(JobMessagesComponent) child2: JobMessagesComponent; @ViewChild(JobPlanDetailComponent) child: JobPlanDetailComponent; columns: { field: string; header: string; width: string }[]; items: MenuItem[]; // Message Tabs messageTabs: MenuItem[]; // Document Tabs documentTabs: MenuItem[]; // Phase Tabs phaseTabs: MenuItem[]; documents: any; brands: any; // Client Id clientId: string; // Get Client details ClientDetails: ClientDetails[]; // Loged Staff Id staffId: string; // Client name clientName: string; // Number of active job activeJobsCount: number; // Today currentDate: Date; // Date Difference diffDays: number; // Due date dueDate: Date; // Minimum Date minmumDate: Date; // Display date displayDate: Date; disaplyMessageTabs = false; // To display document popdetails displayDocumentTabs = false; // To display phase disaplyPhaseTabs = false; subjectName: any; putSubjectArray: any = []; // Category, Sub category, Topic , Super category arrays passing to the api request topicArray = []; categoryArray = []; subCategoryArray = []; superCategoryArray = []; topicName: any; subjectId: any; locationDetails = {}; subjects: any = []; locationId = 0; type = 0; categoryName: any; subCategoryName: any; superCatName: any; // Job plans by location jobPlansbyLocation = []; jobPlansbyLocationSubject: any = []; jobPlansbyLocationTopic: any = []; jobPlansbyLocationCategory: any = []; jobPlansbyLocationSubCategory: any = []; // Click on Job plan card - variables subjectIdbyClick: any; topicIdbyClick: any; categoryIdbyClick: any; subCategoryIdbyClick: any; superCatgoryIdbyClick: any; // Location flags to hide location details topicsShowFlag = false; categoryShowFlag = false; subCategoryShowFlag = false; superCategoryShowFlag = false; // locations by location id - arrays locationsByLocationSubject: any = []; locationsByLocationTopic: any = []; locationsByLocationCategory: any = []; locationsByLocationSubCategory: any = []; subCatgoryIdbyClick: any; onClickJPId: any; showJobPlanDetails = false; // Show/hide boolean flags for location add buttons subCategoryAddButton = false; superCategoryAddButton = false; categoryAddButton = false; topicAddbutton = false; locationIdForAddJP: number; onLickJobPlanId: any; // Location Types // 1 = Subjects // 2 = Topic // 3 = Category // 4 = Sub Category // 5 = Super Category // Global Job Plan Id jobPlanId: number; pageSizes: { label: string; value: number; }[]; // Default Messages defaultMessage: string; topicMessage: string; categoryMessage: string; subCategoryMessage: string; superCategoryMessage: string; // Subject Count numberOfActivities: number; // Snapzing Variable showLoading: boolean = false; constructor(public dialogService: DialogService, private route: ActivatedRoute, private activitiesService: ActivityServicesService, private cookieService: CookieService, private dashboardService: DashboardServicesService) { this.columns = [ { field: 'cSubject', header: 'Subject', width: '25%' }, { field: 'cTopic', header: 'Topic', width: '20%' }, { field: 'cCategory', header: 'Category', width: '20%' }, { field: 'csubCategory', header: 'Sub Category', width: '15%' }, { field: 'csuperSub', header: 'Super Category', width: '15%' } ]; } ngOnInit() { // Enable phase tab this.disaplyPhaseTabs = true; // list of the organisation table columns this.documents = [{ }]; // show page tab list this.phaseTabs = [ { label: 'Phases', command: () => { this.disaplyPhaseTabs = true; this.disaplyMessageTabs = false; this.displayDocumentTabs = false; } }, { label: 'Messages', command: () => { this.disaplyMessageTabs = true; // this.child2.getMessagesExternal(this.jobPlanId, 'EXTERNAL'); // this.child2.getMessagesInternal(this.jobPlanId, 'INTERNAL'); this.disaplyPhaseTabs = false; this.displayDocumentTabs = false; } }, { label: 'Documents', command: () => { this.disaplyMessageTabs = false; this.displayDocumentTabs = true; this.disaplyPhaseTabs = false; } }, ]; this.messageTabs = [ { label: '+ Add Client Message', command: () => { // Open the add message popup const ref = this.dialogService.open(AddMessageComponent, { showHeader: false, width: '50%', data: { isInternalMessage: false, JobPlanId: this.jobPlanId } }); ref.onClose.subscribe(() => { // this.JobMessagesComponent.getMessagesExternal(this.jobPlanId, 'EXTERNAL'); // this.child2.getMessagesExternal(this.jobPlanId, 'EXTERNAL'); this.activitiesService.GetAllMessage(this.jobPlanId, 'EXTERNAL').subscribe( data => { this.child2.setExternelMsgDetails(data); } ); }); } }, { label: '+ Add Internal Message', command: () => { // Open the add message popup const ref = this.dialogService.open(AddMessageComponent, { showHeader: false, width: '50%', data: { isInternalMessage: true, JobPlanId: this.jobPlanId } }); ref.onClose.subscribe(() => { // this.JobMessagesComponent.getMessagesInternal(this.jobPlanId, 'INTERNAL'); this.child2.getMessagesInternal(this.jobPlanId, 'INTERNAL'); }); } } ]; this.documentTabs = [ // Document { label: '+ Add Document', command: () => { // Open the add message popup const ref = this.dialogService.open(AddDocumentComponent, { showHeader: false, width: '50%', data: { JobPlanId: this.jobPlanId } }); // debugger; ref.onClose.subscribe(() => { this.JobDocumentsComponent.GetAllDocuments(this.jobPlanId); this.JobDocumentsComponent.GetAllDocumentTypes(); } ); } } ]; // this.phaseTabs = [ // // Phase // { // label: '+ Add Phase with Job Plan Editor', command: (event) => { // } // } // ]; /** get parameter contactId */ this.route.paramMap.subscribe(params => { this.clientId = params.get('clientId'); this.staffId = params.get('staffId'); }); // Get Client Details this.GetClientDetailsById(this.clientId, this.staffId, +this.cookieService.get('CompanyId')); // Get Job Plan locations this.getJobPlansByLocation(this.clientId, this.locationId, this.type); this.topicMessage = 'Select a subject view topics'; this.categoryMessage = 'Select a topic view categories'; this.subCategoryMessage = 'Select a categories view sub-categories'; this.superCategoryMessage = 'Select a sub-categories view super-categories'; } // Get client details by id GetClientDetailsById(clientId, staffId, companyID) { this.activitiesService.GetClientDetailsById(clientId, staffId, companyID).subscribe( result => { if (result != null) { this.ClientDetails = result; this.clientName = this.ClientDetails[0].ClientName; this.activeJobsCount = this.ClientDetails[0].JobPlans.length; this.subjects = this.ClientDetails[0].SubjectList; if (this.ClientDetails !== null && this.ClientDetails !== undefined) { if (this.ClientDetails[0].SubjectList.length === 0 && this.ClientDetails[0].JobPlans.length === 0) { this.defaultMessage = 'There is no job under this section'; // console.log(this.defaultMessage); } else { this.numberOfActivities = this.ClientDetails[0].JobPlans.length; console.log(this.numberOfActivities); } } if (this.ClientDetails.length > 0) { if (this.ClientDetails[0].JobPlans.length > 0) { // tslint:disable-next-line: prefer-for-of for (let i = 0; i < this.ClientDetails[0].JobPlans.length; i++) { this.currentDate = new Date(); this.diffDays = moment(this.ClientDetails[0].JobPlans[i].EndDate).diff(moment(this.currentDate), 'days'); if (this.diffDays < 0) { this.dueDate = this.ClientDetails[0].JobPlans[i].EndDate; } else { this.minmumDate = this.ClientDetails[0].JobPlans[i].EndDate; } } if (this.dueDate != null) { this.displayDate = this.dueDate; } else { this.displayDate = this.minmumDate; } } } } else { console.log('GetClientDetailsById Fail.'); } } ); } showAddJobPlans(type) { if (type === 0) { this.locationIdForAddJP = 0; } else if (type === 1) { this.locationIdForAddJP = this.subjectIdbyClick; } else if (type === 2) { this.locationIdForAddJP = this.topicIdbyClick; } else if (type === 3) { this.locationIdForAddJP = this.categoryIdbyClick; } else if (type === 4) { this.locationIdForAddJP = this.subCatgoryIdbyClick; } const ref = this.dialogService.open(AddJobPlanComponent, { data: { activityFlag: true, typeId: type, locationId: this.locationIdForAddJP, clientId: this.clientId }, header: 'Add New Job Plan', width: '40%' }); ref.onClose.subscribe(() => { if (type === 0) { this.getJobPlansByLocation(this.clientId, 0, 0); // Get active clients job plans this.GetClientDetailsById(this.clientId, this.staffId, +this.cookieService.get('CompanyId')); } else if (type === 1) { // Get active clients job plans this.GetClientDetailsById(this.clientId, this.staffId, +this.cookieService.get('CompanyId')); this.getJobPlansByLocation(this.clientId, this.subjectIdbyClick, type); } else if (type === 2) { // Get active clients job plans this.GetClientDetailsById(this.clientId, this.staffId, +this.cookieService.get('CompanyId')); this.getJobPlansByLocation(this.clientId, this.topicIdbyClick, type); } else if (type === 3) { // Get active clients job plans this.GetClientDetailsById(this.clientId, this.staffId, +this.cookieService.get('CompanyId')); this.getJobPlansByLocation(this.clientId, this.categoryIdbyClick, type); } else if (type === 4) { // Get active clients job plans this.GetClientDetailsById(this.clientId, this.staffId, +this.cookieService.get('CompanyId')); this.getJobPlansByLocation(this.clientId, this.subCatgoryIdbyClick, type); } }); } focusOutFunction(type, location) { // Check location type to save data if (type === 1) { this.subjectId = -1; } else if (type === 2) { this.subjectId = this.subjectIdbyClick; const topicObj = { SubjectsId: this.subjectIdbyClick, TopicId: -1, TopicDescription: location }; this.topicArray = []; this.topicArray.push(topicObj); this.categoryArray = []; this.subCategoryArray = []; this.superCategoryArray = []; } else if (type === 3) { this.subjectId = this.subjectIdbyClick; const categoryObj = { TopicId: this.topicIdbyClick, CategoryId: -1, CategorDescription: location }; this.categoryArray = []; this.categoryArray.push(categoryObj); this.topicArray = []; this.subCategoryArray = []; this.superCategoryArray = []; } else if (type === 4) { this.subjectId = this.subjectIdbyClick; const subCategoryObj = { CategoryId: this.categoryIdbyClick, SubCategoryId: -1, SubCategoryDescription: location }; this.subjectId = this.subjectIdbyClick; this.subCategoryArray = []; this.subCategoryArray.push(subCategoryObj); this.topicArray = []; this.categoryArray = []; this.superCategoryArray = []; } else if (type === 5) { this.subjectId = this.subjectIdbyClick; const superCategoryObj = { SubCategoryId: this.subCatgoryIdbyClick, SuperCategorId: -1, SuperCategoryDescription: location }; this.superCategoryArray = []; this.superCategoryArray.push(superCategoryObj); this.topicArray = []; this.categoryArray = []; this.subCategoryArray = []; } this.locationDetails = { SubjectsId: this.subjectId, ClientId: this.clientId, SubjectsDescription: this.subjectName, TopicsList: this.topicArray, CategoryList: this.categoryArray, SubCategoryList: this.subCategoryArray, SuperCategoryList: this.superCategoryArray }; this.activitiesService.saveLocationStructure(this.locationDetails) .subscribe(res => { if (type === 1) { this.GetClientDetailsById(this.clientId, this.staffId, +this.cookieService.get('CompanyId')); } else if (type === 2) { this.getLocationsByLocationId(this.clientId, res, 2); } else if (type === 3) { this.getLocationsByLocationId(this.clientId, res, 3); } else if (type === 4) { this.getLocationsByLocationId(this.clientId, res, 4); } else if (type === 5) { this.getLocationsByLocationId(this.clientId, res, 5); } }, error => console.log('Error', error)); } getJobPlansByLocation(clientId, locationId, type) { debugger this.showLoading = true; this.activitiesService.getJobPlansByLocation(clientId, locationId, type) .subscribe(res => { if (type === 0) { this.jobPlansbyLocation = res; this.showLoading = false; } else if (type === 1) { this.jobPlansbyLocationSubject = res; for (let i = 0; this.subjects.length; i++) { if (this.subjects[i]['SubjectsId'] == locationId) { this.subjects[i]['JobCount'] = this.jobPlansbyLocationSubject.length; } } this.showLoading = false; } else if (type === 2) { this.jobPlansbyLocationTopic = res; for (let i = 0; this.locationsByLocationSubject.length; i++) { if (this.locationsByLocationSubject[i]['TopicId'] == locationId) { // this.locationsByLocationSubject[i]['JobCount'] = this.jobPlansbyLocationTopic.length; } } this.showLoading = false; // this.numberOfTopinJobPlan = this.jobPlansbyLocationTopic.length; } else if (type === 3) { this.jobPlansbyLocationCategory = res; for (let i = 0; this.locationsByLocationTopic.length; i++) { if (this.locationsByLocationTopic[i]['CategoryId'] == locationId) { this.locationsByLocationTopic[i]['JobCount'] = this.jobPlansbyLocationCategory.length; } } this.showLoading = false; //this.numberOfCategoryJobPlan = this.jobPlansbyLocationCategory.length; } else if (type === 4) { this.jobPlansbyLocationSubCategory = res; for (let i = 0; this.locationsByLocationCategory.length; i++) { if (this.locationsByLocationCategory[i]['SubCategoryId'] == locationId) { this.locationsByLocationCategory[i]['JobCount'] = this.jobPlansbyLocationSubCategory.length; } } this.showLoading = false; //this.numberOfSubCategoryJobPlan = this.jobPlansbyLocationSubCategory.length; } }, error => console.log('Error', error)); this.showLoading = false; } clickOnSubject(subjectId) { this.subjectIdbyClick = subjectId; this.topicsShowFlag = true; this.categoryShowFlag = false; this.subCategoryShowFlag = false; this.superCategoryShowFlag = false; this.topicAddbutton = true; this.categoryAddButton = false; this.subCategoryAddButton = false; this.superCategoryAddButton = false; this.getJobPlansByLocation(this.clientId, subjectId, 1); this.getLocationsByLocationId(this.clientId, subjectId, 2); } clickOnTopic(topicId) { this.topicIdbyClick = topicId; this.categoryShowFlag = true; this.subCategoryShowFlag = false; this.superCategoryShowFlag = false; this.topicAddbutton = false; this.categoryAddButton = true; this.subCategoryAddButton = false; this.superCategoryAddButton = false; this.getJobPlansByLocation(this.clientId, topicId, 2); this.getLocationsByLocationId(this.clientId, topicId, 3); } clickOnCategory(categoryId) { this.categoryIdbyClick = categoryId; this.subCategoryShowFlag = true; this.categoryAddButton = false; this.subCategoryAddButton = true; this.topicAddbutton = false; this.superCategoryAddButton = false; this.getJobPlansByLocation(this.clientId, categoryId, 3); this.getLocationsByLocationId(this.clientId, categoryId, 4); } clickOnSubCategory(subCategoryId) { this.subCatgoryIdbyClick = subCategoryId; this.superCategoryShowFlag = true; this.topicAddbutton = false; this.categoryAddButton = false; this.subCategoryAddButton = false; this.superCategoryAddButton = true; this.getJobPlansByLocation(this.clientId, subCategoryId, 4); this.getLocationsByLocationId(this.clientId, subCategoryId, 5); } getLocationsByLocationId(clientId, locationId, type) { this.activitiesService.getlocationsByLocation(clientId, locationId, type) .subscribe(res => { if (type === 2) { this.locationsByLocationSubject = res[0].TopicsList; } else if (type === 3) { this.locationsByLocationTopic = res[0].CategoryList; } else if (type === 4) { this.locationsByLocationCategory = res[0].SubCategoryList; } else if (type === 5) { this.locationsByLocationSubCategory = res[0].SuperCategoryList; } }, error => console.log('Error', error)); } onClickJobPlan(id) { this.jobPlanId = id; this.showJobPlanDetails = true; this.onLickJobPlanId = id; this.child.getJobPlanById(id); } doubleClick(id) { console.log('Double Click', id); } // Copy job plan CopyJobPlan(JobPlanId) { // console.log(JobPlanId, this.clientId); this.showLoading = true; this.dashboardService.CopyJobPlan(+this.cookieService.get('CompanyId'), JobPlanId, +this.clientId, 'COPY').subscribe( data => { if (data !== null && data !== undefined) { this.ngOnInit(); this.showLoading = false; } } ); } // Delete job plan DeleteJobPlan(JobPlanId) { // console.log(JobPlanId, this.clientId); this.showLoading = true; this.dashboardService.CopyJobPlan(+this.cookieService.get('CompanyId'), JobPlanId, +this.clientId, 'DEL').subscribe( data => { if (data !== null && data !== undefined) { this.ngOnInit(); this.showLoading = false; } } ); } }