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
Prevent saving undefined from ckeditor with an error
Oliver Günther712267aa7842
diff --git a/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.component.ts b/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.component.tsindex e6d82bc52d3..9b8f97a8805 100644--- a/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.component.ts+++ b/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.component.ts@@ -149,7 +149,7 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl).subscribe((evt:SubmitEvent) => {evt.preventDefault();- this.saveForm(evt);+ void this.saveForm(evt);});}@@ -157,9 +157,10 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin implwindow.OpenProject.pageWasEdited = true;}- public saveForm(evt?:SubmitEvent):void {- this.syncToTextarea();+ public async saveForm(evt?:SubmitEvent):Promise<void> {this.inFlight = true;++ await this.syncToTextarea();window.OpenProject.pageIsSubmitted = true;setTimeout(() => {@@ -191,10 +192,11 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin implreturn editor;}- private syncToTextarea() {+ private async syncToTextarea() {try {- this.wrappedTextArea.value = this.ckEditorInstance.getRawData();+ this.wrappedTextArea.value = await this.ckEditorInstance.getTransformedContent(true);} catch (e) {+ // eslint-disable-next-line @typescript-eslint/no-base-to-stringconst message = (e as Error)?.message || (e as object).toString();console.error(`Failed to save CKEditor body to textarea: ${message}.`);this.Notifications.addError(message || this.I18n.t('js.error.internal'));diff --git a/frontend/src/app/shared/components/editor/components/ckeditor/op-ckeditor.component.ts b/frontend/src/app/shared/components/editor/components/ckeditor/op-ckeditor.component.tsindex ecb70c61d3d..4cb601e5bcc 100644--- a/frontend/src/app/shared/components/editor/components/ckeditor/op-ckeditor.component.ts+++ b/frontend/src/app/shared/components/editor/components/ckeditor/op-ckeditor.component.ts@@ -26,16 +26,7 @@// See COPYRIGHT and LICENSE files for more details.//++-import {- Component,- ElementRef,- EventEmitter,- Input,- OnDestroy,- OnInit,- Output,- ViewChild,-} from '@angular/core';+import { Component, ElementRef, EventEmitter, Input, OnDestroy, OnInit, Output, ViewChild } from '@angular/core';import { ToastService } from 'core-app/shared/components/toaster/toast.service';import { I18nService } from 'core-app/core/i18n/i18n.service';import { ConfigurationService } from 'core-app/core/config/configuration.service';@@ -47,6 +38,7 @@ import {import { CKEditorSetupService } from 'core-app/shared/components/editor/components/ckeditor/ckeditor-setup.service';import { KeyCodes } from 'core-app/shared/helpers/keyCodes.enum';import { debugLog } from 'core-app/shared/helpers/debug_output';+import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';declare module 'codemirror';@@ -55,7 +47,7 @@ declare module 'codemirror';templateUrl: './op-ckeditor.html',styleUrls: ['./op-ckeditor.sass'],})-export class OpCkeditorComponent implements OnInit, OnDestroy {+export class OpCkeditorComponent extends UntilDestroyedMixin implements OnInit, OnDestroy {@Input() context:ICKEditorContext;@Input()@@ -126,6 +118,7 @@ export class OpCkeditorComponent implements OnInit, OnDestroy {private readonly configurationService:ConfigurationService,private readonly ckEditorSetup:CKEditorSetupService,) {+ super();}/**@@ -133,10 +126,22 @@ export class OpCkeditorComponent implements OnInit, OnDestroy {* the data cannot be loaded (MS Edge!)*/public getRawData():string {+ let content:string;+if (this.manualMode) {- return this._content = this.codeMirrorInstance.getValue();+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access+ content = this.codeMirrorInstance.getValue() as string;+ } else {+ content = this.ckEditorInstance.getData({ trim: false });+ }++ if (content === null || content === undefined) {+ console.error('Trying to get content from CKEditor failed, as it returned null.');+ } else {+ this._content = content;}- return this._content = this.ckEditorInstance.getData({ trim: false });++ return content;}/**@@ -148,6 +153,10 @@ export class OpCkeditorComponent implements OnInit, OnDestroy {throw new Error('Tried to access CKEditor instance before initialization.');}+ if (this.componentDestroyed) {+ throw new Error('Component destroyed');+ }+return new Promise<string>((resolve, reject) => {try {resolve(this.getRawData());