2018-03-06 23:32:39 +08:00
|
|
|
module RepositoryDatatableHelper
|
|
|
|
include InputSanitizeHelper
|
2018-03-09 00:36:10 +08:00
|
|
|
def prepare_row_columns(repository_rows,
|
|
|
|
repository,
|
|
|
|
columns_mappings,
|
|
|
|
team,
|
|
|
|
assigned_rows)
|
2018-03-06 23:32:39 +08:00
|
|
|
parsed_records = []
|
|
|
|
repository_rows.each do |record|
|
|
|
|
row = {
|
|
|
|
'DT_RowId': record.id,
|
2018-03-09 00:36:10 +08:00
|
|
|
'1': assigned_row(record, assigned_rows),
|
2018-03-06 23:32:39 +08:00
|
|
|
'2': escape_input(record.name),
|
|
|
|
'3': I18n.l(record.created_at, format: :full),
|
|
|
|
'4': escape_input(record.created_by.full_name),
|
2018-03-09 21:43:12 +08:00
|
|
|
'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)
|
2018-03-06 23:32:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
|
|
|
)
|
|
|
|
end
|
|
|
|
parsed_records << row
|
|
|
|
end
|
|
|
|
parsed_records
|
|
|
|
end
|
|
|
|
|
2018-03-09 00:36:10 +08:00
|
|
|
def assigned_row(record, assigned_rows)
|
|
|
|
if assigned_rows&.include?(record)
|
|
|
|
"<span class='circle'> </span>"
|
|
|
|
else
|
|
|
|
"<span class='circle disabled'> </span>"
|
|
|
|
end
|
2018-03-06 23:32:39 +08:00
|
|
|
end
|
|
|
|
end
|