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
Scope CommentService to single WP component and save draft
Oliver Günther965fd1d69c78
diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.tsindex 3e61a6869aa..c19d7468943 100644--- a/frontend/src/app/app.module.ts+++ b/frontend/src/app/app.module.ts@@ -79,7 +79,6 @@ import { OpHeaderProjectSelectListComponent } from 'core-app/shared/components/himport { PaginationService } from 'core-app/shared/components/table-pagination/pagination-service';import { MainMenuResizerComponent } from 'core-app/shared/components/resizer/resizer/main-menu-resizer.component';-import { CommentService } from 'core-app/features/work-packages/components/wp-activity/comment-service';import { OpenprojectTabsModule } from 'core-app/shared/components/tabs/openproject-tabs.module';import { OpenprojectAdminModule } from 'core-app/features/admin/openproject-admin.module';import { OpenprojectHalModule } from 'core-app/features/hal/openproject-hal.module';@@ -210,8 +209,6 @@ export function initializeServices(injector:Injector) {OpenProjectBackupService,OpenProjectFileUploadService,OpenProjectDirectFileUploadService,- // Split view- CommentService,ConfirmDialogService,RevitAddInSettingsButtonService,],diff --git a/frontend/src/app/features/work-packages/components/work-package-comment/work-package-comment.component.ts b/frontend/src/app/features/work-packages/components/work-package-comment/work-package-comment.component.tsindex ce9c50d7210..f6d225cb345 100644--- a/frontend/src/app/features/work-packages/components/work-package-comment/work-package-comment.component.ts+++ b/frontend/src/app/features/work-packages/components/work-package-comment/work-package-comment.component.ts@@ -51,6 +51,10 @@ import { WorkPackagesActivityService } from 'core-app/features/work-packages/comimport { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';import { ErrorResource } from 'core-app/features/hal/resources/error-resource';import { HalError } from 'core-app/features/hal/services/hal-error';+import {+ filter,+ take,+} from 'rxjs/operators';@Component({selector: 'work-package-comment',@@ -85,7 +89,7 @@ export class WorkPackageCommentComponent extends WorkPackageCommentFieldHandlerprotected injector:Injector,protected commentService:CommentService,protected wpLinkedActivities:WorkPackagesActivityService,- protected ConfigurationService:ConfigurationService,+ protected configurationService:ConfigurationService,protected loadingIndicator:LoadingIndicatorService,protected apiV3Service:ApiV3Service,protected workPackageNotificationService:WorkPackageNotificationService,@@ -95,13 +99,23 @@ export class WorkPackageCommentComponent extends WorkPackageCommentFieldHandlersuper(elementRef, injector);}- public ngOnInit() {+ public ngOnInit():void {super.ngOnInit();this.canAddComment = !!this.workPackage.addComment;- this.showAbove = this.ConfigurationService.commentsSortedInDescendingOrder();+ this.showAbove = this.configurationService.commentsSortedInDescendingOrder();++ this.commentService.draft$+ .pipe(+ this.untilDestroyed(),+ take(1),+ filter((val) => !!val),+ )+ .subscribe((draft:string) => {+ this.activate(draft);+ });- this.commentService.quoteEvents+ this.commentService.quoteEvents$.pipe(this.untilDestroyed(),)@@ -111,8 +125,13 @@ export class WorkPackageCommentComponent extends WorkPackageCommentFieldHandler});}+ public ngOnDestroy():void {+ super.ngOnDestroy();+ this.commentService.draft$.next(this.active ? this.rawComment : null);+ }+// Open the field when its closed and relay drag & drop events to it.- public startDragOverActivation(event:JQuery.TriggeredEvent) {+ public startDragOverActivation(event:JQuery.TriggeredEvent):boolean {if (this.active) {return true;}@@ -123,7 +142,7 @@ export class WorkPackageCommentComponent extends WorkPackageCommentFieldHandlerreturn false;}- public activate(withText?:string) {+ public activate(withText?:string):void {super.activate(withText);if (!this.showAbove) {@@ -133,13 +152,13 @@ export class WorkPackageCommentComponent extends WorkPackageCommentFieldHandlerthis.cdRef.detectChanges();}- public deactivate(focus:boolean) {+ public deactivate(focus:boolean):void {focus && this.focus();this.active = false;this.cdRef.detectChanges();}- public async handleUserSubmit() {+ public async handleUserSubmit():Promise<unknown> {if (this.inFlight || !this.rawComment) {return Promise.resolve();}diff --git a/frontend/src/app/features/work-packages/components/wp-activity/comment-service.ts b/frontend/src/app/features/work-packages/components/wp-activity/comment-service.tsindex 2fee81ad415..76cdb1c1ea3 100644--- a/frontend/src/app/features/work-packages/components/wp-activity/comment-service.ts+++ b/frontend/src/app/features/work-packages/components/wp-activity/comment-service.ts@@ -29,16 +29,19 @@import { Injectable } from '@angular/core';import { I18nService } from 'core-app/core/i18n/i18n.service';import { ToastService } from 'core-app/shared/components/toaster/toast.service';-import { Subject } from 'rxjs';+import {+ BehaviorSubject,+ Subject,+} from 'rxjs';import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';import { HalResource } from 'core-app/features/hal/resources/hal-resource';@Injectable()export class CommentService {- // Replacement for ng1 $scope.$emit on activty-entry to mark comments to be quoted.- // Should be generalized if needed for more than that.- public quoteEvents = new Subject<string>();+ public quoteEvents$ = new Subject<string>();++ public draft$ = new BehaviorSubject<string|null>(null);constructor(readonly I18n:I18nService,diff --git a/frontend/src/app/features/work-packages/components/wp-activity/user/user-activity.component.ts b/frontend/src/app/features/work-packages/components/wp-activity/user/user-activity.component.tsindex 8538970fb3c..8f8fde0432d 100644--- a/frontend/src/app/features/work-packages/components/wp-activity/user/user-activity.component.ts+++ b/frontend/src/app/features/work-packages/components/wp-activity/user/user-activity.component.ts@@ -171,7 +171,8 @@ export class UserActivityComponent extends WorkPackageCommentFieldHandler implem}public quoteComment() {- this.commentService.quoteEvents.next(this.quotedText(this.activity.comment.raw));+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access+ this.commentService.quoteEvents$.next(this.quotedText(this.activity.comment.raw));}public get bcfSnapshotUrl() {diff --git a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.tsindex e041f91f826..cabae93293e 100644--- a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts+++ b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts@@ -35,6 +35,7 @@ import { WorkPackageSingleViewBase } from 'core-app/features/work-packages/routiimport { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.service';+import { CommentService } from 'core-app/features/work-packages/components/wp-activity/comment-service';@Component({templateUrl: './wp-full-view.html',@@ -43,6 +44,7 @@ import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-host: { class: 'work-packages-page--ui-view' },providers: [WpSingleViewService,+ CommentService,{ provide: HalResourceNotificationService, useExisting: WorkPackageNotificationService },],})diff --git a/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.component.ts b/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.component.tsindex 96d56e1ca36..25f33ee38d5 100644--- a/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.component.ts+++ b/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.component.ts@@ -43,6 +43,7 @@ import { HalResourceNotificationService } from 'core-app/features/hal/services/himport { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';import { BackRoutingService } from 'core-app/features/work-packages/components/back-routing/back-routing.service';import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.service';+import { CommentService } from 'core-app/features/work-packages/components/wp-activity/comment-service';@Component({templateUrl: './wp-split-view.html',@@ -50,6 +51,7 @@ import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-selector: 'op-wp-split-view',providers: [WpSingleViewService,+ CommentService,{ provide: HalResourceNotificationService, useClass: WorkPackageNotificationService },],})diff --git a/spec/features/work_packages/details/markdown/activity_comments_spec.rb b/spec/features/work_packages/details/markdown/activity_comments_spec.rbindex 8c4ca1148ea..acb1ed30fe9 100644--- a/spec/features/work_packages/details/markdown/activity_comments_spec.rb+++ b/spec/features/work_packages/details/markdown/activity_comments_spec.rb@@ -250,6 +250,37 @@ describe 'activity comments', js: true, with_mail: false doexpect(page).to have_selector('.user-comment .work-package--quickinfo.preview-trigger', count: 2)endend++ it 'can move away to another tab, keeping the draft comment' do+ comment_field.activate!+ comment_field.input_element.send_keys "I'm typing an important message here ..."++ wp_page.switch_to_tab tab: :files+ expect(page).to have_selector('[data-qa-selector="op-tab-content--tab-section"]')++ wp_page.switch_to_tab tab: :activity++ comment_field.expect_active!+ comment_field.ckeditor.expect_value "I'm typing an important message here ..."++ wp_page.switch_to_tab tab: :overview++ comment_field.expect_active!+ comment_field.ckeditor.expect_value "I'm typing an important message here ..."++ comment_field.cancel_by_click++ # Has removed the draft now++ wp_page.switch_to_tab tab: :files+ expect(page).to have_selector('[data-qa-selector="op-tab-content--tab-section"]')++ wp_page.switch_to_tab tab: :activity+ comment_field.expect_inactive!++ wp_page.switch_to_tab tab: :overview+ comment_field.expect_inactive!+ endendcontext 'with no permission' do