mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-04 03:36:44 +08:00
Code fixes [SCI-1873]
This commit is contained in:
parent
512ee07bde
commit
070711917e
1 changed files with 32 additions and 35 deletions
|
@ -183,7 +183,8 @@ class RepositoryDatatable < CustomDatatable
|
||||||
# number of samples/all samples it's dependant upon sort_record query
|
# number of samples/all samples it's dependant upon sort_record query
|
||||||
def fetch_records
|
def fetch_records
|
||||||
records = get_raw_records
|
records = get_raw_records
|
||||||
records = filter_records(records) if dt_params[:search].present?
|
records = filter_records(records) if dt_params[:search].present? &&
|
||||||
|
dt_params[:search][:value].present?
|
||||||
records = sort_records(records) if order_params.present?
|
records = sort_records(records) if order_params.present?
|
||||||
records = paginate_records(records) unless dt_params[:length].present? &&
|
records = paginate_records(records) unless dt_params[:length].present? &&
|
||||||
dt_params[:length] == '-1'
|
dt_params[:length] == '-1'
|
||||||
|
@ -232,42 +233,38 @@ class RepositoryDatatable < CustomDatatable
|
||||||
|
|
||||||
# Override default sort method if needed
|
# Override default sort method if needed
|
||||||
def sort_records(records)
|
def sort_records(records)
|
||||||
if order_params.present?
|
if sort_column(order_params) == ASSIGNED_SORT_COL
|
||||||
if sort_column(order_params) == ASSIGNED_SORT_COL
|
# If "assigned" column is sorted when viewing assigned items
|
||||||
# If "assigned" column is sorted when viewing assigned items
|
return records if @my_module && dt_params[:assigned] == 'assigned'
|
||||||
return records if @my_module && dt_params[:assigned] == 'assigned'
|
# If "assigned" column is sorted
|
||||||
# If "assigned" column is sorted
|
direction = sort_null_direction(order_params)
|
||||||
direction = sort_null_direction(order_params)
|
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
|
|
||||||
records.joins(
|
|
||||||
"LEFT OUTER JOIN my_module_repository_rows ON
|
|
||||||
(repository_rows.id = my_module_repository_rows.repository_row_id
|
|
||||||
AND (my_module_repository_rows.my_module_id = #{@my_module.id} OR
|
|
||||||
my_module_repository_rows.id IS NULL))"
|
|
||||||
).order("my_module_repository_rows.id NULLS #{direction}")
|
|
||||||
else
|
|
||||||
sort_assigned_records(records, order_params['dir'])
|
|
||||||
end
|
|
||||||
elsif sorting_by_custom_column
|
|
||||||
ci = sortable_displayed_columns[
|
|
||||||
order_params['column'].to_i - 1
|
|
||||||
]
|
|
||||||
column_id = @columns_mappings.key((ci.to_i + 1).to_s)
|
|
||||||
dir = sort_direction(order_params)
|
|
||||||
|
|
||||||
records.joins(
|
records.joins(
|
||||||
"LEFT OUTER JOIN (SELECT repository_cells.repository_row_id,
|
"LEFT OUTER JOIN my_module_repository_rows ON
|
||||||
repository_text_values.data AS value FROM repository_cells
|
(repository_rows.id = my_module_repository_rows.repository_row_id
|
||||||
INNER JOIN repository_text_values
|
AND (my_module_repository_rows.my_module_id = #{@my_module.id} OR
|
||||||
ON repository_text_values.id = repository_cells.value_id
|
my_module_repository_rows.id IS NULL))"
|
||||||
WHERE repository_cells.repository_column_id = #{column_id}) AS values
|
).order("my_module_repository_rows.id NULLS #{direction}")
|
||||||
ON values.repository_row_id = repository_rows.id"
|
|
||||||
).order("values.value #{dir}")
|
|
||||||
else
|
else
|
||||||
super(records)
|
sort_assigned_records(records, order_params['dir'])
|
||||||
end
|
end
|
||||||
|
elsif sorting_by_custom_column
|
||||||
|
ci = sortable_displayed_columns[
|
||||||
|
order_params['column'].to_i - 1
|
||||||
|
]
|
||||||
|
column_id = @columns_mappings.key((ci.to_i + 1).to_s)
|
||||||
|
dir = sort_direction(order_params)
|
||||||
|
|
||||||
|
records.joins(
|
||||||
|
"LEFT OUTER JOIN (SELECT repository_cells.repository_row_id,
|
||||||
|
repository_text_values.data AS value FROM repository_cells
|
||||||
|
INNER JOIN repository_text_values
|
||||||
|
ON repository_text_values.id = repository_cells.value_id
|
||||||
|
WHERE repository_cells.repository_column_id = #{column_id}) AS values
|
||||||
|
ON values.repository_row_id = repository_rows.id"
|
||||||
|
).order("values.value #{dir}")
|
||||||
else
|
else
|
||||||
super(records)
|
super(records)
|
||||||
end
|
end
|
||||||
|
@ -323,7 +320,7 @@ class RepositoryDatatable < CustomDatatable
|
||||||
ids = unassigned + assigned
|
ids = unassigned + assigned
|
||||||
end
|
end
|
||||||
|
|
||||||
order_by_index = ActiveRecord::Base.__send__(
|
order_by_index = ActiveRecord::Base.send(
|
||||||
:sanitize_sql_array,
|
:sanitize_sql_array,
|
||||||
["position((',' || repository_rows.id || ',') in ?)",
|
["position((',' || repository_rows.id || ',') in ?)",
|
||||||
ids.join(',') + ',']
|
ids.join(',') + ',']
|
||||||
|
|
Loading…
Reference in a new issue