Skip to content

Commit c27d707

Browse files
committed
Refactor ProgrammingGroups view controller
1 parent 4cbbc9b commit c27d707

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

app/controllers/programming_groups_controller.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ class ProgrammingGroupsController < ApplicationController
1010
def index
1111
set_exercise_and_authorize if params[:exercise_id].present?
1212
@search = policy_scope(ProgrammingGroup).ransack(params[:q], {auth_object: current_user})
13-
@programming_groups = @search.result.includes(:exercise, :programming_group_memberships, :internal_users, :external_users).order(:id).paginate(page: params[:page], per_page: per_page_param)
13+
if params[:exercise_id].present?
14+
@programming_groups = @search.result.where(exercise: @exercise)
15+
else
16+
@programming_groups = @search.result
17+
end
18+
@programming_groups = @programming_groups.includes(:exercise, :programming_group_memberships, :internal_users, :external_users).order(:id).paginate(page: params[:page], per_page: per_page_param)
1419
authorize!
1520
end
1621

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- if params[:exercise_id].nil?
1+
- if @exercise.nil?
22
h1 = ProgrammingGroup.model_name.human(count: :other)
33
= render(layout: 'shared/form_filters') do |f|
44
.col-auto
@@ -12,33 +12,29 @@
1212
= f.label(:programming_group_memberships_user_of_InternalUser_type_id_eq, ProgrammingGroup.human_attribute_name('internal_user_id'), class: 'visually-hidden form-label')
1313
= f.search_field(:programming_group_memberships_user_of_InternalUser_type_id_eq, class: 'form-control', placeholder: ProgrammingGroup.human_attribute_name('internal_user_id'))
1414
- else
15-
h1 = "#{ProgrammingGroup.model_name.human(count: :other)} for Exercise '#{@exercise.title}'"
15+
h1 = t('.for', model: ProgrammingGroup.model_name.human(count: :other), exercise: @exercise.title)
1616

1717
.table-responsive
1818
table.table.mt-4 class=(@programming_groups.present? ? 'sortable' : '')
1919
thead
2020
tr
2121
th.sortable_nosort = sort_link(@search, :id, ProgrammingGroup.human_attribute_name('name'))
22-
- if params[:exercise_id].blank?
22+
- if @exercise.nil?
2323
th.sorttable_nosort = sort_link(@search, :exercise_id, ProgrammingGroup.human_attribute_name('exercise'))
2424
th = ProgrammingGroup.human_attribute_name('member')
2525
th = ProgrammingGroup.human_attribute_name('member_count')
2626
th.sorttable_nosort = sort_link(@search, :created_at, t('shared.created_at'))
2727
th colspan=3 = t('shared.actions')
2828
tbody
29-
- if params[:exercise_id].nil?
30-
- filtered_programming_groups = @programming_groups
31-
- else
32-
- filtered_programming_groups = @programming_groups.where(exercise_id: params[:exercise_id])
33-
- filtered_programming_groups.each do |programming_group|
29+
- @programming_groups.each do |programming_group|
3430
tr
3531
td = link_to_if(policy(programming_group).show?, programming_group.displayname, programming_group)
36-
- if params[:exercise_id].blank?
32+
- if @exercise.nil?
3733
td = link_to_if(policy(programming_group.exercise).show?, programming_group.exercise.title, programming_group.exercise, 'data-turbolinks': 'false')
3834
td == programming_group.users.map {|user| link_to_if(policy(user).show?, user.name, user) }.join(', ')
3935
td = programming_group.users.size
4036
td = l(programming_group.created_at, format: :short)
41-
td = link_to(t('shared.show'), programming_group) if policy(programming_group).show?
42-
td = link_to(t('shared.edit'), edit_programming_group_path(programming_group)) if policy(programming_group).edit?
43-
td = link_to(t('shared.destroy'), programming_group, data: {confirm: t('shared.confirm_destroy')}, method: :delete) if policy(programming_group).destroy?
37+
td = link_to(t('shared.show'), [@exercise, programming_group]) if policy(programming_group).show?
38+
td = link_to(t('shared.edit'), polymorphic_path([@exercise, programming_group], action: :edit)) if policy(programming_group).edit?
39+
td = link_to(t('shared.destroy'), [@exercise, programming_group], data: {confirm: t('shared.confirm_destroy')}, method: :delete) if policy(programming_group).destroy?
4440
= render('shared/pagination', collection: @programming_groups)

config/locales/de/programming_group.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ de:
2020
programming_partner_ids: 'Sie können mehrere Personen-IDs mit Kommata getrennt eingeben, wie z.B.: ''e123, e234''.'
2121
implement:
2222
info_disconnected: Ihre Verbindung zum Server wurde unterbrochen. Bitte überprüfen Sie Ihre Internetverbindung und laden Sie die Seite erneut.
23+
index:
24+
for: "%{model} für Aufgabe '%{exercise}'"
2325
new:
2426
create_programming_pair: Programmierpaar erstellen
2527
dont_show_modal_again: Auf diesem Gerät nicht mehr anzeigen

config/locales/en/programming_group.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ en:
2020
programming_partner_ids: You can enter several user IDs separated by commas such as 'e123, e234'.
2121
implement:
2222
info_disconnected: You are disconnected from the server. Please check your internet connection and reload the page.
23+
index:
24+
for: "%{model} for Exercise '%{exercise}'"
2325
new:
2426
create_programming_pair: Create Programming Pair
2527
dont_show_modal_again: Don't display on this device anymore

0 commit comments

Comments
 (0)