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
costs exports: use inline job status dialogs to not to navigate away to the job status url
as-op45244d5503a2
diff --git a/frontend/src/stimulus/controllers/dynamic/costs/export.controller.ts b/frontend/src/stimulus/controllers/dynamic/costs/export.controller.tsnew file mode 100644index 00000000000..183aa9ffc91--- /dev/null+++ b/frontend/src/stimulus/controllers/dynamic/costs/export.controller.ts@@ -0,0 +1,61 @@+import { Controller } from '@hotwired/stimulus';+import * as Turbo from '@hotwired/turbo';+import { HttpErrorResponse } from '@angular/common/http';++export default class ExportController extends Controller<HTMLLinkElement> {+ static values = {+ jobStatusDialogUrl: String,+ };++ declare jobStatusDialogUrlValue:string;++ jobModalUrl(job_id:string):string {+ return this.jobStatusDialogUrlValue.replace('_job_uuid_', job_id);+ }++ async showJobModal(job_id:string) {+ console.log(this.jobModalUrl(job_id));+ const response = await fetch(this.jobModalUrl(job_id), {+ method: 'GET',+ headers: { Accept: 'text/vnd.turbo-stream.html' },+ });+ if (response.ok) {+ Turbo.renderStreamMessage(await response.text());+ } else {+ throw new Error(response.statusText || 'Invalid response from server');+ }+ }++ async requestExport(exportURL:string):Promise<string> {+ const response = await fetch(exportURL, {+ method: 'GET',+ headers: { Accept: 'application/json' },+ credentials: 'same-origin',+ });+ if (!response.ok) {+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);+ }+ const result = await response.json() as { job_id:string };+ if (!result.job_id) {+ throw new Error('Invalid response from server');+ }+ return result.job_id;+ }++ get href() {+ return (this.element as HTMLLinkElement).href;+ }++ download(evt:CustomEvent) {+ evt.preventDefault(); // Don't follow the href+ this.requestExport(this.href)+ .then((job_id) => this.showJobModal(job_id))+ .catch((error:HttpErrorResponse) => this.handleError(error));+ }++ private handleError(error:HttpErrorResponse) {+ void window.OpenProject.getPluginContext().then((pluginContext) => {+ pluginContext.services.notifications.addError(error);+ });+ }+}diff --git a/modules/reporting/app/components/cost_reports/index_page_header_component.html.erb b/modules/reporting/app/components/cost_reports/index_page_header_component.html.erbindex 040926aa660..92d133f1d00 100644--- a/modules/reporting/app/components/cost_reports/index_page_header_component.html.erb+++ b/modules/reporting/app/components/cost_reports/index_page_header_component.html.erb@@ -5,23 +5,35 @@if show_export_button?header.with_action_button(scheme: :default,- aria: { label: t(:export_to_excel)},+ aria: { label: t(:export_to_excel) },title: t(:export_to_excel),mobile_icon: "op-file-xls-descriptions",mobile_label: t(:export_to_excel),tag: :a,- href: url_for({ controller: "cost_reports" , action: :index, format: 'xls', project_id: @project })+ href: url_for({ controller: "cost_reports", action: :index, format: 'xls', project_id: @project }),+ data: {+ controller: "costs--export",+ "application-target": "dynamic",+ "costs--export-job-status-dialog-url-value": job_status_dialog_path('_job_uuid_'),+ action: "click->costs--export#download"+ }) do |button|button.with_leading_visual_icon(icon: "op-file-xls-descriptions")t(:export_to_excel)endheader.with_action_button(scheme: :default,- aria: { label: t("export.timesheet.button")},+ aria: { label: t("export.timesheet.button") },title: t("export.timesheet.button"),mobile_icon: "op-file-xls-descriptions",mobile_label: t("export.timesheet.button"),tag: :a,- href: url_for({ controller: "cost_reports" , action: :index, format: 'pdf', project_id: @project })+ href: url_for({ controller: "cost_reports", action: :index, format: 'pdf', project_id: @project }),+ data: {+ controller: "costs--export",+ "application-target": "dynamic",+ "costs--export-job-status-dialog-url-value": job_status_dialog_path('_job_uuid_'),+ action: "click->costs--export#download"+ }) do |button|button.with_leading_visual_icon(icon: "op-file-xls-descriptions")t("export.timesheet.button")diff --git a/modules/reporting/app/controllers/cost_reports_controller.rb b/modules/reporting/app/controllers/cost_reports_controller.rbindex 7a06e2404a2..f2a7e8ef729 100644--- a/modules/reporting/app/controllers/cost_reports_controller.rb+++ b/modules/reporting/app/controllers/cost_reports_controller.rb@@ -95,7 +95,11 @@ class CostReportsController < ApplicationController.call(format, filter_params:, project: @project, cost_types: @cost_types).result- redirect_to job_status_path(job_id)+ if request.headers["Accept"]&.include?("application/json")+ render json: { job_id: }+ else+ redirect_to job_status_path(job_id)+ endend##