2020-06-01 16:24:03 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module RepositoriesDatatableHelper
|
|
|
|
include InputSanitizeHelper
|
|
|
|
|
|
|
|
def prepare_repositories_datatable(repositories, team, _config)
|
|
|
|
result = []
|
2020-06-05 01:07:10 +08:00
|
|
|
repositories = repositories.includes(:repository_rows, :team, :created_by, :archived_by)
|
2020-06-01 16:24:03 +08:00
|
|
|
repositories.each do |repository|
|
|
|
|
result.push(
|
2020-06-09 19:16:50 +08:00
|
|
|
'DT_RowId': repository.id,
|
2020-06-01 16:24:03 +08:00
|
|
|
'1': escape_input(repository.name),
|
2020-07-07 15:48:18 +08:00
|
|
|
'2': repository.active? ? repository.repository_rows.active.size : repository.repository_rows.size,
|
2020-06-24 19:41:00 +08:00
|
|
|
'3': shared_label(repository, team),
|
2020-06-01 16:24:03 +08:00
|
|
|
'4': escape_input(repository.team.name),
|
2020-07-02 20:35:48 +08:00
|
|
|
'5': {
|
|
|
|
display: I18n.l(repository.created_at, format: :full),
|
|
|
|
sort: repository.created_at.to_i
|
|
|
|
},
|
2020-06-01 16:24:03 +08:00
|
|
|
'6': escape_input(repository.created_by.full_name),
|
2020-07-02 20:35:48 +08:00
|
|
|
'7': {
|
|
|
|
display: (I18n.l(repository.archived_on, format: :full) if repository.archived_on),
|
|
|
|
sort: repository.archived_on&.to_i
|
|
|
|
},
|
2020-06-05 01:07:10 +08:00
|
|
|
'8': escape_input(repository.archived_by&.full_name),
|
2020-06-19 21:54:45 +08:00
|
|
|
'repositoryUrl': repository_path(repository),
|
|
|
|
'DT_RowAttr': {
|
|
|
|
'data-delete-modal-url': team_repository_destroy_modal_path(team, repository_id: repository),
|
|
|
|
'data-copy-modal-url': team_repository_copy_modal_path(team, repository_id: repository),
|
2020-06-24 19:41:00 +08:00
|
|
|
'data-rename-modal-url': team_repository_rename_modal_path(team, repository_id: repository),
|
2023-06-15 21:32:01 +08:00
|
|
|
'data-shared': repository.shared_with?(team),
|
2023-10-20 16:05:42 +08:00
|
|
|
'data-i-shared': repository.i_shared?(team),
|
|
|
|
'data-e2e': "e2e-RT-inventories-tableItemRow-#{repository.id}"
|
2020-06-19 21:54:45 +08:00
|
|
|
}
|
2020-06-01 16:24:03 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
2020-06-24 19:41:00 +08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def shared_label(repository, team)
|
2023-06-15 21:32:01 +08:00
|
|
|
return I18n.t('libraries.index.shared') if repository.i_shared?(team)
|
2020-06-24 19:41:00 +08:00
|
|
|
return I18n.t('libraries.index.not_shared') unless repository.shared_with?(team)
|
|
|
|
|
|
|
|
if repository.shared_with_read?(team)
|
|
|
|
I18n.t('libraries.index.shared_for_viewing')
|
2020-07-08 19:42:27 +08:00
|
|
|
else
|
|
|
|
I18n.t('libraries.index.shared_for_editing')
|
2020-06-24 19:41:00 +08:00
|
|
|
end
|
|
|
|
end
|
2020-06-01 16:24:03 +08:00
|
|
|
end
|