From 45fc54b7e0806d5dfa75799d1e218be1823f3e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 6 Jul 2020 09:50:38 +0200 Subject: [PATCH] Allow jobs to define a title for the job status modal --- app/workers/copy_project_job.rb | 6 +++++ .../work_packages/exports/export_job.rb | 6 +++++ config/locales/en.yml | 1 + .../job-status-modal/job-status.modal.html | 3 +-- .../job-status-modal/job-status.modal.ts | 4 +++ .../job-status/job-status.interface.ts | 1 + .../job_status/application_job_with_status.rb | 26 +++++++++++++++++-- spec/features/work_packages/export_spec.rb | 3 +++ spec/workers/copy_project_job_spec.rb | 4 +-- 9 files changed, 48 insertions(+), 6 deletions(-) diff --git a/app/workers/copy_project_job.rb b/app/workers/copy_project_job.rb index 64a88a5cfc..f32340bbb7 100644 --- a/app/workers/copy_project_job.rb +++ b/app/workers/copy_project_job.rb @@ -82,6 +82,12 @@ class CopyProjectJob < ApplicationJob true end + protected + + def title + I18n.t(:label_copy_project) + end + private def successful_status_update diff --git a/app/workers/work_packages/exports/export_job.rb b/app/workers/work_packages/exports/export_job.rb index 77b364eb28..0442293291 100644 --- a/app/workers/work_packages/exports/export_job.rb +++ b/app/workers/work_packages/exports/export_job.rb @@ -18,6 +18,12 @@ module WorkPackages true end + protected + + def title + I18n.t('export.your_work_packages_export') + end + private def export_work_packages(export, mime_type, query, options) diff --git a/config/locales/en.yml b/config/locales/en.yml index ff95690ece..4fd53e34d9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1160,6 +1160,7 @@ en: work_package_note: 'Work Package note added' export: + your_work_packages_export: "Your work packages export" succeeded: "The export has completed successfully." format: atom: "Atom" diff --git a/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.html b/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.html index 65bc176a8b..6de66e1c26 100644 --- a/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.html +++ b/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.html @@ -2,6 +2,7 @@
+

-

-
diff --git a/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.ts b/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.ts index c3644cdd6c..0855de1d9a 100644 --- a/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.ts +++ b/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.ts @@ -50,6 +50,9 @@ export class JobStatusModal extends OpModalComponent implements OnInit { /** Public message to show */ public message:string; + /** Title to show */ + public title:string = this.text.title; + /** A link in case the job results in a download */ public downloadHref:string|null = null; @@ -123,6 +126,7 @@ export class JobStatusModal extends OpModalComponent implements OnInit { this.I18n.t(`js.job_status.generic_messages.${status}`, { defaultValue: status }); if (body.payload) { + this.title = body.payload.title || this.text.title; this.handleRedirect(body.payload?.redirect); this.handleDownload(body.payload?.download); } diff --git a/frontend/src/app/modules/job-status/job-status.interface.ts b/frontend/src/app/modules/job-status/job-status.interface.ts index 3b39dca9fb..369e3274dd 100644 --- a/frontend/src/app/modules/job-status/job-status.interface.ts +++ b/frontend/src/app/modules/job-status/job-status.interface.ts @@ -20,6 +20,7 @@ export interface JobStatusInterface { * Additional payload object */ payload?:{ + title?:string; download?:string; redirect?:string; }; diff --git a/modules/job_status/app/workers/job_status/application_job_with_status.rb b/modules/job_status/app/workers/job_status/application_job_with_status.rb index b2262c39d1..4bce5fe849 100644 --- a/modules/job_status/app/workers/job_status/application_job_with_status.rb +++ b/modules/job_status/app/workers/job_status/application_job_with_status.rb @@ -72,12 +72,34 @@ module JobStatus resource.reference = status_reference end - new_attributes = args.reverse_merge(status: status, message: nil, payload: nil) - resource.update! new_attributes + # Update properties with the language of the user + # to ensure things like the title are correct + User.execute_as(resource.user) do + resource.attributes = build_status_attributes(args.merge(status: status)) + end + + resource.save! end protected + ## + # Builds the attributes for updating the status + def build_status_attributes(attributes) + if title + attributes[:payload] ||= {} + attributes[:payload][:title] = title + end + + attributes.reverse_merge(message: nil, payload: nil) + end + + ## + # Title of the job status, optional + def title + nil + end + ## # Crafts a payload for a redirection result def redirect_payload(path) diff --git a/spec/features/work_packages/export_spec.rb b/spec/features/work_packages/export_spec.rb index a3d2e3be7e..c9068c871d 100644 --- a/spec/features/work_packages/export_spec.rb +++ b/spec/features/work_packages/export_spec.rb @@ -73,6 +73,9 @@ describe 'work package export', type: :feature do expect(page).to have_content I18n.t('js.job_status.generic_messages.in_queue'), wait: 10 + # Expect title + expect(page).to have_selector 'h3', text: I18n.t('export.your_work_packages_export') + begin perform_enqueued_jobs rescue diff --git a/spec/workers/copy_project_job_spec.rb b/spec/workers/copy_project_job_spec.rb index 22360be590..0319708904 100644 --- a/spec/workers/copy_project_job_spec.rb +++ b/spec/workers/copy_project_job_spec.rb @@ -181,7 +181,7 @@ describe CopyProjectJob, type: :model do expect(copy_job.job_status).to be_present expect(copy_job.job_status[:status]).to eq 'failure' expect(copy_job.job_status[:message]).to include "Cannot copy project #{source_project.name}" - expect(copy_job.job_status[:payload]).to be_nil + expect(copy_job.job_status[:payload]).to eq('title' => 'Copy project') end end @@ -199,7 +199,7 @@ describe CopyProjectJob, type: :model do describe 'perform' do before do login_as(user) - expect(User).to receive(:current=).with(user) + expect(User).to receive(:current=).with(user).at_least(:once) end describe 'subproject' do