| Class | GradeEntryFormsController |
| In: |
app/controllers/grade_entry_forms_controller.rb
|
| Parent: | ApplicationController |
The actions necessary for managing grade entry forms.
| G_TABLE_PARAMS | = | { :model => GradeEntryStudent, :per_pages => [15, 30, 50, 100, 150], :filters => { 'none' => { :display => 'Show All', :proc => lambda { Student.all(:conditions => { :hidden => false }, :order => "user_name")} } | Filters will be added as the student UI is implemented (eg. Show Released, Show All,…) |
Download the grades for this grade entry form as a CSV file
# File app/controllers/grade_entry_forms_controller.rb, line 229
229: def csv_download
230: grade_entry_form = GradeEntryForm.find(params[:id])
231: send_data grade_entry_form.get_csv_grades_report,
232: :disposition => 'attachment',
233: :type => 'application/vnd.ms-excel',
234: :filename => "#{grade_entry_form.short_identifier}_grades_report.csv"
235: end
Upload the grades for this grade entry form using a CSV file
# File app/controllers/grade_entry_forms_controller.rb, line 238
238: def csv_upload
239: @grade_entry_form = GradeEntryForm.find(params[:id])
240: grades_file = params[:upload][:grades_file]
241: if request.post? && !grades_file.blank?
242: begin
243: GradeEntryForm.transaction do
244: invalid_lines = []
245: num_updates = GradeEntryForm.parse_csv(grades_file,
246: @grade_entry_form,
247: invalid_lines)
248: if !invalid_lines.empty?
249: flash[:invalid_lines] = invalid_lines
250: flash[:error] = I18n.t('csv_invalid_lines')
251: end
252: if num_updates > 0
253: flash[:upload_notice] = I18n.t(
254: 'grade_entry_forms.csv.upload_success',
255: :num_updates => num_updates)
256: end
257: end
258: end
259: end
260:
261: redirect_to :action => 'grades', :id => @grade_entry_form.id
262: end
Edit the properties of a grade entry form
# File app/controllers/grade_entry_forms_controller.rb, line 55
55: def edit
56: @grade_entry_form = GradeEntryForm.find_by_id(params[:id])
57: return unless request.post?
58:
59: # Process changes to input properties
60: @grade_entry_form.transaction do
61: if @grade_entry_form.update_attributes(params[:grade_entry_form])
62: # Success message
63: flash[:success] = I18n.t('grade_entry_forms.edit.success')
64: redirect_to :action => "edit", :id => @grade_entry_form.id
65: end
66: end
67: end
Handle pagination for grades table (The algorithm used to compute the alphabetical categories (alpha_paginate()) is found in grade_entry_form.rb.)
# File app/controllers/grade_entry_forms_controller.rb, line 100
100: def g_table_paginate
101: @grade_entry_form = GradeEntryForm.find(params[:id])
102: @students, @students_total = handle_paginate_event(
103: G_TABLE_PARAMS,
104: {:grade_entry_form => @grade_entry_form},
105: params)
106:
107: @current_page = params[:page]
108: @per_page = params[:per_page]
109: @filters = get_filters(G_TABLE_PARAMS)
110: @per_pages = G_TABLE_PARAMS[:per_pages]
111: @desc = params[:desc]
112: @filter = params[:filter]
113: if !params[:sort_by].blank?
114: @sort_by = params[:sort_by]
115: else
116: @sort_by = 'last_name'
117: end
118:
119: # Only re-compute the alpha_pagination_options for the drop-down menu
120: # if the number of items per page has changed
121: if params[:update_alpha_pagination_options] == "true"
122: all_students = get_filtered_items(
123: G_TABLE_PARAMS,
124: @filter,
125: @sort_by,
126: {:grade_entry_form => @grade_entry_form})
127: @alpha_pagination_options = @grade_entry_form.alpha_paginate(
128: all_students,
129: @per_page,
130: @students.total_pages)
131: @alpha_category = @alpha_pagination_options.first
132: session[:alpha_pagination_options] = @alpha_pagination_options
133: else
134: @alpha_pagination_options = session[:alpha_pagination_options]
135: @alpha_category = params[:alpha_category]
136: end
137: end
View/modify the grades for this grade entry form
# File app/controllers/grade_entry_forms_controller.rb, line 70
70: def grades
71: @grade_entry_form = GradeEntryForm.find_by_id(params[:id])
72: @filter = 'none'
73:
74: # Pagination options
75: @per_page = 15
76: @current_page = 1
77: @sort_by = 'last_name'
78: @desc = false
79: @filters = get_filters(G_TABLE_PARAMS)
80: @per_pages = G_TABLE_PARAMS[:per_pages]
81:
82: all_students = get_filtered_items(G_TABLE_PARAMS,
83: @filter,
84: @sort_by,
85: {:grade_entry_form => @grade_entry_form})
86: @students = all_students.paginate(:per_page => @per_page,
87: :page => @current_page)
88: @students_total = all_students.size
89: @alpha_pagination_options = @grade_entry_form.alpha_paginate(all_students,
90: @per_page,
91: @students.total_pages)
92: session[:alpha_pagination_options] = @alpha_pagination_options
93: @alpha_category = @alpha_pagination_options.first
94: end
Create a new grade entry form
# File app/controllers/grade_entry_forms_controller.rb, line 40
40: def new
41: @grade_entry_form = GradeEntryForm.new
42: return unless request.post?
43:
44: # Process input properties
45: @grade_entry_form.transaction do
46: if @grade_entry_form.update_attributes(params[:grade_entry_form])
47: # Success message
48: flash[:success] = I18n.t('grade_entry_forms.create.success')
49: redirect_to :action => "edit", :id => @grade_entry_form.id
50: end
51: end
52: end
For students
# File app/controllers/grade_entry_forms_controller.rb, line 157
157: def student_interface
158: @grade_entry_form = GradeEntryForm.find(params[:id])
159: @student = current_user
160: end
Update a grade in the table
# File app/controllers/grade_entry_forms_controller.rb, line 140
140: def update_grade
141: grade_entry_form = GradeEntryForm.find_by_id(params[:id])
142: @student_id = params[:student_id]
143: @grade_entry_item_id = params[:grade_entry_item_id]
144: updated_grade = params[:updated_grade]
145: grade_entry_student =
146: grade_entry_form.grade_entry_students.find_or_create_by_user_id(
147: @student_id)
148: @grade =
149: grade_entry_student.grades.find_or_create_by_grade_entry_item_id(
150: @grade_entry_item_id)
151: @grade.grade = updated_grade
152: @grade_saved = @grade.save
153: @updated_student_total = grade_entry_form.calculate_total_mark(@student_id)
154: end
Release/unrelease the marks for all the students or for a subset of students
# File app/controllers/grade_entry_forms_controller.rb, line 163
163: def update_grade_entry_students
164: return unless request.post?
165: grade_entry_form = GradeEntryForm.find_by_id(params[:id])
166: errors = []
167: grade_entry_students = []
168:
169: if params[:ap_select_full] == 'true'
170:
171: # Make sure we have a filter
172: if params[:filter].blank?
173: raise I18n.t('grade_entry_forms.grades.expected_filter')
174: end
175:
176: # Find the appropriate students using this filter
177: students = G_TABLE_PARAMS[:filters][params[:filter]][:proc].call()
178: students.each do |student|
179: grade_entry_students.push(grade_entry_form.grade_entry_students.find_or_create_by_user_id(student.id))
180: end
181: else
182: # Particular students in the table were selected
183: if params[:students].nil?
184: errors.push(I18n.t('grade_entry_forms.grades.must_select_a_student'))
185: else
186: params[:students].each do |student_id|
187: grade_entry_students.push(grade_entry_form.grade_entry_students.find_or_create_by_user_id(student_id))
188: end
189: end
190: end
191:
192: # Releasing/unreleasing marks should be logged
193: log_message = ""
194: if !params[:release_results].nil?
195: numGradeEntryStudentsChanged = set_release_on_grade_entry_students(
196: grade_entry_students,
197: true,
198: errors)
199: log_message = I18n.t("markus_logger.marks_released_for_grade_entry_form",
200: :grade_entry_form_id => grade_entry_form.id,
201: :grade_entry_form =>
202: grade_entry_form.short_identifier,
203: :number_students => numGradeEntryStudentsChanged)
204: elsif !params[:unrelease_results].nil?
205: numGradeEntryStudentsChanged = set_release_on_grade_entry_students(
206: grade_entry_students,
207: false,
208: errors)
209: log_message = I18n.t(
210: "markus_logger.marks_unreleased_for_grade_entry_form",
211: :grade_entry_form_id => grade_entry_form.id,
212: :grade_entry_form => grade_entry_form.short_identifier,
213: :number_students => numGradeEntryStudentsChanged)
214: end
215:
216: # Display success message
217: if numGradeEntryStudentsChanged > 0
218: flash[:success] = I18n.t('grade_entry_forms.grades.successfully_changed',
219: {:numGradeEntryStudentsChanged => numGradeEntryStudentsChanged})
220: m_logger = MarkusLogger.instance
221: m_logger.log(log_message)
222: end
223: flash[:errors] = errors
224:
225: redirect_to :action => 'grades', :id => params[:id]
226: end