From d162f78b67a78ea8340148835751480eccb7ff33 Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Mon, 16 Oct 2017 11:45:23 +0200 Subject: [PATCH] Add filters to index page --- app/controllers/user_exercise_feedbacks_controller.rb | 3 ++- app/models/user_exercise_feedback.rb | 3 ++- app/views/user_exercise_feedbacks/index.html.slim | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/controllers/user_exercise_feedbacks_controller.rb b/app/controllers/user_exercise_feedbacks_controller.rb index 29b718e9..8abffd66 100644 --- a/app/controllers/user_exercise_feedbacks_controller.rb +++ b/app/controllers/user_exercise_feedbacks_controller.rb @@ -21,7 +21,8 @@ class UserExerciseFeedbacksController < ApplicationController end def index - @uefs = UserExerciseFeedback.order(:id).paginate(page: params[:page]) + @search = UserExerciseFeedback.all.search params[:q] + @uefs = @search.result.includes(:execution_environment).order(:id).paginate(page: params[:page]) authorize! end diff --git a/app/models/user_exercise_feedback.rb b/app/models/user_exercise_feedback.rb index 78d84972..5694573b 100644 --- a/app/models/user_exercise_feedback.rb +++ b/app/models/user_exercise_feedback.rb @@ -2,10 +2,11 @@ class UserExerciseFeedback < ActiveRecord::Base include Creation belongs_to :exercise + has_one :execution_environment, through: :exercise validates :user_id, uniqueness: { scope: [:exercise_id, :user_type] } def to_s "User Exercise Feedback" end -end \ No newline at end of file +end diff --git a/app/views/user_exercise_feedbacks/index.html.slim b/app/views/user_exercise_feedbacks/index.html.slim index 84f2a15f..52249229 100644 --- a/app/views/user_exercise_feedbacks/index.html.slim +++ b/app/views/user_exercise_feedbacks/index.html.slim @@ -1,5 +1,13 @@ h1 = UserExerciseFeedback.model_name.human(count: 2) += render(layout: 'shared/form_filters') do |f| + .form-group + = f.label(:execution_environment_id_eq, t('activerecord.attributes.exercise.execution_environment'), class: 'sr-only') + = f.collection_select(:execution_environment_id_eq, ExecutionEnvironment.with_exercises, :id, :name, class: 'form-control', prompt: t('activerecord.attributes.exercise.execution_environment')) + .form-group + = f.label(:exercise_title_cont, t('activerecord.attributes.request_for_comments.exercise'), class: 'sr-only') + = f.search_field(:exercise_title_cont, class: 'form-control', placeholder: t('activerecord.attributes.request_for_comments.exercise')) + .table-responsive table.table thead