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