feat: institutional + support + training admin sections (backend + frontend)

Ship three fully-wired admin areas end-to-end with APIs, seeds, tests and docs.

Backend (new `encoach_lms_api` addon + existing addons):
- Institutional: academic years/terms, departments, admission registers & admissions,
  courses/batches, lessons, fees (terms + student fees + invoicing with income-account
  auto-wiring), gradebook (assignments/grades), library, facilities (encoach.asset),
  student leave, result templates + marksheets (incl. delete-with-cascade).
- Support: `encoach.ticket` model + CRUD/assignee routes; payment records derived
  from `op.student.fees.details` and `account.move`; platform settings backed by
  `encoach.code` and `ir.config_parameter` (packages + grading config).
- Training: `encoach.vocab.item` + `encoach.grammar.rule` (plus progress models)
  with CRUD, pagination, search/level filters, and upsert-style progress endpoints.
  Odoo 19 compatibility: `_sql_constraints` replaced with `@api.constrains`;
  `ValidationError`/`UserError` mapped to HTTP 400.

Frontend:
- Rewire institutional admin pages (Academic Year Manager, Admissions, Courses,
  Lessons, Fees, Gradebook, Library, Facilities, Student Leave, Marksheets,
  Taxonomy, Resources) to real APIs with React Query invalidation and dialogs.
- New typed services: `payments.service.ts`, `platformSettings.service.ts`,
  `training.service.ts`. Updated `fees/gradebook/lms/courseware/taxonomy/
  resources/student-progress/generation` services + related types.
- Rewrite `VocabularyPage`, `GrammarPage`, `PaymentRecordPage`, `SettingsPage`,
  `TicketsPage` to consume live data with search/filter/progress/CRUD flows.
- New shared components: `TaxonomyCascade`, `MaterialViewer`, `teacher/TeacherLibrary`.
- Favicons/branding assets and misc. UX polish across teacher/student pages.

Tooling & QA:
- Seeders: `seed_demo.py`, `seed_demo_data.py`, `seed_institutional.py` (idempotent,
  covers institutional + support + training fixtures incl. income-account wiring).
- API write-flow test suites: `test_write_flows.py` (institutional),
  `test_support_flows.py` (support), `test_training_flows.py` (training),
  `test_ai_full.py`. All suites pass end-to-end.
- Docs: add `docs/PROJECT_SUMMARY.md` with per-section scope, artifacts and QA.
- `.gitignore`: ignore `pgdata_bak_*/`, `frontend/.vite/`, `frontend/dist/`,
  `frontend/node_modules/`.

Made-with: Cursor
This commit is contained in:
Yamen Ahmad
2026-04-19 03:13:23 +04:00
parent b78124bb7b
commit 435930a827
71 changed files with 6677 additions and 1309 deletions

View File

@@ -8,11 +8,13 @@ import { Label } from "@/components/ui/label";
import { Checkbox } from "@/components/ui/checkbox";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { Plus, Trash2, Loader2, FileText, Video, Image, Link2, Upload, Music } from "lucide-react";
import { useChapter, useChapterMaterials, useUploadMaterial, useDeleteMaterial } from "@/hooks/queries";
import { Plus, Trash2, Loader2, FileText, Video, Image, Link2, Upload, Music, Library, Search, CheckCircle2 } from "lucide-react";
import { useChapter, useChapterMaterials, useUploadMaterial, useDeleteMaterial, useCreateMaterialFromResource } from "@/hooks/queries";
import { coursewareService } from "@/services/courseware.service";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { resourcesService } from "@/services/resources.service";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useToast } from "@/hooks/use-toast";
import type { MaterialType } from "@/types/courseware";
@@ -35,15 +37,32 @@ export default function ChapterDetail() {
const { data: materials = [], isLoading: loadingMaterials } = useChapterMaterials(chId);
const uploadMaterial = useUploadMaterial();
const deleteMaterial = useDeleteMaterial();
const fromResource = useCreateMaterialFromResource();
const fileRef = useRef<HTMLInputElement>(null);
const [showUpload, setShowUpload] = useState(false);
const [dialogTab, setDialogTab] = useState<string>("library");
const [matName, setMatName] = useState("");
const [matType, setMatType] = useState<MaterialType>("pdf");
const [matUrl, setMatUrl] = useState("");
const [matFile, setMatFile] = useState<File | null>(null);
const [allowDownload, setAllowDownload] = useState(true);
const [libSearch, setLibSearch] = useState("");
const [libTypeFilter, setLibTypeFilter] = useState("all");
const [selectedResourceId, setSelectedResourceId] = useState<number | null>(null);
const { data: resourcesData, isLoading: loadingResources } = useQuery({
queryKey: ["resources", "list", { search: libSearch, resource_type: libTypeFilter === "all" ? undefined : libTypeFilter }],
queryFn: () => resourcesService.list({
search: libSearch || undefined,
resource_type: libTypeFilter === "all" ? undefined : libTypeFilter,
limit: 50,
}),
enabled: showUpload,
});
const libraryResources = resourcesData?.items ?? [];
const toggleDownload = useMutation({
mutationFn: ({ id, allow }: { id: number; allow: boolean }) =>
coursewareService.updateMaterial(id, { allow_download: allow }),
@@ -51,7 +70,11 @@ export default function ChapterDetail() {
onError: () => toast({ title: "Error", description: "Failed to update material", variant: "destructive" }),
});
const resetForm = () => { setMatName(""); setMatType("pdf"); setMatUrl(""); setMatFile(null); setAllowDownload(true); };
const resetForm = () => {
setMatName(""); setMatType("pdf"); setMatUrl(""); setMatFile(null);
setAllowDownload(true); setSelectedResourceId(null); setLibSearch("");
setLibTypeFilter("all"); setDialogTab("library");
};
const handleUpload = () => {
const formData = new FormData();
@@ -64,17 +87,28 @@ export default function ChapterDetail() {
uploadMaterial.mutate(
{ chapterId: chId, formData },
{
onSuccess: () => { toast({ title: "Material Uploaded" }); setShowUpload(false); resetForm(); },
onSuccess: () => { toast({ title: "Material uploaded" }); setShowUpload(false); resetForm(); },
onError: () => toast({ title: "Error", description: "Failed to upload material", variant: "destructive" }),
},
);
};
const handleAddFromLibrary = () => {
if (!selectedResourceId) return;
fromResource.mutate(
{ chapterId: chId, resourceId: selectedResourceId },
{
onSuccess: () => { toast({ title: "Material added from library" }); setShowUpload(false); resetForm(); },
onError: () => toast({ title: "Error", description: "Failed to add material from library", variant: "destructive" }),
},
);
};
const handleDelete = (id: number) => {
deleteMaterial.mutate(
{ id, chapterId: chId },
{
onSuccess: () => toast({ title: "Material Deleted" }),
onSuccess: () => toast({ title: "Material deleted" }),
onError: () => toast({ title: "Error", description: "Failed to delete material", variant: "destructive" }),
},
);
@@ -105,49 +139,139 @@ export default function ChapterDetail() {
<div className="flex items-center justify-between">
<h2 className="text-lg font-semibold">Materials</h2>
<Dialog open={showUpload} onOpenChange={setShowUpload}>
<Dialog open={showUpload} onOpenChange={(open) => { setShowUpload(open); if (!open) resetForm(); }}>
<DialogTrigger asChild>
<Button size="sm"><Plus className="mr-2 h-4 w-4" /> Upload Material</Button>
<Button size="sm"><Plus className="mr-2 h-4 w-4" /> Add Material</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader><DialogTitle>Upload Material</DialogTitle></DialogHeader>
<div className="space-y-4 pt-4">
<div className="space-y-2">
<Label>Name</Label>
<Input placeholder="Material name" value={matName} onChange={e => setMatName(e.target.value)} />
</div>
<div className="space-y-2">
<Label>Type</Label>
<Select value={matType} onValueChange={v => setMatType(v as MaterialType)}>
<SelectTrigger><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem value="pdf">PDF</SelectItem>
<SelectItem value="document">Document</SelectItem>
<SelectItem value="video">Video</SelectItem>
<SelectItem value="audio">Audio</SelectItem>
<SelectItem value="image">Image</SelectItem>
<SelectItem value="link">Link</SelectItem>
<SelectItem value="article">Article</SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label>File</Label>
<Input ref={fileRef} type="file" onChange={e => setMatFile(e.target.files?.[0] ?? null)} />
</div>
<div className="space-y-2">
<Label>Or URL</Label>
<Input placeholder="https://..." value={matUrl} onChange={e => setMatUrl(e.target.value)} />
</div>
<div className="flex items-center gap-2">
<Checkbox id="allow-dl" checked={allowDownload} onCheckedChange={v => setAllowDownload(!!v)} />
<Label htmlFor="allow-dl">Allow Download</Label>
</div>
<Button className="w-full" onClick={handleUpload} disabled={uploadMaterial.isPending || !matName}>
{uploadMaterial.isPending && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
<Upload className="mr-2 h-4 w-4" /> Upload
</Button>
</div>
<DialogContent className="sm:max-w-[600px]">
<DialogHeader><DialogTitle>Add Material</DialogTitle></DialogHeader>
<Tabs value={dialogTab} onValueChange={setDialogTab} className="pt-2">
<TabsList className="w-full">
<TabsTrigger value="library" className="flex-1">
<Library className="mr-2 h-4 w-4" /> From Library
</TabsTrigger>
<TabsTrigger value="upload" className="flex-1">
<Upload className="mr-2 h-4 w-4" /> Upload Manual
</TabsTrigger>
</TabsList>
{/* Tab: From Library */}
<TabsContent value="library" className="space-y-4 pt-2">
<div className="flex gap-2">
<div className="relative flex-1">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
<Input
placeholder="Search resources…"
value={libSearch}
onChange={e => setLibSearch(e.target.value)}
className="pl-9"
/>
</div>
<Select value={libTypeFilter} onValueChange={setLibTypeFilter}>
<SelectTrigger className="w-[120px]"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem value="all">All Types</SelectItem>
<SelectItem value="pdf">PDF</SelectItem>
<SelectItem value="video">Video</SelectItem>
<SelectItem value="document">Document</SelectItem>
<SelectItem value="link">Link</SelectItem>
</SelectContent>
</Select>
</div>
<div className="max-h-[300px] overflow-y-auto border rounded-md">
{loadingResources ? (
<div className="flex justify-center py-8">
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
</div>
) : libraryResources.length === 0 ? (
<div className="text-center py-8 text-muted-foreground text-sm">
No resources found. Try a different search or upload manually.
</div>
) : (
<div className="divide-y">
{libraryResources.map(r => {
const selected = selectedResourceId === r.id;
return (
<button
key={r.id}
type="button"
onClick={() => setSelectedResourceId(selected ? null : r.id)}
className={`w-full text-left px-4 py-3 flex items-center gap-3 transition-colors hover:bg-muted/50 ${
selected ? "bg-primary/10 ring-1 ring-primary/30" : ""
}`}
>
<div className="shrink-0">
{selected ? (
<CheckCircle2 className="h-5 w-5 text-primary" />
) : (
typeIcons[r.resource_type as MaterialType] ?? <FileText className="h-5 w-5 text-muted-foreground" />
)}
</div>
<div className="flex-1 min-w-0">
<p className="font-medium text-sm truncate">{r.name}</p>
<p className="text-xs text-muted-foreground">
{r.resource_type} {r.topic_names?.length ? `· ${r.topic_names.slice(0, 2).join(", ")}` : ""}
</p>
</div>
<Badge variant="outline" className="capitalize shrink-0">{r.resource_type}</Badge>
</button>
);
})}
</div>
)}
</div>
<Button
className="w-full"
onClick={handleAddFromLibrary}
disabled={!selectedResourceId || fromResource.isPending}
>
{fromResource.isPending && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
<Library className="mr-2 h-4 w-4" />
Add Selected Resource
</Button>
</TabsContent>
{/* Tab: Manual Upload */}
<TabsContent value="upload" className="space-y-4 pt-2">
<div className="space-y-2">
<Label>Name</Label>
<Input placeholder="Material name" value={matName} onChange={e => setMatName(e.target.value)} />
</div>
<div className="space-y-2">
<Label>Type</Label>
<Select value={matType} onValueChange={v => setMatType(v as MaterialType)}>
<SelectTrigger><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem value="pdf">PDF</SelectItem>
<SelectItem value="document">Document</SelectItem>
<SelectItem value="video">Video</SelectItem>
<SelectItem value="audio">Audio</SelectItem>
<SelectItem value="image">Image</SelectItem>
<SelectItem value="link">Link</SelectItem>
<SelectItem value="article">Article</SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label>File</Label>
<Input ref={fileRef} type="file" onChange={e => setMatFile(e.target.files?.[0] ?? null)} />
</div>
<div className="space-y-2">
<Label>Or URL</Label>
<Input placeholder="https://..." value={matUrl} onChange={e => setMatUrl(e.target.value)} />
</div>
<div className="flex items-center gap-2">
<Checkbox id="allow-dl" checked={allowDownload} onCheckedChange={v => setAllowDownload(!!v)} />
<Label htmlFor="allow-dl">Allow Download</Label>
</div>
<Button className="w-full" onClick={handleUpload} disabled={uploadMaterial.isPending || !matName}>
{uploadMaterial.isPending && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
<Upload className="mr-2 h-4 w-4" /> Upload
</Button>
</TabsContent>
</Tabs>
</DialogContent>
</Dialog>
</div>
@@ -189,7 +313,7 @@ export default function ChapterDetail() {
))}
{materials.length === 0 && (
<TableRow>
<TableCell colSpan={5} className="text-center text-muted-foreground py-8">No materials uploaded yet.</TableCell>
<TableCell colSpan={5} className="text-center text-muted-foreground py-8">No materials added yet.</TableCell>
</TableRow>
)}
</TableBody>