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

Remove client side attachment event handling

Kabiru Mwenjae5bab5fa1f4b
diff --git a/app/controllers/work_packages/activities_tab_controller.rb b/app/controllers/work_packages/activities_tab_controller.rb
index 04143ffcf08..41988dba7f2 100644
--- a/app/controllers/work_packages/activities_tab_controller.rb
+++ b/app/controllers/work_packages/activities_tab_controller.rb
@@ -234,7 +234,7 @@ class WorkPackages::ActivitiesTabController < ApplicationController
end
def journal_params
- params.expect(journal: [:notes, :restricted, { attachment_ids: [] }])
+ params.expect(journal: %i[notes restricted])
end
def handle_successful_create_call(call)
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.ts
index 6fed27393bf..0d0fc718a38 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
@@ -36,31 +36,28 @@ import {
Output,
ViewChild,
} from '@angular/core';
-import { navigator } from '@hotwired/turbo';
-import { componentDestroyed } from '@w11k/ngx-componentdestroyed';
-import { I18nService } from 'core-app/core/i18n/i18n.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
-import { IAttachment } from 'core-app/core/state/attachments/attachment.model';
-import { AttachmentsResourceService } from 'core-app/core/state/attachments/attachments.service';
-import { States } from 'core-app/core/states/states.service';
-import { HAL_NEW_RESOURCE_ID } from 'core-app/features/hal/helpers/is-new-resource';
-import { AttachmentCollectionResource } from 'core-app/features/hal/resources/attachment-collection-resource';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';
-import { populateInputsFromDataset } from 'core-app/shared/components/dataset-inputs';
+import { States } from 'core-app/core/states/states.service';
+import { filter, takeUntil } from 'rxjs/operators';
+import { ToastService } from 'core-app/shared/components/toaster/toast.service';
+import { I18nService } from 'core-app/core/i18n/i18n.service';
import {
ICKEditorMacroType,
ICKEditorType,
} from 'core-app/shared/components/editor/components/ckeditor/ckeditor-setup.service';
+import { OpCkeditorComponent } from 'core-app/shared/components/editor/components/ckeditor/op-ckeditor.component';
+import { componentDestroyed } from '@w11k/ngx-componentdestroyed';
+import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import {
ICKEditorContext,
ICKEditorInstance,
} from 'core-app/shared/components/editor/components/ckeditor/ckeditor.types';
-import { OpCkeditorComponent } from 'core-app/shared/components/editor/components/ckeditor/op-ckeditor.component';
-import { ToastService } from 'core-app/shared/components/toaster/toast.service';
-import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { fromEvent } from 'rxjs';
-import { filter, take, takeUntil } from 'rxjs/operators';
+import { AttachmentCollectionResource } from 'core-app/features/hal/resources/attachment-collection-resource';
+import { populateInputsFromDataset } from 'core-app/shared/components/dataset-inputs';
+import { navigator } from '@hotwired/turbo';
@Component({
@@ -98,9 +95,6 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl
// Output focus events
@Output() editorFocus = new EventEmitter<void>();
- // Output attachment added events
- @Output() attachmentAdded = new EventEmitter<IAttachment>();
-
// Which template to include
public element:HTMLElement;
@@ -137,7 +131,6 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl
protected Notifications:ToastService,
protected I18n:I18nService,
protected states:States,
- protected attachmentsResourceService:AttachmentsResourceService,
) {
super();
populateInputsFromDataset(this);
@@ -239,19 +232,6 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl
private setupAttachmentAddedCallback(editor:ICKEditorInstance) {
editor.model.on('op:attachment-added', () => {
- const collectionKey = AttachmentsResourceService.getAttachmentsSelfLink(this.halResource as HalResource) || HAL_NEW_RESOURCE_ID;
-
- this.attachmentsResourceService
- .collection(collectionKey)
- .pipe(
- take(1),
- filter((attachments) => attachments.length > 0),
- )
- .subscribe((attachments) => {
- const latestAttachment = attachments[attachments.length - 1];
- this.attachmentAdded.emit(latestAttachment);
- });
-
this.states.forResource(this.halResource as HalResource)?.putValue(this.halResource);
});
}
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
index 0a82336698b..b07a2134f00 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
@@ -28,14 +28,12 @@
* ++
*/
-import { ID } from '@datorama/akita';
import { Controller } from '@hotwired/stimulus';
-import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
-import { IAttachment } from 'core-app/core/state/attachments/attachment.model';
-import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service';
import {
ICKEditorInstance,
} from 'core-app/shared/components/editor/components/ckeditor/ckeditor.types';
+import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service';
+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
enum AnchorType {
Comment = 'comment',
@@ -49,10 +47,6 @@ interface CustomEventWithIdParam extends Event {
};
}
-interface AttachmentEvent extends CustomEvent {
- detail:IAttachment;
-}
-
export default class IndexController extends Controller {
static values = {
updateStreamsPath: String,
@@ -101,13 +95,11 @@ export default class IndexController extends Controller {
private adjustMarginBound:EventListener;
private onBlurEditorBound:EventListener;
private onFocusEditorBound:EventListener;
- private onAttachmentAddedBound:EventListener;
private saveInProgress:boolean;
private updateInProgress:boolean;
- private attachmentIds:Set<ID> = new Set();
-
private turboRequests:TurboRequestsService;
+
private apiV3Service:ApiV3Service;
async connect() {
@@ -566,11 +558,6 @@ export default class IndexController extends Controller {
}
};
- this.onAttachmentAddedBound = (event:AttachmentEvent) => {
- const attachment = event.detail;
- this.attachmentIds.add(attachment.id);
- };
-
const editorElement = this.getCkEditorElement();
if (editorElement) {
editorElement.addEventListener('saveRequested', this.onSubmitBound);
@@ -578,7 +565,6 @@ export default class IndexController extends Controller {
editorElement.addEventListener('editorKeyup', this.adjustMarginBound);
editorElement.addEventListener('editorBlur', this.onBlurEditorBound);
editorElement.addEventListener('editorFocus', this.onFocusEditorBound);
- editorElement.addEventListener('attachmentAdded', this.onAttachmentAddedBound);
}
}
@@ -590,7 +576,6 @@ export default class IndexController extends Controller {
editorElement.removeEventListener('editorKeyup', this.adjustMarginBound);
editorElement.removeEventListener('editorBlur', this.onBlurEditorBound);
editorElement.removeEventListener('editorFocus', this.onFocusEditorBound);
- editorElement.removeEventListener('attachmentAdded', this.onAttachmentAddedBound);
}
}
@@ -789,12 +774,6 @@ export default class IndexController extends Controller {
formData.append('filter', this.filterValue);
formData.append('journal[notes]', data);
- if (this.attachmentIds.size > 0) {
- this.attachmentIds.forEach((attachmentId) => {
- formData.append('journal[attachment_ids][]', attachmentId.toString());
- });
- }
-
return formData;
}