class GradersController

Manages actions relating to assigning graders.

Public Instance Methods

add_grader_to_grouping() click to toggle source
# File app/controllers/graders_controller.rb, line 153
def add_grader_to_grouping
  @assignment = Assignment.find(params[:assignment_id])
  @grouping = Grouping.find(params[:grouping_id],
                              :include => [:students, :tas, :group])
  grader = Ta.find(params[:grader_id])
  @grouping.add_tas(grader)
  @groupings_data = construct_table_rows([@grouping.reload],@assignment)
  @graders_data = construct_grader_table_rows([grader], @assignment)
  criteria = grader.get_criterion_associations_by_assignment(@assignment).map{|c| c.criterion}
  criteria.each do |criterion|
    criterion.save
  end
  @criteria_data = construct_criterion_table_rows(criteria, @assignment)
end
csv_upload_grader_criteria_mapping() click to toggle source

Assign TAs to Criteria via a csv file

# File app/controllers/graders_controller.rb, line 92
def csv_upload_grader_criteria_mapping
  @assignment = Assignment.find(params[:assignment_id])
  if !request.post? || params[:grader_criteria_mapping].nil?
    flash[:error] = I18n.t('csv.criteria_to_grader')
    redirect_to :action => 'index', :assignment_id => params[:assignment_id]
    return
  end

  if @assignment.marking_scheme_type == 'rubric'
    invalid_lines = RubricCriterion.assign_tas_by_csv(
    params[:grader_criteria_mapping].read, params[:assignment_id], params[:encoding])
  else
    invalid_lines = FlexibleCriterion.assign_tas_by_csv(
    params[:grader_criteria_mapping].read, params[:assignment_id], params[:encoding])
  end
  if invalid_lines.size > 0
    flash[:error] = I18n.t('csv_invalid_lines') + invalid_lines.join(', ')
  end
  redirect_to :action => 'index', :assignment_id => params[:assignment_id]
end
csv_upload_grader_groups_mapping() click to toggle source

Assign TAs to Groupings via a csv file

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

  invalid_lines = Grouping.assign_tas_by_csv(params[:grader_mapping].read,
                                             params[:assignment_id], params[:encoding])
  if invalid_lines.size > 0
    flash[:error] = I18n.t('csv_invalid_lines') + invalid_lines.join(', ')
  end
  redirect_to :action => 'index', :assignment_id => params[:assignment_id]
end
download_dialog() click to toggle source
# File app/controllers/graders_controller.rb, line 15
def download_dialog
  @assignment = Assignment.find(params[:assignment_id])
  render :partial => 'graders/modal_dialogs/download_dialog.rjs'
end
download_grader_criteria_mapping() click to toggle source
# File app/controllers/graders_controller.rb, line 133
def download_grader_criteria_mapping
  assignment = Assignment.find(params[:assignment_id])

  #get all the criteria
  criteria = assignment.get_criteria

  file_out = CsvHelper::Csv.generate do |csv|
     criteria.each do |criterion|
       criterion_array = [criterion.get_name]
       # csv format is criterion_name, ta1_name, ta2_name, ... etc
       criterion.tas.each do |ta|
          criterion_array.push(ta.user_name)
       end
       csv << criterion_array
     end
   end

  send_data(file_out, :type => 'text/csv', :disposition => 'inline')
end
download_grader_groupings_mapping() click to toggle source
# File app/controllers/graders_controller.rb, line 113
def download_grader_groupings_mapping
  assignment = Assignment.find(params[:assignment_id], :include => [{:groupings => :group}])

  #get all the groups
  groupings = assignment.groupings

  file_out = CsvHelper::Csv.generate do |csv|
     groupings.each do |grouping|
       group_array = [grouping.group.group_name]
       # csv format is group_name, ta1_name, ta2_name, ... etc
       grouping.tas.each do |ta|
          group_array.push(ta.user_name)
       end
       csv << group_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 & groups

# File app/controllers/graders_controller.rb, line 169
def global_actions
  grouping_ids = params[:groupings]
  grader_ids = params[:graders]
  criteria_ids = params[:criteria]

  case params[:current_table]
    when 'groups_table'
      @assignment = Assignment.find(params[:assignment_id],
        :include => [{:rubric_criteria => :criterion_ta_associations},
          {:flexible_criteria => :criterion_ta_associations}])
      if params[:groupings].nil? or params[:groupings].size ==  0
       #if there is a global action than there should be a group selected
        if params[:global_actions]
            @global_action_warning = I18n.t('assignment.group.select_a_group')
            render :partial => 'shared/global_action_warning.rjs'
            return
        end
      end
      groupings = Grouping.where(:id => grouping_ids).includes(:assignment,
                                                               :students,
                                                               {:tas => :criterion_ta_associations},
                                                               :group)
      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(groupings, grader_ids)
          return
        when 'unassign'
          remove_graders(groupings, 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(groupings, grader_ids)
          return
      end
    when 'criteria_table'
      @assignment = Assignment.find(params[:assignment_id],
        :include => [{:groupings => [:students,
              {:tas => :criterion_ta_associations}, :group]}])
      if params[:criteria].nil? or params[:criteria].size ==  0
    #don't do anything if no criteria
        render :nothing => true
        return
      end
      if @assignment.marking_scheme_type == 'rubric'
        criteria = RubricCriterion.where(:id => criteria_ids).includes(:criterion_ta_associations)
      else
        criteria = FlexibleCriterion.where(:id => criteria_ids).includes(:criterion_ta_associations)
      end
      case params[:global_actions]
        when 'assign'
        if params[:graders].nil? or params[:graders].size ==  0
          #don't do anything if no graders
          render :nothing => true
          return
        end
          graders = Ta.where(:id => grader_ids)
          add_graders_to_criteria(criteria, graders)
          return
        when 'unassign'
          remove_graders_from_criteria(criteria, params)
          return
        when 'random_assign'
          if params[:graders].nil? or params[:graders].size ==  0
            #don't do anything if no graders
            render :nothing => true
            return
          end
          randomly_assign_graders_to_criteria(criteria, grader_ids)
          return
      end
  end
end
grader_criteria_dialog() click to toggle source
# File app/controllers/graders_controller.rb, line 26
def grader_criteria_dialog
  @assignment = Assignment.find(params[:assignment_id])
  @grader = Ta.find(params[:grader])
  render :partial => 'graders/modal_dialogs/grader_criteria_dialog.rjs'
end
groups_coverage_dialog() click to toggle source
# File app/controllers/graders_controller.rb, line 20
def groups_coverage_dialog
  @assignment = Assignment.find(params[:assignment_id])
  @grouping = Grouping.find(params[:grouping])
  render :partial => 'graders/modal_dialogs/groups_coverage_dialog.rjs'
end
index() click to toggle source
# File app/controllers/graders_controller.rb, line 70
def index
  @assignment = Assignment.find(params[:assignment_id])
  @sections = Section.all
end
populate() click to toggle source
# File app/controllers/graders_controller.rb, line 33
def populate
  @assignment = Assignment.find(params[:assignment_id],
                                :include => [{
                                    :groupings => [
                                        :students, :tas,
                                      :group]}])
  @groupings = @assignment.groupings
  @table_rows = construct_table_rows(@groupings, @assignment)
end
populate_criteria() click to toggle source
# File app/controllers/graders_controller.rb, line 49
def populate_criteria
  @assignment = Assignment.find(params[:assignment_id],
                                :include => [
                                  {:rubric_criteria =>
                                      :criterion_ta_associations},
                                  {:flexible_criteria =>
                                      :criterion_ta_associations}])
  @criteria = @assignment.get_criteria
  @table_rows = construct_criterion_table_rows(@criteria, @assignment)
end
populate_graders() click to toggle source
# File app/controllers/graders_controller.rb, line 43
def populate_graders
  @assignment = Assignment.find(params[:assignment_id])
  @graders = Ta.all
  @table_rows = construct_grader_table_rows(@graders, @assignment)
end
set_assign_criteria() click to toggle source
# File app/controllers/graders_controller.rb, line 60
def set_assign_criteria
  @assignment = Assignment.find(params[:assignment_id])
  if params[:value] == 'true'
    @assignment.assign_graders_to_criteria = true
  else
    @assignment.assign_graders_to_criteria = false
  end
  @assignment.save
end
upload_dialog() click to toggle source
# File app/controllers/graders_controller.rb, line 10
def upload_dialog
  @assignment = Assignment.find(params[:assignment_id])
  render :partial => 'graders/modal_dialogs/upload_dialog.rjs'
end