scinote-web/app/helpers/repositories_datatable_helper.rb

50 lines
1.8 KiB
Ruby
Raw Normal View History

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,
'3': shared_label(repository, team),
2020-06-01 16:24:03 +08:00
'4': escape_input(repository.team.name),
'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),
'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),
'data-rename-modal-url': team_repository_rename_modal_path(team, repository_id: repository),
'data-shared': repository.shared_with?(team)
2020-06-19 21:54:45 +08:00
}
2020-06-01 16:24:03 +08:00
)
end
result
end
private
def shared_label(repository, team)
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')
end
end
2020-06-01 16:24:03 +08:00
end