#386: Added filter by group

This commit is contained in:
Vokhmin Alexey V 2014-05-15 23:52:43 +04:00
parent 1b9f481754
commit 0d7c1eb4e1
7 changed files with 92 additions and 13 deletions

View File

@ -1,5 +1,6 @@
class Platforms::RepositoriesController < Platforms::BaseController class Platforms::RepositoriesController < Platforms::BaseController
include FileStoreHelper include FileStoreHelper
include RepositoriesHelper
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, only: [:index, :show, :projects_list] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:index, :show, :projects_list] if APP_CONFIG['anonymous_access']
@ -116,7 +117,7 @@ class Platforms::RepositoriesController < Platforms::BaseController
ON projects.owner_id = owner.id AND projects.owner_type = owner.type" ON projects.owner_id = owner.id AND projects.owner_type = owner.type"
colName = ['projects.name'] colName = ['projects.name']
sort_col = params[:iSortCol_0] || 0 sort_col = params[:iSortCol_0] || 0
sort_dir = params[:sSortDir_0]=="asc" ? 'asc' : 'desc' sort_dir = params[:sSortDir_0] == 'asc' ? 'asc' : 'desc'
order = "#{colName[sort_col.to_i]} #{sort_dir}" order = "#{colName[sort_col.to_i]} #{sort_dir}"
if params[:added] == "true" if params[:added] == "true"
@ -131,7 +132,8 @@ class Platforms::RepositoriesController < Platforms::BaseController
) )
@total_projects = @projects.count @total_projects = @projects.count
@projects = @projects.search(params[:sSearch]).order(order) @projects = @projects.by_owner(params[:owner_name]).
search(params[:sSearch]).order(order)
respond_to do |format| respond_to do |format|
format.json { format.json {

View File

@ -0,0 +1,54 @@
module RepositoriesHelper
COLUMNS = [
{ type: 'html' },
{
type: 'html',
sortable: false,
searchable: false
},
{
type: nil,
sortable: false,
searchable: false,
class: 'buttons'
}
]
def repository_projects_datatable(repository)
datatable(
COLUMNS,
{
sort_by: "[0, 'asc']",
# search_label: t('layout.search_by_name'),
search_label: '',
placeholder: t('layout.projects.placeholder.project_name'),
processing: t('layout.processing'),
pagination_labels: {
previous: t('datatables.previous_label'),
next: t('datatables.next_label')
},
empty_label: t('datatables.empty_label'),
info_label: t('datatables.info_label'),
info_empty_label: t('datatables.info_empty_label'),
filtered_label: t('datatables.filtered_label'),
table_dom_id: 'datatable',
auto_width: 'false',
ajax_source: datatable_ajax_source(repository)
}
)
end
private
def datatable_ajax_source(repository)
url_for(
controller: :repositories,
action: :projects_list,
id: repository.id,
added: controller.action_name.to_sym == :show,
format: :json
)
end
end

View File

@ -69,6 +69,7 @@ class Project < ActiveRecord::Base
by_name("%#{q}%").search_order if q.present? by_name("%#{q}%").search_order if q.present?
} }
scope :by_name, ->(name) { where('projects.name ILIKE ?', name) if name.present? } scope :by_name, ->(name) { where('projects.name ILIKE ?', name) if name.present? }
scope :by_owner, ->(name) { where('projects.owner_uname ILIKE ?', "%#{name}%") if name.present? }
scope :by_owner_and_name, ->(*params) { scope :by_owner_and_name, ->(*params) {
term = params.map(&:strip).join('/').downcase term = params.map(&:strip).join('/').downcase
where("lower(concat(owner_uname, '/', name)) ILIKE ?", "%#{term}%") if term.present? where("lower(concat(owner_uname, '/', name)) ILIKE ?", "%#{term}%") if term.present?

View File

@ -1,13 +1,8 @@
- columns = [{type: 'html'}, {type: 'html', sortable: false, searchable: false}, {type: nil, sortable: false, searchable: false, class: 'buttons'}] = raw repository_projects_datatable(@repository)
= raw datatable(columns, {sort_by: "[0, 'asc']", search_label: t("layout.search_by_name"), processing: t("layout.processing"),
pagination_labels: {previous: t("datatables.previous_label"), next: t("datatables.next_label")}, #datatable-additional-filter.dataTables_filter
empty_label: t("datatables.empty_label"), %label
info_label: t("datatables.info_label"), %input{ type: "text", 'aria-controls' => 'datatable', placeholder: t('layout.projects.placeholder.owner_name') }
info_empty_label: t("datatables.info_empty_label"),
filtered_label: t("datatables.filtered_label"),
table_dom_id: 'datatable',
auto_width: 'false',
ajax_source: "#{url_for controller: :repositories, action: :projects_list, id: @repository.id, added: "#{controller.action_name.to_sym == :show}", format: :json}" })
%table#datatable.tablesorter.repo-projects{cellspacing: 0, cellpadding: 0} %table#datatable.tablesorter.repo-projects{cellspacing: 0, cellpadding: 0}
%thead %thead
@ -17,3 +12,19 @@
%th.buttons &nbsp; %th.buttons &nbsp;
%tbody %tbody
%br %br
:javascript
$(function() {
$('#datatable_filter').after($('#datatable-additional-filter'));
$('#datatable-additional-filter input').on('keyup', function() {
$('#datatable').dataTable().fnDraw();
});
});
function dataTableAdditionalFilter() {
return {
'name': 'owner_name',
'value': $('#datatable-additional-filter input').val()
};
}

View File

@ -1,6 +1,9 @@
en: en:
layout: layout:
projects: projects:
placeholder:
project_name: Project name
owner_name: Owner name
build_schedule: Build schedule build_schedule: Build schedule
mass_import: Mass import mass_import: Mass import
branches: Branches branches: Branches

View File

@ -1,6 +1,9 @@
ru: ru:
layout: layout:
projects: projects:
placeholder:
project_name: Название проекта
owner_name: Владелец проекта
build_schedule: Расписание сборок build_schedule: Расписание сборок
mass_import: Массовый импорт mass_import: Массовый импорт
branches: Ветки branches: Ветки

View File

@ -4,6 +4,7 @@ module RailsDatatables
additional_data = opts[:additional_data] || {} additional_data = opts[:additional_data] || {}
search = opts[:search].present? ? opts[:search].to_s : "true" search = opts[:search].present? ? opts[:search].to_s : "true"
search_label = opts[:search_label] || "Search" search_label = opts[:search_label] || "Search"
placeholder = opts[:placeholder]
processing = opts[:processing] || "Processing" processing = opts[:processing] || "Processing"
persist_state = opts[:persist_state].present? ? opts[:persist_state].to_s : "true" persist_state = opts[:persist_state].present? ? opts[:persist_state].to_s : "true"
table_dom_id = opts[:table_dom_id] ? "##{opts[:table_dom_id]}" : ".datatable" table_dom_id = opts[:table_dom_id] ? "##{opts[:table_dom_id]}" : ".datatable"
@ -76,6 +77,9 @@ module RailsDatatables
#{"'fnRowCallback': function( nRow, aData, iDisplayIndex ) { #{row_callback} }," if row_callback} #{"'fnRowCallback': function( nRow, aData, iDisplayIndex ) { #{row_callback} }," if row_callback}
#{"'fnServerData': function ( sSource, aoData, fnCallback ) { #{"'fnServerData': function ( sSource, aoData, fnCallback ) {
aoData.push( #{additional_data_string} ); aoData.push( #{additional_data_string} );
if (typeof dataTableAdditionalFilter == 'function') {
aoData.push(dataTableAdditionalFilter());
}
$.getJSON( sSource, aoData, function (json) { $.getJSON( sSource, aoData, function (json) {
fnCallback(json); fnCallback(json);
} ); } );
@ -84,6 +88,7 @@ module RailsDatatables
})#{append}; })#{append};
$('#datatable_wrapper').append("<div class='both'></div>"); $('#datatable_wrapper').append("<div class='both'></div>");
#{ "$('#datatable_wrapper .dataTables_filter input').attr('placeholder', '#{placeholder}');" if placeholder }
}); });
</script> </script>
} }