Make repository value render more flexible

This commit is contained in:
aignatov-bio 2019-10-09 12:53:41 +02:00 committed by Urban Rotnik
parent e07fad72b6
commit 2ed3054c89

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
module RepositoryDatatableHelper
include InputSanitizeHelper
def prepare_row_columns(repository_rows,
@ -8,25 +10,25 @@ module RepositoryDatatableHelper
parsed_records = []
repository_rows.each do |record|
row = {
'DT_RowId': record.id,
'1': assigned_row(record, assigned_rows),
'2': record.id,
'3': escape_input(record.name),
'4': I18n.l(record.created_at, format: :full),
'5': escape_input(record.created_by.full_name),
'recordEditUrl': Rails.application.routes.url_helpers
.edit_repository_repository_row_path(
repository,
record.id
),
'recordUpdateUrl': Rails.application.routes.url_helpers
.repository_repository_row_path(
repository,
record.id
),
'recordInfoUrl': Rails.application.routes.url_helpers
.repository_row_path(record.id)
}
'DT_RowId': record.id,
'1': assigned_row(record, assigned_rows),
'2': record.id,
'3': escape_input(record.name),
'4': I18n.l(record.created_at, format: :full),
'5': escape_input(record.created_by.full_name),
'recordEditUrl': Rails.application.routes.url_helpers
.edit_repository_repository_row_path(
repository,
record.id
),
'recordUpdateUrl': Rails.application.routes.url_helpers
.repository_repository_row_path(
repository,
record.id
),
'recordInfoUrl': Rails.application.routes.url_helpers
.repository_row_path(record.id)
}
# Add custom columns
record.repository_cells.each do |cell|
@ -38,21 +40,6 @@ module RepositoryDatatableHelper
parsed_records
end
def display_cell_value(cell, team)
if cell.value_type == 'RepositoryAssetValue'
# Return simple file_name if we call this method not from controller
return cell.value.asset.file_name unless defined?(render)
render partial: 'shared/asset_link',
locals: { asset: cell.value.asset, display_image_tag: false },
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-icon'>&nbsp;</span>"
@ -82,4 +69,27 @@ module RepositoryDatatableHelper
col.slice(:visible, :searchable)
end.to_json
end
def display_cell_value(cell, team)
value_type = cell.value_type.underscore
if (DisplayCellValue.respond_to? value_type) && defined?(render)
render DisplayCellValue.public_send(value_type, cell, team)
elsif DisplayCellValue.respond_to? "#{value_type}_text"
DisplayCellValue.public_send("#{value_type}_text", cell, team)
else
custom_auto_link(display_tooltip(cell.value.data, Constants::NAME_MAX_LENGTH),
simple_format: true,
team: team)
end
end
class DisplayCellValue
def self.repository_asset_value(cell, _team)
{
partial: 'shared/asset_link',
locals: { asset: cell.value.asset, display_image_tag: false },
formats: :html
}
end
end
end