Add representation formats to API

pull/9782/head
Oliver Günther 3 years ago
parent eb0feb52d2
commit e904a7e59d
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 8
      lib/api/decorators/offset_paginated_collection.rb
  2. 30
      lib/api/v3/projects/project_collection_representer.rb
  3. 24
      lib/api/v3/work_packages/work_package_collection_representer.rb
  4. 6
      modules/xls_export/lib/open_project/xls_export/engine.rb
  5. 32
      modules/xls_export/lib/open_project/xls_export/patches/api/v3/export_formats.rb

@ -93,8 +93,12 @@ module API
"#{@self_link_base}?#{href_query(page, page_size)}"
end
def href_query(page, page_size)
@query.merge(offset: page, pageSize: page_size).to_query
def href_query(page = @page, page_size = @per_page)
query_params(page, page_size).to_query
end
def query_params(page = @page, page_size = @per_page)
@query.merge(offset: page, pageSize: page_size)
end
def paged_models(models)

@ -36,15 +36,41 @@ require 'roar/json/hal'
module API
module V3
module Projects
class ProjectCollectionRepresenter < ::API::Decorators::UnpaginatedCollection
class ProjectCollectionRepresenter < ::API::Decorators::OffsetPaginatedCollection
self.to_eager_load = ::API::V3::Projects::ProjectRepresenter.to_eager_load
self.checked_permissions = ::API::V3::Projects::ProjectRepresenter.checked_permissions
def initialize(models, self_link:, current_user:)
def initialize(models, **options)
super
@represented = ::API::V3::Projects::ProjectEagerLoadingWrapper.wrap(represented)
end
links :representations do
[
representation_format_csv,
representation_format_xls
]
end
def representation_format(format, mime_type:)
{
href: url_for(controller: :projects, action: :index, format: format, **query_params),
identifier: format,
type: mime_type,
title: I18n.t("export.format.#{format}")
}
end
def representation_format_xls
representation_format 'xls',
mime_type: 'application/vnd.ms-excel'
end
def representation_format_csv
representation_format 'csv',
mime_type: 'text/csv'
end
end
end
end

@ -211,6 +211,9 @@ module API
representation_format_pdf_attachments,
representation_format_pdf_description,
representation_format_pdf_description_attachments,
representation_format_xls,
representation_format_xls_descriptions,
representation_format_xls_relations,
representation_format_csv
]
@ -266,6 +269,27 @@ module API
url_query_extras: 'show_descriptions=true&show_attachments=true'
end
def representation_format_xls
representation_format 'xls',
mime_type: 'application/vnd.ms-excel'
end
def representation_format_xls_descriptions
representation_format 'xls-with-descriptions',
i18n_key: 'xls_with_descriptions',
mime_type: 'application/vnd.ms-excel',
format: 'xls',
url_query_extras: 'show_descriptions=true'
end
def representation_format_xls_relations
representation_format 'xls-with-relations',
i18n_key: 'xls_with_relations',
mime_type: 'application/vnd.ms-excel',
format: 'xls',
url_query_extras: 'show_relations=true'
end
def representation_format_csv
representation_format 'csv',
mime_type: 'text/csv'

@ -10,12 +10,6 @@ module OpenProject::XlsExport
patches %i[CostReportsController]
extend_api_response(:v3, :work_packages, :work_package_collection) do
require_relative 'patches/api/v3/export_formats'
prepend Patches::API::V3::ExportFormats
end
initializer 'xls_export.register_hooks' do
# don't use require_dependency to not reload hooks in development mode

@ -1,32 +0,0 @@
module OpenProject::XlsExport::Patches
module API::V3::ExportFormats
def representation_formats
super + [
representation_format_xls,
representation_format_xls_descriptions,
representation_format_xls_relations
]
end
def representation_format_xls
representation_format 'xls',
mime_type: 'application/vnd.ms-excel'
end
def representation_format_xls_descriptions
representation_format 'xls-with-descriptions',
i18n_key: 'xls_with_descriptions',
mime_type: 'application/vnd.ms-excel',
format: 'xls',
url_query_extras: 'show_descriptions=true'
end
def representation_format_xls_relations
representation_format 'xls-with-relations',
i18n_key: 'xls_with_relations',
mime_type: 'application/vnd.ms-excel',
format: 'xls',
url_query_extras: 'show_relations=true'
end
end
end
Loading…
Cancel
Save