class MarksGradersController

Manages actions relating to assigning graders.

Public Instance Methods

csv_upload_grader_groups_mapping() click to toggle source

Assign TAs to Students via a csv file

# File app/controllers/marks_graders_controller.rb, line 26
def csv_upload_grader_groups_mapping
  if !request.post? || params[:grader_mapping].nil?
    flash[:error] = I18n.t('csv.student_to_grader')
    redirect_to :action => 'index', :grade_entry_form_id => params[:grade_entry_form_id]
    return
  end

  invalid_lines = GradeEntryStudent.assign_tas_by_csv(params[:grader_mapping].read,
    params[:grade_entry_form_id], params[:encoding])

  if invalid_lines.size > 0
    flash[:error] = I18n.t('graders.lines_not_processed') + invalid_lines.join(', ')
  end

  redirect_to :action => 'index', :grade_entry_form_id => params[:grade_entry_form_id]
end
download_grader_students_mapping() click to toggle source

Download grader/student mappings in CSV format.

# File app/controllers/marks_graders_controller.rb, line 44
def download_grader_students_mapping
  grade_entry_form = GradeEntryForm.find(params[:grade_entry_form_id])
  students = Student.all

  file_out = CsvHelper::Csv.generate do |csv|
    students.each do |student|
      # csv format is student_name, ta1_name, ta2_name, ... etc
      student_array = [student.user_name]
      grade_entry_student = grade_entry_form.grade_entry_students.find_by_user_id(student.id)
      unless grade_entry_student.nil?
        grade_entry_student.tas.each { |ta| student_array.push(ta.user_name) }
      end

      csv << student_array
    end
  end

  send_data(file_out, :type => 'text/csv', :disposition => 'inline')
end
global_actions() click to toggle source

These actions act on all currently selected graders & students

# File app/controllers/marks_graders_controller.rb, line 65
def global_actions
  student_ids = params[:students]
  grader_ids = params[:graders]
  criteria_ids = params[:criteria]

  case params[:current_table]
    when 'groups_table'
      @grade_entry_form = GradeEntryForm.find(params[:grade_entry_form_id])
      if params[:students].nil? or params[:students].size ==  0
       # If there is a global action than there should be a student selected
        if params[:global_actions]
            @global_action_warning = I18n.t('assignment.group.select_a_student')
            render :partial => 'shared/global_action_warning.rjs'
            return
        end
      end
      students = Student.where(:id => student_ids)

      case params[:global_actions]
        when "assign"
          if params[:graders].nil? or params[:graders].size ==  0
            @global_action_warning = I18n.t('assignment.group.select_a_grader')
            render :partial => 'shared/global_action_warning.rjs'
            return
          end
          add_graders(students, grader_ids)
          return
        when "unassign"
          remove_graders(students, params)
          return
        when "random_assign"
          if params[:graders].nil? or params[:graders].size ==  0
            @global_action_warning = I18n.t('assignment.group.select_a_grader')
            render :partial => 'shared/global_action_warning.rjs'
            return
          end
          randomly_assign_graders(students, grader_ids)
          return
      end
  end
end
index() click to toggle source
# File app/controllers/marks_graders_controller.rb, line 21
def index
  @grade_entry_form = GradeEntryForm.find(params[:grade_entry_form_id])
end
populate() click to toggle source
# File app/controllers/marks_graders_controller.rb, line 9
def populate
  @grade_entry_form = GradeEntryForm.find(params[:grade_entry_form_id])
  @students = Student.all
  @table_rows = construct_table_rows(@students, @grade_entry_form)
end
populate_graders() click to toggle source
# File app/controllers/marks_graders_controller.rb, line 15
def populate_graders
  @grade_entry_form = GradeEntryForm.find(params[:grade_entry_form_id])
  @graders = Ta.find(:all)
  @table_rows = construct_grader_table_rows(@graders, @grade_entry_form)
end