Skip to content

Commit

Permalink
Added student transcript report
Browse files Browse the repository at this point in the history
 * it's not complete but the outline is there
 * also added the Prawn-Format plugin to make some thing easier(possible)
  • Loading branch information
rnhurt committed Jul 27, 2009
1 parent e01bc2a commit 11257a6
Show file tree
Hide file tree
Showing 22 changed files with 1,726 additions and 51 deletions.
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Expand Up @@ -32,7 +32,7 @@

<div class='span-2'><img class='top' src='/images/logo.png' alt="logo" width='60px' height='60px' /></div>

<div class='span-5'>
<div class='span-6'>
<span class='title last'><%= StaticData.site_name %></span>
<span class='tagline column span-6'><%= StaticData.tag_line %></span>
</div>
Expand Down
1 change: 1 addition & 0 deletions app/views/reports/_report_list.erb
@@ -1,5 +1,6 @@
<% reports = [
{:name => 'Report Card', :url => '/reports/report_card'},
{:name => 'Student Transcript', :url => '/reports/student_transcript'},
{:name => 'Student Roster', :url => '/reports/student_roster'}]%>

<table>
Expand Down
88 changes: 44 additions & 44 deletions app/views/users/_edit.html.erb
@@ -1,50 +1,50 @@
<div class='box span-13'>
<% form_for user do |f| %>
<fieldset>
<% if user.new_record? %>
<%= content_tag :legend, "New #{user.class.name.titleize}" %>
<% form_for user do |f| %>
<fieldset>
<% if user.new_record? %>
<%= content_tag :legend, "New #{user.class.name.titleize}" %>
<% else %>
<%= content_tag :legend, "Editing: #{user.full_name}" %>
<% end %>
<%= f.label :login, {}, :class => 'req' %>
<%= f.text_field :login, :id => 'user_login', :class=>'input' %>
<%= f.label :first_name, {}, :class => 'req' %>
<%= f.text_field :first_name, :class => 'input' %>
<%= f.label :last_name, {}, :class => 'req' %>
<%= f.text_field :last_name, :class => 'input' %>
<%= f.label :email, {}, :class => 'req' %>
<%= f.text_field :email, :class=>'input' %>

<label><%= content_tag :span, f.object.new_record? ? 'Password' : 'Change password',
!f.object.new_record? ? nil : :class=>'required' %></label>
<%= f.password_field :password, :class=>'input' %>
<label><%= content_tag :span, 'Confirm password', !f.object.new_record? ? nil : :class=>'required' %></label>
<%= f.password_field :password_confirmation, :class=>'input' %>
<%= f.label :site, {}, :class => 'req' %>
<%= collection_select user.class.name.underscore, :site_id, Site.find(:all), :id, :name, {}, :class=>'input' %>
<% if user.class.name == 'Student' %>
<%= f.label :class_of, {}, :class => 'req' %>
<%# FIXME: Get the class time properly and stop hardcoding values %>
<%= f.select(:class_of, ((Time.now.year - 1)..(Time.now.year + 10)).to_a, {}, :class=>'input') %>
<%= f.label :homeroom %>
<%= text_field_tag :homeroom1, {}, :maxlength => 20 %>
<%= f.select :homeroom, @homerooms, :include_blank => true %>
<% end %>
<div class="spacer">
<%= submit_tag 'Save', :class => 'btn positive' %>
<%= link_to 'Cancel', {:action=> 'index', :controller=> 'users/'+user.class.name.tableize}, :class => 'btn standard' %>
</div>
</fieldset>
<% end %>
<% end %>
<%= f.label :login, {}, :class => 'req' %>
<%= f.text_field :login, :id => 'user_login', :class=>'input' %>
<%= f.label :first_name, {}, :class => 'req' %>
<%= f.text_field :first_name, :class => 'input' %>
<%= f.label :last_name, {}, :class => 'req' %>
<%= f.text_field :last_name, :class => 'input' %>
<%= f.label :email, {}, :class => 'req' %>
<%= f.text_field :email, :class=>'input' %>

<label><%= content_tag :span, f.object.new_record? ? 'Password' : 'Change password',
!f.object.new_record? ? nil : :class=>'required' %></label>
<%= f.password_field :password, :class=>'input' %>

<label><%= content_tag :span, 'Confirm password', !f.object.new_record? ? nil : :class=>'required' %></label>
<%= f.password_field :password_confirmation, :class=>'input' %>
<%= f.label :site, {}, :class => 'req' %>
<%= collection_select user.class.name.underscore, :site_id, Site.find(:all), :id, :name, {}, :class=>'input' %>
<% if user.class.name == 'Student' %>
<%= f.label :class_of, {}, :class => 'req' %>
<%# FIXME: Get the class time properly and stop hardcoding values %>
<%= f.select(:class_of, ((Time.now.year - 1)..(Time.now.year + 10)).to_a, {}, :class=>'input') %>
<%= f.label :homeroom %>
<%= text_field_tag :homeroom1, {}, :maxlength => 20 %>
<%= f.select :homeroom, @homerooms, :include_blank => true %>
<% end %>

<div class="spacer">
<%= submit_tag 'Save', :class => 'btn positive' %>
<%= link_to 'Cancel', {:action=> 'index', :controller=> 'users/'+user.class.name.tableize}, :class => 'btn standard' %>
</div>
</fieldset>
<% end %>
</div>

<%= set_focus_to_id 'user_login' %>
1 change: 1 addition & 0 deletions config/initializers/prawn.rb
@@ -1,2 +1,3 @@
require "prawn/core"
require "prawn/layout"
require "prawn/format"
2 changes: 1 addition & 1 deletion db/migrate/017_create_supporting_skill_categories.rb
Expand Up @@ -10,6 +10,6 @@ def self.up
end

def self.down
drop_table :supporting_skill_catetories
drop_table :supporting_skill_categories
end
end
4 changes: 2 additions & 2 deletions lib/gradesheet/default_data/loader.rb
Expand Up @@ -37,14 +37,14 @@ def load(lang=nil)

StaticData.transaction do
# Static Data
StaticData.create!(:name => 'SITE_NAME', :value => 'Your School Name')
StaticData.create!(:name => 'SITE_NAME', :value => 'School Name')
StaticData.create!(:name => 'TAG_LINE', :value => 'The Best School Ever!')

# Site Data
site = Site.create!(:name => 'Main Campus', :school_id => 1)

# Administrator user
User.create!(:type => 'Teacher', :login => 'admin', :first_name => 'Admin', :last_name => 'Admin',
Teacher.create!(:login => 'admin', :first_name => 'Admin', :last_name => 'Admin',
:site => site, :is_admin => true, :password_salt => Authlogic::Random.hex_token,
:password => 'admin', :password_confirmation => 'admin', :email => 'admin@example.com' )
end
Expand Down
4 changes: 1 addition & 3 deletions lib/reports/report_card.rb
Expand Up @@ -9,9 +9,7 @@ class ReportCard
GUTTER_SIZE = 5 # The size of the buffer between elements

# Build the parameter window to be shown to the user.
def self.get_params()
# Build the parameter screen

def self.get_params()
# Allow the user to select a single student or multiple students.
students = Student.find(:all)
homerooms = Student.find_homerooms()
Expand Down
166 changes: 166 additions & 0 deletions lib/reports/student_transcript.rb
@@ -0,0 +1,166 @@
# This report prints a student transcript containing the students complete
# academic career.
class StudentTranscript

# Build the parameter screen for this report.
def self.get_params()
# Allow the user to select a single student or multiple students.
students = Student.find(:all)
homerooms = Student.find_homerooms()

params = <<-EOS
<form action="/reports/student_transcript.pdf" method="get">
<fieldset>
<legend>Student Transcript</legend>
<hr />
<label>Homeroom</label>
<select size='1' id="homeroom_id" name="homeroom_id">
EOS

# List each homeroom
homerooms.each do |h|
params += "<option value='#{h}'>#{h}</option>"
end

params += <<-EOS
</select>
<br />
<label>OR<br /><br />Student(s)</label>
<select multiple size="7" id="student_id" name="student_id[]">
EOS

# List all of the students in the school
students.each do |s|
params += "<option value='#{s[:id]}'>#{s[:first_name]} #{s[:last_name]}</option>"
end

params += <<-EOS
</select>
<div class="spacer">
<input class="btn positive" name="commit" type="submit" value="Run Report" />
</div>
</fieldset>
</form>
EOS

end


# Build the report as a PDF and send it to the browser.
def self.draw(params)
if params[:student_id].nil? then
# Process a whole homeroom
students = Student.find_all_by_homeroom(params[:homeroom_id])
else
# Search for individual student(s)
students = Student.find(:all, :conditions => { :id => params[:student_id]})
end

# Create a new document
@pdf = Prawn::Document.new :page_size => "LETTER",
:skip_page_creation => false,
:page_layout => :landscape

# Make it so we don't have to use the 'pdf.' prefix everywhere. :)
@pdf.instance_eval do
# Loop through each student
students.each_with_index do |student, sindex|

# Count the number of pages each student requires so that we can duplex properly
student_page_count = 0

# Build the page header
header margin_box.top_left do
# Insert the school logo
logo = "#{RAILS_ROOT}/public/images/logo.png"
image logo, :at => bounds.top_left, :height => 35

# Insert the school name
text StaticData.site_name, :align => :center, :size => 11
text "STUDENT TRANSCRIPT", :align => :center, :size => 20
stroke_horizontal_rule # make it look pretty

# Insert the student information
move_down(15)
mask(:y) { text "Social Security No. <u><pre>" + ' '*50 + "</pre></u>",
:align => :right, :size => 10
}
text "Student Name <u> #{student.full_name}<pre>" +
' '*(50-student.full_name.length) + "</pre></u>", :align => :left, :size => 10

# move_down(font.height)
# text "Student Address <u><pre>" + ' '*75 + "</pre></u>",
# :align => :left, :size => 10
#
# move_down(font.height)
# text 'Date of Birth <u><pre>' + ' '*15 + '/' + ' '*15 + '/' + ' '*15 +
# '</pre></u>', :align => :left, :size => 10
#
# move_down(font.height)
# text "Program Name <u><pre>" + ' '*75 + "</pre></u>",
# :align => :left, :size => 10

student_page_count += 1 # reset the student page counter
end

# Set up the text options
font "Helvetica"
text_options.update(:size => 7, :align => :left)

student.courses.each do |temp|
puts "**** #{temp.name} "
end

# Print the grades for each class
headers = ['School Year', 'Term', 'Course Name', 'Instructor', 'Grade']
data = []
student.courses.each_with_index do |course, index|
data << [
course.term.school_year,
course.term.name,
course.name,
course.teacher.full_name,
course.calculate_grade(student)[:letter]
]
end # each course

bounding_box([0,bounds.height-75], :width => bounds.width) do
table(
data,
:headers => headers,
:header_color => "0000A0",
:header_text_color => "FFFFFF",
:row_colors => :pdf_writer,
:font_size => 7,
:border_style => :grid,
:width => bounds.width)
end

# Is this the last student?
if sindex < students.count - 1 then
# No, force a page break between students
start_new_page
else
# Yes, make sure we don't add a page break unnecessarily
student_page_count = 0
end

# Always print an even number of pages for a student. This prevents the
# start of one report from printing on the back of the previous report.
start_new_page unless student_page_count.even?

end # each student

end # instance_eval


# Render the document
@pdf.render
end

end

0 comments on commit 11257a6

Please sign in to comment.