#369: updated UI for search
This commit is contained in:
parent
4e4ade8bf9
commit
ec6aebfd5b
|
@ -1,18 +1,13 @@
|
||||||
class SearchController < ApplicationController
|
class SearchController < ApplicationController
|
||||||
|
include PaginateHelper
|
||||||
|
|
||||||
before_filter :authenticate_user! unless APP_CONFIG['anonymous_access']
|
before_filter :authenticate_user! unless APP_CONFIG['anonymous_access']
|
||||||
# load_and_authorize_resource
|
# load_and_authorize_resource
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@type = params[:type] || 'all'
|
@type = Search::TYPES.find{ |t| t == params[:type] } || Search::TYPES.first
|
||||||
@query = params[:query]
|
@query = params[:query]
|
||||||
Search.by_term_and_type(
|
@search = Search.new(@query, current_ability, paginate_params)
|
||||||
@query,
|
@collection = @search.send(@type)
|
||||||
@type,
|
|
||||||
current_ability,
|
|
||||||
{page: params[:page]}
|
|
||||||
).each do |k, v|
|
|
||||||
var = :"@#{k}"
|
|
||||||
instance_variable_set var, v unless instance_variable_defined?(var)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,29 +1,28 @@
|
||||||
class Search
|
class Search < Struct.new(:query, :ability, :paginate_params)
|
||||||
TYPES = ['projects', 'users', 'groups', 'platforms']
|
include ActiveModel::Conversion
|
||||||
|
extend ActiveModel::Naming
|
||||||
|
|
||||||
def self.by_term_and_type(term, type, ability, paginate_params)
|
TYPES = %w(projects users groups platforms)
|
||||||
results = {}
|
|
||||||
case type
|
|
||||||
when 'all'
|
|
||||||
TYPES.each{ |t| results[t] = find_collection(t, term, ability, paginate_params) }
|
|
||||||
when *TYPES
|
|
||||||
results[type] = find_collection(type, term, ability, paginate_params)
|
|
||||||
end
|
|
||||||
results
|
|
||||||
end
|
|
||||||
|
|
||||||
class << self
|
|
||||||
protected
|
|
||||||
|
|
||||||
def find_collection(type, term, ability, paginate_params)
|
TYPES.each do |type|
|
||||||
scope = if type == 'users'
|
define_method type do
|
||||||
User.opened
|
find_collection(type)
|
||||||
else
|
|
||||||
type.classify.constantize.accessible_by(ability, :show)
|
|
||||||
end
|
|
||||||
scope.search(term).
|
|
||||||
search_order.
|
|
||||||
paginate(paginate_params)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def find_collection(type)
|
||||||
|
scope =
|
||||||
|
if type == 'users'
|
||||||
|
User.opened
|
||||||
|
else
|
||||||
|
type.classify.constantize.accessible_by(ability, :show)
|
||||||
|
end
|
||||||
|
scope.search(query).
|
||||||
|
search_order.
|
||||||
|
paginate(paginate_params)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -1,4 +0,0 @@
|
||||||
.search
|
|
||||||
= form_tag search_index_path, method: 'get' do
|
|
||||||
.pic
|
|
||||||
.field= text_field_tag 'query', @query, placeholder: t("layout.search.header")
|
|
|
@ -1,5 +0,0 @@
|
||||||
= form_tag search_index_path, method: 'get' do
|
|
||||||
.leftside= text_field_tag 'query', @query, placeholder: t("layout.search.header"), class: 'exsearch'
|
|
||||||
.lineForm.leftside.rmargin10= select_tag 'type', options_for_select(t('layout.search.types').invert, @type), class: 'sel80 cusel', id: 'selSearch'
|
|
||||||
.leftside= submit_tag t('layout.search.header'), class: 'button width100', data: {'disable-with' => t('layout.processing')}
|
|
||||||
.both
|
|
|
@ -1,3 +0,0 @@
|
||||||
%p.block
|
|
||||||
.img= image_tag 'ava-admin.png'
|
|
||||||
.forimg= link_to group.uname, group
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
h4
|
||||||
|
- size = User::AVATAR_SIZES[:small]
|
||||||
|
=> image_tag avatar_url(group, :small), alt: group.uname, height: size, width: size
|
||||||
|
a href=user_path(group)
|
||||||
|
= group.uname
|
||||||
|
p
|
||||||
|
= group.description.to_s.truncate(255)
|
|
@ -1 +0,0 @@
|
||||||
%p.block= link_to platform.name, platform
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
h4
|
||||||
|
- if platform.hidden?
|
||||||
|
i.fa.fa-lock.text-danger>
|
||||||
|
- else
|
||||||
|
i.fa.fa-unlock-alt.text-success>
|
||||||
|
a href=platform_path(platform)
|
||||||
|
= platform.name
|
||||||
|
p
|
||||||
|
= platform.description.to_s.truncate(255)
|
|
@ -1,4 +0,0 @@
|
||||||
%p.block
|
|
||||||
= link_to "#{project.owner.uname} / #{project.name}", project
|
|
||||||
%br
|
|
||||||
= project.description
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
h4
|
||||||
|
- if project.public?
|
||||||
|
i.fa.fa-unlock-alt.text-success>
|
||||||
|
- else
|
||||||
|
i.fa.fa-lock.text-danger>
|
||||||
|
a href=project_path(project)
|
||||||
|
= project.name_with_owner
|
||||||
|
p
|
||||||
|
= project.description
|
||||||
|
.help-block
|
||||||
|
=> t('.updated')
|
||||||
|
= time_ago_in_words(project.updated_at)
|
|
@ -1,10 +0,0 @@
|
||||||
- collection = instance_variable_get("@#{type}")
|
|
||||||
%table.tablesorter.bmargin5{cellpadding: "0", cellspacing: "0"}
|
|
||||||
%thead
|
|
||||||
%tr
|
|
||||||
%th #{t "layout.#{type}.list_header"} (#{collection.count})
|
|
||||||
%tbody
|
|
||||||
- collection.each do |c|
|
|
||||||
%tr
|
|
||||||
%td= render type.singularize, type.singularize.to_sym => c
|
|
||||||
= link_to t('layout.search.all'), search_index_path(query: @query, type: type) if collection.present?
|
|
|
@ -1,3 +0,0 @@
|
||||||
%p.block
|
|
||||||
.img= image_tag avatar_url(user)
|
|
||||||
.forimg= link_to user.fullname, user
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
h4
|
||||||
|
- size = User::AVATAR_SIZES[:small]
|
||||||
|
=> image_tag avatar_url(user, :small), alt: user.uname, height: size, width: size
|
||||||
|
a href=user_path(user)
|
||||||
|
= user.fullname
|
||||||
|
.help-block
|
||||||
|
- if user.location.present?
|
||||||
|
i.fa.fa-map-marker>
|
||||||
|
=> user.location
|
||||||
|
- unless user.hide_email
|
||||||
|
i.fa.fa-envelope-o>
|
||||||
|
=> mail_to user.email, user.email, class: 'text-muted'
|
|
@ -1,17 +0,0 @@
|
||||||
%h3= title t('layout.search.advanced')
|
|
||||||
= render 'form_advanced'
|
|
||||||
- if @type == 'all'
|
|
||||||
#all
|
|
||||||
= render 'table', type: 'projects'
|
|
||||||
.both
|
|
||||||
.left.width400.rmargin55
|
|
||||||
= render 'table', type: 'users'
|
|
||||||
= render 'table', type: 'groups'
|
|
||||||
.left.width400
|
|
||||||
= render 'table', type: 'platforms'
|
|
||||||
- else
|
|
||||||
- collection = instance_variable_get("@#{@type}")
|
|
||||||
.tmargin10{id: @type}= render collection: collection, partial: @type.to_s.underscore.singularize
|
|
||||||
%br
|
|
||||||
= will_paginate collection
|
|
||||||
.both
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
.row
|
||||||
|
.col-md-3.col-md-offset-1
|
||||||
|
h3
|
||||||
|
= t('.advanced')
|
||||||
|
.col-md-7.offset20
|
||||||
|
= simple_form_for @search, url: search_index_path, method: :get do |f|
|
||||||
|
.row
|
||||||
|
.col-md-6
|
||||||
|
=hidden_field_tag :type, @type
|
||||||
|
= f.input :query, label: false, input_html: { name: 'query' }
|
||||||
|
.col-md-6
|
||||||
|
= f.button :submit, t('.submit')
|
||||||
|
|
|
||||||
|
= t('layout.or')
|
||||||
|
|
|
||||||
|
a href=search_index_path
|
||||||
|
= t('layout.clear')
|
||||||
|
|
||||||
|
|
||||||
|
.row
|
||||||
|
.col-md-3.col-md-offset-1
|
||||||
|
.panel.panel-default
|
||||||
|
.panel-body
|
||||||
|
ul.nav.nav-pills.nav-stacked
|
||||||
|
- t('.types').each do |k, v|
|
||||||
|
li class=('active' if k.to_s == @type)
|
||||||
|
a href=search_index_path(params.merge(type: k, page: 1))
|
||||||
|
span.badge.pull-right
|
||||||
|
= @search.send(k).count
|
||||||
|
= v
|
||||||
|
|
||||||
|
|
||||||
|
.col-md-7
|
||||||
|
table.table.table-striped
|
||||||
|
thead
|
||||||
|
tr
|
||||||
|
th
|
||||||
|
tbody
|
||||||
|
- @collection.each do |c|
|
||||||
|
tr
|
||||||
|
td= render @type.singularize, @type.singularize.to_sym => c
|
||||||
|
= will_paginate @collection
|
|
@ -2,12 +2,21 @@ en:
|
||||||
layout:
|
layout:
|
||||||
search:
|
search:
|
||||||
header: Search
|
header: Search
|
||||||
|
search:
|
||||||
|
index:
|
||||||
|
submit: Search
|
||||||
advanced: Advanced search
|
advanced: Advanced search
|
||||||
all: Show All
|
no_results: 'Nothing found for "%{query}".'
|
||||||
no_results: Nothing found for "%{query}".
|
|
||||||
types:
|
types:
|
||||||
all: All
|
|
||||||
projects: Projects
|
projects: Projects
|
||||||
users: Users
|
users: Users
|
||||||
groups: Groups
|
groups: Groups
|
||||||
platforms: Platforms
|
platforms: Platforms
|
||||||
|
|
||||||
|
project:
|
||||||
|
updated: "Updated:"
|
||||||
|
|
||||||
|
simple_form:
|
||||||
|
placeholders:
|
||||||
|
search:
|
||||||
|
query: "Search"
|
|
@ -2,12 +2,21 @@ ru:
|
||||||
layout:
|
layout:
|
||||||
search:
|
search:
|
||||||
header: Поиск
|
header: Поиск
|
||||||
|
search:
|
||||||
|
index:
|
||||||
|
submit: Поиск
|
||||||
advanced: Расширенный поиск
|
advanced: Расширенный поиск
|
||||||
all: Показать все
|
no_results: 'По запросу "%{query}" ничего не найдено.'
|
||||||
no_results: По запросу "%{query}" ничего не найдено.
|
|
||||||
types:
|
types:
|
||||||
all: Все
|
|
||||||
projects: Проекты
|
projects: Проекты
|
||||||
users: Пользователи
|
users: Пользователи
|
||||||
groups: Группы
|
groups: Группы
|
||||||
platforms: Платформы
|
platforms: Платформы
|
||||||
|
|
||||||
|
project:
|
||||||
|
updated: "Обновлен:"
|
||||||
|
|
||||||
|
simple_form:
|
||||||
|
placeholders:
|
||||||
|
search:
|
||||||
|
query: "Поиск"
|
Loading…
Reference in New Issue