Skip to content

Commit

Permalink
Update student model counts
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidRagone committed Oct 21, 2012
1 parent 7511401 commit dd697ea
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 20 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/student_reports.js.coffee
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/student_reports.css.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the student_reports controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
9 changes: 9 additions & 0 deletions app/controllers/student_reports_controller.rb
@@ -0,0 +1,9 @@
class StudentReportsController < ApplicationController
def index
@students = Student.all
end

def show
@student = Student.find(params[:id])
end
end
5 changes: 5 additions & 0 deletions app/helpers/student_reports_helper.rb
@@ -0,0 +1,5 @@
module StudentReportsHelper
def self.alphabetize(students)
students.sort { |a,b| a.last_name <=> b.last_name }
end
end
26 changes: 11 additions & 15 deletions app/models/student.rb
Expand Up @@ -14,35 +14,31 @@ class Student < ActiveRecord::Base

after_create :create_current_assignments

def completed_assignments
self.student_assignments.select { |s_a| s_a.completion_time && s_a.due_date > Time.zone.now.to_date }
#day's completed assignments
def completed_assignments_today_count
student_assignments.joins(:assignment).completed.where('due_date > ?', Time.zone.now.to_date).count
end

def completed_assignments_count
completed_assignments.length
def completed_assignments_to_date_count
student_assignments.joins(:assignment).completed.count
end

def total_outstanding_assignments
def all_assignments_today
student_assignments.joins(:assignment).where('due_date > ?', Time.zone.now.to_date)
# self.student_assignments.select { |s_a| s_a.due_date > Time.zone.now.to_date }
end

# TODO: You don't need this, you can just do total_outstanding_assignments.count
#
def total_outstanding_assignments_count
total_outstanding_assignments.length
def outstanding_assignments_to_date_count
student_assignments.joins(:assignment).where("student_assignments.completion_time IS NULL").count
end

def remaining_outstanding_assignments_count
total_outstanding_assignments_count - completed_assignments_count
def outstanding_assignments_today_count
student_assignments.joins(:assignment).where("student_assignments.completion_time IS NULL AND due_date > ?", Time.zone.now.to_date).count
end

def assignment_completion_percentage
if total_outstanding_assignments_count == 0
if outstanding_assignments_today_count == 0
return "--"
else
(completed_assignments_count/total_outstanding_assignments.length.to_f).round(2)*100
(completed_assignments_today_count/all_assignments_today.length.to_f).round(2)*100
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Expand Up @@ -40,7 +40,7 @@
</a>
<ul class="dropdown-menu">
<li><%= link_to "Daily Reports", reports_path %></li>
<li><%= link_to "Student Reports", reports_path %></li>
<li><%= link_to "Student Reports", student_reports_path %></li>
</ul>
</li>
<li class="dropdown">
Expand Down
2 changes: 1 addition & 1 deletion app/views/sessions/_student.haml
Expand Up @@ -2,7 +2,7 @@
%td
= full_name(student)
%span.badge.badge-important{ :student_id => student.id }
= student.remaining_outstanding_assignments_count
= student.outstanding_assignments_today_count
%td
- if !student.find_session_attendance(@session.id)
= render partial: 'absent', locals: {student:student, session: @session}
Expand Down
2 changes: 1 addition & 1 deletion app/views/student_assignments/update.js.erb
@@ -1,6 +1,6 @@
$(".span5.student-assignments").html("<%=j render(:partial => '/students/student', :locals => {:student => @student_assignment.student }) %>");

$(".badge[student_id='<%= @student_assignment.student.id %>']").html("<%= @student_assignment.student.remaining_outstanding_assignments_count %>");
$(".badge[student_id='<%= @student_assignment.student.id %>']").html("<%= @student_assignment.student.outstanding_assignments_today_count %>");

$("#<%=j @student_assignment.subject_name %>").html("<%= @student_assignment.student.afterschool_class.sessions.last.subject_completion_percentage(@student_assignment.subject_name) %>");

Expand Down
15 changes: 15 additions & 0 deletions app/views/student_reports/index.html.haml
@@ -0,0 +1,15 @@
%h1 Student Reports
%ul.nav.nav-list
%li.divider
%table.table.table-striped#student_reports_table
%thead
%tr
%th Student
%tbody
- StudentReportsHelper.alphabetize(@students).each do |student|
%tr
%th
= link_to "#{student.first_name} #{student.last_name}", student_report_path(student)
%th
%span.label.label-success
=link_to "Export Report"
27 changes: 27 additions & 0 deletions app/views/student_reports/show.html.haml
@@ -0,0 +1,27 @@
%div
%h3
= full_name(@student)
%table.table.table-striped{ :cellpadding => "3", :cellspacing => "2" }

%tr
%th Status
%th Subject
%th Description
- @student.all_assignments_today.each do |s_a|
%tr
%td
-if s_a.completion_time
%span.label.label-success
= link_to "Complete", student_assignment_path(s_a, :completion_time => "NULL"), method: :put, :remote => true
-else
%span.label.label-important
= link_to "Incomplete", student_assignment_path(s_a, :completion_time => Time.zone.now), method: :put, :remote => true
%td
= s_a.assignment.subject.name
%td
= s_a.assignment.description
/ %td
/ %span.label.label-important
/ = link_to "",student_assignment_path(s_a), :class => "icon-trash", method: :delete, data: {confirm: "Are you sure?"}, :remote => true


2 changes: 1 addition & 1 deletion app/views/students/_student.html.haml
Expand Up @@ -7,7 +7,7 @@
%th Status
%th Subject
%th Description
- student.total_outstanding_assignments.each do |s_a|
- student.all_assignments_today.each do |s_a|
%tr
%td
-if s_a.completion_time
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Expand Up @@ -22,7 +22,7 @@
resources :semesters

resources :reports, only: [:index, :show]

resources :student_reports, only: [:index, :show]

match "/assignments/grade/:grade_level_id" => 'assignments#index'

Expand Down
5 changes: 5 additions & 0 deletions spec/controllers/student_reports_controller_spec.rb
@@ -0,0 +1,5 @@
require 'spec_helper'

describe StudentReportsController do

end
15 changes: 15 additions & 0 deletions spec/helpers/student_reports_helper_spec.rb
@@ -0,0 +1,15 @@
require 'spec_helper'

# Specs in this file have access to a helper object that includes
# the StudentReportsHelper. For example:
#
# describe StudentReportsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe StudentReportsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit dd697ea

Please sign in to comment.