Skip to content

Commit

Permalink
Merge 71c19ff into 8341134
Browse files Browse the repository at this point in the history
  • Loading branch information
fergione committed Mar 28, 2023
2 parents 8341134 + 71c19ff commit c933947
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 175 deletions.
137 changes: 19 additions & 118 deletions app/models/assignment.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Assignment < ApplicationRecord
include ReviewAssignment
include QuizAssignment
include AssignmentHelper
include DueDateMixIn
has_paper_trail
# When an assignment is created, it needs to
# be created as an instance of a subclass of the Assignment (model) class;
Expand Down Expand Up @@ -186,38 +187,6 @@ def path
path_text
end

# Check whether review, metareview, etc.. is allowed
# The permissions of TopicDueDate is the same as AssignmentDueDate.
# Here, column is usually something like 'review_allowed_id'
def check_condition(column, topic_id = nil)
next_due_date = DueDate.get_next_due_date(id, topic_id)
return false if next_due_date.nil?

right_id = next_due_date.send column
right = DeadlineRight.find(right_id)
right && (right.name == 'OK' || right.name == 'Late')
end

# Determine if the next due date from now allows for submissions
def submission_allowed(topic_id = nil)
check_condition('submission_allowed_id', topic_id)
end

# Determine if the next due date from now allows to take the quizzes
def quiz_allowed(topic_id = nil)
check_condition('quiz_allowed_id', topic_id)
end

# Determine if the next due date from now allows for reviews
def can_review(topic_id = nil)
check_condition('review_allowed_id', topic_id)
end

# Determine if the next due date from now allows for metareviews
def metareview_allowed(topic_id = nil)
check_condition('review_of_review_allowed_id', topic_id)
end

# Deletes all instances created as part of assignment and finally destroys itself.
def delete(force = nil)
begin
Expand Down Expand Up @@ -294,76 +263,41 @@ def create_node
node.save
end

# if current stage is submission or review, find the round number
# otherwise, return 0
def number_of_current_round(topic_id)
next_due_date = DueDate.get_next_due_date(id, topic_id)
return 0 if next_due_date.nil?

next_due_date.round ||= 0
end

# For varying rubric feature
def current_stage_name(topic_id = nil)
if staggered_deadline?
return (topic_id.nil? ? 'Unknown' : current_stage(topic_id))
end
# def current_stage_name(topic_id = nil)
# if staggered_deadline?
# return (topic_id.nil? ? 'Unknown' : current_stage(topic_id))
# end

due_date = find_current_stage(topic_id)
unless due_date == 'Finished' || due_date.nil? || due_date.deadline_name.nil?
return due_date.deadline_name
end
# due_date = find_current_stage(topic_id)
# unless due_date == 'Finished' || due_date.nil? || due_date.deadline_name.nil?
# return due_date.deadline_name
# end

current_stage(topic_id)
end
# current_stage(topic_id)
# end

# check if this assignment has multiple review phases with different review rubrics
def varying_rubrics_by_round?
# E-2084 corrected '>=' to '>' to fix logic
AssignmentQuestionnaire.where(assignment_id: id, used_in_round: 2).size > 1
end

def link_for_current_stage(topic_id = nil)
return nil if staggered_and_no_topic?(topic_id)

due_date = find_current_stage(topic_id)
if due_date.nil? || (due_date == 'Finished') || due_date.is_a?(TopicDueDate)
return nil
end

due_date.description_url
end

def stage_deadline(topic_id = nil)
def stage_deadline(participant_id = nil)
topic_id = find_topic_id(participant_id)
return 'Unknown' if staggered_and_no_topic?(topic_id)

due_date = find_current_stage(topic_id)
due_date = find_current_stage(participant_id)
due_date.nil? || due_date == 'Finished' ? due_date : due_date.due_at.to_s
end

def num_review_rounds
due_dates = AssignmentDueDate.where(parent_id: id)
rounds = 0
due_dates.each do |due_date|
rounds = due_date.round if due_date.round > rounds
end
rounds
end

def find_current_stage(topic_id = nil)
next_due_date = DueDate.get_next_due_date(id, topic_id)
return 'Finished' if next_due_date.nil?

next_due_date
end

# Zhewei: this method is almost the same as 'stage_deadline'
def current_stage(topic_id = nil)
return 'Unknown' if staggered_and_no_topic?(topic_id)
# def current_stage(topic_id = nil)
# return 'Unknown' if staggered_and_no_topic?(topic_id)

due_date = find_current_stage(topic_id)
due_date.nil? || due_date == 'Finished' ? 'Finished' : DeadlineType.find(due_date.deadline_type_id).name
end
# due_date = find_current_stage(topic_id)
# due_date.nil? || due_date == 'Finished' ? 'Finished' : DeadlineType.find(due_date.deadline_type_id).name
# end

# Find the ID of a review questionnaire for this assignment
def review_questionnaire_id(round_number = nil, topic_id = nil)
Expand Down Expand Up @@ -566,39 +500,6 @@ def self.export_fields(options)
fields
end

def find_due_dates(type)
due_dates.select { |due_date| due_date.deadline_type_id == DeadlineType.find_by(name: type).id }
end

# Method find_review_period is used in answer_helper.rb to get the start and end dates of a round
def find_review_period(round)
# If round is nil, it means the same questionnaire is used for every round. Thus, we return all periods.
# If round is not nil, we return only the period of that round.

submission_type = DeadlineType.find_by(name: 'submission').id
review_type = DeadlineType.find_by(name: 'review').id

due_dates = []
due_dates += find_due_dates('submission')
due_dates += find_due_dates('review')
due_dates.sort_by!(&:id)

start_dates = []
end_dates = []

if round.nil?
round = 1
while self.due_dates.exists?(round: round)
start_dates << due_dates.select { |due_date| due_date.deadline_type_id == submission_type && due_date.round == round }.last
end_dates << due_dates.select { |due_date| due_date.deadline_type_id == review_type && due_date.round == round }.last
round += 1
end
else
start_dates << due_dates.select { |due_date| due_date.deadline_type_id == submission_type && due_date.round == round }.last
end_dates << due_dates.select { |due_date| due_date.deadline_type_id == review_type && due_date.round == round }.last
end
[start_dates, end_dates]
end

# for program 1 like assignment, if same rubric is used in both rounds,
# the 'used_in_round' field in 'assignment_questionnaires' will be null,
Expand Down
2 changes: 1 addition & 1 deletion app/views/sign_up_sheet/review_bids_others_work.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<% last_response_round = @latest_response.round %>
<%end%>
<% current_round = @assignment.number_of_current_round(topic_id) %>
<% current_round = @assignment.number_of_current_round(@participant.user_id) %>
<td>
<%= link_to "View", {:controller => 'response', :action => 'view', :id => @latest_response.id} %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/student_review/list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<%= render :partial => 'responses', :locals => {:mappings => @review_mappings, :title => 'Review'} %>
<!-- Temporary fix for Staggered Deadline assignment issue preventing students from reviewing 04-23-19 -->
<!-- We need to perform the same check, but on the topic that is being reviewed and not the topic that the reviewer wrote on -->
<% if @assignment.staggered_deadline? or @assignment.number_of_current_round(@topic_id) == 1 or (@assignment.number_of_current_round(@topic_id) > 1 and @assignment.allow_selecting_additional_reviews_after_1st_round) %>
<% if @assignment.staggered_deadline? or @assignment.number_of_current_round(@participant.user_id) == 1 or (@assignment.number_of_current_round(@participant.user_id) > 1 and @assignment.allow_selecting_additional_reviews_after_1st_round) %>
<% if @assignment.dynamic_reviewer_assignment? %>
<% if @num_reviews_in_progress >= Assignment.max_outstanding_reviews %>
<br><br>
Expand Down
6 changes: 3 additions & 3 deletions app/views/student_task/list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
participant = student_task.participant
stage = student_task.current_stage
topic_id = SignedUpTeam.topic_id(participant.parent_id, participant.user_id)
duedate = participant.assignment.stage_deadline(topic_id)
duedate = participant.assignment.stage_deadline(participant.user_id)
controller = ""
action = ""
if stage == "submission"
Expand Down Expand Up @@ -122,8 +122,8 @@
<% end %>
<!--current stage-->
<td>
<% if participant.assignment.link_for_current_stage(topic_id)!= nil && participant.assignment.link_for_current_stage(topic_id).length!=0%>
<%= link_to participant.assignment.current_stage_name(topic_id), participant.assignment.link_for_current_stage(topic_id) %>
<% if participant.assignment.link_for_current_stage(participant.user_id)!= nil && participant.assignment.link_for_current_stage(participant.user_id).length!=0%>
<%= link_to participant.assignment.current_stage_name(topic_id), participant.assignment.link_for_current_stage(participant.user_id) %>
<% else %>
<%= participant.assignment.current_stage_name(topic_id) %>
<% end %>
Expand Down
8 changes: 4 additions & 4 deletions app/views/student_task/view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<!--Show bookmarks if they are allowed for this assignment-->
<% if @use_bookmark %>
<li>
<% if @topic_id and @assignment.submission_allowed(@topic_id) %>
<% if @topic_id and @assignment.submission_allowed(@participant.user_id) %>
<%= link_to "View bookmarks", :controller=>'bookmarks', :action=> 'list', :id => @topic_id %> <%=t ".view_bookmarks_lengthy" %>
<% else %>
<font color="gray"><%=t ".view_bookmarks" %></font><%=t ".choose_topic" %>
Expand All @@ -53,14 +53,14 @@ to display the label "Your team" in the student assignment tasks-->
<li>
<% if @team %>
<% if @topics.size > 0 %>
<% if @topic_id && @assignment.submission_allowed(@topic_id) %>
<% if @topic_id && @assignment.submission_allowed(@participant.user_id) %>
<%= link_to t(".your_work"), :controller => 'submitted_content', :action => 'edit', :id => @participant.id %> <%=t ".submit_work" %>
<% else %>
<!--if one team do not hold a topic (still in waitlist), they cannot submit their work.-->
<font color="gray"><%=t ".your_work" %></font> <%=t ".choose_topic" %>
<% end %>
<% else %>
<% if @assignment.submission_allowed(@topic_id) %>
<% if @assignment.submission_allowed(@participant.user_id) %>
<%= link_to t(".your_work"), :controller => 'submitted_content', :action => 'edit', :id => @participant.id %> <%=t ".submit_work" %>
<% else %>
<font color="gray"><%=t ".your_work" %></font> <%=t ".not_allowed" %>
Expand Down Expand Up @@ -105,7 +105,7 @@ to display the label "Your team" in the student assignment tasks-->
<%if @assignment.require_quiz%>
<% if @authorization == 'participant' or @can_take_quiz == true %>
<li>
<% if @assignment.require_quiz and (@assignment.quiz_allowed(@topic_id) or @assignment.current_stage(@topic_id) == "Finished") %>
<% if @assignment.require_quiz and (@assignment.quiz_allowed(@participant.user_id) or @assignment.current_stage(@topic_id) == "Finished") %>
<%= link_to t(".take_quizzes"), student_quizzes_path(:id => @participant.id) %>
<% else %>
<font color="gray"><%=t ".take_quizzes" %></font>
Expand Down
2 changes: 1 addition & 1 deletion app/views/submitted_content/_self_review.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<% last_response_round = @latest_response.round %>
<% end %>
<% current_round = @assignment.number_of_current_round(@topic_id) %>
<% current_round = @assignment.number_of_current_round(@participant.user_id) %>

<td>&nbsp;&nbsp;</td>
<td><%= link_to 'View', {:controller => 'response', :action => 'view', :id => @latest_response.id} %></td>
Expand Down
Loading

0 comments on commit c933947

Please sign in to comment.