mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-27 02:04:33 +08:00
Add serializers to datatable values
This commit is contained in:
parent
0f3c138a7e
commit
232e4d78be
7 changed files with 48 additions and 30 deletions
|
@ -43,7 +43,7 @@
|
||||||
//= require global_activities/side_pane
|
//= require global_activities/side_pane
|
||||||
//= require protocols/header
|
//= require protocols/header
|
||||||
//= require marvinjslauncher
|
//= require marvinjslauncher
|
||||||
//= require_directory ./repositories/renders
|
//= require_directory ./repositories/renderers
|
||||||
//= require turbolinks
|
//= require turbolinks
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -511,8 +511,8 @@ var RepositoryDatatable = (function(global) {
|
||||||
}, {
|
}, {
|
||||||
targets: '_all',
|
targets: '_all',
|
||||||
render: function(data) {
|
render: function(data) {
|
||||||
if (typeof data === 'object' && $.fn.dataTable.render[data.cell_type]) {
|
if (typeof data === 'object' && $.fn.dataTable.render[data.value_type]) {
|
||||||
return $.fn.dataTable.render[data.cell_type](data);
|
return $.fn.dataTable.render[data.value_type](data);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ module RepositoryDatatableHelper
|
||||||
def prepare_row_columns(repository_rows,
|
def prepare_row_columns(repository_rows,
|
||||||
repository,
|
repository,
|
||||||
columns_mappings,
|
columns_mappings,
|
||||||
team,
|
_team,
|
||||||
assigned_rows)
|
assigned_rows)
|
||||||
parsed_records = []
|
parsed_records = []
|
||||||
repository_rows.each do |record|
|
repository_rows.each do |record|
|
||||||
|
@ -34,7 +34,7 @@ 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]] =
|
||||||
display_cell_value(cell, team)
|
display_cell_value(cell)
|
||||||
end
|
end
|
||||||
parsed_records << row
|
parsed_records << row
|
||||||
end
|
end
|
||||||
|
@ -71,30 +71,7 @@ module RepositoryDatatableHelper
|
||||||
end.to_json
|
end.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_cell_value(cell, team)
|
def display_cell_value(cell)
|
||||||
cell_type = cell.value_type.underscore
|
"RepositoryDatatable::#{cell.value_type}Serializer".constantize.new(cell).serializable_hash
|
||||||
data = if DisplayCellValue.respond_to? cell_type
|
|
||||||
DisplayCellValue.public_send(cell_type, cell, team)
|
|
||||||
else
|
|
||||||
custom_auto_link(display_tooltip(cell.value.data, Constants::NAME_MAX_LENGTH),
|
|
||||||
simple_format: true,
|
|
||||||
team: team)
|
|
||||||
end
|
|
||||||
{
|
|
||||||
cell_type: cell.value_type,
|
|
||||||
data: data
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
class DisplayCellValue
|
|
||||||
def self.repository_asset_value(cell, _team)
|
|
||||||
asset = cell.value.asset
|
|
||||||
{
|
|
||||||
id: asset.id,
|
|
||||||
url: Rails.application.routes.url_helpers.rails_blob_path(asset.file, disposition: 'attachment'),
|
|
||||||
preview_url: Rails.application.routes.url_helpers.asset_file_preview_path(asset),
|
|
||||||
file_name: asset.file_name
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module RepositoryDatatable
|
||||||
|
class RepositoryAssetValueSerializer < ActiveModel::Serializer
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
|
|
||||||
|
attributes :data, :value_type
|
||||||
|
|
||||||
|
def data
|
||||||
|
asset = object.value.asset
|
||||||
|
{
|
||||||
|
id: asset.id,
|
||||||
|
url: rails_blob_path(asset.file, disposition: 'attachment'),
|
||||||
|
preview_url: asset_file_preview_path(asset),
|
||||||
|
file_name: asset.file_name
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,11 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module RepositoryDatatable
|
||||||
|
class RepositoryListValueSerializer < ActiveModel::Serializer
|
||||||
|
attributes :data, :value_type
|
||||||
|
|
||||||
|
def data
|
||||||
|
object.value.data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,11 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module RepositoryDatatable
|
||||||
|
class RepositoryTextValueSerializer < ActiveModel::Serializer
|
||||||
|
attributes :data, :value_type
|
||||||
|
|
||||||
|
def data
|
||||||
|
object.value.data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue