Skip to content

Commit

Permalink
Merge pull request #251 from digitalnatives/ghatighorias/fixes_wrong_…
Browse files Browse the repository at this point in the history
…attendance_order_for_student_and_teacher

Fixes wrong attendance order
  • Loading branch information
rhnonose committed Sep 25, 2017
2 parents 371e5e9 + f5f35ab commit 409d966
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
12 changes: 8 additions & 4 deletions lib/course_planner/attendances/attendances.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,29 @@ defmodule CoursePlanner.Attendances do
Repo.one(from oc in OfferedCourse,
join: s in assoc(oc, :students),
join: c in assoc(oc, :classes),
join: cs in assoc(c, :students),
join: a in assoc(c, :attendances),
join: as in assoc(a, :student),
join: ac in assoc(a, :class),
preload: [:term, :course, :teachers, :students],
preload: [classes: {c, attendances: {a, student: as, class: ac}}],
preload: [classes: {c, students: cs, attendances: {a, student: as, class: ac}}],
where: oc.id == ^offered_course_id,
order_by: [asc: ac.date, asc: s.name, asc: s.family_name])
order_by: [asc: ac.date, asc: as.name, asc: as.family_name])
end

def get_teacher_course_attendances(offered_course_id, teacher_id) do
Repo.one(from oc in OfferedCourse,
join: t in assoc(oc, :teachers),
join: s in assoc(oc, :students),
join: c in assoc(oc, :classes),
join: cs in assoc(c, :students),
join: a in assoc(c, :attendances),
join: as in assoc(a, :student),
join: ac in assoc(a, :class),
preload: [:term, :course, teachers: t, students: s],
preload: [classes: {c, attendances: a}],
preload: [classes: {c, students: cs, attendances: {a, student: as, class: ac}}],
where: oc.id == ^offered_course_id and t.id == ^teacher_id,
order_by: [asc: c.date])
order_by: [asc: ac.date, asc: s.name, asc: s.family_name])
end

def get_student_attendances(offered_course_id, student_id) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<table class="attendance-table">
<thead>
<tr class="attendance-table__thead-tr">
<%= for student <- @offered_course.students do %>
<%= for student <- CoursePlannerWeb.AttendanceView.get_offered_course_students(@offered_course) do %>
<th class="attendance-table__th">
<div class="attendance-table__th-wrapper">
<div class="attendance-table__profile-picture">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<table class="attendance-table">
<thead>
<tr class="attendance-table__thead-tr">
<%= for student <- @offered_course.students do %>
<%= for student <- CoursePlannerWeb.AttendanceView.get_offered_course_students(@offered_course) do %>
<th class="attendance-table__th">
<div class="attendance-table__th-wrapper">
<div class="attendance-table__profile-picture">
Expand Down
8 changes: 8 additions & 0 deletions lib/course_planner_web/views/attendance_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ defmodule CoursePlannerWeb.AttendanceView do
|> Map.new(fn (option) -> {option, option} end)
|> Map.merge(%{"Not set": ""})
end

def get_offered_course_students(offered_course) do
one_class =
offered_course.classes
|> List.first()

Enum.map(one_class.attendances, &(&1.student))
end
end

0 comments on commit 409d966

Please sign in to comment.