Allow jobs to define a title for the job status modal

pull/8489/head
Oliver Günther 4 years ago
parent 0261c8ac6e
commit 45fc54b7e0
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 6
      app/workers/copy_project_job.rb
  2. 6
      app/workers/work_packages/exports/export_job.rb
  3. 1
      config/locales/en.yml
  4. 3
      frontend/src/app/modules/job-status/job-status-modal/job-status.modal.html
  5. 4
      frontend/src/app/modules/job-status/job-status-modal/job-status.modal.ts
  6. 1
      frontend/src/app/modules/job-status/job-status.interface.ts
  7. 26
      modules/job_status/app/workers/job_status/application_job_with_status.rb
  8. 3
      spec/features/work_packages/export_spec.rb
  9. 4
      spec/workers/copy_project_job_spec.rb

@ -82,6 +82,12 @@ class CopyProjectJob < ApplicationJob
true true
end end
protected
def title
I18n.t(:label_copy_project)
end
private private
def successful_status_update def successful_status_update

@ -18,6 +18,12 @@ module WorkPackages
true true
end end
protected
def title
I18n.t('export.your_work_packages_export')
end
private private
def export_work_packages(export, mime_type, query, options) def export_work_packages(export, mime_type, query, options)

@ -1160,6 +1160,7 @@ en:
work_package_note: 'Work Package note added' work_package_note: 'Work Package note added'
export: export:
your_work_packages_export: "Your work packages export"
succeeded: "The export has completed successfully." succeeded: "The export has completed successfully."
format: format:
atom: "Atom" atom: "Atom"

@ -2,6 +2,7 @@
<div class="op-modal--modal-container job-status--modal" <div class="op-modal--modal-container job-status--modal"
tabindex="0"> tabindex="0">
<div class="op-modal--modal-header"> <div class="op-modal--modal-header">
<h3 [textContent]="title"></h3>
<a class="op-modal--modal-close-button"> <a class="op-modal--modal-close-button">
<i <i
class="icon-close" class="icon-close"
@ -11,8 +12,6 @@
</a> </a>
</div> </div>
<h3 [textContent]="text.title"></h3>
<div> <div>
<div class="loading-indicator--location" <div class="loading-indicator--location"
data-indicator-name="modal"> data-indicator-name="modal">

@ -50,6 +50,9 @@ export class JobStatusModal extends OpModalComponent implements OnInit {
/** Public message to show */ /** Public message to show */
public message:string; public message:string;
/** Title to show */
public title:string = this.text.title;
/** A link in case the job results in a download */ /** A link in case the job results in a download */
public downloadHref:string|null = null; 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 }); this.I18n.t(`js.job_status.generic_messages.${status}`, { defaultValue: status });
if (body.payload) { if (body.payload) {
this.title = body.payload.title || this.text.title;
this.handleRedirect(body.payload?.redirect); this.handleRedirect(body.payload?.redirect);
this.handleDownload(body.payload?.download); this.handleDownload(body.payload?.download);
} }

@ -20,6 +20,7 @@ export interface JobStatusInterface {
* Additional payload object * Additional payload object
*/ */
payload?:{ payload?:{
title?:string;
download?:string; download?:string;
redirect?:string; redirect?:string;
}; };

@ -72,12 +72,34 @@ module JobStatus
resource.reference = status_reference resource.reference = status_reference
end end
new_attributes = args.reverse_merge(status: status, message: nil, payload: nil) # Update properties with the language of the user
resource.update! new_attributes # 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 end
protected 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 # Crafts a payload for a redirection result
def redirect_payload(path) def redirect_payload(path)

@ -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'), expect(page).to have_content I18n.t('js.job_status.generic_messages.in_queue'),
wait: 10 wait: 10
# Expect title
expect(page).to have_selector 'h3', text: I18n.t('export.your_work_packages_export')
begin begin
perform_enqueued_jobs perform_enqueued_jobs
rescue rescue

@ -181,7 +181,7 @@ describe CopyProjectJob, type: :model do
expect(copy_job.job_status).to be_present expect(copy_job.job_status).to be_present
expect(copy_job.job_status[:status]).to eq 'failure' 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[: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
end end
@ -199,7 +199,7 @@ describe CopyProjectJob, type: :model do
describe 'perform' do describe 'perform' do
before do before do
login_as(user) login_as(user)
expect(User).to receive(:current=).with(user) expect(User).to receive(:current=).with(user).at_least(:once)
end end
describe 'subproject' do describe 'subproject' do

Loading…
Cancel
Save