From 0a3dd82c47f5df0d55554c80a3b47f54ef6d204b Mon Sep 17 00:00:00 2001 From: Shrey Date: Wed, 10 Jun 2015 12:34:26 +0530 Subject: [PATCH 1/1] Added search for issues --- app/controllers/issues_controller.rb | 17 ++++++++++++++++- app/views/issues/index.html.erb | 7 +++++++ config/locales/en-GB.yml | 4 ++++ config/locales/en.yml | 4 ++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 4f88dce84..ed80777df 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -7,7 +7,22 @@ class IssuesController < ApplicationController before_action :find_issue, only: [:show, :resolve, :reopen, :ignore] def index - @issues = Issue.all.order(:status) + if params[:search_by_user].present? + @user = User.find_by_display_name(params[:search_by_user]) + if @user.present? + @issues = Issue.where(reported_user_id: @user.id).order(:status) + else + @issues = Issue.all.order(:status) + redirect_to issues_path, notice: t('issues.index.search.user_not_found') + end + + if @user.present? and not @issues.present? + @issues = Issue.all.order(:status) + redirect_to issues_path, notice: t('issues.index.search.issues_not_found') + end + else + @issues = Issue.all.order(:status) + end end def show diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index a599abb99..101df96ba 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -4,6 +4,13 @@

List of existing Issues:

<% end %> +<%= form_tag(issues_path, :method => :get) do %> + <%= text_field_tag :search_by_user, params[:search_by_user], placeholder: "Search by Reported User" %> + <%= submit_tag "Search" %> +<% end %> +
+
+ diff --git a/config/locales/en-GB.yml b/config/locales/en-GB.yml index 13349d511..663e78cd4 100644 --- a/config/locales/en-GB.yml +++ b/config/locales/en-GB.yml @@ -940,6 +940,10 @@ en-GB: resolve: Resolve ignore: Ignore reopen: Reopen + index: + search: + user_not_found: User does not exist + issues_not_found: No Issues against the user create: successful_report: Your report has been registered sucessfully provide_details: Please provide the required details diff --git a/config/locales/en.yml b/config/locales/en.yml index 517f3a866..3e898b008 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -910,6 +910,10 @@ en: resolve: Resolve ignore: Ignore reopen: Reopen + index: + search: + user_not_found: User does not exist + issues_not_found: No Issues against the user create: successful_report: Your report has been registered sucessfully provide_details: Please provide the required details -- 2.43.2