Added search for issues
authorShrey <shrey14099@iiitd.ac.in>
Wed, 10 Jun 2015 07:04:26 +0000 (12:34 +0530)
committerMatt Amos <zerebubuth@gmail.com>
Mon, 22 Aug 2016 15:17:54 +0000 (16:17 +0100)
app/controllers/issues_controller.rb
app/views/issues/index.html.erb
config/locales/en-GB.yml
config/locales/en.yml

index 4f88dce849605066cecd7a1ee11ba5519654cd5d..ed80777df8fc0b19a5f5b4b4d0d34eb6dc087c43 100644 (file)
@@ -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
index a599abb994ec4907dae06a8de4164bcca495cc38..101df96ba6e8ffefed16a2a94cbf164ff8b4363f 100644 (file)
@@ -4,6 +4,13 @@
        <h1>List of existing Issues:</h1>
 <% 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 %>
+<br/>
+<br/>
+
 <table>
        <thead>
                <tr>
index 13349d511ef6c8c7b2a4837b04a20237c4cbacac..663e78cd4f80e56772c0fc7248303ea57fabc670 100644 (file)
@@ -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
index 517f3a866f41d69325216c4e88284546298f1f69..3e898b008c4c59033404f480355f9cbd04094717 100644 (file)
@@ -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