Skip to content

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

Modals open again

Benjamin Bädorf1a8333460973
diff --git a/app/views/layouts/angular/angular.html.erb b/app/views/layouts/angular/angular.html.erb
index ece77f89259..d665f72b8b0 100644
--- a/app/views/layouts/angular/angular.html.erb
+++ b/app/views/layouts/angular/angular.html.erb
@@ -43,3 +43,6 @@ See COPYRIGHT and LICENSE files for more details.
<% end -%>
<%= render template: 'layouts/base', locals: local_assigns.merge({ no_action_menu: true }) %>
+
+<%# Modals will be rendered into this global overlay %>
+<op-modal-overlay></op-modal-overlay>
diff --git a/frontend/src/app/core/routing/openproject-router.module.ts b/frontend/src/app/core/routing/openproject-router.module.ts
index d77b6bdd159..d77829f27f6 100644
--- a/frontend/src/app/core/routing/openproject-router.module.ts
+++ b/frontend/src/app/core/routing/openproject-router.module.ts
@@ -29,6 +29,7 @@
import { Injector, NgModule } from '@angular/core';
import { FirstRouteService } from 'core-app/core/routing/first-route-service';
import { UIRouterModule } from '@uirouter/angular';
+import { OpenprojectModalModule } from 'core-app/shared/components/modal/modal.module';
import { ApplicationBaseComponent } from 'core-app/core/routing/base/application-base.component';
import {
initializeUiRouterListeners,
@@ -43,6 +44,9 @@ import {
useHash: false,
config: uiRouterConfiguration,
} as any),
+
+ // Modals
+ OpenprojectModalModule,
],
providers: [
FirstRouteService,
diff --git a/frontend/src/app/core/setup/global-dynamic-components.const.ts b/frontend/src/app/core/setup/global-dynamic-components.const.ts
index 3c02c6cc893..93893c28527 100644
--- a/frontend/src/app/core/setup/global-dynamic-components.const.ts
+++ b/frontend/src/app/core/setup/global-dynamic-components.const.ts
@@ -199,6 +199,7 @@ import {
CalendarSidemenuComponent,
opCalendarSidemenuSelector,
} from 'core-app/features/calendar/sidemenu/calendar-sidemenu.component';
+import { OpModalOverlayComponent, opModalOverlaySelector } from 'core-app/shared/components/modal/modal-overlay.component';
export const globalDynamicComponents:OptionalBootstrapDefinition[] = [
{ selector: appBaseSelector, cls: ApplicationBaseComponent },
@@ -254,4 +255,5 @@ export const globalDynamicComponents:OptionalBootstrapDefinition[] = [
{ selector: backupSelector, cls: BackupComponent },
{ selector: opInAppNotificationBellSelector, cls: InAppNotificationBellComponent },
{ selector: ianMenuSelector, cls: IanMenuComponent },
+ { selector: opModalOverlaySelector, cls: OpModalOverlayComponent },
];
diff --git a/frontend/src/app/core/setup/globals/global-listeners/preview-trigger.service.ts b/frontend/src/app/core/setup/globals/global-listeners/preview-trigger.service.ts
index 735c73006c5..afb33b1523a 100644
--- a/frontend/src/app/core/setup/globals/global-listeners/preview-trigger.service.ts
+++ b/frontend/src/app/core/setup/globals/global-listeners/preview-trigger.service.ts
@@ -32,8 +32,6 @@ import { WpPreviewModalComponent } from 'core-app/shared/components/modals/previ
@Injectable({ providedIn: 'root' })
export class PreviewTriggerService {
- private previewModal:WpPreviewModalComponent;
-
private modalElement:HTMLElement;
private mouseInModal = false;
@@ -54,14 +52,15 @@ export class PreviewTriggerService {
return;
}
- this.previewModal = this.opModalService.show(
+ this.opModalService.show(
WpPreviewModalComponent,
this.injector,
{ workPackageLink: href, event: e },
true,
- );
- this.modalElement = this.previewModal.elementRef.nativeElement;
- this.previewModal.reposition(jQuery(this.modalElement), el);
+ ).subscribe((previewModal) => {
+ this.modalElement = previewModal.elementRef.nativeElement;
+ previewModal.reposition(jQuery(this.modalElement), el);
+ });
});
jQuery(document.body).on('mouseleave', '.preview-trigger', () => {
diff --git a/frontend/src/app/core/setup/globals/global-listeners/request-for-confirmation.ts b/frontend/src/app/core/setup/globals/global-listeners/request-for-confirmation.ts
index e830fa46b96..58fb9f9d7f0 100644
--- a/frontend/src/app/core/setup/globals/global-listeners/request-for-confirmation.ts
+++ b/frontend/src/app/core/setup/globals/global-listeners/request-for-confirmation.ts
@@ -42,20 +42,22 @@ function registerListener(
}
$event.preventDefault();
- const modalComponent = opModalService.show(modal, 'global');
- modalComponent.closingEvent.subscribe((confirmModal:any) => {
- if (confirmModal.confirmed) {
+ opModalService.show(modal, 'global')
+ .subscribe((modal) => modal.closingEvent.subscribe(() => {
+ if (!modal.confirmed) {
+ return;
+ }
+
jQuery('<input>')
.attr({
type: 'hidden',
name: '_password_confirmation',
- value: confirmModal.password_confirmation,
+ value: modal.password_confirmation,
})
.appendTo(form);
form.trigger('submit');
- }
- });
+ }));
return false;
}
diff --git a/frontend/src/app/features/invite-user-modal/invite-user-modal-augment.service.ts b/frontend/src/app/features/invite-user-modal/invite-user-modal-augment.service.ts
index 986edd490e4..452b675f1bd 100644
--- a/frontend/src/app/features/invite-user-modal/invite-user-modal-augment.service.ts
+++ b/frontend/src/app/features/invite-user-modal/invite-user-modal-augment.service.ts
@@ -61,19 +61,17 @@ export class OpInviteUserModalAugmentService {
private spawnModal(event:ClickEvent) {
event.preventDefault();
- const modal = this.opModalService.show(
+ this.opModalService.show(
InviteUserModalComponent,
'global',
{ projectId: this.currentProjectService.id },
- );
-
- modal
+ ).subscribe((modal) => modal
.closingEvent
.subscribe((modal:InviteUserModalComponent) => {
// Just reload the page for now if we saved anything
if (modal.data) {
window.location.reload();
}
- });
+ }));
}
}
diff --git a/frontend/src/app/features/invite-user-modal/invite-user-modal.service.ts b/frontend/src/app/features/invite-user-modal/invite-user-modal.service.ts
index d454838610a..f3c4d73fe5e 100644
--- a/frontend/src/app/features/invite-user-modal/invite-user-modal.service.ts
+++ b/frontend/src/app/features/invite-user-modal/invite-user-modal.service.ts
@@ -47,16 +47,14 @@ export class OpInviteUserModalService {
}
public open(projectId:string|null = this.currentProjectService.id) {
- const modal = this.opModalService.show(
+ this.opModalService.show(
InviteUserModalComponent,
'global',
{ projectId },
- );
-
- modal
+ ).subscribe((modal) => modal
.closingEvent
.subscribe((modal:InviteUserModalComponent) => {
this.close.emit(modal.data);
- });
+ }));
}
}
diff --git a/frontend/src/app/features/job-status/display-job-page/display-job-page.component.ts b/frontend/src/app/features/job-status/display-job-page/display-job-page.component.ts
index e685d23eb4c..795838f5410 100644
--- a/frontend/src/app/features/job-status/display-job-page/display-job-page.component.ts
+++ b/frontend/src/app/features/job-status/display-job-page/display-job-page.component.ts
@@ -3,7 +3,6 @@ import {
} from '@angular/core';
import { StateService } from '@uirouter/core';
import { OpModalService } from 'core-app/shared/components/modal/modal.service';
-import { OpModalComponent } from 'core-app/shared/components/modal/modal.component';
import { JobStatusModalComponent } from 'core-app/features/job-status/job-status-modal/job-status.modal';
import { take } from 'rxjs/operators';
@@ -11,25 +10,23 @@ import { take } from 'rxjs/operators';
template: '',
})
export class DisplayJobPageComponent implements AfterViewInit, OnDestroy {
- private modal?:OpModalComponent;
-
constructor(private $state:StateService,
private modalService:OpModalService) {
}
ngAfterViewInit() {
- this.modal = this.modalService.show(JobStatusModalComponent, 'global', { jobId: this.$state.params.jobId });
- this.modal
- .closingEvent
- .pipe(
- take(1),
- ).subscribe(() => {
- // Go back in history
- window.history.back();
- });
+ this.modalService.show(JobStatusModalComponent, 'global', { jobId: this.$state.params.jobId })
+ .subscribe((modal) => modal
+ .closingEvent
+ .pipe(
+ take(1),
+ ).subscribe(() => {
+ // Go back in history
+ window.history.back();
+ }));
}
ngOnDestroy() {
- this.modal?.closeMe();
+ this.modalService.close();
}
}
diff --git a/frontend/src/app/features/work-packages/components/wp-table/embedded/wp-embedded-table.component.ts b/frontend/src/app/features/work-packages/components/wp-table/embedded/wp-embedded-table.component.ts
index 7cca4bc3e72..206cb792b94 100644
--- a/frontend/src/app/features/work-packages/components/wp-table/embedded/wp-embedded-table.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-table/embedded/wp-embedded-table.component.ts
@@ -92,11 +92,10 @@ export class WorkPackageEmbeddedTableComponent extends WorkPackageEmbeddedBaseCo
this.querySpace.query
.valuesPromise()
.then(() => {
- const modal = this.opModalService
- .show(WpTableConfigurationModalComponent, this.injector);
-
- // Detach this component when the modal closes and pass along the query data
- modal.onDataUpdated.subscribe(onUpdated);
+ this.opModalService
+ .show(WpTableConfigurationModalComponent, this.injector)
+ // Detach this component when the modal closes and pass along the query data
+ .subscribe((modal) => modal.onDataUpdated.subscribe(onUpdated));
});
}
diff --git a/frontend/src/app/features/work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.ts b/frontend/src/app/features/work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.ts
index c13882a4212..90e51747cb6 100644
--- a/frontend/src/app/features/work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.ts
+++ b/frontend/src/app/features/work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.ts
@@ -257,10 +257,7 @@ export class PartitionedQuerySpacePageComponent extends WorkPackagesViewBase imp
protected inviteModal = InviteUserModalComponent;
openInviteUserModal():void {
- const inviteModal = this.opModalService.show(this.inviteModal, 'global');
- inviteModal.closingEvent.subscribe((modal:any) => {
- console.log('Modal closed!', modal);
- });
+ this.opModalService.show(this.inviteModal, 'global');
}
protected loadQuery(firstPage = false):Promise<QueryResource> {
diff --git a/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.ts
index 1b02baeea93..33e2fa41e20 100644
--- a/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.ts
+++ b/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.ts
@@ -49,8 +49,8 @@ export class CombinedDateEditFieldComponent extends DatePickerEditFieldComponent
super.showDatePickerModal();
this
- .modal
- .onDataUpdated
+ .modal?.
+ onDataUpdated
.subscribe((dates:string) => {
this.dates = dates;
this.cdRef.detectChanges();
diff --git a/frontend/src/app/shared/components/fields/edit/field-types/date-picker-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/date-picker-edit-field.component.ts
index 28a2d840af9..7085879402b 100644
--- a/frontend/src/app/shared/components/fields/edit/field-types/date-picker-edit-field.component.ts
+++ b/frontend/src/app/shared/components/fields/edit/field-types/date-picker-edit-field.component.ts
@@ -49,7 +49,7 @@ export abstract class DatePickerEditFieldComponent extends EditFieldComponent im
@InjectField() deviceService:DeviceService;
- protected modal:SingleDateModalComponent|MultiDateModalComponent;
+ protected modal:SingleDateModalComponent|MultiDateModalComponent|null = null;
ngOnInit():void {
super.ngOnInit();
@@ -71,28 +71,30 @@ export abstract class DatePickerEditFieldComponent extends EditFieldComponent im
public showDatePickerModal():void {
const component = this.change.schema.isMilestone ? SingleDateModalComponent : MultiDateModalComponent;
- this.modal = this
+ this
.opModalService
.show<SingleDateModalComponent|MultiDateModalComponent>(
component,
this.injector,
{ changeset: this.change, fieldName: this.name },
!this.deviceService.isMobile,
- );
-
- const { modal } = this;
+ )
+ .subscribe((modal) => {
+ this.modal = modal;
- setTimeout(() => {
- const modalElement = jQuery(modal.elementRef.nativeElement).find('.op-datepicker-modal');
- const field = jQuery(this.elementRef.nativeElement);
- modal.reposition(modalElement, field);
- });
+ setTimeout(() => {
+ const modalElement = jQuery(modal.elementRef.nativeElement).find('.op-datepicker-modal');
+ const field = jQuery(this.elementRef.nativeElement);
+ modal.reposition(modalElement, field);
+ });
- (modal as OpModalComponent)
- .closingEvent
- .pipe(take(1))
- .subscribe(() => {
- this.onModalClosed();
+ (modal as OpModalComponent)
+ .closingEvent
+ .pipe(take(1))
+ .subscribe(() => {
+ this.modal = null;
+ this.onModalClosed();
+ });
});
}
diff --git a/frontend/src/app/shared/components/grids/grid/add-widget.service.ts b/frontend/src/app/shared/components/grids/grid/add-widget.service.ts
index b6d84713deb..f7545b2af69 100644
--- a/frontend/src/app/shared/components/grids/grid/add-widget.service.ts
+++ b/frontend/src/app/shared/components/grids/grid/add-widget.service.ts
@@ -58,31 +58,31 @@ export class GridAddWidgetService {
private select(area:GridArea) {
return new Promise<GridWidgetResource>((resolve, reject) => {
- const modal = this.opModalService.show(AddGridWidgetModalComponent, this.injector, { schema: this.layout.schema });
- modal.closingEvent.subscribe((modal:AddGridWidgetModalComponent) => {
- const registered = modal.chosenWidget;
-
- if (!registered) {
- reject();
- return;
- }
-
- const source = {
- _type: 'GridWidget',
- identifier: registered.identifier,
- startRow: area.startRow,
- endRow: area.endRow,
- startColumn: area.startColumn,
- endColumn: area.endColumn,
- options: registered.properties || {},
- };
-
- const resource:GridWidgetResource = this.halResource.createHalResource(source);
-
- resource.grid = this.layout.gridResource;
-
- resolve(resource);
- });
+ this.opModalService.show(AddGridWidgetModalComponent, this.injector, { schema: this.layout.schema })
+ .subscribe((modal) => modal.closingEvent.subscribe(() => {
+ const registered = modal.chosenWidget;
+
+ if (!registered) {
+ reject();
+ return;
+ }
+
+ const source = {
+ _type: 'GridWidget',
+ identifier: registered.identifier,
+ startRow: area.startRow,
+ endRow: area.endRow,
+ startColumn: area.startColumn,
+ endColumn: area.endColumn,
+ options: registered.properties || {},
+ };
+
+ const resource:GridWidgetResource = this.halResource.createHalResource(source);
+
+ resource.grid = this.layout.gridResource;
+
+ resolve(resource);
+ }));
});
}
diff --git a/frontend/src/app/shared/components/grids/widgets/menu/wp-set-menu.component.ts b/frontend/src/app/shared/components/grids/widgets/menu/wp-set-menu.component.ts
index a958042e554..d5b92d0893b 100644
--- a/frontend/src/app/shared/components/grids/widgets/menu/wp-set-menu.component.ts
+++ b/frontend/src/app/shared/components/grids/widgets/menu/wp-set-menu.component.ts
@@ -65,9 +65,9 @@ export abstract class WidgetWpSetMenuComponent extends WidgetAbstractMenuCompone
linkText: this.i18n.t('js.toolbar.settings.configure_view'),
onClick: () => {
this.opModalService.show(this.configurationComponent, this.injector, this.locals)
- .closingEvent.subscribe((modal:WpGraphConfigurationModalComponent) => {
- this.onConfigured.emit(modal.configuration);
- });
+ .subscribe((modal) => modal.closingEvent.subscribe((modal:WpGraphConfigurationModalComponent) => {
+ this.onConfigured.emit(modal.configuration);
+ }));
return true;
},
};
diff --git a/frontend/src/app/shared/components/grids/widgets/time-entries/current-user/time-entries-current-user-menu.component.ts b/frontend/src/app/shared/components/grids/widgets/time-entries/current-user/time-entries-current-user-menu.component.ts
index 8534cae1192..7618f4a4b32 100644
--- a/frontend/src/app/shared/components/grids/widgets/time-entries/current-user/time-entries-current-user-menu.component.ts
+++ b/frontend/src/app/shared/components/grids/widgets/time-entries/current-user/time-entries-current-user-menu.component.ts
@@ -64,11 +64,15 @@ export class WidgetTimeEntriesCurrentUserMenuComponent extends WidgetAbstractMen
linkText: this.i18n.t('js.grid.configure'),
onClick: () => {
this.opModalService.show(TimeEntriesCurrentUserConfigurationModalComponent, this.injector, this.locals)
- .closingEvent.subscribe((modal:TimeEntriesCurrentUserConfigurationModalComponent) => {
- if (modal.options) {
- this.onConfigured.emit(modal.options);
- }
- });
+ .subscribe(
+ (modal) => modal.closingEvent.subscribe(
+ (modal:TimeEntriesCurrentUserConfigurationModalComponent) => {
+ if (modal.options) {
+ this.onConfigured.emit(modal.options);
+ }
+ },
+ )
+ );
return true;
},
};
diff --git a/frontend/src/app/shared/components/modal/modal-overlay.component.html b/frontend/src/app/shared/components/modal/modal-overlay.component.html
index 224a0a759c6..6ec96c73b0e 100644
--- a/frontend/src/app/shared/components/modal/modal-overlay.component.html
+++ b/frontend/src/app/shared/components/modal/modal-overlay.component.html
@@ -1,7 +1,7 @@
<div
class="spot-modal-overlay"
[ngClass]="{
- 'spot-modal-overlay_active': isActive,
+ 'spot-modal-overlay_active': (activePortal$ | async) !== null,
'spot-modal-overlay_not-full-screen': notFullscreen
}"
tabindex="0"
@@ -17,5 +17,5 @@
>
<span class="spot-icon spot-icon_close"></span>
</button>
- <ng-template [ckdPortalOutlet]="modalPortal$" #portalOutlet></ng-template>
+ <ng-template [cdkPortalOutlet]="activePortal$ | async" #portalOutlet></ng-template>
</div>
diff --git a/frontend/src/app/shared/components/modal/modal-overlay.component.ts b/frontend/src/app/shared/components/modal/modal-overlay.component.ts
index a4bf5f3f940..b88772afbfd 100644
--- a/frontend/src/app/shared/components/modal/modal-overlay.component.ts
+++ b/frontend/src/app/shared/components/modal/modal-overlay.component.ts
@@ -28,70 +28,89 @@
import {
ChangeDetectionStrategy,
- ChangeDetectorRef, Component, ElementRef, OnInit, ViewChild,
+ Component,
+ ComponentRef,
+ OnInit,
+ ViewChild,
} from '@angular/core';
import {
+ CdkPortalOutlet,
ComponentPortal,
- ComponentType,
- PortalInjector,
} from '@angular/cdk/portal';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { OpModalService } from 'core-app/shared/components/modal/modal.service';
+import { OpModalComponent } from './modal.component';
+import { ReplaySubject } from 'rxjs';
+
+export const opModalOverlaySelector = 'op-modal-overlay';
@Component({
+ selector: opModalOverlaySelector,
templateUrl: './modal-overlay.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class OpModalOverlayComponent implements OnInit {
- // override superclass
- // Allowing outside clicks to close the modal leads to the user involuntarily closing
- // the modal when removing error messages or clicking on labels e.g. in the registration modal.
- public closeOnOutsideClick = false;
+ public notFullscreen = false;
- @ViewChild('portalOutlet') portalOutlet: ElementRef<HTMLElement>;
+ @ViewChild('portalOutlet') portalOutlet: CdkPortalOutlet;
- modalPortal$ = this.modalService.activeModal$;
+ activeModalData$ = this.modalService.activeModalData$;
+ activePortal$ = new ReplaySubject();
+ activeModalInstance$ = this.modalService.activeModalInstance$;
constructor(
readonly modalService:OpModalService,
- readonly elementRef:ElementRef,
- readonly cdRef:ChangeDetectorRef,
readonly I18n:I18nService,
) { }
ngOnInit():void {
- // onclose:
// this.active.closingEvent.emit(this.active);
// onopen:
// this.active.onOpen();
+ //
+ console.log('modal overlay active');
- const portal = new ComponentPortal(modal, null, this.injectorFor(injector, locals));
+ this.activeModalData$
+ .subscribe((modalData) => {
+ this.notFullscreen = false;
- setTimeout(() => {
- // Focus on the first element
- this.active && this.active.onOpen();
+ if (modalData === null) {
+ const ref = (this.portalOutlet.attachedRef as ComponentRef<OpModalComponent>);
+ if (!ref) {
+ return;
+ }
+ ref.instance.closingEvent.emit(ref.instance);
+ this.portalOutlet.detach();
+ this.activeModalInstance$.next(null);
+ return;
+ }
- // Mark that we've opened the modal now
- this.opening = false;
+ const {
+ modal,
+ injector,
+ notFullscreen,
+ } = modalData;
+ this.notFullscreen = notFullscreen;
+ const portal = new ComponentPortal(modal, null, injector);
+ this.activePortal$.next(portal);
+ setTimeout(() => {
+ const ref = (this.portalOutlet.attachedRef as ComponentRef<OpModalComponent>);
+ console.log(this);
+ console.log(this.portalOutlet);
+ const instance = ref.instance;
- // Trigger another round of change detection in the modal
- ref.changeDetectorRef.detectChanges();
- }, 20);
- }
+ this.activeModalInstance$.next(instance);
- /**
- * Create an augmented injector that is equal to this service's injector + the additional data
- * passed into +show+.
- * This allows callers to pass data into the newly created modal.
- */
- private injectorFor(injector:Injector, data:Record<string, unknown>) {
- const injectorTokens = new WeakMap();
- // Pass the service because otherwise we're getting a cyclic dependency between the portal
- // host service and the bound portal
- data.service = this;
+ // Focus on the first element
+ instance && instance.onOpen();
- injectorTokens.set(OpModalLocalsToken, data);
+ // Trigger another round of change detection in the modal
+ ref.changeDetectorRef.detectChanges();
+ }, 0);
+ });
+ }
- return new PortalInjector(injector, injectorTokens);
+ public close() {
+ this.modalService.close();
}
}
diff --git a/frontend/src/app/shared/components/modal/modal.module.ts b/frontend/src/app/shared/components/modal/modal.module.ts
index 839d21c0f66..1936f283fa4 100644
--- a/frontend/src/app/shared/components/modal/modal.module.ts
+++ b/frontend/src/app/shared/components/modal/modal.module.ts
@@ -1,18 +1,24 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
+import { PortalModule } from '@angular/cdk/portal';
+import { A11yModule } from '@angular/cdk/a11y';
import { FocusModule } from 'core-app/shared/directives/focus/focus.module';
import { IconModule } from 'core-app/shared/components/icon/icon.module';
import { OpModalService } from './modal.service';
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';
@NgModule({
imports: [
CommonModule,
FocusModule,
IconModule,
+ PortalModule,
+ A11yModule,
],
exports: [
+ OpModalOverlayComponent,
OpModalBannerComponent,
],
providers: [
@@ -21,6 +27,7 @@ import { OpModalBannerComponent } from 'core-app/shared/components/modal/modal-b
],
declarations: [
OpModalBannerComponent,
+ OpModalOverlayComponent,
],
})
export class OpenprojectModalModule { }
diff --git a/frontend/src/app/shared/components/modal/modal.service.ts b/frontend/src/app/shared/components/modal/modal.service.ts
index 5220515c9b3..e597279fef6 100644
--- a/frontend/src/app/shared/components/modal/modal.service.ts
+++ b/frontend/src/app/shared/components/modal/modal.service.ts
@@ -27,34 +27,28 @@
//++
import {
- ApplicationRef,
- ComponentFactoryResolver,
- ComponentRef,
Injectable,
InjectionToken,
Injector,
} from '@angular/core';
-import {
- ComponentPortal,
- ComponentType,
- PortalInjector,
-} from '@angular/cdk/portal';
-import { TransitionService } from '@uirouter/core';
+import { ComponentType, PortalInjector } from '@angular/cdk/portal';
import { OpModalComponent } from 'core-app/shared/components/modal/modal.component';
-import { ReplaySubject } from 'rxjs';
-import { take } from 'rxjs/operators';
+import { Observable, ReplaySubject } from 'rxjs';
+import { filter, skip, take } from 'rxjs/operators';
export const OpModalLocalsToken = new InjectionToken<any>('OP_MODAL_LOCALS');
@Injectable({ providedIn: 'root' })
export class OpModalService {
- public activeModal$ = new ReplaySubject<ComponentPortal<OpModalComponent>|null>();
+ public activeModalInstance$ = new ReplaySubject<OpModalComponent|null>();
+ public activeModalData$ = new ReplaySubject<{
+ modal:ComponentType<OpModalComponent>,
+ injector:Injector,
+ notFullscreen:boolean,
+ }|null>();
constructor(
- private readonly componentFactoryResolver:ComponentFactoryResolver,
- private readonly appRef:ApplicationRef,
- private readonly $transitions:TransitionService,
private readonly injector:Injector,
) {
const hostElement = document.createElement('div');
@@ -67,11 +61,7 @@ export class OpModalService {
return;
}
- this.activeModal$.pipe(take(1)).subscribe((activeModal) => {
- if (activeModal) {
- this.activeModal$.next(null);
- }
- });
+ this.close();
});
}
@@ -82,39 +72,54 @@ export class OpModalService {
* @param injector The injector to pass into the component. Ensure this is the hierarchical injector if needed.
* Can be passed 'global' to take the default (global!) injector of this service.
* @param locals A map to be injected via token into the component.
- * @param notFullScreen Whether the modal is treated as non-overlay
*/
public show<T extends OpModalComponent>(
modal:ComponentType<T>,
injector:Injector|'global',
locals:Record<string, unknown> = {},
- notFullScreen = false,
- ):T {
+ notFullscreen = false,
+ ):Observable<T> {
this.close();
- // Prevent closing events during the opening time frame.
- this.opening = true;
-
// Allow users to pass the global injector when deliberately requested.
if (injector === 'global') {
injector = this.injector;
}
+
+ this.activeModalData$.next({
+ modal,
+ injector: this.injectorFor(injector, locals),
+ notFullscreen,
+ });
+
+ return this.activeModalInstance$
+ .pipe(
+ filter((m) => m !== null),
+ skip(1),
+ take(1),
+ ) as Observable<T>;
}
/**
* Closes currently open modal window
*/
public close():void {
- // Detach any component currently in the portal
- this.activeModal$.next(null);
- /*
- if (this.active && this.active.onClose()) {
- this.active.closingEvent.emit(this.active);
- this.bodyPortalHost.detach();
- this.portalHostElement.classList.remove('spot-modal-overlay_active');
- this.portalHostElement.classList.remove('spot-modal-overlay_not-full-screen');
- this.active = null;
- }
- */
+ this.activeModalData$.next(null);
+ }
+
+ /**
+ * Create an augmented injector that is equal to this service's injector + the additional data
+ * passed into +show+.
+ * This allows callers to pass data into the newly created modal.
+ */
+ private injectorFor(injector:Injector, data:Record<string, unknown>) {
+ const injectorTokens = new WeakMap();
+ // Pass the service because otherwise we're getting a cyclic dependency between the portal
+ // host service and the bound portal
+ data.service = this;
+
+ injectorTokens.set(OpModalLocalsToken, data);
+
+ return new PortalInjector(injector, injectorTokens);
}
}
diff --git a/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.service.ts b/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.service.ts
index df7e9764c5b..e7e6b857dd0 100644
--- a/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.service.ts
+++ b/frontend/src/app/shared/components/modals/confirm-dialog/confirm-dialog.service.ts
@@ -61,14 +61,17 @@ export class ConfirmDialogService {
*/
public confirm(options:ConfirmDialogOptions):Promise<void> {
return new Promise<void>((resolve, reject) => {
- const confirmModal = this.opModalService.show(ConfirmDialogModalComponent, this.injector, { options });
- confirmModal.closingEvent.subscribe((modal:ConfirmDialogModalComponent) => {
+ this.opModalService.show(
+ ConfirmDialogModalComponent,
+ this.injector,
+ { options },
+ ).subscribe((modal) => modal.closingEvent.subscribe(() => {
if (modal.confirmed) {
resolve();
} else {
reject();
}
- });
+ }));
});
}
diff --git a/frontend/src/app/shared/components/modals/editor/editor-macros.service.ts b/frontend/src/app/shared/components/modals/editor/editor-macros.service.ts
index aec476eede8..ce517fd6a22 100644
--- a/frontend/src/app/shared/components/modals/editor/editor-macros.service.ts
+++ b/frontend/src/app/shared/components/modals/editor/editor-macros.service.ts
@@ -45,12 +45,15 @@ export class EditorMacrosService {
*/
public configureWorkPackageButton(typeName?:string, classes?:string):Promise<{ type:string, classes:string }> {
return new Promise<{ type:string, classes:string }>((resolve, reject) => {
- const modal = this.opModalService.show(WpButtonMacroModalComponent, this.injector, { type: typeName, classes });
- modal.closingEvent.subscribe((modal:WpButtonMacroModalComponent) => {
+ this.opModalService.show(
+ WpButtonMacroModalComponent,
+ this.injector,
+ { type: typeName, classes },
+ ).subscribe((modal) => modal.closingEvent.subscribe((modal:WpButtonMacroModalComponent) => {
if (modal.changed) {
resolve({ type: modal.type, classes: modal.classes });
}
- });
+ }));
});
}
@@ -61,12 +64,15 @@ export class EditorMacrosService {
public configureWikiPageInclude(page:string):Promise<string> {
return new Promise<string>((resolve, _) => {
const pageValue = page || '';
- const modal = this.opModalService.show(WikiIncludePageMacroModalComponent, this.injector, { page: pageValue });
- modal.closingEvent.subscribe((modal:WikiIncludePageMacroModalComponent) => {
+ this.opModalService.show(
+ WikiIncludePageMacroModalComponent,
+ this.injector,
+ { page: pageValue },
+ ).subscribe((modal) => modal.closingEvent.subscribe((modal:WikiIncludePageMacroModalComponent) => {
if (modal.changed) {
resolve(modal.page);
}
- });
+ }));
});
}
@@ -76,12 +82,15 @@ export class EditorMacrosService {
*/
public editCodeBlock(content:string, languageClass:string):Promise<{ content:string, languageClass:string }> {
return new Promise<{ content:string, languageClass:string }>((resolve, _) => {
- const modal = this.opModalService.show(CodeBlockMacroModalComponent, this.injector, { content, languageClass });
- modal.closingEvent.subscribe((modal:CodeBlockMacroModalComponent) => {
+ this.opModalService.show(
+ CodeBlockMacroModalComponent,
+ this.injector,
+ { content, languageClass },
+ ).subscribe((modal) => modal.closingEvent.subscribe((modal:CodeBlockMacroModalComponent) => {
if (modal.changed) {
resolve({ languageClass: modal.languageClass, content: modal.content });
}
- });
+ }));
});
}
@@ -91,15 +100,18 @@ export class EditorMacrosService {
*/
public configureChildPages(page:string, includeParent:string):Promise<object> {
return new Promise<object>((resolve, _) => {
- const modal = this.opModalService.show(ChildPagesMacroModalComponent, this.injector, { page, includeParent });
- modal.closingEvent.subscribe((modal:ChildPagesMacroModalComponent) => {
+ this.opModalService.show(
+ ChildPagesMacroModalComponent,
+ this.injector,
+ { page, includeParent },
+ ).subscribe((modal) => modal.closingEvent.subscribe((modal:ChildPagesMacroModalComponent) => {
if (modal.changed) {
resolve({
page: modal.page,
includeParent: modal.includeParent,
});
}
- });
+ }));
});
}
}
diff --git a/frontend/src/app/shared/components/time_entries/create/create.service.ts b/frontend/src/app/shared/components/time_entries/create/create.service.ts
index 26aa1774bfb..d4f6544f829 100644
--- a/frontend/src/app/shared/components/time_entries/create/create.service.ts
+++ b/frontend/src/app/shared/components/time_entries/create/create.service.ts
@@ -38,21 +38,21 @@ export class TimeEntryCreateService {
void this
.createNewTimeEntry(date, wp)
.then((changeset) => {
- const modal = this.opModalService.show(
+ this.opModalService.show(
TimeEntryCreateModalComponent,
this.injector,
{ ...options, changeset },
- );
-
- modal
- .closingEvent
- .pipe(take(1))
- .subscribe(() => {
- if (modal.createdEntry) {
- resolve({ entry: modal.createdEntry, action: 'create' });
- } else {
- reject();
- }
+ ).subscribe((modal) => {
+ modal
+ .closingEvent
+ .pipe(take(1))
+ .subscribe(() => {
+ if (modal.createdEntry) {
+ resolve({ entry: modal.createdEntry, action: 'create' });
+ } else {
+ reject();
+ }
+ });
});
});
});
diff --git a/frontend/src/app/shared/components/time_entries/edit/edit.service.ts b/frontend/src/app/shared/components/time_entries/edit/edit.service.ts
index 90b7f8c0f6e..ff2af81d566 100644
--- a/frontend/src/app/shared/components/time_entries/edit/edit.service.ts
+++ b/frontend/src/app/shared/components/time_entries/edit/edit.service.ts
@@ -32,27 +32,28 @@ export class TimeEntryEditService {
void this
.createChangeset(entry)
.then((changeset) => {
- const modal = this.opModalService.show(
+ this.opModalService.show(
TimeEntryEditModalComponent,
this.injector,
{ ...options, changeset },
- );
-
- modal
- .closingEvent
- .pipe(take(1))
- .subscribe(() => {
- if (modal.destroyedEntry) {
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
- modal.destroyedEntry.delete().then(() => {
- resolve({ entry: modal.destroyedEntry, action: 'destroy' });
- });
- } else if (modal.modifiedEntry) {
- resolve({ entry: modal.modifiedEntry, action: 'update' });
- } else {
- reject();
- }
- });
+ )
+ .subscribe((modal) => {
+ modal
+ .closingEvent
+ .pipe(take(1))
+ .subscribe(() => {
+ if (modal.destroyedEntry) {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
+ modal.destroyedEntry.delete().then(() => {
+ resolve({ entry: modal.destroyedEntry, action: 'destroy' });
+ });
+ } else if (modal.modifiedEntry) {
+ resolve({ entry: modal.modifiedEntry, action: 'update' });
+ } else {
+ reject();
+ }
+ });
+ });
});
});
}