Merge pull request #690 from okriuchykhin/ok_SCI_1346_v2

Fix bug when reordering column to the first position in repositories [SCI-1346]
This commit is contained in:
okriuchykhin 2017-06-16 14:29:08 +02:00 committed by GitHub
commit 05ea00a5d3
3 changed files with 16 additions and 13 deletions

View file

@ -42,6 +42,7 @@ function dataTableInit() {
originalHeader = $('#repository-table thead').children().clone(); originalHeader = $('#repository-table thead').children().clone();
viewAssigned = 'assigned'; viewAssigned = 'assigned';
table = $('#repository-table').DataTable({ table = $('#repository-table').DataTable({
order: [[2, 'desc']],
dom: "R<'row'<'col-sm-9-custom toolbar'l><'col-sm-3-custom'f>>tpi", dom: "R<'row'<'col-sm-9-custom toolbar'l><'col-sm-3-custom'f>>tpi",
stateSave: true, stateSave: true,
processing: true, processing: true,
@ -157,12 +158,8 @@ function dataTableInit() {
// Reload correct column order and visibility (if you refresh page) // Reload correct column order and visibility (if you refresh page)
// First two columns are fixed // First two columns are fixed
table.column(0).visible(true); table.column(0).visible(true);
if ($('#assigned').text().length === 0) { table.column(1).visible(true);
table.column(1).visible(false); for (var i = 2; i < table.columns()[0].length; i++) {
} else {
table.column(1).visible(true);
}
for (var i = 1; i < table.columns()[0].length; i++) {
var visibility = false; var visibility = false;
if (myData.columns[i]) { if (myData.columns[i]) {
visibility = myData.columns[i].visible; visibility = myData.columns[i].visible;

View file

@ -102,7 +102,7 @@ class RepositoryDatatable < AjaxDatatablesRails::Base
records.map do |record| records.map do |record|
row = { row = {
'DT_RowId': record.id, 'DT_RowId': record.id,
'1': @my_module ? assigned_row(record) : '', '1': assigned_row(record),
'2': escape_input(record.name), '2': escape_input(record.name),
'3': I18n.l(record.created_at, format: :full), '3': I18n.l(record.created_at, format: :full),
'4': escape_input(record.created_by.full_name), '4': escape_input(record.created_by.full_name),
@ -155,6 +155,11 @@ class RepositoryDatatable < AjaxDatatablesRails::Base
) )
.joins(:created_by) .joins(:created_by)
.where(repository: @repository) .where(repository: @repository)
else
@assigned_rows = repository_rows.joins(
'INNER JOIN my_module_repository_rows ON
(repository_rows.id = my_module_repository_rows.repository_row_id)'
)
end end
# Make mappings of custom columns, so we have same id for every column # Make mappings of custom columns, so we have same id for every column
@ -206,16 +211,21 @@ class RepositoryDatatable < AjaxDatatablesRails::Base
if params[:order].present? && params[:order].length == 1 if params[:order].present? && params[:order].length == 1
if sort_column(params[:order].values[0]) == ASSIGNED_SORT_COL if sort_column(params[:order].values[0]) == ASSIGNED_SORT_COL
# If "assigned" column is sorted # If "assigned" column is sorted
direction = sort_null_direction(params[:order].values[0])
if @my_module if @my_module
# Depending on the sort, order nulls first or # Depending on the sort, order nulls first or
# nulls last on repository_cells association # nulls last on repository_cells association
direction = sort_null_direction(params[:order].values[0])
records.joins( records.joins(
"LEFT OUTER JOIN my_module_repository_rows ON "LEFT OUTER JOIN my_module_repository_rows ON
(repository_rows.id = my_module_repository_rows.repository_row_id (repository_rows.id = my_module_repository_rows.repository_row_id
AND (my_module_repository_rows.my_module_id = #{@my_module.id} OR AND (my_module_repository_rows.my_module_id = #{@my_module.id} OR
my_module_repository_rows.id IS NULL))" my_module_repository_rows.id IS NULL))"
).order("my_module_repository_rows.id NULLS #{direction}") ).order("my_module_repository_rows.id NULLS #{direction}")
else
records.joins(
'LEFT OUTER JOIN my_module_repository_rows ON
(repository_rows.id = my_module_repository_rows.repository_row_id)'
).order("my_module_repository_rows.id NULLS #{direction}")
end end
elsif sorting_by_custom_column elsif sorting_by_custom_column
# Check if have to filter records first # Check if have to filter records first

View file

@ -15,11 +15,7 @@
<thead> <thead>
<tr> <tr>
<th id="checkbox"><input name="select_all" value="1" type="checkbox"></th> <th id="checkbox"><input name="select_all" value="1" type="checkbox"></th>
<% if @my_module %> <th id="assigned"><%= t("repositories.table.assigned") %></th>
<th id="assigned"><%= t("repositories.table.assigned") %></th>
<% else %>
<th id="assigned"></th>
<% end %>
<th id="row-name"><%= t("repositories.table.row_name") %></th> <th id="row-name"><%= t("repositories.table.row_name") %></th>
<th id="added-on"><%= t("repositories.table.added_on") %></th> <th id="added-on"><%= t("repositories.table.added_on") %></th>
<th id="added-by"><%= t("repositories.table.added_by") %></th> <th id="added-by"><%= t("repositories.table.added_by") %></th>