EchoTex_Payroll/HRM.UI/ClientApp/src/app/picker/portal-cv-picker.component.ts

523 lines
25 KiB
TypeScript
Raw Normal View History

2024-10-14 10:01:49 +06:00
import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
import { ApiService } from '../app.api.service';
import { EmployeeServices } from '../_services/employee/employee.service';
import { DataStateChangeEvent, GridDataResult, SelectableSettings } from '@progress/kendo-angular-grid';
import { SearchEmployee, SearchManager } from '../_models/Employee/searchEmployee';
import { EnumExtension, EnumGender, EnumSearchFrom, EnumSearchObjDataType, EnumSearchParameter, EnumSQLOperator } from '../_models/enums';
import { DynamicPicker, EnumDynamicpickerType } from './dynamic-picker/Dynamic-Picker';
import { BasicService } from '../_services/Basic/basic.service';
import { Subscription, Subject } from 'rxjs';
import { PickerDataTransferService } from '../data.transfer.service';
import { loadingPanelService } from '../hrm-loding panel/loding.panel.service';
import { RecruitmentRequisition } from '../_models/Requisition/recruitmentRequisition';
import { RecruitmentService } from '../_services/recruitment/recruitment.service';
import { CV } from '../_models/Recruitement/CV';
import { Candidate } from '../_models/Recruitement/Candidate';
import { process, State } from '@progress/kendo-data-query';
import { DomSanitizer } from '@angular/platform-browser';
import { InternalRecruitment } from '../_models/Requisition/InternalRecruitment';
import { ErCV } from '../_models/Recruitement/ercv';
@Component({
selector: 'app-portal-cv-picker',
templateUrl: './portal-cv-picker.component.html',
//styleUrls: ['../../assets/kendo-grid/grid.css'],
encapsulation: ViewEncapsulation.None,
})
export class PortalCVPickerComponent implements OnInit {
valueChangedSubscription: Subscription;
genders: any = EnumExtension.getNamesAndValues(EnumGender);
public active = true;
public showPopUp = false;
public checkboxOnly = false;
public mode = 'multiple';
public selectableSettings: SelectableSettings;
taggedSelection: number[] = [];
CandidateItems: Candidate[] = [];
assignCandidate: Candidate;
public searchItems: ErCV[];
public selectedItems: RecruitmentRequisition[] = [];
public selectedItem: InternalRecruitment;
public selectedCV: ErCV;
public searchCVs: ErCV[];
CVItems: ErCV[] = [];
public gridState: State = {
sort: [],
skip: 0,
take: 10
};
public state: State = {
skip: 0,
take: 10
};
//@Input() isRequisitionActive: boolean;
public isRequisitionSelected;
public gridView: GridDataResult;
ItemCount: number = 0;
@Input() pickerFormGroup: FormGroup;
@Output() ItemSelected: EventEmitter<any> = new EventEmitter();
objectUrl: string;
@Input()
public set setSelectedItem(inputedItem: InternalRecruitment) {
debugger;
if (inputedItem !== undefined) {
this.selectedItem = inputedItem;
this.selectedItemText = this.selectedItem.positionName;
this.portalCvLoad(inputedItem.id);
} else {
this.selectedItem = new InternalRecruitment();
this.selectedItemText = '';
}
}
cvCount: number;
private empCodeNameList: Array<string>;
private empCodeNameListSource: Array<string>;
public selectedItemText: string;
public gridMultiSelect = false;
@Input()
public set MultiSelect(ismultiselect: boolean) {
if (ismultiselect !== undefined) {
/* this.gridMultiSelect = true;*/
this.gridMultiSelect = ismultiselect;
this.setSelectableSettings();
}
}
@Input()
public set isActive(isActive: boolean) {
this.active = isActive;
}
@Input()
public set isRequisitionActive(isRequisition: boolean) {
//this.isRequisitionSelected = true;
//if (isRequisition !== undefined) {
// this.isRequisitionSelected = !isRequisition;
//}
this.isRequisitionSelected = !isRequisition;
}
/** role-permission-entry ctor */
constructor(public api: ApiService,
public formBuilder: FormBuilder,
public router: Router,
public route: ActivatedRoute,
public empSrvc: EmployeeServices,
public basicService: BasicService,
public pickerService: PickerDataTransferService,
public loadingService: loadingPanelService,
public recruitmentService: RecruitmentService,
private sanitizer: DomSanitizer
) {
if (this.pickerFormGroup === undefined) {
this.pickerFormGroup = new FormGroup({
});
}
}
ngOnInit() {
this.setSelectableSettings();
this.valueChangedSubscription == this.pickerService.dataChanged.subscribe(
x => {
if (x) {
//this.employeeCount = x;
}
}
);
}
public GetSelectedRequisition(childData) {
//this.selectedRequisition = new InternalRecruitment();
//this.selectedRequisition = childData;
this.CVItems = [];
this.loadGrid();
this.portalCvLoad(childData.id);
}
setSelectableSettings(): void {
this.selectableSettings = {
checkboxOnly: true,
mode: 'multiple', // this.mode
};
}
//public portalCvLoad(requisitionID:number) {
// this.searchItems = [];
// this.loadingService.ShowLoadingPanel = true;
// this.recruitmentService.getOnlinePortalCVs(requisitionID).subscribe(
// (resp) => {
// this.searchItems = resp;
// },
// (x) => {
// console.log(x);
// this.loadingService.ShowLoadingPanel = false;
// },
// () => {
// console.log(this.searchItems);
// this.loadingService.ShowLoadingPanel = false;
// if (this.searchItems !== undefined && this.searchItems.length > 0) {
// debugger;
// this.searchItems.forEach(x => {
// if (x.irFileAttacments !== null && x.irFileAttacments.length > 0) {
// x.irFileAttacments.forEach(y => {
// if (y.fileType === 10) {
// let fileName = y.originalFileName;
// let str = y.fileTobase64;
// var fileExtension = fileName.split('.').pop();
// let _type = this.function(fileExtension.toLowerCase());
// const byteCharacters = atob(str);
// const byteNumbers = new Array(byteCharacters.length);
// for (let i = 0; i < byteCharacters.length; i++) {
// byteNumbers[i] = byteCharacters.charCodeAt(i);
// }
// const byteArray = new Uint8Array(byteNumbers);
// const blob = new Blob([byteArray], { type: _type });
// // x.imageBlob = blob;
// let objectUrl = URL.createObjectURL(blob);
// x.profilePhotoUrl = this.sanitizer.bypassSecurityTrustResourceUrl(objectUrl);
// }
// })
// }
// if (this.CVItems !== undefined && this.CVItems.length > 0) {
// debugger;
// console.log(this.CVItems);
// let ItemExist = this.CVItems.find(c => c.id === x.id);
// if (ItemExist === undefined) {
// let temp = new CV();
// temp = x;
// temp.details = "Name: " + x.name + "\n" + "Mobile: " + x.mobile + "\n" + "Email: " + x.email + "\n" + "Expected Salary: " + "\n";
// if (x.allEduQualifications !== undefined && x.allEduQualifications.length > 0) {
// for (let i = 0; i < x.allEduQualifications.length; i++) {
// debugger;
// temp.educationalSummary = "Degree Title: " + (x.allEduQualifications[i].educationLevels.length > 0 ? (x.allEduQualifications[i].educationLevels.find(c => c.id == x.allEduQualifications[i].degreeTitleID).description) : "") + "\n"
// + "Department: " + (x.allEduQualifications[i].disciplines.length < 0 ) ? "" : x.allEduQualifications[i].disciplines.find(c => c.id == x.allEduQualifications[i].disciplineID).description + "\n"
// + "Institute: " + x.allEduQualifications[i].instituteName + "\n"
// + "Passing Year: " + x.allEduQualifications[i].passingYear + "\n"
// + "CGPA: " + x.allEduQualifications[i].outOF + "\n"
// }
// }
// if (x.allExperiences !== undefined && x.allExperiences.length > 0) {
// for (let i = 0; i < x.allExperiences.length; i++) {
// const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
// let firstDate: any = new Date(x.allExperiences[i].fromDate);
// let secondDate: any = new Date(x.allExperiences[i].toDate);
// let diffTime = Math.abs(secondDate - firstDate);
// const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
// temp.careerSummary = "Total Experince: " + diffDays + "\n"
// + "Company: " + x.allExperiences[i].industry + "\n"
// + "Position: " + x.allExperiences[i].designation + "\n"
// + "Role: " + x.allExperiences[i].roleDefination + "\n"
// }
// }
// this.CVItems.push(temp);
// }
// }
// else {
// let temp = new CV();
// temp = x;
// temp.details = "Name: " + x.name + "\n" + "Mobile: " + x.mobile + "\n" + "Email: " + x.email + "\n" + "Expected Salary: " + "\n";
// if (x.allEduQualifications !== undefined && x.allEduQualifications.length > 0) {
// for (let i = 0; i < x.allEduQualifications.length; i++) {
// temp.educationalSummary = "Degree Title: " + (x.allEduQualifications[i].educationLevels.length > 0 ? (x.allEduQualifications[i].educationLevels.find(c => c.id == x.allEduQualifications[i].degreeTitleID).description) : "")
// + "\n"
// + "Department: " + (x.allEduQualifications[i].disciplines.length > 0 ? x.allEduQualifications[i].disciplines.find(c => c.id == x.allEduQualifications[i].disciplineID).description : " ") + "\n"
// + "Institute: " + x.allEduQualifications[i].instituteName + "\n"
// + "Passing Year: " + x.allEduQualifications[i].passingYear + "\n"
// + "CGPA: " + x.allEduQualifications[i].outOF + "\n"
// }
// }
// if (x.allExperiences !== undefined && x.allExperiences.length > 0) {
// for (let i = 0; i < x.allExperiences.length; i++) {
// const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
// let firstDate: any = new Date(x.allExperiences[i].fromDate);
// let secondDate: any = new Date(x.allExperiences[i].toDate);
// let diffTime = Math.abs(secondDate - firstDate);
// const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
// temp.careerSummary = "Total Experince: " + diffDays + "\n"
// + "Company: " + x.allExperiences[i].industry + "\n"
// + "Position: " + x.allExperiences[i].designation + "\n"
// + "Role: " + x.allExperiences[i].roleDefination + "\n"
// }
// }
// this.CVItems.push(temp);
// }
// })
// }
// //this.saveMultipleCandidates();
// this.loadGrid();
// },
// );
//}
public portalCvLoad(requisitionID: number) {
this.searchItems = [];
this.loadingService.ShowLoadingPanel = true;
this.recruitmentService.getErCvByRequisitionId(requisitionID).subscribe(
(resp) => {
this.searchItems = resp;
},
(x) => {
console.log(x);
this.loadingService.ShowLoadingPanel = false;
},
() => {
console.log(this.searchItems);
this.loadingService.ShowLoadingPanel = false;
if (this.searchItems !== undefined && this.searchItems.length > 0) {
debugger;
this.searchItems.forEach(x => {
if (x.irFileAttacments !== null && x.irFileAttacments.length > 0) {
x.irFileAttacments.forEach(y => {
if (y.fileType === 9) { //ercv
let fileName = y.originalFileName;
let str = y.fileTobase64;
var fileExtension = fileName.split('.').pop();
let _type = this.function(fileExtension.toLowerCase());
const byteCharacters = atob(str);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
const blob = new Blob([byteArray], { type: _type });
// x.imageBlob = blob;
let objectUrl = URL.createObjectURL(blob);
x.profilePhotoUrl = this.sanitizer.bypassSecurityTrustResourceUrl(objectUrl);
}
})
}
if (this.CVItems !== undefined && this.CVItems.length > 0) {
debugger;
console.log(this.CVItems);
let ItemExist = this.CVItems.find(c => c.id === x.id);
if (ItemExist === undefined) {
let temp = new ErCV();
temp = x;
temp.details = "Name: " + x.name + "\n" + "Mobile: " + x.mobile + "\n" + "Email: " + x.email + "\n" + "Expected Salary: " + "\n";
if (x.allEduQualifications !== undefined && x.allEduQualifications.length > 0) {
for (let i = 0; i < x.allEduQualifications.length; i++) {
debugger;
//temp.educationalSummary = "Degree Title: " + (x.allEduQualifications[i].educationLevels.length > 0 ? (x.allEduQualifications[i].educationLevels.find(c => c.id == x.allEduQualifications[i].degreeTitleID).description) : "") + "\n"
// + "Department: " + (x.allEduQualifications[i].disciplines.length < 0) ? "" : x.allEduQualifications[i].disciplines.find(c => c.id == x.allEduQualifications[i].disciplineID).description + "\n"
// + "Institute: " + x.allEduQualifications[i].instituteName + "\n"
// + "Passing Year: " + x.allEduQualifications[i].passingYear + "\n"
// + "CGPA: " + x.allEduQualifications[i].outOF + "\n"
}
}
if (x.allExperiences !== undefined && x.allExperiences.length > 0) {
for (let i = 0; i < x.allExperiences.length; i++) {
const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
let firstDate: any = new Date(x.allExperiences[i].fromDate);
let secondDate: any = new Date(x.allExperiences[i].toDate);
let diffTime = Math.abs(secondDate - firstDate);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
temp.careerSummary = "Total Experince: " + diffDays + "\n"
+ "Company: " + x.allExperiences[i].industry + "\n"
+ "Position: " + x.allExperiences[i].designation + "\n"
+ "Role: " + x.allExperiences[i].roleDefination + "\n"
}
}
this.CVItems.push(temp);
}
}
else {
let temp = new ErCV();
temp = x;
temp.details = "Name: " + x.name + "\n" + "Mobile: " + x.mobile + "\n" + "Email: " + x.email + "\n" + "Expected Salary: " + "\n";
if (x.allEduQualifications !== undefined && x.allEduQualifications.length > 0) {
//for (let i = 0; i < x.allEduQualifications.length; i++) {
// temp.educationalSummary = "Degree Title: " + (x.allEduQualifications[i].educationLevels.length > 0 ? (x.allEduQualifications[i].educationLevels.find(c => c.id == x.allEduQualifications[i].degreeTitleID).description) : "")
// + "\n"
// + "Department: " + (x.allEduQualifications[i].disciplines.length > 0 ? x.allEduQualifications[i].disciplines.find(c => c.id == x.allEduQualifications[i].disciplineID).description : " ") + "\n"
// + "Institute: " + x.allEduQualifications[i].instituteName + "\n"
// + "Passing Year: " + x.allEduQualifications[i].passingYear + "\n"
// + "CGPA: " + x.allEduQualifications[i].outOF + "\n"
//}
}
if (x.allExperiences !== undefined && x.allExperiences.length > 0) {
for (let i = 0; i < x.allExperiences.length; i++) {
const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
let firstDate: any = new Date(x.allExperiences[i].fromDate);
let secondDate: any = new Date(x.allExperiences[i].toDate);
let diffTime = Math.abs(secondDate - firstDate);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
temp.careerSummary = "Total Experince: " + diffDays + "\n"
+ "Company: " + x.allExperiences[i].industry + "\n"
+ "Position: " + x.allExperiences[i].designation + "\n"
+ "Role: " + x.allExperiences[i].roleDefination + "\n"
}
}
this.CVItems.push(temp);
}
})
}
//this.saveMultipleCandidates();
this.loadGrid();
},
);
}
loadGrid() {
this.gridView = process(this.CVItems, this.state);
}
public dataStateChange(state: DataStateChangeEvent): void {
this.state = state;
this.gridView = process(this.CVItems, this.state);
}
//saveMultipleCandidates() {
// this.CandidateItems = [];
// this.CVItems.forEach(
// x => {
// if (x.candidateID === undefined || x.candidateID === null || x.candidateID === 0) {
// this.assignCandidate = new Candidate();
// this.assignCandidate.startDate = new Date();
// this.assignCandidate.isEmployee = false;
// this.assignCandidate.isSelected = false;
// this.assignCandidate.processId = 0//this.selectedRequisition.id;
// this.assignCandidate.cvID = x.id;
// this.assignCandidate.cv = new CV();
// this.assignCandidate.cv = x;
// this.CandidateItems.push(this.assignCandidate);
// }
// }
// );
// this.loadingService.ShowLoadingPanel = true;
// this.recruitmentService.saveCandidatesforRecruitment(this.CandidateItems).subscribe(
// (resp) => {
// },
// (x) => {
// this.showError(x.message);
// this.loadingService.ShowLoadingPanel = false;
// },
// () => {
// // this._notificationService.showSuccess('Saved Successfully');
// this.loadingService.ShowLoadingPanel = false;
// // this.previousCVLoad();
// }
// );
//}
function(ext) {
if (ext != undefined) {
return this.extToMimes(ext);
}
return undefined;
}
extToMimes(ext) {
let type = undefined;
switch (ext) {
case 'jpg':
type = 'image/jpeg';
break;
case 'png':
type = 'image/jpeg';
break;
case 'jpeg':
type = 'image/jpeg';
break;
case 'txt':
type = 'text/plain';
break;
case 'xls':
type = 'application/vnd.ms-excel';
break;
case 'doc':
type = 'application/msword';
break;
case 'xlsx':
type = 'application/vnd.ms-excel';
break;
default:
}
return type;
}
showError(message: any) {
throw new Error('Method not implemented.');
}
//search() {
// this.loadingService.ShowLoadingPanel = true;
// this.recruitmentService.getCVs().subscribe(
// (resp) => {
// this.searchItems = resp;
// },
// (x) => {
// console.log(x);
// this.loadingService.ShowLoadingPanel = false;
// },
// () => {
// this.loadingService.ShowLoadingPanel = false;
// },
// );
//}
public onCancel(e): void {
this.closeForm();
}
public onSelect(): void {
this.searchCVs = [];
this.selectedCV = new ErCV();
debugger;
if (this.taggedSelection.length > 0) {
this.taggedSelection.forEach(positionid => {
this.searchCVs.push(this.searchItems.find(x => x.id === positionid));
});
}
this.ItemSelected.emit(this.searchCVs);
this.cvCount = this.searchCVs === undefined ? 0 : this.searchCVs.length;
}
private closeForm(): void {
this.showPopUp = false;
}
private OpenForm(): void {
//this.selectedEmployees = [];
//this.selectedEmployee = new SearchEmployee();
//this.taggedSelection = [];
this.showPopUp = true;
}
onClose() {
}
onSelectCv() {
}
}