Skip to content

Commit

Permalink
Merge 948246b into 8341134
Browse files Browse the repository at this point in the history
  • Loading branch information
fergione committed Mar 27, 2023
2 parents 8341134 + 948246b commit 93abf4a
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 155 deletions.
102 changes: 1 addition & 101 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,15 +263,6 @@ 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?
Expand All @@ -323,40 +283,13 @@ def varying_rubrics_by_round?
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)
return 'Unknown' if staggered_and_no_topic?(topic_id)

due_date = find_current_stage(topic_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)
Expand Down Expand Up @@ -566,39 +499,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
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
143 changes: 143 additions & 0 deletions lib/due_date_mix_in.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# frozen_String_literal: true

# lib/due_date_mix_in.rb
module DueDateMixIn
# finds the topic_id given the participant user_id
def find_topic_id(participant_id)
topic_id = if participant_id.nil?
nil
else
SignedUpTeam.topic_id(id, participant_id)
end
end

# Determine if the next due date from now allows for submissions
def submission_allowed(participant_id = nil)
# Find topic id for given participant for selected assignment
# Return nil if no participant is given
topic_id = find_topic_id(participant_id)
# only need to pass @participiant to search, can this be done locally
next_due_date = DueDate.get_next_due_date(id, topic_id)
return false if next_due_date.nil?

# find the quiz allowed id, then check if that deadline is passed
right_id = next_due_date.submission_allowed_id
right = DeadlineRight.find(right_id)
# check is assignment action deadline is ok or late (i.e. not no)
right && (right.name != 'No')
end

# Determine if the next due date from now allows for reviews
# Should be renamed to review_allowed from can_review
def can_review(participant_id = nil)
topic_id = find_topic_id(participant_id)
next_due_date = DueDate.get_next_due_date(id, topic_id)
return false if next_due_date.nil?

# find the quiz allowed id, then check if that deadline is passed
right_id = next_due_date.review_allowed_id
right = DeadlineRight.find(right_id)
# check is assignment action deadline is ok or late (i.e. not no)
right && (right.name != 'No')
end

# Determine if the next due date from now allows for metareviews
def metareview_allowed(participant_id = nil)
topic_id = find_topic_id(participant_id)
next_due_date = DueDate.get_next_due_date(id, topic_id)
return false if next_due_date.nil?

# find the quiz allowed id, then check if that deadline is passed
right_id = next_due_date.review_of_review_allowed_id # meta-review id
right = DeadlineRight.find(right_id)
# check is assignment action deadline is ok or late (i.e. not no)
right && (right.name != 'No')
end

# Determine if the next due date from now allows to take the quizzes
def quiz_allowed(participant_id = nil)
topic_id = find_topic_id(participant_id)
next_due_date = DueDate.get_next_due_date(id, topic_id)
return false if next_due_date.nil?

# find the quiz allowed id, then check if that deadline is passed
right_id = next_due_date.quiz_allowed_id
right = DeadlineRight.find(right_id)
# check is assignment action deadline is ok or late (i.e. not no)
right && (right.name != 'No')
end

# if current stage is submission or review, find the round number
# otherwise, return 0
def number_of_current_round(participant_id = nil)
topic_id = find_topic_id(participant_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

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 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(participant_id = nil)
topic_id = find_topic_id(participant_id)
next_due_date = DueDate.get_next_due_date(id, topic_id)
return 'Finished' if next_due_date.nil?

next_due_date
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

# END OF MODULE #
end

0 comments on commit 93abf4a

Please sign in to comment.