All checks were successful
Deploy on Master Change / deploy (push) Successful in 1m45s
6.5 KiB
6.5 KiB
Walkthrough - Attendance Local Approval, Modal Redesign & Native HTTP MJPEG Streaming
We have successfully updated the leave requests approval logic to operate locally, redesigned the attendance panel into a spacious full-height modal, and implemented a high-performance native HTTP MJPEG streaming architecture based on raia_v3.
Changes Made
1. Backend Implementation
Leave Approvals & Redesign
- Model Addition (models.go):
- Defined
LocalLeaveRequestto keep track of approvals and rejections locally inside Simple Care database.
- Defined
- Database Migration (db.go):
- Registered
LocalLeaveRequestmodel for Gorm AutoMigrate.
- Registered
- Approval Logic (handlers_attendance.go):
- Modified
UpdateLeaveStatusHandlerto store status overrides directly to the local database, completely bypassing the externalqldtClient.UpdateLeaveStatusAPI call.
- Modified
- Leave Query status overriding (handlers_attendance.go):
- Modified
GetLeaveRequestsHandlerto intercept the QLDT API list response and override the status field of leave requests with the stored local database values before returning it to the frontend.
- Modified
High-Performance HTTP MJPEG Streaming
- HTTP MJPEG Endpoint Support (websocket.go):
- Added
RegisterHttpSubscriberandUnregisterHttpSubscribermethods toWsHubto manage active HTTP streaming connections dynamically. - Implemented
GetStudentScreenStreamHandlerandGetStudentWebcamStreamHandlerFiber controllers. - Upon receiving streaming frames over the WebSocket connection from a student, the server decodes the base64 JPEGs to raw binary JPEGs and feeds them directly to the corresponding HTTP MJPEG channels.
- Automatically triggers the student's screenshot/webcam capture stream when an HTTP connection is established, and stops it when all subscribers disconnect, saving huge amounts of client CPU and network bandwidth.
- Added
- Unified Query Parameter Auth (staff.go):
- Updated
RequireStaff()middleware to accept the JWT token from the query parameter?token=...if noAuthorizationheader is present. This allows standard<img>tags to securely request stream data.
- Updated
- Stream Routing (main.go):
- Registered routes
/api/students/:studentId/stream/screenand/api/students/:studentId/stream/webcamunder the authenticatedstaffrouter.
- Registered routes
2. Frontend UI / UX Redesign
Modal wrapper for Attendance
- Modal layout (AttendancePanel.tsx):
- Redesigned the main container of
<AttendancePanel>to be a full-screen backdrop modal (.attendance-modal-overlayand.attendance-modal-container) with a top header containing a close button (×).
- Redesigned the main container of
- Modal Dismiss callback (ClassWorkspace.tsx):
- Configured
onClosecallback on the<AttendancePanel>to automatically navigate the teacher back to the roster tab ('roster') when they dismiss the modal.
- Configured
- Leave Modal Notices (AttendancePanel.tsx):
- Added a clear alert notice informing teachers that approving or rejecting a leave request records the action locally inside Simple Care only and does not sync back to the QLDT portal. Approving will mark the student's status to "Nghỉ có phép".
- Responsive CSS Styles (index.css):
- Implemented
.attendance-modal-overlay,.attendance-modal-container, and.attendance-modal-bodyCSS styles. The container utilizeswidth: 98vw !importantandheight: 96vh !importantto provide a spacious UI layout with full scroll support, avoiding squeezed tables on small screens and low-height devices.
- Implemented
- Exam Violations Notice (ViolationsPanel.tsx):
- Added an amber warning notice label in the violations list tab specifically during exam mode (
props.mode === 'exam') stating: "Lưu ý: Chức năng theo dõi vi phạm đang được theo dõi đánh giá tính chuẩn xác, hiện tại kết quả chạy thử chỉ mang tính chất tham khảo."
- Added an amber warning notice label in the violations list tab specifically during exam mode (
Native Stream Rendering (MJPEG)
- StudentStreamImage Component (StudentStreamImage.tsx):
- Created a reusable component that binds directly to the HTTP stream.
- Automatically manages connection establishment, listens to error states (e.g. when a student is offline or stream is dropped), and retries the connection after a small delay.
- Stream Panel Integration (ProctorStreamPanels.tsx):
- Rewrote the panel component to render screens and webcams using
<StudentStreamImage>. - Completely removed all complex WebSocket subscription state management, subscriptions, and connection setups from the component, eliminating lag, thread blocks, and frontend JSON parsing overhead.
- Rewrote the panel component to render screens and webcams using
- Grid View Integration (ExamGridProctor.tsx):
- Simplified the grid view by using
<StudentStreamImage>for both card frames and the zoomed modal. - Bypassed WebSocket connections completely for grid monitoring, reducing frontend CPU load and rendering overhead to zero.
- Simplified the grid view by using
Verification Results
Backend Compile Check
- Built Go code successfully:
Backend compiles cleanly without errors.
go build -o server_test.exe main.go
Frontend Build Check
- Ran Vite production compilation:
Frontend builds and type-checks successfully with all TS checks passing.
npx tsc --noEmit