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

Extract logic to update the edit field after the turboFrame was submitted into a directive so that it can be used for the datepicker as well

Henriette Dargedf351f02ce80
diff --git a/app/components/work_packages/date_picker/dialog_content_component.html.erb b/app/components/work_packages/date_picker/dialog_content_component.html.erb
index 4e47c7e08ca..def051400c9 100644
--- a/app/components/work_packages/date_picker/dialog_content_component.html.erb
+++ b/app/components/work_packages/date_picker/dialog_content_component.html.erb
@@ -65,6 +65,7 @@
end
second_row.with_column do
render(Primer::Alpha::TextField.new(name: :duration,
+ type: "number",
label: I18n.t("activerecord.attributes.work_package.duration"),
value: work_package.duration))
end
diff --git a/app/controllers/work_packages/date_picker_controller.rb b/app/controllers/work_packages/date_picker_controller.rb
index d25e4078245..b8837108fd0 100644
--- a/app/controllers/work_packages/date_picker_controller.rb
+++ b/app/controllers/work_packages/date_picker_controller.rb
@@ -60,6 +60,8 @@ class WorkPackages::DatePickerController < ApplicationController
end
def update
+ # Todo
+ params[:duration] = params[:duration].to_i
service_call = WorkPackages::UpdateService
.new(user: current_user,
model: @work_package)
@@ -79,7 +81,7 @@ class WorkPackages::DatePickerController < ApplicationController
# the request in order to fetch the new set of Work Package
# attributes in the ancestry solely on success.
render turbo_stream: [
- turbo_stream.morph("work_package_datepicker_modal", datepicker_modal_component)
+ turbo_stream.morph("wp-datepicker-dialog--content", datepicker_modal_component)
], status: :unprocessable_entity
end
end
@@ -88,7 +90,7 @@ class WorkPackages::DatePickerController < ApplicationController
private
- def progress_modal_component
+ def datepicker_modal_component
WorkPackages::DatePicker::DialogContentComponent.new(work_package: @work_package, manually_scheduled:, focused_field:,
touched_field_map:)
end
@@ -102,8 +104,7 @@ class WorkPackages::DatePickerController < ApplicationController
end
def touched_field_map
- params.require(:work_package)
- .slice("schedule_manually_touched",
+ params.slice("schedule_manually_touched",
"ignore_non_working_days_touched",
"start_date_touched",
"due_date_touched",
@@ -121,20 +122,19 @@ class WorkPackages::DatePickerController < ApplicationController
end
def work_package_datepicker_params
- params.require(:work_package)
- .slice(*allowed_touched_params)
+ params.slice(*allowed_params)
.permit!
end
- def allowed_touched_params
- allowed_params.filter { touched?(_1) }
- end
+ # def allowed_touched_params
+ # allowed_params.filter { touched?(_1) }
+ # end
def allowed_params
%i[schedule_manually ignore_non_working_days start_date due_date duration]
end
- def touched?(field)
- touched_field_map[:"#{field}_touched"]
- end
+ # def touched?(field)
+ # touched_field_map[:"#{field}_touched"]
+ # end
end
diff --git a/frontend/src/app/shared/components/datepicker/datepicker.module.ts b/frontend/src/app/shared/components/datepicker/datepicker.module.ts
index a059dcefd58..aa7f871935c 100644
--- a/frontend/src/app/shared/components/datepicker/datepicker.module.ts
+++ b/frontend/src/app/shared/components/datepicker/datepicker.module.ts
@@ -15,7 +15,6 @@ import { OpSpotModule } from 'core-app/spot/spot.module';
import { OpenprojectModalModule } from '../modal/modal.module';
import { OpDatePickerSheetComponent } from 'core-app/shared/components/datepicker/sheet/date-picker-sheet.component';
import { OpenprojectContentLoaderModule } from 'core-app/shared/components/op-content-loader/openproject-content-loader.module';
-import { OpWpMultiDateDialogContentComponent } from 'core-app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-dialog-content.component';
import { OpWpModalDatePickerComponent } from 'core-app/shared/components/datepicker/wp-modal-date-picker/wp-modal-date-picker.component';
@NgModule({
@@ -39,7 +38,6 @@ import { OpWpModalDatePickerComponent } from 'core-app/shared/components/datepic
OpWpMultiDateFormComponent,
OpWpSingleDateFormComponent,
OpDatePickerSheetComponent,
- OpWpMultiDateDialogContentComponent,
OpWpModalDatePickerComponent,
],
@@ -49,7 +47,6 @@ import { OpWpModalDatePickerComponent } from 'core-app/shared/components/datepic
OpWpSingleDateFormComponent,
OpBasicDatePickerModule,
OpDatePickerSheetComponent,
- OpWpMultiDateDialogContentComponent,
OpWpModalDatePickerComponent,
],
})
diff --git a/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-dialog-content.component.ts b/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-dialog-content.component.ts
deleted file mode 100644
index 3432d342d7d..00000000000
--- a/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-dialog-content.component.ts
+++ /dev/null
@@ -1,82 +0,0 @@
-//-- 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.
-//++
-
-import {
- ChangeDetectionStrategy,
- Component,
- HostBinding,
- Input,
- OnInit,
- ViewEncapsulation,
-} from '@angular/core';
-import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
-import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
-import { ResourceChangeset } from 'core-app/shared/components/fields/changeset/resource-changeset';
-
-@Component({
- selector: 'op-wp-multi-date-dialog-content',
- template: `
- <turbo-frame *ngIf="turboFrameSrc"
- [src]="turboFrameSrc"
- id="wp-datepicker-dialog--content">
- <op-content-loader viewBox="0 0 100 100">
- <svg:rect x="5" y="5" width="70" height="5" rx="1"/>
-
- <svg:rect x="80" y="5" width="15" height="5" rx="1"/>
-
- <svg:rect x="5" y="15" width="90" height="8" rx="1"/>
-
- <svg:rect x="5" y="30" width="90" height="12" rx="1"/>
- </op-content-loader>
- </turbo-frame>
- `,
- styleUrls: [
- '../styles/datepicker.modal.sass',
- ],
- changeDetection: ChangeDetectionStrategy.OnPush,
- encapsulation: ViewEncapsulation.None,
-})
-export class OpWpMultiDateDialogContentComponent extends UntilDestroyedMixin implements OnInit {
- @HostBinding('class.op-datepicker-modal') className = true;
-
- @HostBinding('class.op-datepicker-modal_wide') classNameWide = true;
-
- @Input() changeset:ResourceChangeset;
-
- public turboFrameSrc:string;
-
- constructor(
- readonly pathHelper:PathHelperService,
- ) {
- super();
- }
-
- ngOnInit():void {
- this.turboFrameSrc = this.pathHelper.workPackageDatepickerDialogContentPath(this.changeset.id);
- }
-}
diff --git a/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.html b/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.html
index 626713f1d5b..66578feafca 100644
--- a/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.html
+++ b/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.html
@@ -20,10 +20,25 @@
(save)="save()"
(cancel)="cancel()"
></op-wp-single-date-form>
- <op-wp-multi-date-dialog-content
- *ngIf="opened && isMultiDate"
- [changeset]="change"
- ></op-wp-multi-date-dialog-content>
+
+ <turbo-frame *ngIf="turboFrameSrc && opened && isMultiDate"
+ [src]="turboFrameSrc"
+ opModalWithTurboContent
+ [change]="change"
+ [resource]="resource"
+ (successfulCreate)="handleSuccessfulCreate($event)"
+ (successfulUpdate)="handleSuccessfulUpdate()"
+ id="wp-datepicker-dialog--content">
+ <op-content-loader viewBox="0 0 100 100">
+ <svg:rect x="5" y="5" width="70" height="5" rx="1"/>
+
+ <svg:rect x="80" y="5" width="15" height="5" rx="1"/>
+
+ <svg:rect x="5" y="15" width="90" height="8" rx="1"/>
+
+ <svg:rect x="5" y="30" width="90" height="12" rx="1"/>
+ </op-content-loader>
+ </turbo-frame>
<!--<op-wp-multi-date-form
*ngIf="opened && isMultiDate"
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 0644b1ae725..307b2cdf766 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
@@ -26,18 +26,38 @@
// See COPYRIGHT and LICENSE files for more details.
//++
-import { Component } from '@angular/core';
+import {
+ ChangeDetectorRef,
+ Component,
+ ElementRef,
+ Inject,
+ Injector,
+ OnInit,
+} from '@angular/core';
import { DatePickerEditFieldComponent } from 'core-app/shared/components/fields/edit/field-types/date-picker-edit-field.component';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
+import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
+import { I18nService } from 'core-app/core/i18n/i18n.service';
+import { ResourceChangeset } from 'core-app/shared/components/fields/changeset/resource-changeset';
+import { HalResource } from 'core-app/features/hal/resources/hal-resource';
+import { IFieldSchema } from 'core-app/shared/components/fields/field.base';
+import { EditFieldHandler } from 'core-app/shared/components/fields/edit/editing-portal/edit-field-handler';
+import {
+ OpEditingPortalChangesetToken,
+ OpEditingPortalHandlerToken,
+ OpEditingPortalSchemaToken,
+} from 'core-app/shared/components/fields/edit/edit-field.component';
@Component({
templateUrl: './combined-date-edit-field.component.html',
})
-export class CombinedDateEditFieldComponent extends DatePickerEditFieldComponent {
+export class CombinedDateEditFieldComponent extends DatePickerEditFieldComponent implements OnInit {
dates = '';
opened = false;
+ turboFrameSrc:string;
+
text = {
placeholder: {
startDate: this.I18n.t('js.label_no_start_date'),
@@ -46,6 +66,24 @@ export class CombinedDateEditFieldComponent extends DatePickerEditFieldComponent
},
};
+ constructor(
+ readonly I18n:I18nService,
+ readonly elementRef:ElementRef,
+ @Inject(OpEditingPortalChangesetToken) protected change:ResourceChangeset<HalResource>,
+ @Inject(OpEditingPortalSchemaToken) public schema:IFieldSchema,
+ @Inject(OpEditingPortalHandlerToken) readonly handler:EditFieldHandler,
+ readonly cdRef:ChangeDetectorRef,
+ readonly injector:Injector,
+ readonly pathHelper:PathHelperService,
+ ) {
+ super(I18n, elementRef, change, schema, handler, cdRef, injector);
+ }
+
+ ngOnInit() {
+ super.ngOnInit();
+ this.turboFrameSrc = `${this.pathHelper.workPackageDatepickerDialogContentPath(this.change.id)}?field=${this.name}`;
+ }
+
get isMultiDate():boolean {
return !this.change.schema.isMilestone;
}
@@ -67,13 +105,22 @@ export class CombinedDateEditFieldComponent extends DatePickerEditFieldComponent
this.resetDates();
}
- public save():void {
- this.handler.handleUserSubmit();
+ public handleSuccessfulCreate(JSONResponse:{ duration:number, startDate:Date, dueDate:Date, includeNonWorkingDays:boolean, scheduleManually:boolean }):void {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
+ this.resource.duration = JSONResponse.duration;
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
+ this.resource.dueDate = JSONResponse.dueDate;
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
+ this.resource.startDate = JSONResponse.startDate;
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
+ this.resource.includeNonWorkingDays = JSONResponse.includeNonWorkingDays;
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
+ this.resource.scheduleManually = JSONResponse.scheduleManually;
+
this.onModalClosed();
}
- public cancel():void {
- this.handler.reset();
+ public handleSuccessfulUpdate():void {
this.onModalClosed();
}
diff --git a/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.html b/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.html
index 73a7cba6318..3807e504d4b 100644
--- a/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.html
+++ b/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.html
@@ -37,9 +37,14 @@
<div class="spot-drop-modal--content">
<turbo-frame
- #frameElement
id="work_package_progress_modal"
- [attr.src]="this.frameSrc">
+ [attr.src]="this.frameSrc"
+ opModalWithTurboContent
+ [change]="change"
+ [resource]="resource"
+ (successfulCreate)="handleSuccessfulCreate($event)"
+ (successfulUpdate)="handleSuccessfulUpdate()"
+ >
<op-content-loader
viewBox="0 0 180 80"
>
diff --git a/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.ts
index bfe9678b209..8660af62d91 100644
--- a/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.ts
+++ b/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.ts
@@ -29,22 +29,17 @@
*/
import {
- AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
Inject,
Injector,
- OnDestroy,
OnInit,
- ViewChild,
} from '@angular/core';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
-import {
- ProgressEditFieldComponent,
-} from 'core-app/shared/components/fields/edit/field-types/progress-edit-field.component';
+import { ProgressEditFieldComponent } from 'core-app/shared/components/fields/edit/field-types/progress-edit-field.component';
import { ResourceChangeset } from 'core-app/shared/components/fields/changeset/resource-changeset';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { IFieldSchema } from 'core-app/shared/components/fields/field.base';
@@ -55,7 +50,6 @@ import {
OpEditingPortalSchemaToken,
} from 'core-app/shared/components/fields/edit/edit-field.component';
import { HalEventsService } from 'core-app/features/hal/services/hal-events.service';
-import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
import { ToastService } from 'core-app/shared/components/toaster/toast.service';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
@@ -65,9 +59,7 @@ import { TimezoneService } from 'core-app/core/datetime/timezone.service';
styleUrls: ['./progress-popover-edit-field.component.sass'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class ProgressPopoverEditFieldComponent extends ProgressEditFieldComponent implements OnInit, AfterViewInit, OnDestroy {
- @ViewChild('frameElement') frameElement:ElementRef<HTMLIFrameElement>;
-
+export class ProgressPopoverEditFieldComponent extends ProgressEditFieldComponent implements OnInit {
text = {
title: this.I18n.t('js.work_packages.progress.title'),
button_close: this.I18n.t('js.button_close'),
@@ -79,8 +71,6 @@ export class ProgressPopoverEditFieldComponent extends ProgressEditFieldComponen
opened = false;
- private boundListener = this.contextBasedListener.bind(this);
-
constructor(
readonly I18n:I18nService,
readonly elementRef:ElementRef,
@@ -109,22 +99,6 @@ export class ProgressPopoverEditFieldComponent extends ProgressEditFieldComponen
this.frameId = 'work_package_progress_modal';
}
- ngAfterViewInit() {
- this
- .frameElement
- .nativeElement
- .addEventListener('turbo:submit-end', this.boundListener);
- }
-
- ngOnDestroy() {
- super.ngOnDestroy();
-
- this
- .frameElement
- .nativeElement
- .removeEventListener('turbo:submit-end', this.boundListener);
- }
-
public get asHoursOrPercent():string {
return this.name === 'percentageDone' ? this.asPercent : this.asHours;
}
@@ -158,62 +132,19 @@ export class ProgressPopoverEditFieldComponent extends ProgressEditFieldComponen
return value;
}
- private contextBasedListener(event:CustomEvent) {
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
- if (this.resource.id === 'new') {
- void this.propagateSuccessfulCreate(event);
- } else {
- this.propagateSuccessfulUpdate(event);
- }
- }
-
- private async propagateSuccessfulCreate(event:CustomEvent) {
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
- const { fetchResponse } = event.detail;
-
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
- if (fetchResponse.succeeded) {
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
- const JSONresponse = await this.extractJSONFromResponse(fetchResponse.response.body);
-
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
- this.resource.estimatedTime = JSONresponse.estimatedTime;
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
- this.resource.remainingTime = JSONresponse.remainingTime;
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
- this.resource.percentageDone = JSONresponse.percentageDone;
-
- this.onModalClosed();
-
- this.change.push();
- this.cdRef.detectChanges();
- }
- }
-
- private propagateSuccessfulUpdate(event:CustomEvent) {
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
- const { fetchResponse } = event.detail;
-
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
- if (fetchResponse.succeeded) {
- this.halEvents.push(
- this.resource as WorkPackageResource,
- { eventType: 'updated' },
- );
-
- void this.apiV3Service.work_packages.id(this.resource as WorkPackageResource).refresh();
+ public handleSuccessfulCreate(JSONResponse:{ estimatedTime:string, remainingTime:string, percentageDone:string }):void {
+// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
+ this.resource.estimatedTime = JSONResponse.estimatedTime;
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
+ this.resource.remainingTime = JSONResponse.remainingTime;
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
+ this.resource.percentageDone = JSONResponse.percentageDone;
- this.onModalClosed();
-
- this.toastService.addSuccess(this.I18n.t('js.notice_successful_update'));
- }
+ this.onModalClosed();
}
- private async extractJSONFromResponse(response:ReadableStream) {
- const readStream = await response.getReader().read();
-
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
- return JSON.parse(new TextDecoder('utf-8').decode(new Uint8Array(readStream.value as ArrayBufferLike)));
+ public handleSuccessfulUpdate():void {
+ this.onModalClosed();
}
private updateFrameSrc():void {
diff --git a/frontend/src/app/shared/components/fields/edit/modal-with-turbo-content/modal-with-turbo-content.directive.ts b/frontend/src/app/shared/components/fields/edit/modal-with-turbo-content/modal-with-turbo-content.directive.ts
new file mode 100644
index 00000000000..2ab4460b7d8
--- /dev/null
+++ b/frontend/src/app/shared/components/fields/edit/modal-with-turbo-content/modal-with-turbo-content.directive.ts
@@ -0,0 +1,134 @@
+//-- 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.
+//++
+
+import {
+ AfterViewInit,
+ ChangeDetectorRef,
+ Directive,
+ ElementRef,
+ EventEmitter,
+ Input,
+ OnDestroy,
+ Output,
+} from '@angular/core';
+import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
+import { HalResource } from 'core-app/features/hal/resources/hal-resource';
+import { HalEventsService } from 'core-app/features/hal/services/hal-events.service';
+import { ToastService } from 'core-app/shared/components/toaster/toast.service';
+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
+import { I18nService } from 'core-app/core/i18n/i18n.service';
+import { ResourceChangeset } from 'core-app/shared/components/fields/changeset/resource-changeset';
+
+@Directive({
+ selector: '[opModalWithTurboContent]',
+})
+export class ModalWithTurboContentDirective implements AfterViewInit, OnDestroy {
+ @Input() resource:HalResource;
+ @Input() change:ResourceChangeset<HalResource>;
+
+ @Output() successfulCreate= new EventEmitter<unknown>();
+ @Output() successfulUpdate= new EventEmitter();
+
+ private boundListener = this.contextBasedListener.bind(this);
+
+ constructor(
+ readonly elementRef:ElementRef,
+ readonly cdRef:ChangeDetectorRef,
+ readonly halEvents:HalEventsService,
+ readonly apiV3Service:ApiV3Service,
+ readonly toastService:ToastService,
+ readonly I18n:I18nService,
+ ) {
+
+ }
+
+ ngAfterViewInit() {
+ this
+ .elementRef
+ .nativeElement
+ .addEventListener('turbo:submit-end', this.boundListener);
+ }
+
+ ngOnDestroy() {
+ this
+ .elementRef
+ .nativeElement
+ .removeEventListener('turbo:submit-end', this.boundListener);
+ }
+
+ private contextBasedListener(event:CustomEvent) {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+ if (this.resource.id === 'new') {
+ void this.propagateSuccessfulCreate(event);
+ } else {
+ this.propagateSuccessfulUpdate(event);
+ }
+ }
+
+ private async propagateSuccessfulCreate(event:CustomEvent) {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
+ const { fetchResponse } = event.detail;
+
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+ if (fetchResponse.succeeded) {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
+ const JSONresponse:unknown = await this.extractJSONFromResponse(fetchResponse.response.body);
+
+ this.successfulCreate.emit(JSONresponse);
+
+ this.change.push();
+ this.cdRef.detectChanges();
+ }
+ }
+
+ private propagateSuccessfulUpdate(event:CustomEvent) {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
+ const { fetchResponse } = event.detail;
+
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+ if (fetchResponse.succeeded) {
+ this.halEvents.push(
+ this.resource as WorkPackageResource,
+ { eventType: 'updated' },
+ );
+
+ void this.apiV3Service.work_packages.id(this.resource as WorkPackageResource).refresh();
+
+ this.successfulUpdate.emit();
+
+ this.toastService.addSuccess(this.I18n.t('js.notice_successful_update'));
+ }
+ }
+
+ private async extractJSONFromResponse(response:ReadableStream) {
+ const readStream = await response.getReader().read();
+
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
+ return JSON.parse(new TextDecoder('utf-8').decode(new Uint8Array(readStream.value as ArrayBufferLike)));
+ }
+}
diff --git a/frontend/src/app/shared/components/fields/openproject-fields.module.ts b/frontend/src/app/shared/components/fields/openproject-fields.module.ts
index ffb58fa6bad..ef4a2c64b97 100644
--- a/frontend/src/app/shared/components/fields/openproject-fields.module.ts
+++ b/frontend/src/app/shared/components/fields/openproject-fields.module.ts
@@ -106,6 +106,7 @@ import {
import { CombinedDateEditFieldComponent } from './edit/field-types/combined-date-edit-field.component';
import { NgSelectModule } from '@ng-select/ng-select';
import { FormsModule } from '@angular/forms';
+import { ModalWithTurboContentDirective } from 'core-app/shared/components/fields/edit/modal-with-turbo-content/modal-with-turbo-content.directive';
@NgModule({
imports: [
@@ -169,6 +170,8 @@ import { FormsModule } from '@angular/forms';
AttributeLabelMacroComponent,
WorkPackageQuickinfoMacroComponent,
+
+ ModalWithTurboContentDirective,
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})