Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preload the latest submission in the editor on the activity show page #4485

Merged
merged 11 commits into from
Mar 22, 2023
7 changes: 5 additions & 2 deletions app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,20 @@ def show
@submissions = @activity.submissions.includes(:annotations)
@submissions = @submissions.in_course(@course) if @course.present? && current_user&.member_of?(@course)
@submissions = @submissions.of_user(current_user) if current_user
@submissions = policy_scope(@submissions).paginate(page: parse_pagination_param(params[:page]))
@submissions = policy_scope(@submissions)
if params[:edit_submission]
@edit_submission = Submission.find(params[:edit_submission])
authorize @edit_submission, :edit?
elsif @submissions.any? && !params[:show_boilerplate]
@last_submission = @submissions.first
end
@submissions = @submissions.paginate(page: parse_pagination_param(params[:page]))
if params[:from_solution]
@solution = @activity.solutions[params[:from_solution]]
authorize @activity, :info?
end

@code = @edit_submission.try(:code) || @solution || @activity.boilerplate
@code = @edit_submission.try(:code) || @solution || @last_submission.try(:code) || @activity.boilerplate
elsif @activity.content_page?
@read_state = if current_user&.member_of?(@course)
@activity.activity_read_states.find_by(user: current_user, course: @course)
Expand Down
6 changes: 6 additions & 0 deletions app/views/activities/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ end %>
<%= t('.deadline_passed', deadline: @series.deadline.today? ? @series.deadline.strftime('%R') : @series.deadline.strftime('%F %R')) %>
</div>
<% end %>
<% if !@edit_submission && !@solution && @last_submission %>
<div class="alert alert-info">
<%= t ".preloaded_info" %>
<%= link_to t(@activity.boilerplate ? ".preloaded_restore" : ".preloaded_clear"), activity_scoped_path(activity: @activity, series: @series, course: @course, options: {show_boilerplate: true}) %>
</div>
<% end %>
<div id="editor-window" class='tex2jax_ignore'>
<div id="editor-text"><%= @code %></div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions config/locales/views/activities/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ en:
back_to_course_actionable: Go back to course
mark_as_read: Mark as read
read_at: "Marked as read on %{timestamp}"
preloaded_info: "We have preloaded your latest submission into the editor."
preloaded_clear: Clear editor.
preloaded_restore: Restore the boilerplate code.
series_activities_add_table:
course_added_to_usable: "Adding this exercise will allow this course to use all of the private exercises in this exercise's repository. Are you sure?"
edit:
Expand Down
3 changes: 3 additions & 0 deletions config/locales/views/activities/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ nl:
back_to_course_actionable: Ga terug naar de cursus
mark_as_read: Markeren als gelezen
read_at: "Gelezen op %{timestamp}"
preloaded_info: We hebben jouw laatste oplossing ingeladen in de editor.
preloaded_clear: Maak de editor leeg.
preloaded_restore: Herstel de boilerplate-code.
series_activities_add_table:
course_added_to_usable: "Deze oefening toevoegen zal deze cursus toegang geven tot alle privé oefeningen in de repository van deze oefening. Ben je zeker?"
edit:
Expand Down