@@ -85,49 +85,49 @@ document.addEventListener("DOMContentLoaded", async function () {
8585
8686//Function to add consultancy feedback (stored as an array)
8787
88- async function addConsultancyRemark ( email , remark , date ) {
89- if ( ! email || ! remark || ! date ) {
90- alert ( "Please enter a remark and select a valid date." ) ;
91- return ;
92- }
93-
94- try {
95- const userRef = doc ( db , "user_consultancies" , email ) ; // Use email as document ID
96- const userDoc = await getDoc ( userRef ) ;
97- console . log ( userDoc ) ;
98-
99- if ( userDoc . exists ( ) ) {
100- // Update existing document: push new remark to array
101- await updateDoc ( userRef , {
102- remarks : arrayUnion ( {
103- text : remark ,
104- date : Timestamp . fromDate ( new Date ( date ) ) ,
105- createdAt : Timestamp . now ( )
106- } ) ,
107- updatedAt : Timestamp . now ( )
108- } ) ;
109- } else {
110- // Create new document with remarks array
111- await setDoc ( userRef , {
112- email : email ,
113- remarks : [
114- {
115- text : remark ,
116- date : Timestamp . fromDate ( new Date ( date ) ) ,
117- createdAt : Timestamp . now ( )
118- }
119- ] ,
120- createdAt : Timestamp . now ( ) ,
121- updatedAt : Timestamp . now ( )
122- } ) ;
123- }
124-
125- alert ( "Remark added successfully!" ) ;
126- } catch ( error ) {
127- console . error ( "Error adding consultancy remark:" , error ) ;
128- alert ( "Failed to add remark. Please try again." ) ;
129- }
130- }
88+ // async function addConsultancyRemark(email, remark, date) {
89+ // if (!email || !remark || !date) {
90+ // alert("Please enter a remark and select a valid date.");
91+ // return;
92+ // }
93+
94+ // try {
95+ // const userRef = doc(db, "user_consultancies", email); // Use email as document ID
96+ // const userDoc = await getDoc(userRef);
97+ // console.log(userDoc);
98+
99+ // if (userDoc.exists()) {
100+ // // Update existing document: push new remark to array
101+ // await updateDoc(userRef, {
102+ // remarks: arrayUnion({
103+ // text: remark,
104+ // date: Timestamp.fromDate(new Date(date)),
105+ // createdAt: Timestamp.now()
106+ // }),
107+ // updatedAt: Timestamp.now()
108+ // });
109+ // } else {
110+ // // Create new document with remarks array
111+ // await setDoc(userRef, {
112+ // email: email,
113+ // remarks: [
114+ // {
115+ // text: remark,
116+ // date: Timestamp.fromDate(new Date(date)),
117+ // createdAt: Timestamp.now()
118+ // }
119+ // ],
120+ // createdAt: Timestamp.now(),
121+ // updatedAt: Timestamp.now()
122+ // });
123+ // }
124+
125+ // alert("Remark added successfully!");
126+ // } catch (error) {
127+ // console.error("Error adding consultancy remark:", error);
128+ // alert("Failed to add remark. Please try again.");
129+ // }
130+ // }
131131
132132//Function to add interview feedback (stored as an array)
133133
@@ -517,12 +517,14 @@ let currentPage = 1;
517517const rowsPerPage = 5 ;
518518
519519//function to populate table
520+
520521async function populateUserProfilesTable ( data ) {
521522 const tableBody = document . querySelector ( "#userProfilesTable tbody" ) ;
522523 tableBody . innerHTML = "" ; // Clear existing rows
523524
524525 try {
525526 let selectedRating = document . getElementById ( "ratingDropdown" ) . value ; // Get selected rating
527+ const globalSearchValue = document . getElementById ( "globalSearch" ) . value . toLowerCase ( ) . trim ( ) ;
526528 let filteredUsers = [ ] ;
527529
528530 if ( selectedRating && selectedRating !== "all" ) {
@@ -534,6 +536,65 @@ async function populateUserProfilesTable(data) {
534536 console . log ( "Selected Rating:" , selectedRating ) ;
535537console . log ( "Filtered Users:" , filteredUsers ) ;
536538
539+ // calculating experience
540+ function calculateExperience ( start , end ) {
541+ const startDate = new Date ( start ) ;
542+ const endDate = new Date ( end ) ;
543+ if ( isNaN ( startDate ) || isNaN ( endDate ) ) return "Invalid dates" ;
544+
545+ const months =
546+ ( endDate . getFullYear ( ) - startDate . getFullYear ( ) ) * 12 +
547+ ( endDate . getMonth ( ) - startDate . getMonth ( ) ) ;
548+
549+ if ( months < 12 ) return `${ months } months` ;
550+ const years = Math . floor ( months / 12 ) ;
551+ const remMonths = months % 12 ;
552+ return `${ years } year${ years > 1 ? "s" : "" } ${ remMonths ? ` ${ remMonths } months` : "" } ` ;
553+ }
554+ // Apply Global Search Filtering (after all other filters)
555+ if ( globalSearchValue ) {
556+ filteredUsers = filteredUsers . filter ( user => {
557+ const values = [
558+ user . about ?. firstName ,
559+ user . about ?. lastName ,
560+ user . about ?. email ,
561+ user . about ?. gender ,
562+ user . education ?. [ 0 ] ?. school ,
563+ user . education ?. [ 0 ] ?. degree ,
564+ user . education ?. [ 0 ] ?. graduation_date ,
565+ user . about ?. dob ? calculateAge ( user . about . dob ) . toString ( ) + " years" : "" ,
566+ user . skills ?. join ( ", " ) ,
567+ user . social ?. github ,
568+ user . social ?. instagram ,
569+ user . social ?. linkedin ,
570+ user . social ?. leetcode ,
571+ ...( user . experience || [ ] ) . map ( exp => {
572+ const duration = calculateExperience ( exp . startDate , exp . endDate ) ;
573+ return `${ exp . companyName } ${ duration } ` ;
574+ } ) ,
575+ user . address ?. present ?. address ,
576+ user . address ?. present ?. city ,
577+ user . address ?. present ?. state ,
578+ user . address ?. present ?. zip ,
579+ user . address ?. permanent ?. address ,
580+ user . address ?. permanent ?. city ,
581+ user . address ?. permanent ?. state ,
582+ user . address ?. permanent ?. zip ,
583+ user . rating ?. toString ( ) ,
584+ user . interview ?. feedback || ""
585+ ] ;
586+ return values . filter ( Boolean ) . some ( field =>
587+ typeof field === "string" && field . toLowerCase ( ) . includes ( globalSearchValue )
588+ ) ;
589+
590+
591+ // Check if any field includes the search term
592+ return values . some ( field =>
593+ typeof field === "string" && field . toLowerCase ( ) . includes ( globalSearchValue )
594+ ) ;
595+ } ) ;
596+ }
597+
537598 if ( ! Array . isArray ( filteredUsers ) || filteredUsers . length === 0 ) {
538599 tableBody . innerHTML = "<tr><td colspan='14'>No users found</td></tr>" ;
539600 updatePaginationControls ( 0 ) ;
@@ -592,21 +653,7 @@ console.log("Filtered Users:", filteredUsers);
592653
593654 ` ;
594655
595- // calculating experience
596- function calculateExperience ( start , end ) {
597- const startDate = new Date ( start ) ;
598- const endDate = new Date ( end ) ;
599- if ( isNaN ( startDate ) || isNaN ( endDate ) ) return "Invalid dates" ;
600-
601- const months =
602- ( endDate . getFullYear ( ) - startDate . getFullYear ( ) ) * 12 +
603- ( endDate . getMonth ( ) - startDate . getMonth ( ) ) ;
604-
605- if ( months < 12 ) return `${ months } months` ;
606- const years = Math . floor ( months / 12 ) ;
607- const remMonths = months % 12 ;
608- return `${ years } year${ years > 1 ? "s" : "" } ${ remMonths ? ` ${ remMonths } months` : "" } ` ;
609- }
656+
610657
611658 // Rating Dropdown
612659 // const ratingCell = document.createElement("td");
@@ -677,6 +724,12 @@ row.appendChild(ratingCell);
677724 console . error ( "Error getting user profiles:" , error ) ;
678725 }
679726}
727+ function handleGlobalSearch ( ) {
728+ populateUserProfilesTable ( ) ;
729+ }
730+ window . handleGlobalSearch = handleGlobalSearch ;
731+
732+
680733
681734// calculating age from dob
682735function calculateAge ( dob ) {
0 commit comments