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

Add extra draft filter for activities #5209

Merged
merged 5 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/assets/javascripts/i18n/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
"course_labels": "Member label",
"courses": "Course",
"description_languages": "Language",
"draft": "Draft/Published",
"event_types": "Event type",
"exercises": "Exercise",
"institutions": "Institution",
Expand Down Expand Up @@ -734,6 +735,7 @@
"course_labels": "Gebruikerlabel",
"courses": "Cursus",
"description_languages": "Taal",
"draft": "Concept/Gepubliceerd",
"event_types": "Event type",
"exercises": "Oefening",
"institutions": "Onderwijsinstelling",
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ActivitiesController < ApplicationController
has_scope :by_description_languages, as: 'description_languages', type: :array
has_scope :by_judge, as: 'judge_id'
has_scope :by_popularities, as: 'popularity', type: :array
has_scope :is_draft, as: 'draft', type: :boolean
has_scope :is_draft, as: 'draft'

has_scope :repository_scope, as: 'tab' do |controller, scope, value|
course = Series.find(controller.params[:id]).course if controller.params[:id]
Expand Down
2 changes: 1 addition & 1 deletion app/models/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Activity < ApplicationRecord
scope :by_programming_language, ->(programming_language) { includes(:programming_language).where(programming_languages: { name: programming_language }) }
scope :by_type, ->(type) { where(type: type) }
scope :by_judge, ->(judge) { where(judge_id: judge) }
scope :is_draft, -> { where(draft: true) }
scope :is_draft, ->(value = true) { where(draft: value) }
scope :by_description_languages, lambda { |languages|
by_language = all # allow chaining of scopes
by_language = by_language.where(description_en_present: true) if languages.include? 'en'
Expand Down
2 changes: 1 addition & 1 deletion app/views/activities/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>
<div class="card-supporting-text">
<d-filter-tabs labels="<%= @tabs.to_json %>"></d-filter-tabs>
<%= render partial: 'layouts/searchbar', locals: {labels: @labels, programming_languages: @programming_languages, repositories: @repositories, activity_types: [ContentPage, Exercise], description_languages: ["en", "nl"], judges: @judges, popularity: Activity::POPULARITY_THRESHOLDS.keys, no_dropdown_for: ["judges"]} %>
<%= render partial: 'layouts/searchbar', locals: {labels: @labels, programming_languages: @programming_languages, repositories: @repositories, activity_types: [ContentPage, Exercise], description_languages: ["en", "nl"], judges: @judges, popularity: Activity::POPULARITY_THRESHOLDS.keys, draft: current_user&.draft_exercises&.any?, no_dropdown_for: ["judges"]} %>
<div id="activities-table-wrapper">
<%= render partial: 'activities_table', locals: {activities: @activities} %>
</div>
Expand Down
16 changes: 16 additions & 0 deletions app/views/layouts/_searchbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,22 @@
},
};
<% end %>
<% if local_assigns.fetch :draft, false %>
filterCollections["draft"] = {
param: "draft",
paramVal: function (s) {
return s.id.toString();
},
multi: false,
data: [
{id: true, name: "<%= I18n.t("activities.index.filters.draft") %>"},
{id: false, name: "<%= I18n.t("activities.index.filters.not_draft") %>"}
],
color: function () {
return "brown";
},
};
<% end %>

dodona.search.setRefreshElement("<%= local_assigns.fetch :refresh_element, "" %>");

Expand Down
2 changes: 1 addition & 1 deletion app/views/series/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<div class="col-12">
<h4 id="add-activities"><%= t ".add_activities" %></h4>
<d-filter-tabs labels="<%= @tabs.to_json %>"></d-filter-tabs>
<%= render partial: 'layouts/searchbar', locals: {baseUrl: available_activities_series_path(@series), eager: true, labels: @labels, programming_languages: @programming_languages, repositories: @repositories, activity_types: [ContentPage, Exercise], description_languages: ["en", "nl"], popularity: Activity::POPULARITY_THRESHOLDS.keys, local_storage_key: 'seriesActivitySearch'} %>
<%= render partial: 'layouts/searchbar', locals: {baseUrl: available_activities_series_path(@series), eager: true, labels: @labels, programming_languages: @programming_languages, repositories: @repositories, activity_types: [ContentPage, Exercise], description_languages: ["en", "nl"], popularity: Activity::POPULARITY_THRESHOLDS.keys, local_storage_key: 'seriesActivitySearch', draft: current_user&.draft_exercises&.any?} %>
<div id="activities-table-wrapper">
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions config/locales/js/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ en:
question_states: Status
popularity: Popularity
exercises: Exercise
draft: "Draft/Published"
saved_annotation:
title: Title
annotation_text: Text
Expand Down
1 change: 1 addition & 0 deletions config/locales/js/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ nl:
question_states: Toestand
popularity: Populariteit
exercises: Oefening
draft: "Concept/Gepubliceerd"
saved_annotation:
title: Titel
annotation_text: Tekst
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 @@ -68,6 +68,9 @@ en:
featured: "Featured activities"
all: "All activities"
draft-notice: "This activity is a draft and thus not visible for students."
filters:
draft: "Draft activities"
not_draft: "Published activities"
show:
code: Code
handin: Hand in
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 @@ -68,6 +68,9 @@ nl:
featured: "Uitgelichte activiteiten"
all: "Alle activiteiten"
draft-notice: "Deze activiteit is nog een concept. Ze is niet zichtbaar voor studenten."
filters:
draft: "Concept activititeiten"
jorg-vr marked this conversation as resolved.
Show resolved Hide resolved
not_draft: "Gepubliceerde activiteiten"
show:
code: Code
handin: Indienen
Expand Down