mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-04-13 15:50:27 +08:00
add asset field preview/sort/search in repository table [fixes SCI-2076]
This commit is contained in:
parent
e608d629c7
commit
b51ad84ee5
4 changed files with 68 additions and 19 deletions
app
assets/javascripts/repositories
helpers
services
views/repositories
|
@ -202,6 +202,7 @@ var RepositoryDatatable = (function(global) {
|
||||||
initHeaderTooltip();
|
initHeaderTooltip();
|
||||||
initRowSelection();
|
initRowSelection();
|
||||||
bindExportActions();
|
bindExportActions();
|
||||||
|
disableCheckboxToggleOnAssetDownload();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -289,6 +290,11 @@ var RepositoryDatatable = (function(global) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function disableCheckboxToggleOnAssetDownload() {
|
||||||
|
$('.file-preview-link').on('click', function(ev) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function appendInput(form, val, name) {
|
function appendInput(form, val, name) {
|
||||||
$(form).append(
|
$(form).append(
|
||||||
|
|
|
@ -31,18 +31,26 @@ module RepositoryDatatableHelper
|
||||||
# Add custom columns
|
# Add custom columns
|
||||||
record.repository_cells.each do |cell|
|
record.repository_cells.each do |cell|
|
||||||
row[columns_mappings[cell.repository_column.id]] =
|
row[columns_mappings[cell.repository_column.id]] =
|
||||||
custom_auto_link(
|
display_cell_value(cell, team)
|
||||||
display_tooltip(cell.value.data,
|
|
||||||
Constants::NAME_MAX_LENGTH),
|
|
||||||
simple_format: true,
|
|
||||||
team: team
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
parsed_records << row
|
parsed_records << row
|
||||||
end
|
end
|
||||||
parsed_records
|
parsed_records
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def display_cell_value(cell, team)
|
||||||
|
if cell.value_type == 'RepositoryAssetValue'
|
||||||
|
render partial: 'repositories/asset_link',
|
||||||
|
locals: { asset: cell.value.asset },
|
||||||
|
formats: :html
|
||||||
|
else
|
||||||
|
custom_auto_link(display_tooltip(cell.value.data,
|
||||||
|
Constants::NAME_MAX_LENGTH),
|
||||||
|
simple_format: true,
|
||||||
|
team: team)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def assigned_row(record, assigned_rows)
|
def assigned_row(record, assigned_rows)
|
||||||
if assigned_rows&.include?(record)
|
if assigned_rows&.include?(record)
|
||||||
"<span class='circle'> </span>"
|
"<span class='circle'> </span>"
|
||||||
|
|
|
@ -16,7 +16,7 @@ class RepositoryDatatableService
|
||||||
def create_columns_mappings
|
def create_columns_mappings
|
||||||
# Make mappings of custom columns, so we have same id for every
|
# Make mappings of custom columns, so we have same id for every
|
||||||
# column
|
# column
|
||||||
index = 5
|
index = 6
|
||||||
@mappings = {}
|
@mappings = {}
|
||||||
@repository.repository_columns.order(:id).each do |column|
|
@repository.repository_columns.order(:id).each do |column|
|
||||||
@mappings[column.id] = index.to_s
|
@mappings[column.id] = index.to_s
|
||||||
|
@ -59,12 +59,13 @@ class RepositoryDatatableService
|
||||||
'users.full_name',
|
'users.full_name',
|
||||||
'repository_rows.id'] +
|
'repository_rows.id'] +
|
||||||
Extends::REPOSITORY_EXTRA_SEARCH_ATTR
|
Extends::REPOSITORY_EXTRA_SEARCH_ATTR
|
||||||
|
ids = @repository.repository_rows
|
||||||
RepositoryRow.left_outer_joins(:created_by)
|
.left_outer_joins(:created_by)
|
||||||
.left_outer_joins(includes_json)
|
.left_outer_joins(includes_json)
|
||||||
.where(repository: @repository)
|
.where_attributes_like(searchable_attributes, value)
|
||||||
.where_attributes_like(searchable_attributes, value)
|
.pluck(:id)
|
||||||
.distinct
|
# using distinct raises an error when combined with sort
|
||||||
|
RepositoryRow.where(id: ids.uniq)
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_conditions(params)
|
def build_conditions(params)
|
||||||
|
@ -151,12 +152,14 @@ class RepositoryDatatableService
|
||||||
|
|
||||||
def select_type(type, records, id, dir)
|
def select_type(type, records, id, dir)
|
||||||
case type
|
case type
|
||||||
when 'RepositoryTextValue'
|
when 'RepositoryTextValue'
|
||||||
filter_by_text_value(records, id, dir)
|
filter_by_text_value(records, id, dir)
|
||||||
when 'RepositoryListValue'
|
when 'RepositoryListValue'
|
||||||
filter_by_list_value(records, id, dir)
|
filter_by_list_value(records, id, dir)
|
||||||
else
|
when 'RepositoryAssetValue'
|
||||||
records
|
filter_by_asset_value(records, id, dir)
|
||||||
|
else
|
||||||
|
records
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -164,6 +167,20 @@ class RepositoryDatatableService
|
||||||
val == 'ASC' ? 'LAST' : 'FIRST'
|
val == 'ASC' ? 'LAST' : 'FIRST'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def filter_by_asset_value(records, id, dir)
|
||||||
|
records.joins(
|
||||||
|
"LEFT OUTER JOIN (SELECT repository_cells.repository_row_id,
|
||||||
|
assets.file_file_name AS value
|
||||||
|
FROM repository_cells
|
||||||
|
INNER JOIN repository_asset_values
|
||||||
|
ON repository_asset_values.id = repository_cells.value_id
|
||||||
|
INNER JOIN assets
|
||||||
|
ON repository_asset_values.asset_id = assets.id
|
||||||
|
WHERE repository_cells.repository_column_id = #{id}) AS values
|
||||||
|
ON values.repository_row_id = repository_rows.id"
|
||||||
|
).order("values.value #{dir}")
|
||||||
|
end
|
||||||
|
|
||||||
def filter_by_text_value(records, id, dir)
|
def filter_by_text_value(records, id, dir)
|
||||||
records.joins(
|
records.joins(
|
||||||
"LEFT OUTER JOIN (SELECT repository_cells.repository_row_id,
|
"LEFT OUTER JOIN (SELECT repository_cells.repository_row_id,
|
||||||
|
|
18
app/views/repositories/_asset_link.html.erb
Normal file
18
app/views/repositories/_asset_link.html.erb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<% if asset.file_present %>
|
||||||
|
<% if asset.file.processing? %>
|
||||||
|
<span data-status='asset-loading'
|
||||||
|
data-present-url='<%= file_present_asset_path(asset.id) %>'>
|
||||||
|
<%= image_tag 'medium/processing.gif' %>
|
||||||
|
</span>
|
||||||
|
<% else %>
|
||||||
|
<%= link_to download_asset_path(asset),
|
||||||
|
class: 'file-preview-link',
|
||||||
|
id: "modal_link#{asset.id}",
|
||||||
|
data: { no_turbolink: true, id: true, status: 'asset-present', 'preview-url': asset_file_preview_path(asset) } do %>
|
||||||
|
<p><%= truncate(asset.file_file_name,
|
||||||
|
length: Constants::FILENAME_TRUNCATION_LENGTH) %></p>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<%= image_tag 'medium/processing.gif' %>
|
||||||
|
<% end %>
|
Loading…
Add table
Reference in a new issue