Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Modules/Database/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import StudentCreditTotalsReport from "./reports/StudentCreditTotalsReport";
import CourseRegistrationCountsReport from "./reports/CourseRegistrationCountsReport";
import SwayamRegistrationsReport from "./reports/SwayamRegistrationsReport";
import SemesterRegistrationsReport from "./reports/SemesterRegistrationsReport";
import CreditsEarnedReport from "./reports/CreditsEarnedReport";

// One entry per report. Adding a report means adding an entry here; the list
// page and the report page both read from this.
Expand Down Expand Up @@ -51,6 +52,14 @@ export const DATABASE_REPORTS = [
filters: "Batch, semester",
Component: SemesterRegistrationsReport,
},
{
id: "credits-earned",
title: "Total credits earned",
summary:
"Regular, backlog/improvement and swayam credits each student of a batch has earned so far",
filters: "Batch",
Component: CreditsEarnedReport,
},
];

export const findReport = (id) =>
Expand Down
98 changes: 98 additions & 0 deletions src/Modules/Database/reports/CreditsEarnedReport.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { useState } from "react";
import PropTypes from "prop-types";
import { Button, Group, Select, Stack, Text } from "@mantine/core";
import { showNotification } from "@mantine/notifications";
import { IconSearch } from "@tabler/icons-react";
import axios from "axios";
import { databaseCreditsEarnedRoute } from "../../../routes/academicRoutes";
import ReportTable from "../ReportTable";

const COLUMNS = [
{ key: "roll_no", label: "Roll No" },
{ key: "student_name", label: "Student Name" },
{ key: "regular_credits", label: "Regular Credits" },
{ key: "backlog_improvement_credits", label: "Backlog/Improvement Credits" },
{ key: "swayam_credits", label: "Swayam Credits" },
{ key: "total_credits_earned", label: "Total Credits Earned" },
];

const asOptions = (values) =>
(values || []).map((v) => ({ value: String(v), label: String(v) }));

export default function CreditsEarnedReport({ filters }) {
const [batch, setBatch] = useState(null);
const [result, setResult] = useState(null);
const [loading, setLoading] = useState(false);

const ready = Boolean(batch);

const run = async () => {
setLoading(true);
try {
const token = localStorage.getItem("authToken");
const { data } = await axios.get(databaseCreditsEarnedRoute, {
params: { batch },
headers: token ? { Authorization: `Token ${token}` } : {},
});
setResult(data);
if (!data.count) {
showNotification({
title: "Nothing found",
message: "No graded students match that batch.",
color: "yellow",
});
}
} catch (error) {
showNotification({
title: "Error",
message: error.response?.data?.detail || "Could not load the credits.",
color: "red",
});
} finally {
setLoading(false);
}
};

return (
<Stack gap="md">
<Group align="flex-end" gap="md">
<Select
label="Batch"
placeholder="Select batch"
data={asOptions(filters.batches)}
value={batch}
onChange={setBatch}
style={{ flex: 1, minWidth: 130 }}
/>
<Button
leftSection={<IconSearch size={16} />}
onClick={run}
loading={loading}
disabled={!ready}
style={{ flexShrink: 0 }}
>
Fetch
</Button>
</Group>

{result ? (
<ReportTable
columns={COLUMNS}
rows={result.rows}
filename={`credits_earned_${batch}`}
badges={[{ label: `${result.credits} credits`, color: "teal" }]}
/>
) : (
<Text size="sm" c="dimmed">
Choose a batch, then fetch.
</Text>
)}
</Stack>
);
}

CreditsEarnedReport.propTypes = {
filters: PropTypes.shape({
batches: PropTypes.arrayOf(PropTypes.number),
}).isRequired,
};
1 change: 1 addition & 0 deletions src/routes/academicRoutes/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const databaseStudentCreditTotalsRoute = `${host}/aims/api/database/stude
export const databaseCourseRegistrationCountsRoute = `${host}/aims/api/database/course-registration-counts/`;
export const databaseSwayamRegistrationsRoute = `${host}/aims/api/database/swayam-registrations/`;
export const databaseSemesterRegistrationsRoute = `${host}/aims/api/database/semester-registrations/`;
export const databaseCreditsEarnedRoute = `${host}/aims/api/database/credits-earned/`;
export const academicProceduresFaculty = `${host}/academic-procedures/api/fac/academic_procedures_faculty`;
export const getAllCourses = `${host}/academic-procedures/api/acad/get_all_courses`;
export const generateprereport = `${host}/aims/api/generate_preregistration_report/`;
Expand Down
Loading