From 0a10c7c54c89a5886253c478331ad5628d73d56c Mon Sep 17 00:00:00 2001 From: Jahir <124062934+juddin927@users.noreply.github.com> Date: Fri, 24 Nov 2023 11:53:14 +0000 Subject: [PATCH] Feature search function (#753) * adding search button function in the index page to query serach terms against the Site Name,Fits_id and Subnet CIDR * updated site controller to return sites in the order of the fits id --------- Co-authored-by: Jahir --- app/controllers/sites_controller.rb | 10 ++++++++++ app/views/sites/index.html.erb | 8 +++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index e7d0e979..33c89dfa 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -4,6 +4,16 @@ class SitesController < ApplicationController def index @sites = Site.order(:fits_id).all @navigation_crumbs = [["Home", root_path]] + @sites = if params[:query].present? + Site.where('name LIKE ? OR fits_id LIKE ? OR id IN ( + SELECT sn.site_id + FROM subnets s + INNER JOIN shared_networks sn ON s.shared_network_id = sn.id + WHERE s.cidr_block LIKE ? + )', "%#{params[:query]}%", "%#{params[:query]}%", "%#{params[:query]}%") + else + Site.order(:fits_id).all + end end def show diff --git a/app/views/sites/index.html.erb b/app/views/sites/index.html.erb index fc532db1..eb18bbaa 100644 --- a/app/views/sites/index.html.erb +++ b/app/views/sites/index.html.erb @@ -5,7 +5,13 @@ <%= link_to "Client classes", client_classes_path, class: "govuk-button govuk-button--secondary" %>

Sites

- + +
+ <%= form_tag(dhcp_path, method: :get, class: "govuk-form") do %> + <%= text_field_tag :query, params[:query], placeholder: "Search sites by FITS ID or name...", class: 'govuk-input govuk-input--width-10' %> + <%= submit_tag "Search", class: "govuk-button", "data-module" => "govuk-button" %> + <% end %> +
<% if can? :create, Site %> <%= link_to "Create a new site", new_site_path, class: "govuk-button" %> <% end %>