coursePanel dropdown, 6 emails per subject
This commit is contained in:
@@ -193,7 +193,7 @@ const ConsolidatedTable = () => {
|
||||
formData.append("file", file);
|
||||
|
||||
try {
|
||||
const emailResponse = await sendEmail(formData);
|
||||
const emailResponse = await sendEmail(formData, "excel");
|
||||
toast.success(`Email sent successfully to ${facultyEmail}`);
|
||||
console.log("Response from server:", emailResponse);
|
||||
} catch (emailError) {
|
||||
|
||||
@@ -43,7 +43,10 @@ const CourseForm = () => {
|
||||
const fetchOptionsAndFaculties = async () => {
|
||||
try {
|
||||
const facultiesData = await fetchFaculties();
|
||||
setOptions((prev) => ({ ...prev, faculties: facultiesData }));
|
||||
const filteredFaculties = facultiesData.filter(
|
||||
(faculty) => faculty.courses.includes(course?.courseId || id) // Only faculties with this course
|
||||
);
|
||||
setOptions((prev) => ({ ...prev, faculties: filteredFaculties }));
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch faculties:", error);
|
||||
}
|
||||
@@ -67,19 +70,22 @@ const CourseForm = () => {
|
||||
};
|
||||
|
||||
const handleAddFaculty = (field) => {
|
||||
if (!formData[field]) return;
|
||||
|
||||
const selectedFaculty = options.faculties.find(
|
||||
(faculty) => faculty.name === formData[field]
|
||||
);
|
||||
|
||||
if (selectedFaculty) {
|
||||
setTempAssignments((prev) => ({
|
||||
...prev,
|
||||
[field]: [...prev[field], selectedFaculty],
|
||||
}));
|
||||
setFormData({ ...formData, [field]: "" });
|
||||
setSuggestions((prev) => ({ ...prev, [field]: [] }));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const handleRemoveFaculty = (field, index) => {
|
||||
setTempAssignments((prev) => {
|
||||
const updatedAssignments = [...prev[field]];
|
||||
@@ -160,13 +166,23 @@ const CourseForm = () => {
|
||||
<div>
|
||||
<label className="courseFormLabel">
|
||||
Course ID:
|
||||
<input type="text" className="courseFormInput courseFormReadOnly" value={course?.courseId || id} readOnly />
|
||||
<input
|
||||
type="text"
|
||||
className="courseFormInput courseFormReadOnly"
|
||||
value={course?.courseId || id}
|
||||
readOnly
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label className="courseFormLabel">
|
||||
Course Name:
|
||||
<input type="text" className="courseFormInput courseFormReadOnly" value={course?.name || ""} readOnly />
|
||||
<input
|
||||
type="text"
|
||||
className="courseFormInput courseFormReadOnly"
|
||||
value={course?.name || ""}
|
||||
readOnly
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div className={errors.examPeriod ? "courseFormErrorSelect" : ""}>
|
||||
@@ -180,47 +196,92 @@ const CourseForm = () => {
|
||||
<select
|
||||
className="courseFormSelect"
|
||||
value={examPeriod.startMonth}
|
||||
onChange={(e) => setExamPeriod({ ...examPeriod, startMonth: e.target.value })}
|
||||
onChange={(e) =>
|
||||
setExamPeriod({ ...examPeriod, startMonth: e.target.value })
|
||||
}
|
||||
>
|
||||
<option value="">Start Month</option>
|
||||
{["January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December"]
|
||||
.map(month => (
|
||||
<option key={month} value={month}>{month}</option>
|
||||
{[
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December",
|
||||
].map((month) => (
|
||||
<option key={month} value={month}>
|
||||
{month}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
className="courseFormSelect"
|
||||
value={examPeriod.endMonth}
|
||||
onChange={(e) => setExamPeriod({ ...examPeriod, endMonth: e.target.value })}
|
||||
onChange={(e) =>
|
||||
setExamPeriod({ ...examPeriod, endMonth: e.target.value })
|
||||
}
|
||||
>
|
||||
<option value="">End Month</option>
|
||||
{["January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December"]
|
||||
.map(month => (
|
||||
<option key={month} value={month}>{month}</option>
|
||||
{[
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December",
|
||||
].map((month) => (
|
||||
<option key={month} value={month}>
|
||||
{month}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{errors.examPeriod && <span className="courseFormErrorMessage">{errors.examPeriod}</span>}
|
||||
{errors.examPeriod && (
|
||||
<span className="courseFormErrorMessage">
|
||||
{errors.examPeriod}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{[{ name: "oralsPracticals", label: "Orals/Practicals" },
|
||||
{[
|
||||
{ name: "oralsPracticals", label: "Orals/Practicals" },
|
||||
{ name: "assessment", label: "Assessment" },
|
||||
{ name: "reassessment", label: "Reassessment" },
|
||||
{ name: "paperSetting", label: "Paper Setting" },
|
||||
{ name: "moderation", label: "Moderation" },
|
||||
{ name: "pwdPaperSetter", label: "PwD Paper Setter" }]
|
||||
.map(({ name, label }) => (
|
||||
<div key={name} className={errors[name] ? "courseFormErrorInput" : ""}>
|
||||
{ name: "pwdPaperSetter", label: "PwD Paper Setter" },
|
||||
].map(({ name, label }) => (
|
||||
<div
|
||||
key={name}
|
||||
className={errors[name] ? "courseFormErrorInput" : ""}
|
||||
>
|
||||
<label className="courseFormLabel">
|
||||
{label}:
|
||||
<input
|
||||
type="text"
|
||||
className="courseFormInput"
|
||||
<select
|
||||
className="courseFormSelect"
|
||||
name={name}
|
||||
value={formData[name]}
|
||||
onChange={handleInputChange}
|
||||
placeholder={`Search faculty for ${label}`}
|
||||
/>
|
||||
onChange={(e) =>
|
||||
setFormData({ ...formData, [name]: e.target.value })
|
||||
}
|
||||
>
|
||||
<option value="">Select Faculty</option>
|
||||
{options.faculties.map((faculty) => (
|
||||
<option key={faculty.facultyId} value={faculty.name}>
|
||||
{faculty.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<button
|
||||
type="button"
|
||||
className="courseFormButton"
|
||||
@@ -229,13 +290,25 @@ const CourseForm = () => {
|
||||
>
|
||||
Add
|
||||
</button>
|
||||
<ul className="courseFormSuggestions" id={`suggestions-${name}`}
|
||||
style={{ display: (suggestions[name] || []).length > 0 ? "block" : "none" }}>
|
||||
<ul
|
||||
className="courseFormSuggestions"
|
||||
id={`suggestions-${name}`}
|
||||
style={{
|
||||
display:
|
||||
(suggestions[name] || []).length > 0
|
||||
? "block"
|
||||
: "none",
|
||||
}}
|
||||
>
|
||||
{(suggestions[name] || []).map((faculty) => (
|
||||
<li className="courseFormSuggestionsItem" key={faculty.facultyId} onClick={() => {
|
||||
<li
|
||||
className="courseFormSuggestionsItem"
|
||||
key={faculty.facultyId}
|
||||
onClick={() => {
|
||||
setFormData({ ...formData, [name]: faculty.name });
|
||||
setSuggestions((prev) => ({ ...prev, [name]: [] }));
|
||||
}}>
|
||||
}}
|
||||
>
|
||||
{faculty.name}
|
||||
</li>
|
||||
))}
|
||||
@@ -257,19 +330,26 @@ const CourseForm = () => {
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{errors[name] && <span className="courseFormErrorMessage">{errors[name]}</span>}
|
||||
{errors[name] && (
|
||||
<span className="courseFormErrorMessage">
|
||||
{errors[name]}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
|
||||
<button type="submit" className="courseFormButton" style={{ gridColumn: "1 / -1" }}>Submit</button>
|
||||
<button
|
||||
type="submit"
|
||||
className="courseFormButton"
|
||||
style={{ gridColumn: "1 / -1" }}
|
||||
>
|
||||
Submit
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</>
|
||||
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ const Navbar = () => {
|
||||
try {
|
||||
// Call the logout API
|
||||
await axios.get("http://localhost:8080/auth/logout", { withCredentials: true });
|
||||
localStorage.clear();
|
||||
|
||||
// Redirect to the login page after successful logout
|
||||
navigate("/");
|
||||
|
||||
@@ -3,6 +3,8 @@ import axios from "axios";
|
||||
import { jsPDF } from "jspdf";
|
||||
import autoTable from "jspdf-autotable";
|
||||
import Navbar from "./Navbar";
|
||||
import { toast, ToastContainer } from "react-toastify";
|
||||
import { sendEmail } from "../api";
|
||||
|
||||
|
||||
const CourseConsolidated = () => {
|
||||
@@ -13,6 +15,7 @@ const CourseConsolidated = () => {
|
||||
const tablesPerPage = 5;
|
||||
const [expandedCourse, setExpandedCourse] = useState(null);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
@@ -36,16 +39,16 @@ const CourseConsolidated = () => {
|
||||
}
|
||||
|
||||
// Extract unique courses by courseCode
|
||||
const filteredCourses = [...new Set(data.map((row) => row.courseCode))].filter(
|
||||
(courseCode) => {
|
||||
const courseName = data.find((row) => row.courseCode === courseCode)
|
||||
?.courseName;
|
||||
const filteredCourses = [
|
||||
...new Set(data.map((row) => row.courseCode)),
|
||||
].filter((courseCode) => {
|
||||
const courseName = data.find(
|
||||
(row) => row.courseCode === courseCode
|
||||
)?.courseName;
|
||||
return (
|
||||
courseName &&
|
||||
courseName.toLowerCase().includes(searchQuery.toLowerCase())
|
||||
);
|
||||
}
|
||||
courseName && courseName.toLowerCase().includes(searchQuery.toLowerCase())
|
||||
);
|
||||
});
|
||||
|
||||
const totalPages = Math.ceil(filteredCourses.length / tablesPerPage);
|
||||
const indexOfLastTable = currentPage * tablesPerPage;
|
||||
@@ -55,7 +58,6 @@ const CourseConsolidated = () => {
|
||||
indexOfLastTable
|
||||
);
|
||||
|
||||
|
||||
const handleNextPage = () => {
|
||||
if (currentPage < totalPages) setCurrentPage((prevPage) => prevPage + 1);
|
||||
};
|
||||
@@ -64,17 +66,37 @@ const CourseConsolidated = () => {
|
||||
if (currentPage > 1) setCurrentPage((prevPage) => prevPage - 1);
|
||||
};
|
||||
|
||||
const generateAppointmentPDF = async (courseData, courseName) => {
|
||||
const doc = new jsPDF();
|
||||
const fetchFacultyEmail = async (facultyId) => {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`http://localhost:8080/api/faculty/${facultyId}`,
|
||||
{ withCredentials: true }
|
||||
);
|
||||
return response.data.email; // Assuming API returns { email: "faculty@example.com" }
|
||||
} catch (error) {
|
||||
console.error(`Error fetching email for ${facultyId}:`, error);
|
||||
return "N/A"; // Return "N/A" if email is not found
|
||||
}
|
||||
};
|
||||
|
||||
const generateAppointmentPDFs = async (courseData, courseName) => {
|
||||
const maroon = [128, 0, 0];
|
||||
const roles = [
|
||||
{ key: "oralPracticalTeachers", role: "Oral/Practical Teacher" },
|
||||
{ key: "assessmentTeachers", role: "Assessment Teacher" },
|
||||
{ key: "reassessmentTeachers", role: "Reassessment Teacher" },
|
||||
{ key: "paperSettingTeachers", role: "Paper Setter" },
|
||||
{ key: "moderationTeachers", role: "Moderator" },
|
||||
{ key: "pwdPaperSettingTeachers", role: "PwD Paper Setter" },
|
||||
];
|
||||
|
||||
for (const { key, role } of roles) {
|
||||
if (!courseData[key] || courseData[key].length === 0) continue; // Skip empty roles
|
||||
|
||||
const doc = new jsPDF();
|
||||
|
||||
// College Logo
|
||||
const logoUrl = "/logo.png"; // Ensure the logo is placed in the public folder
|
||||
const logoWidth = 40;
|
||||
const logoHeight = 40;
|
||||
const logoX = 10;
|
||||
const logoY = 10;
|
||||
|
||||
const logoUrl = "/logo.png";
|
||||
const loadImage = async (url) => {
|
||||
const response = await fetch(url);
|
||||
const blob = await response.blob();
|
||||
@@ -88,7 +110,7 @@ const CourseConsolidated = () => {
|
||||
|
||||
try {
|
||||
const logoBase64 = await loadImage(logoUrl);
|
||||
doc.addImage(logoBase64, "PNG", logoX, logoY, logoWidth, logoHeight);
|
||||
doc.addImage(logoBase64, "PNG", 10, 10, 40, 40);
|
||||
} catch (error) {
|
||||
console.error("Failed to load logo:", error);
|
||||
}
|
||||
@@ -101,60 +123,33 @@ const CourseConsolidated = () => {
|
||||
doc.setFontSize(14);
|
||||
doc.text("CONFIDENTIAL", 10, 60);
|
||||
doc.setFontSize(10);
|
||||
doc.text(
|
||||
"LETTER OF APPOINTMENT AS QUESTION PAPER SETTER",
|
||||
105,
|
||||
70,
|
||||
{ align: "center" }
|
||||
);
|
||||
doc.text(`LETTER OF APPOINTMENT AS ${role.toUpperCase()}`, 105, 70, {
|
||||
align: "center",
|
||||
});
|
||||
|
||||
// Appointment Table
|
||||
const table1Data = [
|
||||
...(courseData.oralPracticalTeachers?.map((teacher) => [
|
||||
teacher,
|
||||
"K. J. Somaiya School of Engineering",
|
||||
"Oral/Practical Teacher",
|
||||
"Contact Number",
|
||||
]) || []),
|
||||
...(courseData.assessmentTeachers?.map((teacher) => [
|
||||
teacher,
|
||||
"K. J. Somaiya School of Engineering",
|
||||
"Reassessment Teacher",
|
||||
"Contact Number",
|
||||
]) || []),
|
||||
...(courseData.reassessmentTeachers?.map((teacher) => [
|
||||
teacher,
|
||||
"K. J. Somaiya School of Engineering",
|
||||
"Reassessment Teacher",
|
||||
"Contact Number",
|
||||
]) || []),
|
||||
...(courseData.paperSettingTeachers?.map((teacher) => [
|
||||
teacher,
|
||||
"K. J. Somaiya School of Engineering",
|
||||
"Paper Setter",
|
||||
"Contact Number",
|
||||
]) || []),
|
||||
...(courseData.moderationTeachers?.map((teacher) => [
|
||||
teacher,
|
||||
"K. J. Somaiya School of Engineering",
|
||||
"Moderator",
|
||||
"Contact Number",
|
||||
]) || []),
|
||||
...(courseData.pwdPaperSettingTeachers?.map((teacher) => [
|
||||
teacher,
|
||||
"K. J. Somaiya School of Engineering",
|
||||
"PwD Paper Setter",
|
||||
"Contact Number",
|
||||
]) || []),
|
||||
];
|
||||
// Fetch Emails and Prepare Table Data
|
||||
let table1Data = [];
|
||||
let emails = [];
|
||||
|
||||
for (const teacher of courseData[key]) {
|
||||
const email = await fetchFacultyEmail(teacher.facultyId);
|
||||
emails.push(email);
|
||||
table1Data.push([
|
||||
teacher.facultyName,
|
||||
"K. J. Somaiya School of Engineering",
|
||||
role,
|
||||
email,
|
||||
]);
|
||||
}
|
||||
|
||||
// Generate Table
|
||||
autoTable(doc, {
|
||||
head: [["Name", "Affiliation", "Appointment Role", "Email"]],
|
||||
body: table1Data,
|
||||
startY: 80,
|
||||
theme: "grid",
|
||||
headStyles: { fillColor: maroon, textColor: [255, 255, 255] },
|
||||
styles: { textColor: [0, 0, 0] }, // Keep body text black
|
||||
styles: { textColor: [0, 0, 0] },
|
||||
});
|
||||
|
||||
// Content Table
|
||||
@@ -173,18 +168,17 @@ const CourseConsolidated = () => {
|
||||
autoTable(doc, {
|
||||
body: detailsTableData,
|
||||
startY: doc.previousAutoTable.finalY + 10,
|
||||
theme: "grid", // Plain table style
|
||||
theme: "grid",
|
||||
styles: { textColor: [0, 0, 0] },
|
||||
});
|
||||
|
||||
// Footer Section
|
||||
const footerY = doc.previousAutoTable.finalY + 10; // Dynamic Y-coordinate
|
||||
// Footer
|
||||
const footerY = doc.previousAutoTable.finalY + 10;
|
||||
doc.setFontSize(12);
|
||||
doc.text("Dr. S. K. Ukarande", 10, footerY);
|
||||
doc.text("Principal", 10, footerY + 5);
|
||||
doc.text("K. J. Somaiya School of Engineering", 10, footerY + 10);
|
||||
|
||||
// Footer Contact Details
|
||||
const footerContactY = footerY + 20;
|
||||
doc.setFontSize(10);
|
||||
doc.text(
|
||||
@@ -196,16 +190,44 @@ const CourseConsolidated = () => {
|
||||
doc.text("Email: principal.tech@somaiya.edu", 10, footerContactY + 10);
|
||||
doc.text("Web: www.somaiya.edu/kjsieit", 10, footerContactY + 15);
|
||||
|
||||
// Save PDF
|
||||
doc.save(`${courseName} - AppointmentOrder.pdf`);
|
||||
// Convert PDF to Blob
|
||||
const pdfBlob = doc.output("blob");
|
||||
|
||||
// Send Email to Each Faculty
|
||||
for (const email of emails) {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append("pdfFile", pdfBlob, `${courseName}-${role}.pdf`);
|
||||
formData.append("fileName", `${courseName}-${role}.pdf`);
|
||||
formData.append("recipientEmail", email);
|
||||
formData.append("role", role);
|
||||
formData.append("courseName", courseName);
|
||||
|
||||
const emailResponse = await sendEmail(formData, "pdf");
|
||||
toast.success(`✅ Email sent successfully to ${email}`);
|
||||
console.log("Response from server:", emailResponse);
|
||||
} catch (emailError) {
|
||||
toast.error(`❌ Error sending email to ${email}:`, emailError.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<Navbar/>
|
||||
<Navbar />
|
||||
<ToastContainer />
|
||||
<div>
|
||||
<h1 style={{ textAlign: "center", background: "#003366", color: "white", padding: "20px 0", fontSize: "24px", }}>
|
||||
<h1
|
||||
style={{
|
||||
textAlign: "center",
|
||||
background: "#003366",
|
||||
color: "white",
|
||||
padding: "20px 0",
|
||||
fontSize: "24px",
|
||||
}}
|
||||
>
|
||||
Course Tables with Download Options
|
||||
</h1>
|
||||
|
||||
@@ -225,7 +247,6 @@ const CourseConsolidated = () => {
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
<div
|
||||
style={{
|
||||
maxHeight: "70vh",
|
||||
@@ -241,6 +262,7 @@ const CourseConsolidated = () => {
|
||||
const courseData = data.filter(
|
||||
(row) => row.courseCode === courseCode
|
||||
);
|
||||
console.log(courseData);
|
||||
const courseName = courseData[0]?.courseName; // Get course name from first item
|
||||
return (
|
||||
<div key={index} style={{ marginBottom: "20px" }}>
|
||||
@@ -263,7 +285,9 @@ const CourseConsolidated = () => {
|
||||
>
|
||||
<h2 style={{ margin: 0 }}>{courseName}'s Table</h2>
|
||||
<button
|
||||
onClick={() => generateAppointmentPDF(courseData[0], courseName)}
|
||||
onClick={() =>
|
||||
generateAppointmentPDFs(courseData[0], courseName)
|
||||
}
|
||||
className="btn btn-primary"
|
||||
style={{
|
||||
padding: "10px 15px",
|
||||
@@ -313,9 +337,11 @@ const CourseConsolidated = () => {
|
||||
{row.oralPracticalTeachers &&
|
||||
row.oralPracticalTeachers.length > 0 ? (
|
||||
<ul style={{ margin: 0, paddingLeft: "20px" }}>
|
||||
{row.oralPracticalTeachers.map((teacher, idx) => (
|
||||
<li key={idx}>{teacher}</li>
|
||||
))}
|
||||
{row.oralPracticalTeachers.map(
|
||||
(teacher, idx) => (
|
||||
<li key={idx}>{teacher.facultyName}</li>
|
||||
)
|
||||
)}
|
||||
</ul>
|
||||
) : (
|
||||
"N/A"
|
||||
@@ -326,7 +352,7 @@ const CourseConsolidated = () => {
|
||||
row.assessmentTeachers.length > 0 ? (
|
||||
<ul style={{ margin: 0, paddingLeft: "20px" }}>
|
||||
{row.assessmentTeachers.map((teacher, idx) => (
|
||||
<li key={idx}>{teacher}</li>
|
||||
<li key={idx}>{teacher.facultyName}</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
@@ -337,9 +363,11 @@ const CourseConsolidated = () => {
|
||||
{row.reassessmentTeachers &&
|
||||
row.reassessmentTeachers.length > 0 ? (
|
||||
<ul style={{ margin: 0, paddingLeft: "20px" }}>
|
||||
{row.reassessmentTeachers.map((teacher, idx) => (
|
||||
<li key={idx}>{teacher}</li>
|
||||
))}
|
||||
{row.reassessmentTeachers.map(
|
||||
(teacher, idx) => (
|
||||
<li key={idx}>{teacher.facultyName}</li>
|
||||
)
|
||||
)}
|
||||
</ul>
|
||||
) : (
|
||||
"N/A"
|
||||
@@ -349,9 +377,11 @@ const CourseConsolidated = () => {
|
||||
{row.paperSettingTeachers &&
|
||||
row.paperSettingTeachers.length > 0 ? (
|
||||
<ul style={{ margin: 0, paddingLeft: "20px" }}>
|
||||
{row.paperSettingTeachers.map((teacher, idx) => (
|
||||
<li key={idx}>{teacher}</li>
|
||||
))}
|
||||
{row.paperSettingTeachers.map(
|
||||
(teacher, idx) => (
|
||||
<li key={idx}>{teacher.facultyName}</li>
|
||||
)
|
||||
)}
|
||||
</ul>
|
||||
) : (
|
||||
"N/A"
|
||||
@@ -362,7 +392,7 @@ const CourseConsolidated = () => {
|
||||
row.moderationTeachers.length > 0 ? (
|
||||
<ul style={{ margin: 0, paddingLeft: "20px" }}>
|
||||
{row.moderationTeachers.map((teacher, idx) => (
|
||||
<li key={idx}>{teacher}</li>
|
||||
<li key={idx}>{teacher.facultyName}</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
@@ -375,7 +405,7 @@ const CourseConsolidated = () => {
|
||||
<ul style={{ margin: 0, paddingLeft: "20px" }}>
|
||||
{row.pwdPaperSettingTeachers.map(
|
||||
(teacher, idx) => (
|
||||
<li key={idx}>{teacher}</li>
|
||||
<li key={idx}>{teacher.facultyName}</li>
|
||||
)
|
||||
)}
|
||||
</ul>
|
||||
|
||||
@@ -151,9 +151,9 @@ export const updateCourseStatus = async (courseId) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const sendEmail = async (formData) => {
|
||||
export const sendEmail = async (formData, type) => {
|
||||
try {
|
||||
const url = `${BASE_URL}/send-email`;
|
||||
const url = `${BASE_URL}/send-email/${type}`;
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
body: formData, // Directly pass FormData
|
||||
|
||||
@@ -6,6 +6,7 @@ const FacultySchema = new mongoose.Schema({
|
||||
email: { type: String, required: true },
|
||||
department: { type: String, required: true },
|
||||
program: { type: String, required: true },
|
||||
courses: [{ type: String }],
|
||||
});
|
||||
|
||||
module.exports = mongoose.model("Faculty", FacultySchema);
|
||||
|
||||
@@ -108,7 +108,7 @@ router.get("/course-consolidated", async (req, res) => {
|
||||
|
||||
// Add the faculty name to the appropriate task
|
||||
if (appointment.task && groupedByCourse[courseId].tasks[appointment.task]) {
|
||||
groupedByCourse[courseId].tasks[appointment.task].add(appointment.facultyName);
|
||||
groupedByCourse[courseId].tasks[appointment.task].add(JSON.stringify({ facultyId: appointment.facultyId, facultyName: appointment.facultyName }));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -130,12 +130,12 @@ router.get("/course-consolidated", async (req, res) => {
|
||||
semester: course.semester,
|
||||
examType: course.examType,
|
||||
year: course.year,
|
||||
oralPracticalTeachers: Array.from(course.tasks.oralsPracticals),
|
||||
assessmentTeachers: Array.from(course.tasks.assessment),
|
||||
reassessmentTeachers: Array.from(course.tasks.reassessment),
|
||||
paperSettingTeachers: Array.from(course.tasks.paperSetting),
|
||||
moderationTeachers: Array.from(course.tasks.moderation),
|
||||
pwdPaperSettingTeachers: Array.from(course.tasks.pwdPaperSetter),
|
||||
oralPracticalTeachers: Array.from(course.tasks.oralsPracticals).map((data) => JSON.parse(data)),
|
||||
assessmentTeachers: Array.from(course.tasks.assessment).map((data) => JSON.parse(data)),
|
||||
reassessmentTeachers: Array.from(course.tasks.reassessment).map((data) => JSON.parse(data)),
|
||||
paperSettingTeachers: Array.from(course.tasks.paperSetting).map((data) => JSON.parse(data)),
|
||||
moderationTeachers: Array.from(course.tasks.moderation).map((data) => JSON.parse(data)),
|
||||
pwdPaperSettingTeachers: Array.from(course.tasks.pwdPaperSetter).map((data) => JSON.parse(data)),
|
||||
}));
|
||||
|
||||
res.status(200).json(consolidatedData);
|
||||
@@ -215,5 +215,37 @@ router.get("/department-consolidated", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.get("/panel-consolidated", async (req, res) => {
|
||||
try {
|
||||
const courses = await Course.find();
|
||||
const faculties = await Faculty.find();
|
||||
|
||||
// Create a structure where each course has its associated faculty
|
||||
const consolidatedData = courses.map((course) => {
|
||||
return {
|
||||
courseId: course.courseId,
|
||||
courseName: course.courseName,
|
||||
semester: course.semester,
|
||||
examType: course.scheme,
|
||||
program: course.program,
|
||||
faculty: faculties
|
||||
.filter((faculty) => faculty.courses.includes(course.courseId))
|
||||
.map((faculty) => ({
|
||||
facultyId: faculty.facultyId,
|
||||
name: faculty.name,
|
||||
email: faculty.email,
|
||||
qualification: faculty.qualification,
|
||||
experience: faculty.experience,
|
||||
})),
|
||||
};
|
||||
});
|
||||
|
||||
res.status(200).json(consolidatedData);
|
||||
} catch (error) {
|
||||
console.error("Error fetching panel consolidated data:", error);
|
||||
res.status(500).json({ message: "Failed to fetch panel consolidated data" });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -17,7 +17,7 @@ const storage = multer.diskStorage({
|
||||
const upload = multer({ storage });
|
||||
|
||||
// Route to handle email sending with file attachment
|
||||
router.post("/", upload.single("file"), async (req, res) => {
|
||||
router.post("/excel", upload.single("file"), async (req, res) => {
|
||||
const { teacher, fileName, recipientEmail } = req.body;
|
||||
|
||||
if (!teacher || !fileName || !recipientEmail || !req.file) {
|
||||
@@ -31,6 +31,9 @@ router.post("/", upload.single("file"), async (req, res) => {
|
||||
user: "swdc.ate@gmail.com", // Replace with your email
|
||||
pass: "umlc hbkr dpga iywd", // Replace with your app-specific password or token
|
||||
},
|
||||
tls: {
|
||||
rejectUnauthorized: false, // Ignore self-signed certificate errors
|
||||
},
|
||||
connectionTimeout: 15000,
|
||||
greetingTimeout: 15000,
|
||||
socketTimeout: 15000,
|
||||
@@ -57,12 +60,13 @@ Your cooperation regarding the upcoming examination duties is highly solicited.`
|
||||
path: req.file.path, // Use the uploaded file's path
|
||||
},
|
||||
],
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
try {
|
||||
// Send email
|
||||
await transporter.sendMail(mailOptions);
|
||||
transporter.close();
|
||||
|
||||
// Delete the temporary file after sending the email
|
||||
fs.unlinkSync(req.file.path);
|
||||
@@ -74,4 +78,64 @@ Your cooperation regarding the upcoming examination duties is highly solicited.`
|
||||
}
|
||||
});
|
||||
|
||||
// Route to send emails with PDF attachments
|
||||
router.post("/pdf", upload.single("pdfFile"), async (req, res) => {
|
||||
const { fileName, recipientEmail, role, courseName } = req.body;
|
||||
|
||||
if (!fileName || !recipientEmail || !role || !courseName || !req.file) {
|
||||
return res.status(400).json({ error: "Missing required fields or file" });
|
||||
}
|
||||
|
||||
// Configure Nodemailer transporter
|
||||
const transporter = nodemailer.createTransport({
|
||||
service: "gmail",
|
||||
auth: {
|
||||
user: "swdc.ate@gmail.com", // Replace with your email
|
||||
pass: "umlc hbkr dpga iywd", // Replace with your app-specific password
|
||||
},
|
||||
tls: {
|
||||
rejectUnauthorized: false,
|
||||
},
|
||||
connectionTimeout: 15000,
|
||||
greetingTimeout: 15000,
|
||||
socketTimeout: 15000,
|
||||
});
|
||||
|
||||
// Email options
|
||||
const mailOptions = {
|
||||
from: "SWDC Admin <swdc.ate@gmail.com>",
|
||||
to: recipientEmail,
|
||||
subject: `Appointment as ${role} - ${courseName}`,
|
||||
text: `Dear teacher,
|
||||
|
||||
You have been appointed as a ${role} for the course "${courseName}".
|
||||
Please find your appointment letter attached.
|
||||
|
||||
If you have any queries, please contact the Examination In-charge.
|
||||
|
||||
Best regards,
|
||||
Examination Department`,
|
||||
attachments: [
|
||||
{
|
||||
filename: fileName,
|
||||
path: req.file.path, // Path to the uploaded PDF
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
try {
|
||||
// Send email
|
||||
await transporter.sendMail(mailOptions);
|
||||
transporter.close();
|
||||
|
||||
// Delete the PDF file after sending
|
||||
// fs.unlinkSync(req.file.path);
|
||||
|
||||
res.status(200).json({ message: "Email sent successfully" });
|
||||
} catch (error) {
|
||||
console.error("Error sending email:", error);
|
||||
res.status(500).json({ error: "Failed to send email" });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user