Merge pull request #1080 from ZmagoD/zd_SCI_2076

add asset field preview/sort/search in repository table [fixes SCI-2076]
This commit is contained in:
Zmago Devetak 2018-04-09 14:29:45 +02:00 committed by GitHub
commit eca69cfc75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 19 deletions

View file

@ -202,6 +202,7 @@ var RepositoryDatatable = (function(global) {
initHeaderTooltip();
initRowSelection();
bindExportActions();
disableCheckboxToggleOnAssetDownload();
}
});
@ -288,6 +289,11 @@ var RepositoryDatatable = (function(global) {
});
}
function disableCheckboxToggleOnAssetDownload() {
$('.file-preview-link').on('click', function(ev) {
ev.stopPropagation();
});
}
function appendInput(form, val, name) {
$(form).append(

View file

@ -31,18 +31,26 @@ module RepositoryDatatableHelper
# Add custom columns
record.repository_cells.each do |cell|
row[columns_mappings[cell.repository_column.id]] =
custom_auto_link(
display_tooltip(cell.value.data,
Constants::NAME_MAX_LENGTH),
simple_format: true,
team: team
)
display_cell_value(cell, team)
end
parsed_records << row
end
parsed_records
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)
if assigned_rows&.include?(record)
"<span class='circle'>&nbsp;</span>"

View file

@ -16,7 +16,7 @@ class RepositoryDatatableService
def create_columns_mappings
# Make mappings of custom columns, so we have same id for every
# column
index = 5
index = 6
@mappings = {}
@repository.repository_columns.order(:id).each do |column|
@mappings[column.id] = index.to_s
@ -59,12 +59,13 @@ class RepositoryDatatableService
'users.full_name',
'repository_rows.id'] +
Extends::REPOSITORY_EXTRA_SEARCH_ATTR
RepositoryRow.left_outer_joins(:created_by)
.left_outer_joins(includes_json)
.where(repository: @repository)
.where_attributes_like(searchable_attributes, value)
.distinct
ids = @repository.repository_rows
.left_outer_joins(:created_by)
.left_outer_joins(includes_json)
.where_attributes_like(searchable_attributes, value)
.pluck(:id)
# using distinct raises an error when combined with sort
RepositoryRow.where(id: ids.uniq)
end
def build_conditions(params)
@ -151,12 +152,14 @@ class RepositoryDatatableService
def select_type(type, records, id, dir)
case type
when 'RepositoryTextValue'
filter_by_text_value(records, id, dir)
when 'RepositoryListValue'
filter_by_list_value(records, id, dir)
else
records
when 'RepositoryTextValue'
filter_by_text_value(records, id, dir)
when 'RepositoryListValue'
filter_by_list_value(records, id, dir)
when 'RepositoryAssetValue'
filter_by_asset_value(records, id, dir)
else
records
end
end
@ -164,6 +167,20 @@ class RepositoryDatatableService
val == 'ASC' ? 'LAST' : 'FIRST'
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)
records.joins(
"LEFT OUTER JOIN (SELECT repository_cells.repository_row_id,

View 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 %>