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
Show progressBar instead of intermediate loading dialog
Oliver Günther4353abaee7f9
diff --git a/frontend/src/stimulus/controllers/async-dialog.controller.ts b/frontend/src/stimulus/controllers/async-dialog.controller.tsindex 3f65e3b6e65..2d0892701fe 100644--- a/frontend/src/stimulus/controllers/async-dialog.controller.ts+++ b/frontend/src/stimulus/controllers/async-dialog.controller.ts@@ -30,10 +30,9 @@import { ApplicationController } from 'stimulus-use';import { renderStreamMessage } from '@hotwired/turbo';+import { TurboHelpers } from '../../turbo/helpers';export default class AsyncDialogController extends ApplicationController {- private loadingDialog:HTMLDialogElement|null;-connect() {this.element.addEventListener('click', (e) => {e.preventDefault();@@ -42,48 +41,20 @@ export default class AsyncDialogController extends ApplicationController {}triggerTurboStream():void {- let loaded = false;-- setTimeout(() => {- if (!loaded) {- this.addLoading();- }- }, 100);+ TurboHelpers.showProgressBar();- fetch(this.href, {+ void fetch(this.href, {method: this.method,headers: {Accept: 'text/vnd.turbo-stream.html',},}).then((r) => r.text()).then((html) => {- loaded = true;renderStreamMessage(html);})- .finally(() => this.removeLoading());- }-- removeLoading() {- this.loadingDialog?.remove();- }-- addLoading() {- this.removeLoading();- const dialog = document.createElement('dialog');- dialog.classList.add('Overlay', 'Overlay--size-medium', 'Overlay--motion-scaleFade');- dialog.style.height = '150px';- dialog.style.display = 'grid';- dialog.style.placeContent = 'center';- dialog.id = 'loading';- dialog.innerHTML = `- <svg style="box-sizing: content-box; color: var(--color-icon-primary);" width="32" height="32" viewBox="0 0 16 16" fill="none" data-view-component="true" class="anim-rotate">- <circle cx="8" cy="8" r="7" stroke="currentColor" stroke-opacity="0.25" stroke-width="2" vector-effect="non-scaling-stroke" fill="none" />- <path d="M15 8a7.002 7.002 0 00-7-7" stroke="currentColor" stroke-width="2" stroke-linecap="round" vector-effect="non-scaling-stroke" />- </svg>- `;- document.body.appendChild(dialog);- dialog.showModal();- this.loadingDialog = dialog;+ .finally(() => {+ TurboHelpers.hideProgressBar();+ });}get href() {diff --git a/frontend/src/turbo/helpers.ts b/frontend/src/turbo/helpers.tsnew file mode 100644index 00000000000..5922eb37f44--- /dev/null+++ b/frontend/src/turbo/helpers.ts@@ -0,0 +1,11 @@+import * as Turbo from '@hotwired/turbo';++export namespace TurboHelpers {+ export function showProgressBar() {+ Turbo.session.adapter.formSubmissionStarted();+ }++ export function hideProgressBar() {+ Turbo.session.adapter.formSubmissionFinished();+ }+}diff --git a/frontend/src/typings/shims.d.ts b/frontend/src/typings/shims.d.tsindex c3552ccee51..d00919774d9 100644--- a/frontend/src/typings/shims.d.ts+++ b/frontend/src/typings/shims.d.ts@@ -29,8 +29,14 @@ declare module 'dom-autoscroller';declare module 'core-vendor/enjoyhint';declare module '@hotwired/turbo' {+ interface BrowserAdapter {+ formSubmissionStarted:() => void;+ formSubmissionFinished:() => void;+ }+export const session:{drive:boolean;+ adapter:BrowserAdapter;};export const navigator:{diff --git a/lookbook/docs/patterns/05-dialogs.md.erb b/lookbook/docs/patterns/05-dialogs.md.erbindex 12e96903868..7890b6183e2 100644--- a/lookbook/docs/patterns/05-dialogs.md.erb+++ b/lookbook/docs/patterns/05-dialogs.md.erb@@ -24,6 +24,7 @@ end```On the Rails controller you wish to render the dialog, you need to respond to the request with the dialog content.+The async-controller stimulus controller will ensure that a loading progress bar will be shown on the top of the page.```rubyclass TestController < ApplicationControler