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
feat[Op#55967]: Add a custom target to modal component
Kabiru Mwenja8e56d10d509e
diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.tsindex bf937e791d7..468f2de121f 100644--- a/frontend/src/app/app.module.ts+++ b/frontend/src/app/app.module.ts@@ -179,6 +179,7 @@ import {import {LocationPickerModalComponent,} from 'core-app/shared/components/storages/location-picker-modal/location-picker-modal.component';+import { OpCustomModalOverlayComponent } from 'core-app/shared/components/modal/custom-modal-overlay.component';export function initializeServices(injector:Injector) {return () => {@@ -370,6 +371,7 @@ export class OpenProjectModule {registerCustomElement('opce-attachments', OpAttachmentsComponent, { injector });registerCustomElement('opce-storage-login-button', StorageLoginButtonComponent, { injector });registerCustomElement('opce-location-picker-modal', LocationPickerModalComponent, { injector });+ registerCustomElement('opce-custom-modal-overlay', OpCustomModalOverlayComponent, { injector });// TODO: These elements are now registered custom elements, but are actually single-use components. They should be removed when we move these pages to Rails.registerCustomElement('opce-new-project', NewProjectComponent, { injector });diff --git a/frontend/src/app/shared/components/modal/custom-modal-overlay.component.ts b/frontend/src/app/shared/components/modal/custom-modal-overlay.component.tsnew file mode 100644index 00000000000..a919192fced--- /dev/null+++ b/frontend/src/app/shared/components/modal/custom-modal-overlay.component.ts@@ -0,0 +1,51 @@+// -- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2024 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.+//++++import {+ ChangeDetectionStrategy,+ Component,+} from '@angular/core';++import { ModalData } from 'core-app/shared/components/modal/modal.service';+import { OpModalOverlayComponent } from 'core-app/shared/components/modal/modal-overlay.component';+import { PortalOutletTarget } from 'core-app/shared/components/modal/portal-outlet-target.enum';++export const opCustomModalOverlaySelector = 'op-custom-modal-overlay';++@Component({+ selector: opCustomModalOverlaySelector,+ templateUrl: './modal-overlay.component.html',+ changeDetection: ChangeDetectionStrategy.OnPush,+})+export class OpCustomModalOverlayComponent extends OpModalOverlayComponent {+ protected isDefaultTarget(modalData:ModalData | null):boolean {+ if (modalData === null) return true;++ return modalData.target === PortalOutletTarget.Custom;+ }+}diff --git a/frontend/src/app/shared/components/modal/modal-overlay.component.ts b/frontend/src/app/shared/components/modal/modal-overlay.component.tsindex 5fdd4dd9077..d7e1c0c857c 100644--- a/frontend/src/app/shared/components/modal/modal-overlay.component.ts+++ b/frontend/src/app/shared/components/modal/modal-overlay.component.ts@@ -39,11 +39,12 @@ import {ComponentPortal,} from '@angular/cdk/portal';import { combineLatest } from 'rxjs';-import { distinctUntilChanged } from 'rxjs/operators';+import { distinctUntilChanged, filter } from 'rxjs/operators';import { I18nService } from 'core-app/core/i18n/i18n.service';import { OpModalComponent } from 'core-app/shared/components/modal/modal.component';import { ModalData, OpModalService } from 'core-app/shared/components/modal/modal.service';+import { PortalOutletTarget } from 'core-app/shared/components/modal/portal-outlet-target.enum';export const opModalOverlaySelector = 'op-modal-overlay';@@ -84,7 +85,7 @@ export class OpModalOverlayComponent {combineLatest([this.activeModalInstance$,// multiple 'closing' events in a row are squashed- this.activeModalData$.pipe(distinctUntilChanged()),+ this.activeModalData$.pipe(distinctUntilChanged(), filter(this.isDefaultTarget.bind(this))),]).subscribe(([instance, data]) => {if (instance === null && data === null) {@@ -103,6 +104,12 @@ export class OpModalOverlayComponent {});}+ protected isDefaultTarget(modalData:ModalData | null):boolean {+ if (modalData === null) return true;++ return modalData.target === PortalOutletTarget.Default;+ }+public close($event:MouseEvent, includeChildClicks = true):void {if (!includeChildClicks && $event.currentTarget !== $event.target) {return;diff --git a/frontend/src/app/shared/components/modal/modal.module.ts b/frontend/src/app/shared/components/modal/modal.module.tsindex 36012dedd72..ebae80a4730 100644--- a/frontend/src/app/shared/components/modal/modal.module.ts+++ b/frontend/src/app/shared/components/modal/modal.module.ts@@ -7,6 +7,7 @@ import { OpModalWrapperAugmentService } from './modal-wrapper-augment.service';import { OpModalBannerComponent } from 'core-app/shared/components/modal/modal-banner/modal-banner.component';import { OpModalOverlayComponent } from 'core-app/shared/components/modal/modal-overlay.component';import { CommonModule } from '@angular/common';+import { OpCustomModalOverlayComponent } from 'core-app/shared/components/modal/custom-modal-overlay.component';@NgModule({imports: [@@ -18,6 +19,7 @@ import { CommonModule } from '@angular/common';],exports: [OpModalOverlayComponent,+ OpCustomModalOverlayComponent,OpModalBannerComponent,],providers: [@@ -26,6 +28,7 @@ import { CommonModule } from '@angular/common';declarations: [OpModalBannerComponent,OpModalOverlayComponent,+ OpCustomModalOverlayComponent,],})export class OpenprojectModalModule { }diff --git a/frontend/src/app/shared/components/modal/modal.service.ts b/frontend/src/app/shared/components/modal/modal.service.tsindex 436fe194481..c495e3d8a3d 100644--- a/frontend/src/app/shared/components/modal/modal.service.ts+++ b/frontend/src/app/shared/components/modal/modal.service.ts@@ -26,16 +26,17 @@// See COPYRIGHT and LICENSE files for more details.//+++import { ComponentType, PortalInjector } from '@angular/cdk/portal';import {Injectable,InjectionToken,Injector,} from '@angular/core';-import { ComponentType, PortalInjector } from '@angular/cdk/portal';import { BehaviorSubject, Observable } from 'rxjs';import { filter, take } from 'rxjs/operators';import { OpModalComponent } from 'core-app/shared/components/modal/modal.component';+import { PortalOutletTarget } from 'core-app/shared/components/modal/portal-outlet-target.enum';export const OpModalLocalsToken = new InjectionToken<never>('OP_MODAL_LOCALS');@@ -44,6 +45,7 @@ export interface ModalData {injector:Injector;notFullscreen:boolean;mobileTopPosition:boolean;+ target:PortalOutletTarget;}@Injectable({ providedIn: 'root' })@@ -74,6 +76,7 @@ export class OpModalService {* @param locals A map to be injected via token into the component.* @param notFullscreen* @param mobileTopPosition+ * @param target An optional target override for the modal portal outlet*/public show<T extends OpModalComponent>(modal:ComponentType<T>,@@ -81,6 +84,7 @@ export class OpModalService {locals:Record<string, unknown> = {},notFullscreen = false,mobileTopPosition = false,+ target = PortalOutletTarget.Default,):Observable<T> {this.close();@@ -94,6 +98,7 @@ export class OpModalService {injector: this.injectorFor(injector, locals),notFullscreen,mobileTopPosition,+ target,});return this.activeModalInstance$diff --git a/frontend/src/app/shared/components/modal/portal-outlet-target.enum.ts b/frontend/src/app/shared/components/modal/portal-outlet-target.enum.tsnew file mode 100644index 00000000000..35fe06e77d9--- /dev/null+++ b/frontend/src/app/shared/components/modal/portal-outlet-target.enum.ts@@ -0,0 +1,32 @@+// -- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2024 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.+//++++export enum PortalOutletTarget {+ Default = 1, // targets 'op-modal-overlay' in base.html+ Custom, // targets 'op-custom-modal-overlay' (can be anywhere)+}diff --git a/frontend/src/stimulus/controllers/dynamic/storages/project-folder-mode-form.controller.ts b/frontend/src/stimulus/controllers/dynamic/storages/project-folder-mode-form.controller.tsindex 83e00307a4d..588cd136ffa 100644--- a/frontend/src/stimulus/controllers/dynamic/storages/project-folder-mode-form.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/storages/project-folder-mode-form.controller.ts@@ -44,6 +44,7 @@ import {import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';import { IStorage } from 'core-app/core/state/storages/storage.model';import { OpModalService } from 'core-app/shared/components/modal/modal.service';+import { PortalOutletTarget } from 'core-app/shared/components/modal/portal-outlet-target.enum';import {LocationPickerModalComponent,} from 'core-app/shared/components/storages/location-picker-modal/location-picker-modal.component';@@ -108,7 +109,7 @@ export default class ProjectFolderModeForm extends Controller {this.modalService.pipe(- switchMap((service) => service.show(LocationPickerModalComponent, 'global', locals)),+ switchMap((service) => service.show(LocationPickerModalComponent, 'global', locals, false, false, PortalOutletTarget.Custom)),switchMap((modal) => modal.closingEvent),filter((modal) => modal.submitted),)diff --git a/modules/storages/app/components/storages/admin/storages/add_projects_form_modal_component.html.erb b/modules/storages/app/components/storages/admin/storages/add_projects_form_modal_component.html.erbindex 2ef1aa7fbea..7acc10220a3 100644--- a/modules/storages/app/components/storages/admin/storages/add_projects_form_modal_component.html.erb+++ b/modules/storages/app/components/storages/admin/storages/add_projects_form_modal_component.html.erb@@ -42,6 +42,10 @@ See COPYRIGHT and LICENSE files for more details.aria: { label: title })) doflex_layout do |flex|+ flex.with_row do+ angular_component_tag 'opce-custom-modal-overlay'+ end+flex.with_row(mb: 3) dorender(Storages::Admin::Storages::AddProjectsAutocompleterForm.new(form, project_storage:))enddiff --git a/modules/storages/app/components/storages/admin/storages/add_projects_form_modal_component.rb b/modules/storages/app/components/storages/admin/storages/add_projects_form_modal_component.rbindex c8ab831a2c6..9093db2cd38 100644--- a/modules/storages/app/components/storages/admin/storages/add_projects_form_modal_component.rb+++ b/modules/storages/app/components/storages/admin/storages/add_projects_form_modal_component.rb@@ -33,6 +33,7 @@ module Storagesinclude OpPrimer::ComponentHelpersinclude OpTurbo::Streamableinclude StimulusHelper+ include AngularHelperdef initialize(project_storage:, **)@project_storage = project_storage