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 primer/turbo job status modal dialog
as-op9b31c0311584
diff --git a/app/components/work_packages/exports/modal_dialog_component.html.erb b/app/components/work_packages/exports/modal_dialog_component.html.erbindex a450f961a1b..829c6bb94a6 100644--- a/app/components/work_packages/exports/modal_dialog_component.html.erb+++ b/app/components/work_packages/exports/modal_dialog_component.html.erb@@ -36,6 +36,7 @@"application-target": "dynamic",action: "submit->work-packages--export--form#submitForm",controller: "work-packages--export--form",+ "work-packages--export--form-job-status-dialog-url-value": job_status_dialog_path('_job_uuid_')}) do |form| %><input type="hidden" name="query" value="<%= query_params %>">diff --git a/frontend/src/stimulus/controllers/dynamic/job-status-polling.controller.ts b/frontend/src/stimulus/controllers/dynamic/job-status-polling.controller.tsnew file mode 100644index 00000000000..0899031113e--- /dev/null+++ b/frontend/src/stimulus/controllers/dynamic/job-status-polling.controller.ts@@ -0,0 +1,31 @@+import { Controller } from "@hotwired/stimulus";+import { FrameElement } from '@hotwired/turbo';++export default class JobStatusPollingController extends Controller<FrameElement> {+ static targets = ["finished", "download", "redirect"];++ interval:ReturnType<typeof setInterval>;++ connect() {+ this.interval = setInterval(() => {+ void this.element.reload();+ },+ 2000)+ }++ disconnect() {+ this.finishedTargetConnected();+ }++ finishedTargetConnected() {+ clearInterval(this.interval);+ }++ downloadTargetConnected(element:HTMLLinkElement) {+ setTimeout(() => element.click(), 50);+ }++ redirectTargetConnected(element:HTMLLinkElement) {+ setTimeout(() => { window.location.href = element.href; }, 2000);+ }+}diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/export/form.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/export/form.controller.tsindex 8707577c3f6..5f3e6c4df4c 100644--- a/frontend/src/stimulus/controllers/dynamic/work-packages/export/form.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/export/form.controller.ts@@ -1,21 +1,52 @@import { Controller } from '@hotwired/stimulus';+import * as Turbo from '@hotwired/turbo';export default class FormController extends Controller<HTMLFormElement> {+ 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) {+ 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('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) {+ const result = await response.json() as { job_id:string };+ if (!result.job_id) {+ throw new Error('Invalid response from server');+ }+ return result.job_id;+ }+ throw new Error(response.statusText);+ }+submitForm(evt:CustomEvent) {evt.preventDefault(); // Don't submitconst formatURL = this.element.getAttribute('action');const searchParams = this.getExportParams();const exportURL = `${formatURL}?${searchParams.toString()}`;- fetch(exportURL, {- method: 'GET',- headers: { Accept: 'application/json' },- credentials: 'same-origin',- })- .then((r) => r.json())- .then((result:{ job_id:string }) => {- // TODO: implement with turbo and open job modal- window.location.href = `/job_statuses/${result.job_id}`;- })+ this.requestExport(exportURL)+ .then((job_id) => this.showJobModal(job_id)).catch((error) => {// TODO: error handlingconsole.error(error);diff --git a/modules/job_status/app/components/job_status/dialog/body_component.html.erb b/modules/job_status/app/components/job_status/dialog/body_component.html.erbnew file mode 100644index 00000000000..476fec9ff7e--- /dev/null+++ b/modules/job_status/app/components/job_status/dialog/body_component.html.erb@@ -0,0 +1,42 @@+<%= turbo_frame_tag "job_status_modal" do %>+ <% if pending? %>+ <%= component_wrapper do %>+ <div class="op-loading-indicator"><div></div><div></div></div>+ <% end %>+ <% else %>+ <%= content_tag :div, "", data: { "job-status-polling-target": "finished" } %>+ <% end %>+ <%= render Primer::Beta::Blankslate.new do |component|+ component.with_visual_icon(icon: icon, size: :medium) unless icon.nil?+ component.with_heading(tag: :h2).with_content(title)+ component.with_description { message }+ end %>+ <% if redirect_url? %>+ <%= render(Primer::Beta::Link.new(+ href: redirect_url,+ target: "_blank",+ data: {+ "job-status-polling-target": "redirect"+ }+ )) { I18n.t('js.job_status.redirect_link') } %>+ <% end %>+ <% if download_url? %>+ <%= flex_layout do |flex|+ flex.with_row(text_align: :center) { render(Primer::Beta::Text.new) { I18n.t('js.job_status.download_starts') } }+ flex.with_row(text_align: :center) {+ render(Primer::Beta::Link.new(+ href: download_url,+ target: "_blank",+ data: {+ "job-status-polling-target": "download"+ }+ )) { I18n.t('js.job_status.click_to_download') }+ }+ end %>+ <% end %>+ <% if job_html? %>+ <%= flex_layout do |flex|+ flex.with_row(text_align: :center) { job_html.html_safe }+ end %>+ <% end %>+<% end %>diff --git a/modules/job_status/app/components/job_status/dialog/body_component.rb b/modules/job_status/app/components/job_status/dialog/body_component.rbnew file mode 100644index 00000000000..cf718dbf36b--- /dev/null+++ b/modules/job_status/app/components/job_status/dialog/body_component.rb@@ -0,0 +1,118 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+# ++++module JobStatus+ module Dialog+ class BodyComponent < ApplicationComponent+ include Turbo::FramesHelper+ include OpTurbo::Streamable+ include OpPrimer::ComponentHelpers++ attr_reader :job++ def initialize(job:)+ super++ @job = job+ end++ def pending_statuses+ ::JobStatus::Status.statuses.slice(:in_queue, :in_process).values+ end++ def error_statuses+ ::JobStatus::Status.statuses.slice(:error, :failure, :cancelled).values+ end++ def success_statuses+ ::JobStatus::Status.statuses.slice(:success).values+ end++ def redirect_url?+ return false if job.nil?++ job.payload["redirect"].present?+ end++ def redirect_url+ job.payload["redirect"]+ end++ def download_url?+ return false if job.nil?++ job.payload["download"].present?+ end++ def download_url+ job.payload["download"]+ end++ def job_html?+ return false if job.nil?++ job.payload["html"].present?+ end++ def job_html+ return false if job.nil?++ job.payload["html"].present?+ end++ def pending?+ return false if job.nil?++ pending_statuses.include?(job.status)+ end++ def title+ return I18n.t("js.job_status.generic_messages.not_found") if job.nil?++ return I18n.t("js.job_status.errors") if error_statuses.include?(job.status)++ job.payload["title"] || I18n.t("js.job_status.title")+ end++ def icon+ return :alert if job.nil?+ return :"x-circle" if error_statuses.include?(job.status)++ :"issue-closed" if success_statuses.include?(job.status)+ end++ def message+ return "" if job.nil?++ job.message || I18n.t("js.job_status.generic_messages.#{job.status}")+ end+ end+ end+enddiff --git a/modules/job_status/app/components/job_status/dialog/dialog_component.html.erb b/modules/job_status/app/components/job_status/dialog/dialog_component.html.erbnew file mode 100644index 00000000000..8a6f335fec6--- /dev/null+++ b/modules/job_status/app/components/job_status/dialog/dialog_component.html.erb@@ -0,0 +1,16 @@+<%= render(Primer::Alpha::Dialog.new(+ title: I18n.t('js.job_status.title'),+ visually_hide_title: true,+ id: MODAL_ID+)) do |dialog| %>+ <% dialog.with_body do %>+ <%= turbo_frame_tag("job_status_modal",+ src: job_status_dialog_body_path(job_uuid: job_uuid),+ data: {+ "application-target": "dynamic",+ controller: 'job-status-polling',+ }+ ) do %>+ <% end %>+ <% end %>+<% end %>diff --git a/modules/job_status/app/components/job_status/dialog/dialog_component.rb b/modules/job_status/app/components/job_status/dialog/dialog_component.rbnew file mode 100644index 00000000000..9ab504f5dbc--- /dev/null+++ b/modules/job_status/app/components/job_status/dialog/dialog_component.rb@@ -0,0 +1,49 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+# ++++module JobStatus+ module Dialog+ class DialogComponent < ApplicationComponent+ MODAL_ID = "job-status-modal-dialog"++ include Turbo::FramesHelper+ include OpTurbo::Streamable+ include OpPrimer::ComponentHelpers++ attr_reader :job_uuid++ def initialize(job_uuid:)+ super++ @job_uuid = job_uuid+ end+ end+ end+enddiff --git a/modules/job_status/app/controllers/job_statuses_controller.rb b/modules/job_status/app/controllers/job_statuses_controller.rbindex b2a9b1978dd..c775f8216af 100644--- a/modules/job_status/app/controllers/job_statuses_controller.rb+++ b/modules/job_status/app/controllers/job_statuses_controller.rb@@ -27,9 +27,28 @@#++class JobStatusesController < ApplicationController- no_authorization_required! :show+ include OpTurbo::ComponentStream+ include OpTurbo::DialogStreamHelper++ no_authorization_required! :show, :dialog, :dialog_body+ before_action :validate_job, only: [:dialog_body]def showrender layout: "angular/angular"end++ def dialog+ respond_with_dialog ::JobStatus::Dialog::DialogComponent.new(job_uuid: params[:job_uuid])+ end++ def dialog_body+ render ::JobStatus::Dialog::BodyComponent.new(job: @job), layout: false+ end++ private++ def validate_job+ @job = ::JobStatus::Status+ .find_by(job_id: params[:job_uuid], user_id: current_user.id)+ endenddiff --git a/modules/job_status/config/routes.rb b/modules/job_status/config/routes.rbindex 82a5ae26a72..c15c37d31cb 100644--- a/modules/job_status/config/routes.rb+++ b/modules/job_status/config/routes.rb@@ -1,4 +1,6 @@Rails.application.routes.draw do+ get "/job_statuses/dialog/:job_uuid", to: "job_statuses#dialog", as: "job_status_dialog"+ get "/job_statuses/dialog/:job_uuid/body", to: "job_statuses#dialog_body", as: "job_status_dialog_body"get "/job_statuses/:job_uuid",to: "job_statuses#show",as: "job_status"