Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search by any field #64

Closed
Luckyvb opened this issue May 17, 2020 · 3 comments
Closed

Search by any field #64

Luckyvb opened this issue May 17, 2020 · 3 comments
Assignees

Comments

@Luckyvb
Copy link

Luckyvb commented May 17, 2020

Add search type any and set by default.

@Luckyvb
Copy link
Author

Luckyvb commented May 17, 2020

diff --git a/app/controllers/keys_controller.rb b/app/controllers/keys_controller.rb
index 970e0da..c254709 100644
--- a/app/controllers/keys_controller.rb
+++ b/app/controllers/keys_controller.rb
@@ -27,7 +27,7 @@ class KeysController < ApplicationController
@query = params[:query]

if params[:search_fild] == nila
- @search_fild = 'name'
+ @search_fild = 'any'
else
@search_fild = params[:search_fild]
end
@@ -38,10 +38,14 @@ class KeysController < ApplicationController
tag = Vault::Tag.find_by_name(tag_string)
@keys = tag.nil? ? nil : tag.keys.where(project: @project)
else
- if params[:search_fild] == 'name'
- @keys = @project.keys.where(name: @query)
+ if params[:search_fild] == 'any'
+ @keys = @project.keys.where("name LIKE ? or login LIKE ?", "%"+@query+"%", "%"+@query+"%").or(@project.keys.where("url LIKE ?", "%"+@query+"%"))
+ tag = Vault::Tag.find_by_name(@query)
+ @keys.union(tag.keys.where(project: @project)) if !tag.nil?
+ elsif params[:search_fild] == 'name'
+ @keys = @project.keys.where("name LIKE ? or login LIKE ?", "%"+@query+"%", "%"+@query+"%")
elsif params[:search_fild] == 'url'
- @keys = @project.keys.where(url: @query)
+ @keys = @project.keys.where("url LIKE ?", "%"+@query+"%")
elsif params[:search_fild] == 'tag'
tag = Vault::Tag.find_by_name(@query)
@keys = tag.nil? ? nil : tag.keys.where(project: @project)

diff --git a/app/views/keys/index.html.erb b/app/views/keys/index.html.erb
index 0c2c521..dd4e1f2 100644
--- a/app/views/keys/index.html.erb
+++ b/app/views/keys/index.html.erb
@@ -14,6 +14,9 @@
<%= text_field_tag(:query, @query, class: 'autocomplete') %>

<font size="2">
+ <%= radio_button_tag(:search_fild, "any", @search_fild == 'any' ? true : false ) %>
+ <%= label_tag(:any, t('key.attr.any')) %>
+
<%= radio_button_tag(:search_fild, "name", @search_fild == 'name' ? true : false ) %>
<%= label_tag(:name, t('key.attr.name')) %>

diff --git a/config/locales/ru.yml b/config/locales/ru.yml
index bd41238..2f6fe95 100644
--- a/config/locales/ru.yml
+++ b/config/locales/ru.yml
@@ -53,6 +60,7 @@ ru:
file: "Файл ключа"
comment: "Комментарий"
whitelist: "Список доступа"
+ any: "Любое"

whitelist:
selected_members: "Выбранные участники"

@noshutdown-ru-user noshutdown-ru-user self-assigned this May 18, 2020
@noshutdown-ru-user
Copy link
Member

Thx for report, we will take a look

@mr-exz
Copy link
Contributor

mr-exz commented Dec 30, 2024

Released in 0.5.0

@mr-exz mr-exz closed this as completed Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants