Skip to content

Commit

Permalink
Merge pull request #8266 from eduardoj/remove_bento_from_search_contr…
Browse files Browse the repository at this point in the history
…oller

Replace Bento by Bootstrap for search
  • Loading branch information
hennevogel committed Sep 4, 2019
2 parents 4a17a00 + a9884dc commit 767922b
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 338 deletions.
139 changes: 60 additions & 79 deletions src/api/app/controllers/webui/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class Webui::SearchController < Webui::WebuiController
before_action :set_attribute_list
before_action :set_tracker_list
before_action :set_parameters, except: :issue
before_action :check_beta, only: :issue

def index
switch_to_webui2
Expand Down Expand Up @@ -46,67 +45,6 @@ def issue
flash[:notice] = 'Your search did not return any results.' if @results.empty?
end

# The search method does the search and renders the results
# if there is something to search for. If not then it just
# renders a search bar.
#
# * *Args* :
# - @search_text -> The search string we search for
# - @search_what -> Array of result limits
# - @search_where -> Array of where we search
# - @search_attrib_type_id -> Limit results to this attribute type
# - @search_issue -> Limit results to packages with this issue in the changelog
# - @owner_limit -> Limit the amount of owners
# - @owner_devel -> Follow devel links for owner search
# * *Returns* :
# - +@results+ -> An array of results
def search
# If there is nothing to search for, just return
return unless params[:search_text]
# If the search is too short, return too
if (!@search_text || @search_text.length < 2) && !@search_attrib_type_id && !@search_issue
flash[:error] = 'Search string must contain at least two characters.'
return
end

# request number when string starts with a #
if @search_text.starts_with?('#') && @search_text[1..-1].to_i > 0
redirect_to controller: 'request', action: 'show', number: @search_text[1..-1]
return
end

# The user entered an OBS-specific RPM disturl, redirect to package source files with respective revision
if @search_text.starts_with?('obs://')
disturl_project, _, disturl_pkgrev = @search_text.split('/')[3..5]
unless disturl_pkgrev.nil?
disturl_rev, disturl_package = disturl_pkgrev.split('-', 2)
end
if disturl_project.present? && disturl_package.present? && Package.exists_by_project_and_name(disturl_project, disturl_package, follow_multibuild: true)
redirect_to controller: 'package', action: 'show', project: disturl_project, package: disturl_package, rev: disturl_rev
return
else
redirect_back(fallback_location: root_path, notice: 'Sorry, this disturl does not compute...')
return
end
end

logger.debug "Searching for the string \"#{@search_text}\" in the #{@search_where}'s of #{@search_what}'s"
if @search_where.empty? && !@search_attrib_type_id && !@search_issue
flash[:error] = "You have to search for #{@search_text} in something. Click the advanced button..."
return
end

@per_page = 20
search = FullTextSearch.new(text: @search_text,
classes: @search_what,
attrib_type_id: @search_attrib_type_id,
fields: @search_where,
issue_name: @search_issue,
issue_tracker_name: @search_tracker)
@results = search.search(page: params[:page], per_page: @per_page)
flash[:notice] = 'Your search did not return any results.' if @results.empty?
end

private

# This sets the needed defaults and input we've got for instance variables
Expand Down Expand Up @@ -154,21 +92,10 @@ def search_issue
end

def search_what
# FIXME: Simplify this after webui2 final migration.
@search_what = []
switch_to_webui2? ? search_what_for_webui2 : search_what_for_bento
@search_what << 'owner' if params[:owner] == '1' && !@search_issue
end

def search_what_for_webui2
@search_what << 'package' if params[:search_for].in?(['0', '2'])
@search_what << 'project' if params[:search_for].in?(['0', '1'])
end

def search_what_for_bento
# TODO: bento_only
@search_what << 'package' if params[:package] == '1'
@search_what << 'project' if params[:project] == '1' || !@search_issue
@search_what << 'owner' if params[:owner] == '1' && !@search_issue
end

def set_attribute_list
Expand All @@ -186,10 +113,64 @@ def set_tracker_list
@default_tracker = ::Configuration.default_tracker
end

# FIXME: bento_only remove this callback when we have fully migrated to Boostrap
# This view only exists for webui2, if the user leaves the beta program at this point,
# they are redirected to the index page.
def check_beta
redirect_to action: :index unless switch_to_webui2?
# The search method does the search and renders the results
# if there is something to search for. If not then it just
# renders a search bar.
#
# * *Args* :
# - @search_text -> The search string we search for
# - @search_what -> Array of result limits
# - @search_where -> Array of where we search
# - @search_attrib_type_id -> Limit results to this attribute type
# - @search_issue -> Limit results to packages with this issue in the changelog
# - @owner_limit -> Limit the amount of owners
# - @owner_devel -> Follow devel links for owner search
# * *Returns* :
# - +@results+ -> An array of results
def search
# If there is nothing to search for, just return
return unless params[:search_text]
# If the search is too short, return too
if (!@search_text || @search_text.length < 2) && !@search_attrib_type_id && !@search_issue
flash[:error] = 'Search string must contain at least two characters.'
return
end

# request number when string starts with a #
if @search_text.starts_with?('#') && @search_text[1..-1].to_i > 0
redirect_to controller: 'request', action: 'show', number: @search_text[1..-1]
return
end

# The user entered an OBS-specific RPM disturl, redirect to package source files with respective revision
if @search_text.starts_with?('obs://')
disturl_project, _, disturl_pkgrev = @search_text.split('/')[3..5]
unless disturl_pkgrev.nil?
disturl_rev, disturl_package = disturl_pkgrev.split('-', 2)
end
if disturl_project.present? && disturl_package.present? && Package.exists_by_project_and_name(disturl_project, disturl_package, follow_multibuild: true)
redirect_to controller: 'package', action: 'show', project: disturl_project, package: disturl_package, rev: disturl_rev
return
else
redirect_back(fallback_location: root_path, notice: 'Sorry, this disturl does not compute...')
return
end
end

logger.debug "Searching for the string \"#{@search_text}\" in the #{@search_where}'s of #{@search_what}'s"
if @search_where.empty? && !@search_attrib_type_id && !@search_issue
flash[:error] = "You have to search for #{@search_text} in something. Click the advanced button..."
return
end

@per_page = 20
search = FullTextSearch.new(text: @search_text,
classes: @search_what,
attrib_type_id: @search_attrib_type_id,
fields: @search_where,
issue_name: @search_issue,
issue_tracker_name: @search_tracker)
@results = search.search(page: params[:page], per_page: @per_page)
flash[:notice] = 'Your search did not return any results.' if @results.empty?
end
end
15 changes: 0 additions & 15 deletions src/api/app/views/webui/search/_owners.html.haml

This file was deleted.

47 changes: 24 additions & 23 deletions src/api/app/views/webui/search/_results.html.haml
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
#search-results
- @results.each do |result|
- if result.kind_of? Project
- project = result.name
- package = nil
- rtype = 'project'
- else
- project = result.project_name
- package = result.name
- rtype = 'package'
.search_result
%h6.data-title
= sprite_tag(rtype, class: rtype, title: rtype.humanize)
= project_or_package_link project: project, package: package, short: false, trim_to: nil
= content_tag :span, result.sphinx_attributes, style: 'display:none'
.mt-4#search-results
%h4 Results:
- results.each do |result|
:ruby
if result.is_a? Project
project = result.name
package = nil
else
project = result.project_name
package = result.name
end
.search_result.mt-3
%h6
%i.mr-1.fa{ class: result.is_a?(Project) ? 'fa-cubes text-secondary' : 'fa-archive text-warning' }
= project_or_package_link(project: project, package: package, short: false, trim_to: nil)
%span.d-none= result.sphinx_attributes
= ": #{result.title}" if result.title.present?
- if result.description.blank?
%p.data-description ...
- else
- desc = truncate(result.description, length: 80)
%p.data-description
%p.pl-4
- if result.description.blank?
= '...'
- else
- desc = truncate(result.description, length: 80)
- desc.split(/\n/).each do |line|
= highlight(line, @search_text, highlighter: '<b>\1</b>')
- if @per_page
= paginate @results
= highlight(line, search_text, highlighter: '<b>\1</b>')
- if per_page
= paginate results
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
- else
= truncate(result.description, length: 80)
- if per_page
= paginate results, views_prefix: 'webui2/webui'
= paginate results
12 changes: 8 additions & 4 deletions src/api/app/views/webui/search/_tabs.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
.box-header.header-tabs#search-tabs
%ul
= tab 'index', 'Packages/Projects', controller: 'search', action: 'index'
= tab 'owner', 'Owners', controller: 'search', action: 'owner'
.bg-light
%ul.nav.nav-tabs.pt-2.px-3.flex-nowrap.collapsible{ 'role': 'tablist' }
%li.nav-item
= tab_link('Packages/Projects', search_path, action_name == 'index', false)
%li.nav-item
= tab_link('Issues', search_issue_path, action_name == 'issue', false)
%li.nav-item
= tab_link('Owners', search_owner_path, action_name == 'owner', false)
58 changes: 18 additions & 40 deletions src/api/app/views/webui/search/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,43 +1,21 @@
- require 'active_support/inflector'
- @pagetitle = 'Search'
- @crumb_list = [@pagetitle]
- @layouttype = 'custom'
= content_for :ready_function do
:plain
$('#search-text').focus();
$('#advanced-link' ).click(function() {
$('#advanced-container').toggle("drop");
return false;
});
.grid_16.alpha.omega.box.box-shadow

.card.mb-3
= render partial: 'tabs'
%h3 Search for packages or projects:
#search-form
= form_tag({ controller: 'search', action: 'index' }, { method: :get }) do
%p
= text_field_tag('search_text', params[:search_text], placeholder: 'Search', id: 'search_input')
= submit_tag(nil, id: 'search_button', title: 'Search')
= select_tag(:issue_tracker, options_for_select(@issue_tracker_list, params[:issue_tracker] || @default_tracker))
= text_field_tag('issue', params[:issue], size: 10)
%button#advanced-link{ type: "button" } Advanced
#advanced-container{ style: "display: none;" }
%h4 Search for:
%p
= check_box_tag('project', 1, params[:project].nil? || params[:project] == "1")
%label{ for: "project" } Projects
= check_box_tag('package', 1, params[:package].nil? || params[:package] == "1")
%label{ for: "package" } Packages
%h4 Search in:
%p
= check_box_tag('name', 1, params[:name].nil? || params[:name] == "1")
%label{ for: "name" } Name
= check_box_tag('title', 1, params[:title] == "1")
%label{ for: "title" } Title
= check_box_tag('description', 1, params[:description] == "1")
%label{ for: "description" } Description
%h4 Require attribute:
%p
= select_tag(:attrib_type_id, options_for_select(@attrib_type_list, params[:attrib_type_id]), id: 'attribute_list')
.card-body
%h3 Search for packages or projects:
.d-flex.justify-content-center
= form_tag(search_path, method: :get, class: 'my-3 w-75') do
.form-group.input-group
= text_field_tag('search_text', params[:search_text], placeholder: 'Search', autofocus: true,
required: true, minlength: 2, class: 'form-control rounded', id: 'search_input')
%button.btn.btn-primary.ml-1{ type: 'submit', title: 'Search' }
%i.fa.fa-search

= render(partial: 'search_for')
= render(partial: 'advanced_search', locals: { attrib_type_list: @attrib_type_list,
issue_tracker_list: @issue_tracker_list,
default_tracker: @default_tracker })

- unless @results.nil? || @results.empty?
= render(partial: 'results')
- if @results.present?
= render(partial: 'results', locals: { results: @results, per_page: @per_page, search_text: @search_text })
Loading

0 comments on commit 767922b

Please sign in to comment.