Skip to content

Commit aa6b5ef

Browse files
CK-7vncorypride
authored andcommitted
Ck 7vn/total refactor classes (#1087)
* feat: class page click to details * feat: update Roster tab to fit redesign in classes * fix: small screen handling * feat: add breadcrumbs to class ecosystem * feat: add class modal * fix: class creation issues * fix: room conflict modal fix * feat: add pagintaion to class * fix: requirements fixed * feat: new requirements * fix: PR comments header program filter * fix: cancel by instructor modal * fix: time display format
1 parent 0842c32 commit aa6b5ef

31 files changed

Lines changed: 3000 additions & 1069 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.claude
44
.idea
55
.claude/*
6+
node_modules/
67
frontend-v2/dist/
78
Claude.md
89
AGENTS.md

backend/src/database/events_attendance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ func (db *DB) GetCumulativeAttendanceRatesForClasses(ctx context.Context, classI
561561
GROUP BY class_id`
562562

563563
type row struct {
564-
ClassID uint `gorm:"column:class_id"`
564+
ClassID uint `gorm:"column:class_id"`
565565
AttendanceRate float64 `gorm:"column:attendance_percentage"`
566566
}
567567
rows := []row{}

backend/src/database/program_classes.go

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,26 @@ func (db *DB) GetClasses(args *models.QueryContext, facilityID *uint) ([]models.
7474
return nil, newGetRecordsDBError(err, "program classes")
7575
}
7676

77-
tx = tx.Preload("Events").Preload("Events.RoomRef")
77+
tx = tx.Preload("Events").Preload("Events.RoomRef").Preload("Enrollments").Preload("Program").Preload("Facility")
7878
if !args.All {
7979
tx = tx.Limit(args.PerPage).Offset(args.CalcOffset())
8080
}
8181
if err := tx.Find(&content).Error; err != nil {
8282
return nil, newGetRecordsDBError(err, "program classes")
8383
}
84+
for i := range content {
85+
var enrollments, completed int
86+
for _, e := range content[i].Enrollments {
87+
switch e.EnrollmentStatus {
88+
case models.Enrolled:
89+
enrollments++
90+
case models.EnrollmentCompleted:
91+
completed++
92+
}
93+
}
94+
content[i].Enrolled = int64(enrollments)
95+
content[i].Completed = int64(completed)
96+
}
8497
return content, nil
8598
}
8699

@@ -439,31 +452,55 @@ func (db *DB) GetClassesByInstructor(instructorID, facilityID int, startDate, en
439452
}
440453

441454
for i := range classes {
442-
totalSessions, upcomingSessions, cancelledSessions, err := db.calculateSessionCounts(classes[i].ID, start, end)
455+
totalSessions, upcomingSessions, cancelledSessions, sessionDates, err := db.calculateSessionCounts(classes[i].ID, start, end)
443456
if err != nil {
444457
return nil, err
445458
}
446459

447460
classes[i].SessionCount = totalSessions
448461
classes[i].UpcomingSessions = upcomingSessions
449462
classes[i].CancelledSessions = cancelledSessions
463+
classes[i].SessionDates = sessionDates
464+
465+
var event struct {
466+
RecurrenceRule string `gorm:"column:recurrence_rule"`
467+
Duration string `gorm:"column:duration"`
468+
RoomName string `gorm:"column:room_name"`
469+
}
470+
db.Table("program_class_events pce").
471+
Select("pce.recurrence_rule, pce.duration, COALESCE(r.name, '') as room_name").
472+
Joins("LEFT JOIN rooms r ON r.id = pce.room_id").
473+
Where("pce.class_id = ?", classes[i].ID).
474+
Order("pce.created_at ASC").
475+
Limit(1).
476+
Scan(&event)
477+
478+
if event.RecurrenceRule != "" {
479+
rule, rErr := rrule.StrToRRule(event.RecurrenceRule)
480+
if rErr == nil {
481+
classes[i].StartTime = rule.GetDTStart().Format("15:04")
482+
}
483+
}
484+
classes[i].Duration = event.Duration
485+
classes[i].Room = event.RoomName
450486
}
451487

452488
return classes, nil
453489
}
454490

455-
func (db *DB) calculateSessionCounts(classID int, startDate, endDate time.Time) (int, int, int, error) {
491+
func (db *DB) calculateSessionCounts(classID int, startDate, endDate time.Time) (int, int, int, []string, error) {
456492

457493
var events []struct {
458494
models.ProgramClassEvent
459495
Overrides []models.ProgramClassEventOverride `gorm:"foreignKey:EventID;references:ID"`
460496
}
461497

462498
if err := db.Preload("Overrides").Where("class_id = ?", classID).Find(&events).Error; err != nil {
463-
return 0, 0, 0, newGetRecordsDBError(err, "class events")
499+
return 0, 0, 0, nil, newGetRecordsDBError(err, "class events")
464500
}
465501

466502
var totalSessions, upcomingSessions, cancelledSessions int
503+
var sessionDates []string
467504

468505
for _, event := range events {
469506
rule, err := rrule.StrToRRule(event.RecurrenceRule)
@@ -494,16 +531,18 @@ func (db *DB) calculateSessionCounts(classID int, startDate, endDate time.Time)
494531

495532
actualUpcoming := 0
496533
for _, occurrence := range occurrences {
497-
if !cancelledDates[occurrence.Format("2006-01-02")] {
534+
dateStr := occurrence.Format("2006-01-02")
535+
if !cancelledDates[dateStr] {
498536
actualUpcoming++
537+
sessionDates = append(sessionDates, dateStr)
499538
}
500539
}
501540
upcomingSessions += actualUpcoming
502541

503542
cancelledSessions += cancelledInDateRange
504543
}
505544

506-
return totalSessions, upcomingSessions, cancelledSessions, nil
545+
return totalSessions, upcomingSessions, cancelledSessions, sessionDates, nil
507546
}
508547

509548
func (db *DB) BulkCancelSessions(req *models.BulkCancelSessionsRequest, facilityID int, claims BulkCancelClaims) (*models.BulkCancelSessionsResponse, error) {

backend/src/database/programs.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ func (db *DB) GetPrograms(args *models.QueryContext) ([]models.Program, error) {
8181
content := make([]models.Program, 0, args.PerPage)
8282
tx := db.WithContext(args.Ctx).Model(&models.Program{}).
8383
Preload("ProgramTypes").
84-
Preload("ProgramCreditTypes")
84+
Preload("ProgramCreditTypes").
85+
Preload("FacilitiesPrograms.Facility")
8586
if len(args.Tags) > 0 {
8687
tx = tx.Joins("JOIN program_types t ON t.program_id = programs.id").Where("t.id IN (?)", args.Tags)
8788
}
@@ -97,6 +98,13 @@ func (db *DB) GetPrograms(args *models.QueryContext) ([]models.Program, error) {
9798
if err := tx.Limit(args.PerPage).Offset(args.CalcOffset()).Find(&content).Error; err != nil {
9899
return nil, newGetRecordsDBError(err, "programs")
99100
}
101+
for i := range content {
102+
for _, fp := range content[i].FacilitiesPrograms {
103+
if fp.Facility != nil {
104+
content[i].Facilities = append(content[i].Facilities, *fp.Facility)
105+
}
106+
}
107+
}
100108
return content, nil
101109
}
102110

backend/src/models/program_classes.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ func IsTerminalEnrollment(s ProgramEnrollmentStatus) bool {
231231

232232
type ProgramClassDetail struct {
233233
ProgramClass
234-
FacilityName string `json:"facility_name"`
235-
Enrolled int `json:"enrolled"`
236-
Schedule string `json:"schedule"`
237-
Room string `json:"room"`
234+
FacilityName string `json:"facility_name"`
235+
Enrolled int `json:"enrolled"`
236+
Schedule string `json:"schedule"`
237+
Room string `json:"room"`
238238
AttendanceRate float64 `json:"attendance_rate"`
239239
}
240240

@@ -356,10 +356,14 @@ type Instructor struct {
356356
}
357357

358358
type InstructorClassData struct {
359-
ID int `json:"id"`
360-
Name string `json:"name"`
361-
SessionCount int `json:"sessionCount"`
362-
EnrolledCount int `json:"enrolledCount"`
363-
UpcomingSessions int `json:"upcomingSessions"`
364-
CancelledSessions int `json:"cancelledSessions"`
359+
ID int `json:"id"`
360+
Name string `json:"name"`
361+
SessionCount int `json:"sessionCount"`
362+
EnrolledCount int `json:"enrolledCount"`
363+
UpcomingSessions int `json:"upcomingSessions"`
364+
CancelledSessions int `json:"cancelledSessions"`
365+
StartTime string `json:"startTime"`
366+
Duration string `json:"duration"`
367+
Room string `json:"room"`
368+
SessionDates []string `json:"sessionDates" gorm:"-"`
365369
}

0 commit comments

Comments
 (0)