Merge pull request #8489 from opf/feature/job-status-title

Allow jobs to define a title for the job status modal
pull/8494/head
ulferts 4 years ago committed by GitHub
commit aa04931b11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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
end
protected
def title
I18n.t(:label_copy_project)
end
private
def successful_status_update

@ -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)

@ -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"

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

@ -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);
}

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

@ -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)

@ -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

@ -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

Loading…
Cancel
Save