diff --git a/app/controllers/platforms/repositories_controller.rb b/app/controllers/platforms/repositories_controller.rb index 6582467b0..a84b2a65b 100644 --- a/app/controllers/platforms/repositories_controller.rb +++ b/app/controllers/platforms/repositories_controller.rb @@ -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 { diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb new file mode 100644 index 000000000..2bd11ba20 --- /dev/null +++ b/app/helpers/repositories_helper.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index 8accb89fa..0d95ad6e4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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? diff --git a/app/views/platforms/repositories/_proj_list.html.haml b/app/views/platforms/repositories/_proj_list.html.haml index 3e0b4b546..3d63b6d87 100644 --- a/app/views/platforms/repositories/_proj_list.html.haml +++ b/app/views/platforms/repositories/_proj_list.html.haml @@ -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   %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() + }; + } diff --git a/config/locales/models/project.en.yml b/config/locales/models/project.en.yml index eef753e8e..803b58ffa 100644 --- a/config/locales/models/project.en.yml +++ b/config/locales/models/project.en.yml @@ -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 diff --git a/config/locales/models/project.ru.yml b/config/locales/models/project.ru.yml index 6d8e90e50..86c3f54f8 100644 --- a/config/locales/models/project.ru.yml +++ b/config/locales/models/project.ru.yml @@ -1,6 +1,9 @@ ru: layout: projects: + placeholder: + project_name: Название проекта + owner_name: Владелец проекта build_schedule: Расписание сборок mass_import: Массовый импорт branches: Ветки diff --git a/lib/plugins/rails_datatables/rails_datatables.rb b/lib/plugins/rails_datatables/rails_datatables.rb index 93826a8fa..5fdb5971f 100644 --- a/lib/plugins/rails_datatables/rails_datatables.rb +++ b/lib/plugins/rails_datatables/rails_datatables.rb @@ -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("
"); + #{ "$('#datatable_wrapper .dataTables_filter input').attr('placeholder', '#{placeholder}');" if placeholder } }); }