OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add representation formats to API
Oliver Günthere904a7e59d29
diff --git a/lib/api/decorators/offset_paginated_collection.rb b/lib/api/decorators/offset_paginated_collection.rbindex d4e50692244..b5f58fc7b9c 100644--- a/lib/api/decorators/offset_paginated_collection.rb+++ b/lib/api/decorators/offset_paginated_collection.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)enddef paged_models(models)diff --git a/lib/api/v3/projects/project_collection_representer.rb b/lib/api/v3/projects/project_collection_representer.rbindex b6aa01a1c04..3c90aaac6c2 100644--- a/lib/api/v3/projects/project_collection_representer.rb+++ b/lib/api/v3/projects/project_collection_representer.rb@@ -36,15 +36,41 @@ require 'roar/json/hal'module APImodule V3module Projects- class ProjectCollectionRepresenter < ::API::Decorators::UnpaginatedCollection+ class ProjectCollectionRepresenter < ::API::Decorators::OffsetPaginatedCollectionself.to_eager_load = ::API::V3::Projects::ProjectRepresenter.to_eager_loadself.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'+ endendendenddiff --git a/lib/api/v3/work_packages/work_package_collection_representer.rb b/lib/api/v3/work_packages/work_package_collection_representer.rbindex 5782f347a04..4aa8b0331a0 100644--- a/lib/api/v3/work_packages/work_package_collection_representer.rb+++ b/lib/api/v3/work_packages/work_package_collection_representer.rb@@ -211,6 +211,9 @@ module APIrepresentation_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 APIurl_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_csvrepresentation_format 'csv',mime_type: 'text/csv'diff --git a/modules/xls_export/lib/open_project/xls_export/engine.rb b/modules/xls_export/lib/open_project/xls_export/engine.rbindex d28f0414d43..105795123a7 100644--- a/modules/xls_export/lib/open_project/xls_export/engine.rb+++ b/modules/xls_export/lib/open_project/xls_export/engine.rb@@ -10,12 +10,6 @@ module OpenProject::XlsExportpatches %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 modediff --git a/modules/xls_export/lib/open_project/xls_export/patches/api/v3/export_formats.rb b/modules/xls_export/lib/open_project/xls_export/patches/api/v3/export_formats.rbdeleted file mode 100644index 6bb403aa6b1..00000000000--- a/modules/xls_export/lib/open_project/xls_export/patches/api/v3/export_formats.rb+++ /dev/null@@ -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