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

Add drop zone to attachment list (#11606)

Benjamin Bädorffecb2805f425
diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb
index dc551a3007f..310aaeb921c 100644
--- a/app/helpers/attachments_helper.rb
+++ b/app/helpers/attachments_helper.rb
@@ -42,7 +42,7 @@ module AttachmentsHelper
# Within ckeditor-augmented-textarea-form, this attachment list is added automatically
# when a resource is added.
def list_attachments(resource)
- content_tag 'attachments',
+ content_tag 'op-attachments',
'',
'data-resource': resource.to_json,
'data-allow-uploading': false,
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 7dcb472e6bb..1dd68387bbe 100644
--- a/frontend/src/app/core/setup/global-dynamic-components.const.ts
+++ b/frontend/src/app/core/setup/global-dynamic-components.const.ts
@@ -13,7 +13,7 @@ import {
zenModeComponentSelector,
} from 'core-app/features/work-packages/components/wp-buttons/zen-mode-toggle-button/zen-mode-toggle-button.component';
import {
- AttachmentsComponent,
+ OpAttachmentsComponent,
attachmentsSelector,
} from 'core-app/shared/components/attachments/attachments.component';
import {
@@ -211,7 +211,7 @@ export const globalDynamicComponents:OptionalBootstrapDefinition[] = [
{ selector: wpEmbeddedTableMacroSelector, cls: EmbeddedTablesMacroComponent, embeddable: true },
{ selector: colorsAutocompleterSelector, cls: ColorsAutocompleterComponent },
{ selector: zenModeComponentSelector, cls: ZenModeButtonComponent },
- { selector: attachmentsSelector, cls: AttachmentsComponent, embeddable: true },
+ { selector: attachmentsSelector, cls: OpAttachmentsComponent, embeddable: true },
{ selector: usersAutocompleterSelector, cls: UserAutocompleterComponent },
{ selector: membersAutocompleterSelector, cls: MembersAutocompleterComponent },
{ selector: globalSearchTabsSelector, cls: GlobalSearchTabsComponent },
diff --git a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.html b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.html
similarity index 85%
rename from frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.html
rename to frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.html
index 7a35833cc2a..cb55bd5d1f6 100644
--- a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.html
+++ b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.html
@@ -14,9 +14,7 @@
<span class="op-tab-content--header-text" [textContent]="text.attachments.label"></span>
</div>
- <op-attachment-list [resource]="workPackage"></op-attachment-list>
-
- <op-attachments-upload [resource]="workPackage"></op-attachments-upload>
+ <op-attachments [resource]="workPackage"></op-attachments>
</section>
<section
diff --git a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts
index 61c05d5431b..e917a9005b5 100644
--- a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts
@@ -54,7 +54,7 @@ import { HalResource } from 'core-app/features/hal/resources/hal-resource';
@Component({
selector: 'op-files-tab',
- templateUrl: './op-files-tab.html',
+ templateUrl: './op-files-tab.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class WorkPackageFilesTabComponent implements OnInit {
diff --git a/frontend/src/app/features/work-packages/openproject-work-packages.module.ts b/frontend/src/app/features/work-packages/openproject-work-packages.module.ts
index 5096b597282..5c2404e7845 100644
--- a/frontend/src/app/features/work-packages/openproject-work-packages.module.ts
+++ b/frontend/src/app/features/work-packages/openproject-work-packages.module.ts
@@ -157,8 +157,7 @@ import { WorkPackageCopyFullViewComponent } from 'core-app/features/work-package
import { OpenprojectTabsModule } from 'core-app/shared/components/tabs/openproject-tabs.module';
import { TimeEntryChangeset } from 'core-app/features/work-packages/helpers/time-entries/time-entry-changeset';
-import { AttachmentsUploadComponent } from 'core-app/shared/components/attachments/attachments-upload/attachments-upload.component';
-import { AttachmentListComponent } from 'core-app/shared/components/attachments/attachment-list/attachment-list.component';
+import { OpAttachmentsComponent } from 'core-app/shared/components/attachments/attachments.component';
import { QueryFiltersComponent } from 'core-app/features/work-packages/components/filters/query-filters/query-filters.component';
import { FilterDateTimesValueComponent } from 'core-app/features/work-packages/components/filters/filter-date-times-value/filter-date-times-value.component';
import { FilterSearchableMultiselectValueComponent } from 'core-app/features/work-packages/components/filters/filter-searchable-multiselect-value/filter-searchable-multiselect-value.component';
@@ -485,9 +484,7 @@ export class OpenprojectWorkPackagesModule {
return null;
});
- hookService.register('workPackageAttachmentUploadComponent', () => AttachmentsUploadComponent);
-
- hookService.register('workPackageAttachmentListComponent', () => AttachmentListComponent);
+ hookService.register('workPackageAttachmentListComponent', () => OpAttachmentsComponent);
/** Return specialized work package changeset for editing service */
hookService.register('halResourceChangesetClass', (resource:HalResource) => {
diff --git a/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.html b/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.component.html
similarity index 98%
rename from frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.html
rename to frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.component.html
index 2024b801528..8dca08e1148 100644
--- a/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.html
+++ b/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.component.html
@@ -32,6 +32,7 @@
class="spot-list--item-floating-actions op-file-list--item-floating-actions hidden-for-mobile"
>
<button
+ type="button"
class="spot-link"
[title]="deleteIconTitle"
(click)="confirmRemoveAttachment()"
diff --git a/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.component.ts b/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.component.ts
index 433cd259419..45943c12aa9 100644
--- a/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.component.ts
+++ b/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.component.ts
@@ -56,10 +56,10 @@ import idFromLink from 'core-app/features/hal/helpers/id-from-link';
@Component({
// eslint-disable-next-line @angular-eslint/component-selector
selector: '[op-attachment-list-item]',
- templateUrl: './attachment-list-item.html',
+ templateUrl: './attachment-list-item.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class AttachmentListItemComponent extends UntilDestroyedMixin implements OnInit, AfterViewInit {
+export class OpAttachmentListItemComponent extends UntilDestroyedMixin implements OnInit, AfterViewInit {
@Input() public attachment:IAttachment;
@Input() public index:number;
@@ -173,7 +173,7 @@ export class AttachmentListItemComponent extends UntilDestroyedMixin implements
private get isImage():boolean {
const ext = this.attachment.fileName.split('.').pop() || '';
- return AttachmentListItemComponent.imageFileExtensions.indexOf(ext.toLowerCase()) > -1;
+ return OpAttachmentListItemComponent.imageFileExtensions.indexOf(ext.toLowerCase()) > -1;
}
public confirmRemoveAttachment():void {
diff --git a/frontend/src/app/shared/components/attachments/attachment-list/attachment-list.component.html b/frontend/src/app/shared/components/attachments/attachment-list/attachment-list.component.html
new file mode 100644
index 00000000000..0afc37dab41
--- /dev/null
+++ b/frontend/src/app/shared/components/attachments/attachment-list/attachment-list.component.html
@@ -0,0 +1,14 @@
+<ul
+ *ngIf="attachments.length > 0"
+ class="spot-list spot-list_compact op-file-list"
+>
+ <li
+ *ngFor="let attachment of attachments; let i = index;"
+ op-attachment-list-item
+ class="spot-list--item op-file-list--item"
+ data-qa-selector="op-attachment-list-item"
+ [attachment]="attachment"
+ [index]="i"
+ (removeAttachment)="removeAttachment(attachment)"
+ ></li>
+</ul>
diff --git a/frontend/src/app/shared/components/attachments/attachment-list/attachment-list.component.ts b/frontend/src/app/shared/components/attachments/attachment-list/attachment-list.component.ts
index 1b94238bf2b..cf3aff712be 100644
--- a/frontend/src/app/shared/components/attachments/attachment-list/attachment-list.component.ts
+++ b/frontend/src/app/shared/components/attachments/attachment-list/attachment-list.component.ts
@@ -32,67 +32,27 @@ import {
Input,
OnInit,
} from '@angular/core';
-import { map, tap } from 'rxjs/operators';
-import { Observable } from 'rxjs';
-import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { IAttachment } from 'core-app/core/state/attachments/attachment.model';
-import { TimezoneService } from 'core-app/core/datetime/timezone.service';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { AttachmentsResourceService } from 'core-app/core/state/attachments/attachments.service';
-import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
@Component({
selector: 'op-attachment-list',
- templateUrl: './attachment-list.html',
+ templateUrl: './attachment-list.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class AttachmentListComponent extends UntilDestroyedMixin implements OnInit {
- @Input() public resource:HalResource;
+export class OpAttachmentListComponent extends UntilDestroyedMixin implements OnInit {
+ @Input() public attachments:IAttachment[] = [];
- $attachments:Observable<IAttachment[]>;
-
- private get attachmentsSelfLink():string {
- const attachments = this.resource.attachments as unknown&{ href:string };
- return attachments.href;
- }
-
- private get collectionKey():string {
- return isNewResource(this.resource) ? 'new' : this.attachmentsSelfLink;
- }
+ @Input() public collectionKey:string;
constructor(
- private readonly timezoneService:TimezoneService,
private readonly attachmentsResourceService:AttachmentsResourceService,
) {
super();
}
ngOnInit():void {
- // ensure collection is loaded to the store
- if (!isNewResource(this.resource)) {
- this.attachmentsResourceService.requireCollection(this.attachmentsSelfLink);
- }
-
- const compareCreatedAtTimestamps = (a:IAttachment, b:IAttachment):number => {
- const rightCreatedAt = this.timezoneService.parseDatetime(b.createdAt);
- const leftCreatedAt = this.timezoneService.parseDatetime(a.createdAt);
- return rightCreatedAt.isBefore(leftCreatedAt) ? -1 : 1;
- };
-
- this.$attachments = this
- .attachmentsResourceService
- .collection(this.collectionKey)
- .pipe(
- this.untilDestroyed(),
- map((attachments) => attachments.sort(compareCreatedAtTimestamps)),
- // store attachments for new resources directly into the resource. This way, the POST request to create the
- // resource embeds the attachments and the backend reroutes the anonymous attachments to the resource.
- tap((attachments) => {
- if (isNewResource(this.resource)) {
- this.resource.attachments = { elements: attachments.map((a) => a._links.self) };
- }
- }),
- );
}
public removeAttachment(attachment:IAttachment):void {
diff --git a/frontend/src/app/shared/components/attachments/attachment-list/attachment-list.html b/frontend/src/app/shared/components/attachments/attachment-list/attachment-list.html
deleted file mode 100644
index 848d29ef1a8..00000000000
--- a/frontend/src/app/shared/components/attachments/attachment-list/attachment-list.html
+++ /dev/null
@@ -1,17 +0,0 @@
-<div
- *ngIf="resource && $attachments | async as attachments"
->
- <ul
- *ngIf="attachments.length > 0"
- class="spot-list spot-list_compact op-file-list">
- <li
- *ngFor="let attachment of attachments; let i = index;"
- op-attachment-list-item
- class="spot-list--item op-file-list--item"
- data-qa-selector="op-attachment-list-item"
- [attachment]="attachment"
- [index]="i"
- (removeAttachment)="removeAttachment(attachment)"
- ></li>
- </ul>
-</div>
diff --git a/frontend/src/app/shared/components/attachments/attachments-upload/attachments-upload.component.ts b/frontend/src/app/shared/components/attachments/attachments-upload/attachments-upload.component.ts
deleted file mode 100644
index 93b8c676fdb..00000000000
--- a/frontend/src/app/shared/components/attachments/attachments-upload/attachments-upload.component.ts
+++ /dev/null
@@ -1,182 +0,0 @@
-// -- copyright
-// OpenProject is an open source project management software.
-// Copyright (C) 2012-2022 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,
- ElementRef,
- Input,
- OnInit,
- ViewChild,
-} from '@angular/core';
-import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { ConfigurationService } from 'core-app/core/config/configuration.service';
-import { HalResource } from 'core-app/features/hal/resources/hal-resource';
-import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';
-import { ToastService } from 'core-app/shared/components/toaster/toast.service';
-import { UploadFile } from 'core-app/core/file-upload/op-file-upload.service';
-import { AttachmentsResourceService } from 'core-app/core/state/attachments/attachments.service';
-
-@Component({
- selector: 'op-attachments-upload',
- templateUrl: './attachments-upload.html',
- changeDetection: ChangeDetectionStrategy.OnPush,
-})
-export class AttachmentsUploadComponent implements OnInit {
- @Input() public resource:HalResource;
-
- @ViewChild('hiddenFileInput') public filePicker:ElementRef<HTMLInputElement>;
-
- public draggingOver = false;
-
- public text = {
- uploadLabel: this.I18n.t('js.label_add_attachments'),
- dropFiles: this.I18n.t('js.label_drop_files'),
- dropFilesHint: this.I18n.t('js.label_drop_files_hint'),
- foldersWarning: this.I18n.t('js.label_drop_folders_hint'),
- };
-
- public maxFileSize:number;
-
- public $element:JQuery;
-
- constructor(readonly I18n:I18nService,
- private readonly attachmentsResourceService:AttachmentsResourceService,
- readonly configurationService:ConfigurationService,
- readonly toastService:ToastService,
- protected elementRef:ElementRef,
- protected halResourceService:HalResourceService) { }
-
- ngOnInit():void {
- this.$element = jQuery<HTMLElement>(this.elementRef.nativeElement);
-
- void this.configurationService.initialized.then(() => {
- this.maxFileSize = this.configurationService.maximumAttachmentFileSize as number;
- });
- }
-
- public triggerFileInput(event:MouseEvent):boolean {
- this.filePicker.nativeElement.click();
-
- event.preventDefault();
- event.stopPropagation();
- return false;
- }
-
- public onDropFiles(event:DragEvent):void {
- if (event.dataTransfer === null) return;
-
- // eslint-disable-next-line no-param-reassign
- event.dataTransfer.dropEffect = 'copy';
- event.preventDefault();
- event.stopPropagation();
-
- const dfFiles = event.dataTransfer.files;
- const length:number = dfFiles ? dfFiles.length : 0;
-
- const files:UploadFile[] = [];
- for (let i = 0; i < length; i++) {
- files.push(dfFiles[i]);
- }
-
- this.uploadFiles(files);
- this.draggingOver = false;
- }
-
- public onDragOver(event:DragEvent):void {
- if (event.dataTransfer !== null && AttachmentsUploadComponent.containsFiles(event.dataTransfer)) {
- // eslint-disable-next-line no-param-reassign
- event.dataTransfer.dropEffect = 'copy';
- this.draggingOver = true;
- }
-
- event.preventDefault();
- event.stopPropagation();
- }
-
- public onDragLeave(event:DragEvent):void {
- this.draggingOver = false;
- event.preventDefault();
- event.stopPropagation();
- }
-
- public onFilePickerChanged():void {
- const fileList = this.filePicker.nativeElement.files;
- if (fileList === null) return;
-
- const files:UploadFile[] = Array.from(fileList);
- this.uploadFiles(files);
- }
-
- private static containsFiles(dataTransfer:DataTransfer):boolean {
- return dataTransfer.types.indexOf('Files') >= 0;
- }
-
- protected uploadFiles(files:UploadFile[]):void {
- let uploadFiles = files || [];
- const countBefore = files.length;
- uploadFiles = this.filterFolders(uploadFiles);
-
- if (uploadFiles.length === 0) {
- // If we filtered all files as directories, show a notice
- if (countBefore > 0) {
- this.toastService.addNotice(this.text.foldersWarning);
- }
-
- return;
- }
-
- this
- .attachmentsResourceService
- .attachFiles(this.resource, uploadFiles)
- .subscribe();
- }
-
- /**
- * We try to detect folders by checking for either empty types
- * or empty file sizes.
- * @param files
- */
- protected filterFolders(files:UploadFile[]):UploadFile[] {
- return files.filter((file) => {
- // Folders never have a mime type
- if (file.type !== '') {
- return true;
- }
-
- // Files however MAY have no mime type as well
- // so fall back to checking zero or 4096 bytes
- if (file.size === 0 || file.size === 4096) {
- console.warn(`Skipping file because of file size (${file.size}) %O`, file);
- return false;
- }
-
- return true;
- });
- }
-}
diff --git a/frontend/src/app/shared/components/attachments/attachments-upload/attachments-upload.html b/frontend/src/app/shared/components/attachments/attachments-upload/attachments-upload.html
deleted file mode 100644
index 391fa2393e7..00000000000
--- a/frontend/src/app/shared/components/attachments/attachments-upload/attachments-upload.html
+++ /dev/null
@@ -1,29 +0,0 @@
-<div
- *ngIf="resource.canAddAttachments"
- class="wp-attachment-upload hide-when-print op-files-tab--file-upload"
- (drop)="onDropFiles($event)"
- (dragover)="onDragOver($event)"
- (dragleave)="onDragLeave($event)"
- [attr.aria-label]="text.uploadLabel">
- <input #hiddenFileInput
- type="file"
- id="attachment_files"
- name="attachment_files"
- (change)="onFilePickerChanged()"
- hidden
- multiple/>
- <button
- type="button"
- class="work-package--attachments--drop-box"
- (click)="triggerFileInput($event)"
- [class.-dragging]="draggingOver"
- >
- <span class="work-package--attachments--label">
- <op-icon icon-classes="icon-attachment"></op-icon>
- <label for="attachment_files">
- {{ text.dropFiles }} <br>
- {{ text.dropFilesHint }}
- </label>
- </span>
- </button>
-</div>
diff --git a/frontend/src/app/shared/components/attachments/attachments.component.html b/frontend/src/app/shared/components/attachments/attachments.component.html
new file mode 100644
index 00000000000..8a483ac802f
--- /dev/null
+++ b/frontend/src/app/shared/components/attachments/attachments.component.html
@@ -0,0 +1,66 @@
+<op-attachment-list
+ [ngClass]="{
+ 'op-attachments--list': true,
+ 'op-attachments--list_dragging': dragging
+ }"
+ *ngIf="(attachments$ | async).length"
+ [attachments]="attachments$ | async"
+ [collectionKey]="collectionKey"
+ [allowUploading]="allowUploading"
+></op-attachment-list>
+
+<input
+ *ngIf="allowUploading && resource.canAddAttachments"
+ #hiddenFileInput
+ type="file"
+ id="attachment_files"
+ name="attachment_files"
+ (change)="onFilePickerChanged()"
+ hidden
+ multiple
+/>
+
+<div
+ *ngIf="allowUploading && resource.canAddAttachments && (attachments$ | async).length"
+ class="op-attachments--actions"
+>
+ <button
+ type="button"
+ class="spot-link"
+ (click)="triggerFileInput($event)"
+ data-qa-selector="op-attachments--upload-button"
+ >
+ <span class="spot-icon spot-icon_attachment"></span>
+
+ Add attachment
+ </button>
+</div>
+
+<button
+ *ngIf="allowUploading && resource.canAddAttachments"
+ [attr.aria-label]="text.uploadLabel"
+ data-qa-selector="op-attachments--drop-box"
+ [ngClass]="{
+ 'hide-when-print': true,
+ 'op-attachments--drop-box': true,
+ 'op-attachments--drop-box_dragging': dragging,
+ 'op-attachments--drop-box_dragging-over': draggingOverDropZone,
+ 'op-attachments--drop-box_float': (attachments$ | async).length
+ }"
+ type="button"
+ (click)="triggerFileInput()"
+ (dragover)="onDragOver($event)"
+ (dragleave)="onDragLeave($event)"
+ (drop)="onDropFiles($event)"
+>
+ <span
+ class="spot-icon spot-icon_attachment op-attachments--drop-box-icon"
+ ></span>
+ <label
+ for="attachment_files"
+ class="op-attachments--drop-box-text"
+ >
+ {{ text.dropFiles }}<br>
+ {{ text.dropFilesHint }}
+ </label>
+</button>
diff --git a/frontend/src/app/shared/components/attachments/attachments.component.sass b/frontend/src/app/shared/components/attachments/attachments.component.sass
new file mode 100644
index 00000000000..73881932b45
--- /dev/null
+++ b/frontend/src/app/shared/components/attachments/attachments.component.sass
@@ -0,0 +1,85 @@
+@import "helpers"
+
+.op-attachments
+ display: flex
+ flex-direction: column
+ position: relative
+
+ &--actions
+ @include spot-body-small
+
+ &--drop-box
+ @include unset-button-styles
+ display: flex
+ justify-content: center
+ align-items: center
+ width: 100%
+ margin-top: $spot-spacing-0_75
+ border: 2px dashed var(--light-gray)
+ border-radius: 2px
+ padding: 20px
+ cursor: pointer
+ color: var(--light-gray)
+ background: rgba($spot-color-basic-white, 0.9)
+
+ &_float
+ display: none
+ position: absolute
+ top: 0
+ left: 0
+ height: 100%
+ width: 100%
+ z-index: 1
+ background: transparent
+ border: 0
+
+ &::after,
+ &::before
+ display: block
+ content: ''
+ position: absolute
+
+ &::before
+ top: -1 * $spot-spacing-0_75
+ height: calc(100% + #{$spot-spacing-1_5})
+ left: 0
+ width: 100%
+
+ left: 0
+ width: 100%
+
+ background: rgba($spot-color-basic-white, 0.9)
+ z-index: -2
+
+ &::after
+ z-index: -1
+ top: 0
+ height: 100%
+ left: $spot-spacing-0_75
+ width: calc(100% - #{$spot-spacing-1_5})
+ border: 2px dashed $spot-color-basic-gray-4
+ border-radius: 2px
+
+ &_dragging
+ display: flex
+
+ &_dragging-over::after
+ background: $spot-color-basic-gray-6
+
+ &_dragging-over:not(#{&}_float)
+ background: $spot-color-basic-gray-6
+
+ &-text
+ cursor: pointer
+ color: $spot-color-basic-gray-3
+ font-size: 0.9rem
+ font-weight: bold
+ line-height: 1.4
+ margin: 0 0 0 $spot-spacing-0_75
+ text-align: left
+
+ &-icon
+ font-size: $spot-spacing-3
+
+ &--list_dragging
+ min-height: $spot-spacing-4
diff --git a/frontend/src/app/shared/components/attachments/attachments.component.ts b/frontend/src/app/shared/components/attachments/attachments.component.ts
index cc67002db89..ef392762138 100644
--- a/frontend/src/app/shared/components/attachments/attachments.component.ts
+++ b/frontend/src/app/shared/components/attachments/attachments.component.ts
@@ -27,64 +27,104 @@
//++
import {
- Component, ElementRef, Input, OnInit,
+ ChangeDetectionStrategy,
+ ChangeDetectorRef,
+ Component,
+ ElementRef,
+ HostBinding,
+ Input,
+ OnDestroy,
+ OnInit,
+ ViewChild,
+ ViewEncapsulation,
} from '@angular/core';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { States } from 'core-app/core/states/states.service';
-import { filter } from 'rxjs/operators';
+import { filter, map, tap } from 'rxjs/operators';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
+import { populateInputsFromDataset } from 'core-app/shared/components/dataset-inputs';
+import { UploadFile } from 'core-app/core/file-upload/op-file-upload.service';
+import { AttachmentsResourceService } from 'core-app/core/state/attachments/attachments.service';
+import { ToastService } from 'core-app/shared/components/toaster/toast.service';
+import { TimezoneService } from 'core-app/core/datetime/timezone.service';
+import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
+import { IAttachment } from 'core-app/core/state/attachments/attachment.model';
+import { Observable } from 'rxjs';
-export const attachmentsSelector = 'attachments';
+function containsFiles(dataTransfer:DataTransfer):boolean {
+ return dataTransfer.types.indexOf('Files') >= 0;
+}
+
+export const attachmentsSelector = 'op-attachments';
@Component({
selector: attachmentsSelector,
- templateUrl: './attachments.html',
+ templateUrl: './attachments.component.html',
+ styleUrls: ['./attachments.component.sass'],
+ encapsulation: ViewEncapsulation.None,
+ changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class AttachmentsComponent extends UntilDestroyedMixin implements OnInit {
+export class OpAttachmentsComponent extends UntilDestroyedMixin implements OnInit, OnDestroy {
+ @HostBinding('attr.data-qa-selector') public qaSelector = 'op-attachments';
+
+ @HostBinding('id.attachments_fields') public hostId = true;
+
+ @HostBinding('class.op-attachments') public className = true;
+
@Input('resource') public resource:HalResource;
- public $element:JQuery;
+ @Input() public allowUploading = true;
- public allowUploading:boolean;
+ @Input() public destroyImmediately = true;
- public destroyImmediately:boolean;
+ public attachments$:Observable<IAttachment[]>;
- public text:any;
+ public draggingOverDropZone = false;
- constructor(protected elementRef:ElementRef,
- protected I18n:I18nService,
- protected states:States,
- protected halResourceService:HalResourceService) {
- super();
+ public dragging = false;
- this.text = {
- attachments: this.I18n.t('js.label_attachments'),
- };
- }
+ @ViewChild('hiddenFileInput') public filePicker:ElementRef<HTMLInputElement>;
- ngOnInit() {
- this.$element = jQuery(this.elementRef.nativeElement);
+ public text = {
+ attachments: this.I18n.t('js.label_attachments'),
+ uploadLabel: this.I18n.t('js.label_add_attachments'),
+ dropFiles: this.I18n.t('js.label_drop_files'),
+ dropFilesHint: this.I18n.t('js.label_drop_files_hint'),
+ foldersWarning: this.I18n.t('js.label_drop_folders_hint'),
+ };
- if (!this.resource) {
- // Parse the resource if any exists
- const source = this.$element.data('resource');
- this.resource = this.halResourceService.createHalResource(source, true);
- }
+ private get attachmentsSelfLink():string {
+ const attachments = this.resource.attachments as unknown&{ href:string };
+ return attachments.href;
+ }
- this.allowUploading = this.$element.data('allow-uploading');
+ private get collectionKey():string {
+ return isNewResource(this.resource) ? 'new' : this.attachmentsSelfLink;
+ }
- if (this.$element.data('destroy-immediately') !== undefined) {
- this.destroyImmediately = this.$element.data('destroy-immediately');
- } else {
- this.destroyImmediately = true;
- }
+ constructor(
+ public elementRef:ElementRef,
+ protected readonly I18n:I18nService,
+ protected readonly states:States,
+ protected readonly halResourceService:HalResourceService,
+ protected readonly attachmentsResourceService:AttachmentsResourceService,
+ protected readonly toastService:ToastService,
+ protected readonly timezoneService:TimezoneService,
+ protected readonly cdRef:ChangeDetectorRef,
+ ) {
+ super();
- this.setupResourceUpdateListener();
+ populateInputsFromDataset(this);
}
- public setupResourceUpdateListener() {
+ ngOnInit():void {
+ if (!(this.resource instanceof HalResource)) {
+ // Parse the resource if any exists
+ this.resource = this.halResourceService.createHalResource(this.resource, true);
+ }
+
this.states.forResource(this.resource)!.changes$()
.pipe(
this.untilDestroyed(),
@@ -93,11 +133,139 @@ export class AttachmentsComponent extends UntilDestroyedMixin implements OnInit
.subscribe((newResource:HalResource) => {
this.resource = newResource || this.resource;
});
+
+ // ensure collection is loaded to the store
+ if (!isNewResource(this.resource)) {
+ this.attachmentsResourceService.requireCollection(this.attachmentsSelfLink);
+ }
+
+ const compareCreatedAtTimestamps = (a:IAttachment, b:IAttachment):number => {
+ const rightCreatedAt = this.timezoneService.parseDatetime(b.createdAt);
+ const leftCreatedAt = this.timezoneService.parseDatetime(a.createdAt);
+ return rightCreatedAt.isBefore(leftCreatedAt) ? -1 : 1;
+ };
+
+ this.attachments$ = this
+ .attachmentsResourceService
+ .collection(this.collectionKey)
+ .pipe(
+ this.untilDestroyed(),
+ map((attachments) => attachments.sort(compareCreatedAtTimestamps)),
+ // store attachments for new resources directly into the resource. This way, the POST request to create the
+ // resource embeds the attachments and the backend reroutes the anonymous attachments to the resource.
+ tap((attachments) => {
+ if (isNewResource(this.resource)) {
+ this.resource.attachments = { elements: attachments.map((a) => a._links.self) };
+ }
+ }),
+ );
+
+ document.body.addEventListener('dragover', this.onGlobalDragOver.bind(this));
+ document.body.addEventListener('dragleave', this.onGlobalDragLeave.bind(this));
+ }
+
+ ngOnDestroy():void {
+ document.body.removeEventListener('dragover', this.onGlobalDragOver.bind(this));
+ document.body.removeEventListener('dragleave', this.onGlobalDragLeave.bind(this));
+ }
+
+ public triggerFileInput():void {
+ this.filePicker.nativeElement.click();
}
- // Only show attachment list when allow uploading is set
- // or when at least one attachment exists
- public showAttachments() {
- return this.allowUploading || _.get(this.resource, 'attachments.count', 0) > 0;
+ public onFilePickerChanged():void {
+ const fileList = this.filePicker.nativeElement.files;
+ if (fileList === null) return;
+
+ const files:UploadFile[] = Array.from(fileList);
+ this.uploadFiles(files);
+ }
+
+ public onDropFiles(event:DragEvent):void {
+ if (event.dataTransfer === null) return;
+
+ // eslint-disable-next-line no-param-reassign
+ event.dataTransfer.dropEffect = 'copy';
+ event.preventDefault();
+ event.stopPropagation();
+
+ const dfFiles = event.dataTransfer.files;
+ const length:number = dfFiles ? dfFiles.length : 0;
+
+ const files:UploadFile[] = [];
+ for (let i = 0; i < length; i++) {
+ files.push(dfFiles[i]);
+ }
+
+ this.uploadFiles(files);
+ this.draggingOverDropZone = false;
+ this.dragging = false;
+ }
+
+ public onDragOver(event:DragEvent):void {
+ if (event.dataTransfer !== null && containsFiles(event.dataTransfer)) {
+ // eslint-disable-next-line no-param-reassign
+ event.dataTransfer.dropEffect = 'copy';
+ this.draggingOverDropZone = true;
+ }
+ }
+
+ public onDragLeave(_event:DragEvent):void {
+ this.draggingOverDropZone = false;
+ }
+
+ public onGlobalDragLeave():void {
+ this.dragging = false;
+
+ this.cdRef.detectChanges();
+ }
+
+ public onGlobalDragOver():void {
+ this.dragging = true;
+
+ this.cdRef.detectChanges();
+ }
+
+ protected uploadFiles(files:UploadFile[]):void {
+ let uploadFiles = files || [];
+ const countBefore = files.length;
+ uploadFiles = this.filterFolders(uploadFiles);
+
+ if (uploadFiles.length === 0) {
+ // If we filtered all files as directories, show a notice
+ if (countBefore > 0) {
+ this.toastService.addNotice(this.text.foldersWarning);
+ }
+
+ return;
+ }
+
+ this
+ .attachmentsResourceService
+ .attachFiles(this.resource, uploadFiles)
+ .subscribe();
+ }
+
+ /**
+ * We try to detect folders by checking for either empty types
+ * or empty file sizes.
+ * @param files
+ */
+ protected filterFolders(files:UploadFile[]):UploadFile[] {
+ return files.filter((file) => {
+ // Folders never have a mime type
+ if (file.type !== '') {
+ return true;
+ }
+
+ // Files however MAY have no mime type as well
+ // so fall back to checking zero or 4096 bytes
+ if (file.size === 0 || file.size === 4096) {
+ console.warn(`Skipping file because of file size (${file.size}) %O`, file);
+ return false;
+ }
+
+ return true;
+ });
}
}
diff --git a/frontend/src/app/shared/components/attachments/attachments.html b/frontend/src/app/shared/components/attachments/attachments.html
deleted file mode 100644
index 90e12c9aee8..00000000000
--- a/frontend/src/app/shared/components/attachments/attachments.html
+++ /dev/null
@@ -1,15 +0,0 @@
-<fieldset class="form--fieldset" *ngIf="showAttachments()">
- <legend class="form--fieldset-legend">
- {{ text.attachments }}
- </legend>
- <div id="attachments_fields">
- <op-attachment-list *ngIf="resource.attachments"
- [resource]="resource">
- </op-attachment-list>
- <op-attachments-upload [resource]="resource"
- class="hide-when-print"
- *ngIf="allowUploading">
- </op-attachments-upload>
- </div>
-</fieldset>
-
diff --git a/frontend/src/app/shared/components/attachments/authoring/authoring.component.html b/frontend/src/app/shared/components/attachments/authoring/authoring.component.html
deleted file mode 100644
index 409cf6cc4c7..00000000000
--- a/frontend/src/app/shared/components/attachments/authoring/authoring.component.html
+++ /dev/null
@@ -1,17 +0,0 @@
-<div class="op-authoring">
- <span
- *ngIf="showAuthorAsLink"
- [textContent]="authorName"
- ></span>
- <a
- *ngIf="!showAuthorAsLink"
- [attr.href]="authorLink"
- [textContent]="authorName"
- ></a>
-
- <span
- class="op-authoring--timestamp"
- [textContent]="timeago"
- [attr.title]="time"
- ></span>
-</div>
diff --git a/frontend/src/app/shared/components/attachments/authoring/authoring.component.sass b/frontend/src/app/shared/components/attachments/authoring/authoring.component.sass
deleted file mode 100644
index fab996a0931..00000000000
--- a/frontend/src/app/shared/components/attachments/authoring/authoring.component.sass
+++ /dev/null
@@ -1,4 +0,0 @@
-.op-authoring
- &--timestamp:before
- content: " "
- white-space: pre
diff --git a/frontend/src/app/shared/components/attachments/authoring/authoring.component.ts b/frontend/src/app/shared/components/attachments/authoring/authoring.component.ts
deleted file mode 100644
index 8c48e7420ec..00000000000
--- a/frontend/src/app/shared/components/attachments/authoring/authoring.component.ts
+++ /dev/null
@@ -1,71 +0,0 @@
-// -- copyright
-// OpenProject is an open source project management software.
-// Copyright (C) 2012-2022 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, Input, OnInit,
-} from '@angular/core';
-import { Moment } from 'moment-timezone';
-import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
-import { TimezoneService } from 'core-app/core/datetime/timezone.service';
-import { IUser } from 'core-app/core/state/principals/user.model';
-
-@Component({
- templateUrl: './authoring.component.html',
- styleUrls: ['./authoring.component.sass'],
- selector: 'op-authoring',
- changeDetection: ChangeDetectionStrategy.OnPush,
-})
-export class AuthoringComponent implements OnInit {
- @Input() createdOn:string;
-
- @Input() author:IUser;
-
- @Input() showAuthorAsLink:boolean;
-
- public createdOnTime:Moment;
-
- public timeago:string;
-
- public time:string;
-
- public get authorName():string {
- return (this.author && this.author.name) || '';
- }
-
- public get authorLink():string {
- return (this.author && this.PathHelper.userPath(this.author.id)) || '';
- }
-
- public constructor(readonly PathHelper:PathHelperService, readonly timezoneService:TimezoneService) { }
-
- ngOnInit():void {
- this.createdOnTime = this.timezoneService.parseDatetime(this.createdOn);
- this.timeago = this.createdOnTime.fromNow();
- this.time = this.createdOnTime.format('LLL');
- }
-}
diff --git a/frontend/src/app/shared/components/attachments/openproject-attachments.module.ts b/frontend/src/app/shared/components/attachments/openproject-attachments.module.ts
index 63e5c70dcb2..e6aaabec81a 100644
--- a/frontend/src/app/shared/components/attachments/openproject-attachments.module.ts
+++ b/frontend/src/app/shared/components/attachments/openproject-attachments.module.ts
@@ -31,11 +31,9 @@ import { CommonModule } from '@angular/common';
import { IconModule } from 'core-app/shared/components/icon/icon.module';
-import { AttachmentsComponent } from './attachments.component';
-import { AttachmentListComponent } from './attachment-list/attachment-list.component';
-import { AttachmentListItemComponent } from './attachment-list/attachment-list-item.component';
-import { AttachmentsUploadComponent } from './attachments-upload/attachments-upload.component';
-import { AuthoringComponent } from './authoring/authoring.component';
+import { OpAttachmentsComponent } from './attachments.component';
+import { OpAttachmentListComponent } from './attachment-list/attachment-list.component';
+import { OpAttachmentListItemComponent } from './attachment-list/attachment-list-item.component';
@NgModule({
imports: [
@@ -43,20 +41,15 @@ import { AuthoringComponent } from './authoring/authoring.component';
IconModule,
],
declarations: [
- AttachmentsComponent,
- AttachmentListComponent,
- AttachmentListItemComponent,
- AttachmentsUploadComponent,
-
- AuthoringComponent,
+ OpAttachmentsComponent,
+ OpAttachmentListComponent,
+ OpAttachmentListItemComponent,
],
exports: [
- AttachmentsUploadComponent,
- AttachmentListComponent,
- AttachmentsComponent,
+ OpAttachmentListComponent,
+ OpAttachmentsComponent,
- AuthoringComponent,
- AttachmentListItemComponent,
+ OpAttachmentListItemComponent,
],
})
export class OpenprojectAttachmentsModule {
diff --git a/frontend/src/app/shared/components/attribute-help-texts/attribute-help-text.modal.ts b/frontend/src/app/shared/components/attribute-help-texts/attribute-help-text.modal.ts
index aed153e76cd..d7194c149b7 100644
--- a/frontend/src/app/shared/components/attribute-help-texts/attribute-help-text.modal.ts
+++ b/frontend/src/app/shared/components/attribute-help-texts/attribute-help-text.modal.ts
@@ -41,6 +41,7 @@ import { HelpTextResource } from 'core-app/features/hal/resources/help-text-reso
})
export class AttributeHelpTextModalComponent extends OpModalComponent implements OnInit {
readonly text = {
+ attachments: this.I18n.t('js.label_attachments'),
edit: this.I18n.t('js.button_edit'),
close: this.I18n.t('js.button_close'),
};
diff --git a/frontend/src/app/shared/components/attribute-help-texts/help-text.modal.html b/frontend/src/app/shared/components/attribute-help-texts/help-text.modal.html
index c9cebff7770..95b117e2d26 100644
--- a/frontend/src/app/shared/components/attribute-help-texts/help-text.modal.html
+++ b/frontend/src/app/shared/components/attribute-help-texts/help-text.modal.html
@@ -17,11 +17,15 @@
[innerHtml]="helpText.helpText.html"
></div>
- <attachments
- *ngIf="helpText && helpText.attachments.elements.length > 0"
- [resource]="helpText"
- data-allow-uploading="false"
- ></attachments>
+ <fieldset class="form--fieldset" *ngIf="helpText && helpText.attachments.elements.length > 0">
+ <legend class="form--fieldset-legend">
+ {{ text.attachments }}
+ </legend>
+ <op-attachments
+ [resource]="helpText"
+ [allowUploading]="false"
+ ></op-attachments>
+ </fieldset>
</div>
<div class="spot-action-bar">
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 c23dc73ef23..0bc8178f494 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
@@ -29,7 +29,6 @@
import {
Component, ElementRef, OnInit, ViewChild,
} from '@angular/core';
-import { ConfigurationService } from 'core-app/core/config/configuration.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';
@@ -80,6 +79,10 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl
public macros:boolean;
+ public text = {
+ attachments: this.I18n.t('js.label_attachments'),
+ };
+
// Reference to the actual ckeditor instance component
@ViewChild(OpCkeditorComponent, { static: true }) private ckEditorInstance:OpCkeditorComponent;
@@ -87,13 +90,14 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl
private isEditing = false;
- constructor(protected elementRef:ElementRef,
+ constructor(
+ protected elementRef:ElementRef,
protected pathHelper:PathHelperService,
protected halResourceService:HalResourceService,
protected Notifications:ToastService,
protected I18n:I18nService,
protected states:States,
- protected ConfigurationService:ConfigurationService) {
+ ) {
super();
}
@@ -150,7 +154,8 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl
// Listen for form submission to set textarea content
this.formElement.on('submit.ckeditor change.ckeditor', () => {
try {
- this.wrappedTextArea.val(this.ckEditorInstance.getRawData());
+ const data = this.ckEditorInstance.getRawData();
+ this.wrappedTextArea.val(data);
} catch (e) {
console.error(`Failed to save CKEditor body to textarea: ${e}.`);
this.Notifications.addError(e || this.I18n.t('js.error.internal'));
@@ -170,9 +175,19 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl
return editor;
}
+ private stopDragging() {
+ // The attachment list listens globally for drag events, but when
+ // an item gets dropped in the editor, this event never makes it to the list.
+ // Manually dispatching the event makes sure the `op-attachments` component
+ // knows we are certainly not dragging anymore.
+ const event = new DragEvent('dragleave');
+ document.body.dispatchEvent(event);
+ }
+
private setupAttachmentAddedCallback(editor:ICKEditorInstance) {
editor.model.on('op:attachment-added', () => {
this.states.forResource(this.resource!)!.putValue(this.resource);
+ this.stopDragging();
});
}
@@ -195,6 +210,7 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl
}
this.attachments = _.clone(resource!.attachments.elements);
+ this.stopDragging();
});
}
diff --git a/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.html b/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.html
index bebd9564bd0..2c7273d92b8 100644
--- a/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.html
+++ b/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.html
@@ -1,16 +1,21 @@
-<ng-container>
- <div class="op-ckeditor--wrapper">
- <op-ckeditor [context]="context"
- [content]="initialContent"
- (onInitialized)="setup($event)"
- (onContentChange)="markEdited()">
- </op-ckeditor>
- </div>
+<div class="op-ckeditor--wrapper">
+ <op-ckeditor
+ [context]="context"
+ [content]="initialContent"
+ (onInitialized)="setup($event)"
+ (onContentChange)="markEdited()"
+ ></op-ckeditor>
+</div>
- <ng-container *ngIf="resource && resource.attachments">
- <attachments [resource]="resource"
- data-allow-uploading="true"
- data-destroy-immediately="false">
- </attachments>
- </ng-container>
-</ng-container>
+<fieldset
+ class="form--fieldset"
+ *ngIf="resource && resource.attachments"
+>
+ <legend class="form--fieldset-legend">
+ {{ text.attachments }}
+ </legend>
+ <op-attachments
+ [resource]="resource"
+ [destroyImmediately]="false"
+ ></op-attachments>
+</fieldset>
diff --git a/frontend/src/app/shared/components/grids/widgets/custom-text/custom-text.component.html b/frontend/src/app/shared/components/grids/widgets/custom-text/custom-text.component.html
index 7a1f9087c83..53060907050 100644
--- a/frontend/src/app/shared/components/grids/widgets/custom-text/custom-text.component.html
+++ b/frontend/src/app/shared/components/grids/widgets/custom-text/custom-text.component.html
@@ -22,19 +22,28 @@
<div class="grid--widget-content -custom-text -allow-inner-overflow">
<div class="inline-edit--container inplace-edit">
- <edit-form-portal *ngIf="active"
- [schemaInput]="schema"
- [changeInput]="changeset"
- [editFieldHandler]="handler">
- </edit-form-portal>
- <attachments *ngIf="active"
- [resource]="resource.grid"
- data-allow-uploading="true">
- </attachments>
+ <edit-form-portal
+ *ngIf="active"
+ [schemaInput]="schema"
+ [changeInput]="changeset"
+ [editFieldHandler]="handler"
+ ></edit-form-portal>
- <div *ngIf="!active"
- class="inplace-edit--read wiki -no-label"
- [ngClass]="{'inline-edit--container': isTextEditable}">
+ <fieldset
+ *ngIf="active"
+ class="form--fieldset"
+ >
+ <legend class="form--fieldset-legend">
+ {{ text.attachments }}
+ </legend>
+ <op-attachments [resource]="resource.grid"></op-attachments>
+ </fieldset>
+
+ <div
+ *ngIf="!active"
+ class="inplace-edit--read wiki -no-label"
+ [ngClass]="{'inline-edit--container': isTextEditable}"
+ >
<button
type="button"
*ngIf="isTextEditable"
diff --git a/frontend/src/app/shared/components/grids/widgets/custom-text/custom-text.component.ts b/frontend/src/app/shared/components/grids/widgets/custom-text/custom-text.component.ts
index 62d9f124530..5e6698859a4 100644
--- a/frontend/src/app/shared/components/grids/widgets/custom-text/custom-text.component.ts
+++ b/frontend/src/app/shared/components/grids/widgets/custom-text/custom-text.component.ts
@@ -32,16 +32,22 @@ export class WidgetCustomTextComponent extends AbstractWidgetComponent implement
public customText:SafeHtml;
+ public text = {
+ attachments: this.I18n.t('js.label_attachments'),
+ };
+
@ViewChild('displayContainer') readonly displayContainer:ElementRef;
- constructor(protected i18n:I18nService,
+ constructor(
+ protected I18n:I18nService,
protected injector:Injector,
public handler:CustomTextEditFieldService,
protected cdr:ChangeDetectorRef,
protected sanitization:DomSanitizer,
protected appRef:ApplicationRef,
- protected layout:GridAreaService) {
- super(i18n, injector);
+ protected layout:GridAreaService,
+ ) {
+ super(I18n, injector);
}
ngOnInit():void {
@@ -81,7 +87,7 @@ export class WidgetCustomTextComponent extends AbstractWidgetComponent implement
}
public get placeholderText() {
- return this.i18n.t('js.grid.widgets.work_packages_overview.placeholder');
+ return this.I18n.t('js.grid.widgets.work_packages_overview.placeholder');
}
public get inplaceEditClasses() {
diff --git a/frontend/src/global_styles/content/_work_packages.sass b/frontend/src/global_styles/content/_work_packages.sass
index dbbd3eba57b..9fb416a9f49 100644
--- a/frontend/src/global_styles/content/_work_packages.sass
+++ b/frontend/src/global_styles/content/_work_packages.sass
@@ -46,7 +46,6 @@
// WP single view styles
@import work_packages/single_view/single_view
-@import work_packages/single_view/attachments
@import work_packages/single_view/work_package_comment
// WP fullscreen specific styles
diff --git a/frontend/src/global_styles/content/work_packages/single_view/_attachments.sass b/frontend/src/global_styles/content/work_packages/single_view/_attachments.sass
deleted file mode 100644
index 4d1c3e21b47..00000000000
--- a/frontend/src/global_styles/content/work_packages/single_view/_attachments.sass
+++ /dev/null
@@ -1,91 +0,0 @@
-//-- copyright
-// OpenProject is an open source project management software.
-// Copyright (C) 2012-2022 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.
-//++
-
-.attachments-container
- float: left
- margin: 0 0 30px 0
- width: 100%
- ul
- margin: 0
- padding: 0
- list-style-type: none
- li
- margin: 0
- padding: 0
- line-height: 20px
-
-.upload-file
- display: block
- width: 100%
- float: left
- margin: 20px 0 0 0
- padding: 20px 0 0 0
- border-top: 1px solid #ddd
-
-.work-package--attachments--drop-box
- @include unset-button-styles
- display: block
- width: 100%
- border: 2px dashed var(--light-gray)
- border-radius: 2px
- text-align: center
- padding: 20px
- cursor: pointer
-
- &.-dragging
- background: #f4f4f4
-
-
-.work-package--attachments--label
- color: var(--light-gray)
- text-align: center
-
- i, label
- display: inline-block
- vertical-align: middle
-
- .icon-attachment:before
- color: var(--light-gray)
- font-size: 3rem
-
- label
- cursor: pointer
- color: var(--gray-dark)
- font-size: 0.9rem
- font-weight: bold
- line-height: 1.4
- margin: 0 0 0 10px
- text-align: left
-
-
-.add-another-file
- .button
- margin-bottom: 0
-
-.work-package--attachments--draggable-item
- cursor: pointer
diff --git a/frontend/src/global_styles/content/work_packages/tabs/_tab_content.sass b/frontend/src/global_styles/content/work_packages/tabs/_tab_content.sass
index cbdbd5a7342..bce605436d5 100644
--- a/frontend/src/global_styles/content/work_packages/tabs/_tab_content.sass
+++ b/frontend/src/global_styles/content/work_packages/tabs/_tab_content.sass
@@ -48,6 +48,10 @@
padding-bottom: $spot-spacing-0_75
display: flex
align-items: center
+ position: sticky
+ top: 0
+ background: $spot-color-basic-white
+ z-index: 1
&-text
line-height: $spot-spacing-1_5
diff --git a/modules/budgets/spec/features/budgets/attachment_upload_spec.rb b/modules/budgets/spec/features/budgets/attachment_upload_spec.rb
index a795c3ffe56..deb80dce12a 100644
--- a/modules/budgets/spec/features/budgets/attachment_upload_spec.rb
+++ b/modules/budgets/spec/features/budgets/attachment_upload_spec.rb
@@ -80,4 +80,43 @@ describe 'Upload attachment to budget', js: true do
expect(page).to have_content('Image uploaded the second time')
expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png', count: 2)
end
+
+ it 'can upload an image to new and existing budgets via drag & drop on attachment list' do
+ visit projects_budgets_path(project)
+
+ within '.toolbar-items' do
+ click_on "Budget"
+ end
+
+ fill_in "Subject", with: 'New budget'
+ editor.set_markdown "Some content because it's required"
+
+ # adding an image
+ find("[data-qa-selector='op-attachments--drop-box']").drop(image_fixture.path)
+
+ expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png')
+
+ click_on 'Create'
+
+ expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png')
+
+ within '.toolbar-items' do
+ click_on "Update"
+ end
+
+ script = <<~JS
+ const event = new DragEvent('dragover');
+ document.body.dispatchEvent(event);
+ JS
+ page.execute_script(script)
+
+ # adding an image
+ find("[data-qa-selector='op-attachments--drop-box']").drop(image_fixture.path)
+
+ expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png', count: 2)
+
+ click_on 'Submit'
+
+ expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png', count: 2)
+ end
end
diff --git a/modules/documents/spec/features/attachment_upload_spec.rb b/modules/documents/spec/features/attachment_upload_spec.rb
index 574d7a267e5..0cdae71d22e 100644
--- a/modules/documents/spec/features/attachment_upload_spec.rb
+++ b/modules/documents/spec/features/attachment_upload_spec.rb
@@ -67,9 +67,15 @@ describe 'Upload attachment to documents',
select(category.name, from: 'Category')
fill_in "Title", with: 'New documentation'
+ # adding an image via the attachments-list
+ find("[data-qa-selector='op-attachments--drop-box']").drop(image_fixture.path)
+
+ expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png', count: 1)
+
# adding an image
editor.drag_attachment image_fixture.path, 'Image uploaded on creation'
- expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png')
+ expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png', count: 2)
+ expect(page).not_to have_selector('op-toasters-upload-progress')
perform_enqueued_jobs do
click_on 'Create'
@@ -97,9 +103,28 @@ describe 'Upload attachment to documents',
# editor.click_and_type_slowly 'abc'
SeleniumHubWaiter.wait
- editor.drag_attachment image_fixture.path, 'Image uploaded the second time'
+
expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png', count: 2)
+ editor.drag_attachment image_fixture.path, 'Image uploaded the second time'
+
+ expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png', count: 3)
+
+ scroll_to_element(page.find('[data-qa-selector="op-attachments"]'))
+
+ script = <<~JS
+ const event = new DragEvent('dragover');
+ document.body.dispatchEvent(event);
+ JS
+ page.execute_script(script)
+
+ # adding an image via the attachments-list
+ find("[data-qa-selector='op-attachments--drop-box']").drop(image_fixture.path)
+
+ expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png', count: 4)
+
+ expect(page).not_to have_selector('op-toasters-upload-progress')
+
perform_enqueued_jobs do
click_on 'Save'
end
@@ -108,7 +133,7 @@ describe 'Upload attachment to documents',
expect(page).to have_selector('#content img', count: 2)
expect(page).to have_content('Image uploaded on creation')
expect(page).to have_content('Image uploaded the second time')
- expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png', count: 2)
+ expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png', count: 4)
# Expect a mail to be sent to the user having subscribed to all notifications
expect(ActionMailer::Base.deliveries.size)
diff --git a/modules/meeting/spec/features/meetings_attachments_spec.rb b/modules/meeting/spec/features/meetings_attachments_spec.rb
index 2c45a61b4f7..625ebb80290 100644
--- a/modules/meeting/spec/features/meetings_attachments_spec.rb
+++ b/modules/meeting/spec/features/meetings_attachments_spec.rb
@@ -58,7 +58,7 @@ describe 'Add an attachment to a meeting (agenda)', js: true do
it 'can upload an image via attaching and drag & drop' do
# called the same for all Wysiwyg dditors no matter if for work packages
# or not
- container = page.find('.wp-attachment-upload')
+ container = page.find('[data-qa-selector="op-attachments"]')
scroll_to_element(container)
##
diff --git a/spec/features/forums/attachment_upload_spec.rb b/spec/features/forums/attachment_upload_spec.rb
index 4af05fe4fa4..b5a0533b11e 100644
--- a/spec/features/forums/attachment_upload_spec.rb
+++ b/spec/features/forums/attachment_upload_spec.rb
@@ -89,4 +89,45 @@ describe 'Upload attachment to forum message', js: true do
expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png', count: 2)
end
+
+ it 'can upload an image to new and existing messages via drag & drop on attachments' do
+ index_page.visit!
+ click_link forum.name
+
+ create_page = index_page.click_create_message
+ create_page.set_subject 'A new message'
+
+ expect(page).not_to have_selector('[data-qa-selector="op-attachment-list-item"]')
+
+ editor.set_markdown "Some text because it's required"
+
+ # adding an image
+ find("[data-qa-selector='op-attachments--drop-box']").drop(image_fixture.path)
+
+ expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png')
+ expect(page).not_to have_selector('op-toasters-upload-progress')
+
+ show_page = create_page.click_save
+
+ expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png')
+
+ within '.toolbar-items' do
+ click_on "Edit"
+ end
+
+ script = <<~JS
+ const event = new DragEvent('dragover');
+ document.body.dispatchEvent(event);
+ JS
+ page.execute_script(script)
+
+ find("[data-qa-selector='op-attachments--drop-box']").drop(image_fixture.path)
+
+ expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png', count: 2)
+ expect(page).not_to have_selector('op-toasters-upload-progress')
+
+ show_page.click_save
+
+ expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png', count: 2)
+ end
end
diff --git a/spec/features/statuses/read_only_statuses_spec.rb b/spec/features/statuses/read_only_statuses_spec.rb
index 31b9bb58635..12e43d7a70a 100644
--- a/spec/features/statuses/read_only_statuses_spec.rb
+++ b/spec/features/statuses/read_only_statuses_spec.rb
@@ -75,7 +75,7 @@ describe 'Read-only statuses affect work package editing',
it 'locks the work package on a read only status' do
wp_page.switch_to_tab(tab: 'FILES')
- expect(page).to have_selector '.work-package--attachments--drop-box'
+ expect(page).to have_selector '[data-qa-selector="op-attachments--drop-box"]'
subject_field = wp_page.edit_field :subject
subject_field.activate!
@@ -94,6 +94,6 @@ describe 'Read-only statuses affect work package editing',
subject_field.expect_read_only
# Expect attachments not available
- expect(page).to have_no_selector '.work-package--attachments--drop-box'
+ expect(page).not_to have_selector '[data-qa-selector="op-attachments--drop-box"]'
end
end
diff --git a/spec/features/wiki/attachment_upload_spec.rb b/spec/features/wiki/attachment_upload_spec.rb
index 5329c592039..a707cc89fb9 100644
--- a/spec/features/wiki/attachment_upload_spec.rb
+++ b/spec/features/wiki/attachment_upload_spec.rb
@@ -45,7 +45,7 @@ describe 'Upload attachment to wiki page', js: true do
login_as(user)
end
- it 'can upload an image to new and existing wiki page via drag & drop' do
+ it 'can upload an image to new and existing wiki page via drag & drop in editor' do
visit project_wiki_path(project, 'test')
# adding an image
@@ -102,4 +102,46 @@ describe 'Upload attachment to wiki page', js: true do
expect(wiki_page_content).to have_selector '.op-uc-image[src^="/api/v3/attachments"]'
end
+
+ it 'can upload an image to new and existing wiki page via drag & drop on attachments' do
+ visit project_wiki_path(project, 'test')
+
+ expect(page).not_to have_selector('[data-qa-selector="op-attachment-list-item"]')
+
+ # adding an image
+ find("[data-qa-selector='op-attachments--drop-box']").drop(image_fixture.path)
+
+ expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png')
+ expect(page).not_to have_selector('op-toasters-upload-progress')
+
+ click_on 'Save'
+
+ expect(page).to have_text("Successful creation")
+ expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png')
+
+ # required sleep otherwise clicking on the Edit button doesn't do anything
+ SeleniumHubWaiter.wait
+
+ within '.toolbar-items' do
+ click_on "Edit"
+ end
+
+ expect(page).to have_selector('.ck-editor__editable', wait: 5)
+
+ script = <<~JS
+ const event = new DragEvent('dragover');
+ document.body.dispatchEvent(event);
+ JS
+ page.execute_script(script)
+
+ # adding an image
+ find("[data-qa-selector='op-attachments--drop-box']").drop(image_fixture.path)
+
+ expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png', count: 2)
+ expect(page).not_to have_selector('op-toasters-upload-progress')
+
+ click_on 'Save'
+ expect(page).to have_text("Successful update")
+ expect(page).to have_selector('[data-qa-selector="op-attachment-list-item"]', text: 'image.png', count: 2)
+ end
end
diff --git a/spec/features/work_packages/attachments/attachment_upload_spec.rb b/spec/features/work_packages/attachments/attachment_upload_spec.rb
index 4a0ed6ebd8e..9ab1ab9c018 100644
--- a/spec/features/work_packages/attachments/attachment_upload_spec.rb
+++ b/spec/features/work_packages/attachments/attachment_upload_spec.rb
@@ -134,7 +134,7 @@ describe 'Upload attachment to work package', js: true do
scroll_to_and_click find('#work-packages--edit-actions-save')
- new_page.expect_toast(
+ new_page.expect_and_dismiss_toaster(
message: 'Successful creation.'
)
@@ -247,7 +247,7 @@ describe 'Upload attachment to work package', js: true do
describe 'attachment dropzone' do
it 'can drag something to the files tab and have it open' do
wp_page.expect_tab 'Activity'
- attachments.drag_and_drop_file '.wp-attachment-upload',
+ attachments.drag_and_drop_file '[data-qa-selector="op-attachments--drop-box"]',
image_fixture.path,
:center,
page.find('[data-qa-tab-id="files"]')
@@ -270,7 +270,7 @@ describe 'Upload attachment to work package', js: true do
it 'can upload an image via attaching and drag & drop' do
wp_page.switch_to_tab(tab: 'files')
- container = page.find('.wp-attachment-upload')
+ container = page.find('[data-qa-selector="op-attachments--drop-box"]')
##
# Attach file manually
diff --git a/spec/features/work_packages/tabs/files_tab_spec.rb b/spec/features/work_packages/tabs/files_tab_spec.rb
index 37a6b228c45..bcf15b389a9 100644
--- a/spec/features/work_packages/tabs/files_tab_spec.rb
+++ b/spec/features/work_packages/tabs/files_tab_spec.rb
@@ -47,13 +47,13 @@ describe 'Files tab', js: true do
context 'if on work packages full view' do
it 'must open files tab' do
wp_page.switch_to_tab tab: 'activity'
- expect(page).not_to have_selector '.work-package--attachments--drop-box'
+ expect(page).not_to have_selector '[data-qa-selector="op-attachments--drop-box"]'
files_link = wp_page.find('.work-packages--files-container .attributes-group--icon-indented-text a')
files_link.click
expect(page).to have_current_path project_work_package_path(project, work_package, 'files')
- expect(page).to have_selector '.work-package--attachments--drop-box'
+ expect(page).to have_selector '[data-qa-selector="op-attachments--drop-box"]'
end
end
@@ -62,13 +62,13 @@ describe 'Files tab', js: true do
it 'must open files tab' do
wp_page.switch_to_tab tab: 'overview'
- expect(page).not_to have_selector '.work-package--attachments--drop-box'
+ expect(page).not_to have_selector '[data-qa-selector="op-attachments--drop-box"]'
files_link = wp_page.find('.work-packages--files-container .attributes-group--icon-indented-text a')
files_link.click
expect(page).to have_current_path project_work_packages_path(project) + "/details/#{work_package.id}/files"
- expect(page).to have_selector '.work-package--attachments--drop-box'
+ expect(page).to have_selector '[data-qa-selector="op-attachments--drop-box"]'
end
end
end