Skip to content

Commit

Permalink
Show conditions to user
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Jan 31, 2024
1 parent 145b5b8 commit 7725640
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 20 deletions.
20 changes: 20 additions & 0 deletions app/assets/stylesheets/models/activities.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,23 @@ center img {
background-color: var(--d-code-bg);
}
}

.draft-notice {
.form-check-input[disabled] ~ .form-check-label, .form-check-input:disabled ~ .form-check-label {
opacity: 1;
}

.form-check-input:disabled {
opacity: 1;
}

.form-check-input:checked {
background-color: var(--d-warning);
border-color: var(--d-warning);
}

.form-check-input {
background-color: transparent;
border-color: var(--d-warning);
}
}
26 changes: 13 additions & 13 deletions app/models/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,19 @@ def types
end
end

def correct_submission?
return true if content_page?

Check warning on line 447 in app/models/activity.rb

View check run for this annotation

Codecov / codecov/patch

app/models/activity.rb#L447

Added line #L447 was not covered by tests

submissions.any?(&:accepted?)

Check warning on line 449 in app/models/activity.rb

View check run for this annotation

Codecov / codecov/patch

app/models/activity.rb#L449

Added line #L449 was not covered by tests
end

def valid_config?
config
true

Check warning on line 454 in app/models/activity.rb

View check run for this annotation

Codecov / codecov/patch

app/models/activity.rb#L453-L454

Added lines #L453 - L454 were not covered by tests
rescue ConfigParseError
false

Check warning on line 456 in app/models/activity.rb

View check run for this annotation

Codecov / codecov/patch

app/models/activity.rb#L456

Added line #L456 was not covered by tests
end

private

def activity_status_for(user, series = nil)
Expand Down Expand Up @@ -512,19 +525,6 @@ def unique_labels(hash)
hash
end

def correct_submission?
return true if content_page?

submissions.any?(&:accepted?)
end

def valid_config?
config
true
rescue ConfigParseError
false
end

def require_correct_submission_before_publish
return if draft?
return unless draft_was
Expand Down
29 changes: 26 additions & 3 deletions app/views/activities/_draft_notice.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
<% if @activity.draft? %>
<div class="alert alert-warning">
<div class="alert alert-warning draft-notice">
<i class="mdi mdi-file-document-edit-outline"></i>
<%= t "activities.show.alert_draft_html" %>
<%= t "activities.show.alert_draft.text_html" %>
<% if policy(@activity).edit? %>
<% edit_path = @series.present? ?
course_series_activity_path(@series&.course, @series, @activity, {activity: {draft: false}}) :
activity_path(@activity, {activity: {draft: false}})
%>
<%= link_to t("activities.show.alert_draft_edit"), edit_path, method: :put %>

<% if @activity.ok? && @activity.correct_submission? && @activity.valid_config? %>
<%= link_to t("activities.show.alert_draft.edit"), edit_path, method: :put %>
<% else %>
<div style="margin-left: 5px; margin-top: 8px;">
<%= t("activities.show.alert_draft.before_publish") %>
<div style="margin-left: 16px;margin-top: 8px;">
<div class="form-check">
<input type="checkbox" id="valid-config" class="form-check-input" disabled <%= "checked" if @activity.valid_config? %>>
<label class="form-check-label" for="valid-config"><%= t('activities.show.alert_draft.valid_config') %></label>
</div>
<div class="form-check">
<input type="checkbox" id="is-valid" class="form-check-input" disabled <%= "checked" if @activity.ok? %>>
<label class="form-check-label" for="is-valid"><%= t('activities.show.alert_draft.is_valid') %></label>
</div>
<% if @activity.exercise? %>
<div class="form-check">
<input type="checkbox" id="correct-submission" class="form-check-input" disabled <%= "checked" if @activity.correct_submission? %>>
<label class="form-check-label" for="correct-submission"><%= t('activities.show.alert_draft.correct_submission') %></label>
</div>
<% end %>
</div>
</div>
<% end %>

<% end %>
</div>
Expand Down
9 changes: 7 additions & 2 deletions config/locales/views/activities/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,13 @@ en:
preloaded_info: "We have preloaded your latest submission into the editor."
preloaded_clear: Clear editor.
preloaded_restore: Restore the initial code.
alert_draft_html: This activity is a <a href="https://docs.dodona.be/en/faq/activities/#what-is-a-draft-activity" target="_blank">draft</a> and thus not visible for students.
alert_draft_edit: Publish activity.
alert_draft:
text_html: This activity is a <a href="https://docs.dodona.be/en/faq/activities/#what-is-a-draft-activity" target="_blank">draft</a> and thus not visible for students.
edit: Publish activity.
before_publish: "Before you can publish this activity, the following conditions must be met:"
valid_config: "The JSON configuration must be valid."
is_valid: "The activity must have a name and a description."
correct_submission: "There must be at least one correct submission."
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
9 changes: 7 additions & 2 deletions config/locales/views/activities/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,13 @@ nl:
preloaded_info: We hebben jouw laatste oplossing ingeladen in de editor.
preloaded_clear: Maak de editor leeg.
preloaded_restore: Zet de voorbeeldcode terug.
alert_draft_html: Deze oefening is nog een <a href="https://docs.dodona.be/nl/faq/activities/#wat-is-een-conceptactiviteit" target="_blank">concept</a>. Ze is niet zichtbaar voor studenten.
alert_draft_edit: Deze oefening publiceren.
alert_draft:
text_html: Deze oefening is nog een <a href="https://docs.dodona.be/nl/faq/activities/#wat-is-een-conceptactiviteit" target="_blank">concept</a>. Ze is niet zichtbaar voor studenten.
edit: Deze oefening publiceren.
before_publish: "Vooraleer je deze oefening kan publiceren, moet aan de volgende voorwaarden voldaan zijn:"
valid_config: "De JSON-configuratie moet geldig zijn."
is_valid: "De oefening moet een naam en een beschrijving hebben."
correct_submission: "Er moet minstens één correcte oplossing zijn."
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

0 comments on commit 7725640

Please sign in to comment.