Merge pull request #387 from abf/rosa-build:386-add-filter-by-group-when-adding-projects-to-repository

#386: Add filter by group when adding projects to repository
This commit is contained in:
avokhmin 2014-05-16 13:19:23 +04:00
commit 7cf8a91de4
7 changed files with 91 additions and 13 deletions

View File

@ -1,5 +1,6 @@
class Platforms::RepositoriesController < Platforms::BaseController
include FileStoreHelper
include RepositoriesHelper
before_filter :authenticate_user!
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"
colName = ['projects.name']
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}"
if params[:added] == "true"
@ -131,7 +132,8 @@ class Platforms::RepositoriesController < Platforms::BaseController
)
@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|
format.json {

View File

@ -0,0 +1,53 @@
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: '',
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

@ -68,7 +68,8 @@ class Project < ActiveRecord::Base
q = q.to_s.strip
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) {
term = params.map(&:strip).join('/').downcase
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 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")},
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: "#{url_for controller: :repositories, action: :projects_list, id: @repository.id, added: "#{controller.action_name.to_sym == :show}", format: :json}" })
= raw repository_projects_datatable(@repository)
#datatable-additional-filter.dataTables_filter
%label
%input{ type: "text", 'aria-controls' => 'datatable', placeholder: t('layout.projects.placeholder.owner_name') }
%table#datatable.tablesorter.repo-projects{cellspacing: 0, cellpadding: 0}
%thead
@ -17,3 +12,19 @@
%th.buttons &nbsp;
%tbody
%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:
layout:
projects:
placeholder:
project_name: Project name
owner_name: Owner name
build_schedule: Build schedule
mass_import: Mass import
branches: Branches

View File

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

View File

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