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

[#46254] Resolve conflict with files with the same name when upload

Eric Schubert863e91d80263
diff --git a/frontend/src/app/core/state/compare-id.ts b/frontend/src/app/core/state/compare-id.ts
new file mode 100644
index 00000000000..d8556ec2a6b
--- /dev/null
+++ b/frontend/src/app/core/state/compare-id.ts
@@ -0,0 +1,33 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2023 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 { ID } from '@datorama/akita';
+
+export default function compareId(a:ID, b:ID):boolean {
+ return String(a) === String(b);
+}
diff --git a/frontend/src/app/shared/components/modal/modal-overlay.component.html b/frontend/src/app/shared/components/modal/modal-overlay.component.html
index 3d9411c16dd..53292f0137a 100644
--- a/frontend/src/app/shared/components/modal/modal-overlay.component.html
+++ b/frontend/src/app/shared/components/modal/modal-overlay.component.html
@@ -1,6 +1,7 @@
<div
class="spot-modal-overlay"
[class.spot-modal-overlay_active]="(activeModalInstance$ | async) !== null"
+ [class.spot-modal-overlay_not-active]="(activeModalInstance$ | async) === null"
[class.spot-modal-overlay_not-full-screen]="notFullscreen"
#overlay
tabindex="0"
diff --git a/frontend/src/app/shared/components/modal/modal-overlay.component.ts b/frontend/src/app/shared/components/modal/modal-overlay.component.ts
index 3192be67d0d..549be54aa61 100644
--- a/frontend/src/app/shared/components/modal/modal-overlay.component.ts
+++ b/frontend/src/app/shared/components/modal/modal-overlay.component.ts
@@ -38,9 +38,12 @@ import {
CdkPortalOutlet,
ComponentPortal,
} from '@angular/cdk/portal';
+import { combineLatest } from 'rxjs';
+import { distinctUntilChanged } from 'rxjs/operators';
+
import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { OpModalService } from 'core-app/shared/components/modal/modal.service';
-import { OpModalComponent } from './modal.component';
+import { OpModalComponent } from 'core-app/shared/components/modal/modal.component';
+import { ModalData, OpModalService } from 'core-app/shared/components/modal/modal.service';
export const opModalOverlaySelector = 'op-modal-overlay';
@@ -67,7 +70,7 @@ export class OpModalOverlayComponent {
activeModalData$ = this.modalService.activeModalData$;
- activeModalInstance$ = this.modalService.activeModalInstance$.asObservable();
+ activeModalInstance$ = this.modalService.activeModalInstance$;
constructor(
readonly modalService:OpModalService,
@@ -76,45 +79,25 @@ export class OpModalOverlayComponent {
) {}
setupListener():void {
- this.activeModalData$
- .subscribe((modalData) => {
- this.notFullscreen = false;
-
- if (modalData === null) {
- const ref = (this.portalOutlet.attachedRef as ComponentRef<OpModalComponent>);
- if (!ref) {
- return;
- }
-
- if (!ref.instance.onClose()) {
- return;
- }
-
- ref.instance.closingEvent.emit(ref.instance);
- this.modalService.activeModalInstance$.next(null);
-
- this.portalOutlet.detach();
+ combineLatest([
+ this.activeModalInstance$,
+ // multiple 'closing' events in a row are squashed
+ this.activeModalData$.pipe(distinctUntilChanged()),
+ ])
+ .subscribe(([instance, data]) => {
+ if (instance === null && data === null) {
+ // do nothing
+ return;
+ }
+ if (instance !== null && data === null) {
+ this.detachPortalInstance();
return;
}
- const {
- modal,
- injector,
- notFullscreen,
- } = modalData;
- this.notFullscreen = notFullscreen;
- const portal = new ComponentPortal(modal, null, injector);
- const ref = this.portalOutlet.attach(portal);
- const instance = ref.instance;
- this.modalService.activeModalInstance$.next(instance);
- this.cdRef.detectChanges();
-
- // Focus on wrapper by default
- (this.overlay.nativeElement as HTMLElement).focus();
-
- // Focus on the first element
- instance && instance.onOpen();
+ if (instance === null && data !== null) {
+ this.createAndAttachPortalInstance(data);
+ }
});
}
@@ -124,4 +107,36 @@ export class OpModalOverlayComponent {
}
this.modalService.close();
}
+
+ private detachPortalInstance():void {
+ const ref = (this.portalOutlet.attachedRef as ComponentRef<OpModalComponent>);
+ if (!ref) {
+ return;
+ }
+
+ if (!ref.instance.onClose()) {
+ return;
+ }
+
+ ref.instance.closingEvent.emit(ref.instance);
+ this.portalOutlet.detach();
+ this.modalService.activeModalInstance$.next(null);
+ }
+
+ private createAndAttachPortalInstance(data:ModalData):void {
+ const { modal, injector, notFullscreen } = data;
+ this.notFullscreen = notFullscreen;
+ const portal = new ComponentPortal(modal, null, injector);
+ const ref = this.portalOutlet.attach(portal);
+ const instance = ref.instance;
+
+ this.modalService.activeModalInstance$.next(instance);
+ this.cdRef.detectChanges();
+
+ // Focus on wrapper by default
+ (this.overlay.nativeElement as HTMLElement).focus();
+
+ // Focus on the first element
+ instance && instance.onOpen();
+ }
}
diff --git a/frontend/src/app/shared/components/modal/modal.component.ts b/frontend/src/app/shared/components/modal/modal.component.ts
index d240eb8c90a..bcbd4adc95b 100644
--- a/frontend/src/app/shared/components/modal/modal.component.ts
+++ b/frontend/src/app/shared/components/modal/modal.component.ts
@@ -1,8 +1,37 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2023 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 {
- ChangeDetectorRef, Directive, ElementRef, EventEmitter, OnDestroy, OnInit,
+ ChangeDetectorRef, Directive, ElementRef, EventEmitter, Inject, OnDestroy, OnInit,
} from '@angular/core';
+
import { OpModalLocalsMap } from 'core-app/shared/components/modal/modal.types';
-import { OpModalService } from 'core-app/shared/components/modal/modal.service';
+import { OpModalLocalsToken, OpModalService } from 'core-app/shared/components/modal/modal.service';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
@Directive()
@@ -21,7 +50,7 @@ export abstract class OpModalComponent extends UntilDestroyedMixin implements On
public data:unknown;
protected constructor(
- public locals:OpModalLocalsMap,
+ @Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,
readonly cdRef:ChangeDetectorRef,
readonly elementRef:ElementRef,
) {
diff --git a/frontend/src/app/shared/components/modal/modal.service.ts b/frontend/src/app/shared/components/modal/modal.service.ts
index 78f8bbc9d10..40c5d67a98b 100644
--- a/frontend/src/app/shared/components/modal/modal.service.ts
+++ b/frontend/src/app/shared/components/modal/modal.service.ts
@@ -32,22 +32,24 @@ import {
Injector,
} from '@angular/core';
import { ComponentType, PortalInjector } from '@angular/cdk/portal';
+import { BehaviorSubject, Observable } from 'rxjs';
+import { filter } from 'rxjs/operators';
import { OpModalComponent } from 'core-app/shared/components/modal/modal.component';
-import { Observable, ReplaySubject } from 'rxjs';
-import { filter, take } from 'rxjs/operators';
-export const OpModalLocalsToken = new InjectionToken<any>('OP_MODAL_LOCALS');
+export const OpModalLocalsToken = new InjectionToken<never>('OP_MODAL_LOCALS');
+
+export interface ModalData {
+ modal:ComponentType<OpModalComponent>;
+ injector:Injector;
+ notFullscreen:boolean;
+}
@Injectable({ providedIn: 'root' })
export class OpModalService {
- public activeModalInstance$ = new ReplaySubject<OpModalComponent|null>(1);
+ public activeModalInstance$ = new BehaviorSubject<OpModalComponent|null>(null);
- public activeModalData$ = new ReplaySubject<{
- modal:ComponentType<OpModalComponent>,
- injector:Injector,
- notFullscreen:boolean,
- }|null>(1);
+ public activeModalData$ = new BehaviorSubject<ModalData|null>(null);
constructor(
private readonly injector:Injector,
@@ -69,6 +71,7 @@ export class OpModalService {
* @param injector The injector to pass into the component. Ensure this is the hierarchical injector if needed.
* Can be passed 'global' to take the default (global!) injector of this service.
* @param locals A map to be injected via token into the component.
+ * @param notFullscreen
*/
public show<T extends OpModalComponent>(
modal:ComponentType<T>,
@@ -90,10 +93,7 @@ export class OpModalService {
});
return this.activeModalInstance$
- .pipe(
- filter((m) => m !== null),
- take(1),
- ) as Observable<T>;
+ .pipe(filter((m) => m instanceof modal)) as Observable<T>;
}
/**
diff --git a/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.ts b/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.ts
index 42498c40147..f5346b435fd 100644
--- a/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.ts
+++ b/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.ts
@@ -78,6 +78,10 @@ export class LocationPickerModalComponent extends FilePickerBaseModalComponent {
return this.currentDirectory.id as string;
}
+ public get filesAtLocation():IStorageFile[] {
+ return this.storageFiles$.getValue();
+ }
+
public get canChooseLocation():boolean {
if (!this.currentDirectory) {
return false;
diff --git a/frontend/src/app/shared/components/storages/openproject-storages.module.ts b/frontend/src/app/shared/components/storages/openproject-storages.module.ts
index c6225a40cd8..a55edac9522 100644
--- a/frontend/src/app/shared/components/storages/openproject-storages.module.ts
+++ b/frontend/src/app/shared/components/storages/openproject-storages.module.ts
@@ -54,6 +54,9 @@ import {
import {
LoadingFileListComponent,
} from 'core-app/shared/components/storages/loading-file-list/loading-file-list.component';
+import {
+ UploadConflictModalComponent,
+} from 'core-app/shared/components/storages/upload-conflict-modal/upload-conflict-modal.component';
@NgModule({
imports: [
@@ -71,6 +74,7 @@ import {
StorageInformationComponent,
StorageFileListItemComponent,
SortFilesPipe,
+ UploadConflictModalComponent,
],
exports: [
StorageComponent,
diff --git a/frontend/src/app/shared/components/storages/storage/interfaces.ts b/frontend/src/app/shared/components/storages/storage/interfaces.ts
new file mode 100644
index 00000000000..c11d245d5a0
--- /dev/null
+++ b/frontend/src/app/shared/components/storages/storage/interfaces.ts
@@ -0,0 +1,45 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2023 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 { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';
+
+export interface UploadData {
+ file:File;
+ location:string;
+ overwrite:boolean|null;
+}
+
+export interface LocationData {
+ location:string;
+ files:IStorageFile[];
+}
+
+export interface FileUploadResponse {
+ file_name:string;
+ file_id:number;
+}
diff --git a/frontend/src/app/shared/components/storages/storage/storage.component.ts b/frontend/src/app/shared/components/storages/storage/storage.component.ts
index 5a9dc3cef3b..3eda4560c90 100644
--- a/frontend/src/app/shared/components/storages/storage/storage.component.ts
+++ b/frontend/src/app/shared/components/storages/storage/storage.component.ts
@@ -42,7 +42,12 @@ import {
HttpEventType,
HttpResponse,
} from '@angular/common/http';
-import { BehaviorSubject, Observable, throwError } from 'rxjs';
+import {
+ BehaviorSubject,
+ Observable,
+ of,
+ throwError,
+} from 'rxjs';
import {
catchError,
filter,
@@ -83,11 +88,18 @@ import {
LocationPickerModalComponent,
} from 'core-app/shared/components/storages/location-picker-modal/location-picker-modal.component';
import { ToastService } from 'core-app/shared/components/toaster/toast.service';
-import { UploadFile } from 'core-app/core/file-upload/op-file-upload.service';
import { StorageFilesResourceService } from 'core-app/core/state/storage-files/storage-files.service';
import { IUploadLink } from 'core-app/core/state/storage-files/upload-link.model';
+import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
+import {
+ UploadConflictModalComponent,
+} from 'core-app/shared/components/storages/upload-conflict-modal/upload-conflict-modal.component';
+import { EXTERNAL_REQUEST_HEADER } from 'core-app/features/hal/http/openproject-header-interceptor';
+import { FileUploadResponse, LocationData, UploadData } from 'core-app/shared/components/storages/storage/interfaces';
+import isNotNull from 'core-app/core/state/is-not-null';
+import compareId from 'core-app/core/state/compare-id';
@Component({
selector: 'op-storage',
@@ -197,9 +209,9 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnD
};
constructor(
+ private readonly http:HttpClient,
private readonly i18n:I18nService,
private readonly cdRef:ChangeDetectorRef,
- private readonly http:HttpClient,
private readonly toastService:ToastService,
private readonly cookieService:CookieService,
private readonly opModalService:OpModalService,
@@ -276,43 +288,70 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnD
const fileList = this.filePicker.nativeElement.files;
if (fileList === null) return;
- this.openSelectLocationDialog(fileList[0]);
+ this.storageFileUpload(fileList[0]);
// reset file input, so that selecting the same file again triggers a change
this.filePicker.nativeElement.value = '';
}
- private openSelectLocationDialog(file:File):void {
+ private storageFileUpload(file:File):void {
+ this.selectUploadLocation()
+ .pipe(
+ switchMap((data) => this.resolveUploadConflicts(file, data.files, data.location)),
+ )
+ .subscribe((data) => {
+ this.uploadAndCreateFileLink(data);
+ });
+ }
+
+ private selectUploadLocation():Observable<LocationData> {
const locals = {
storageType: this.storage._links.type.href,
storageName: this.storage.name,
storageLink: this.storage._links.self,
};
- this.opModalService.show<LocationPickerModalComponent>(LocationPickerModalComponent, 'global', locals)
- .subscribe((m) => {
- m.closingEvent.subscribe((modal) => {
- if (modal.submitted) {
- this.uploadFile(file, modal.location);
- }
- });
- });
+
+ return this.opModalService.show<LocationPickerModalComponent>(LocationPickerModalComponent, 'global', locals)
+ .pipe(
+ switchMap((modal) => modal.closingEvent),
+ filter((modal) => modal.submitted),
+ take(1),
+ map((modal) => ({ location: modal.location, files: modal.filesAtLocation })),
+ );
+ }
+
+ private resolveUploadConflicts(file:File, storageFiles:IStorageFile[], location:string):Observable<UploadData> {
+ const conflict = storageFiles.find((f) => f.name === file.name);
+ if (!conflict) {
+ return of({ file, location, overwrite: null });
+ }
+
+ return this.opModalService.show<UploadConflictModalComponent>(UploadConflictModalComponent, 'global', { fileName: file.name })
+ .pipe(
+ switchMap((modal) => modal.closingEvent),
+ filter((modal) => modal.overwrite !== null),
+ take(1),
+ map((modal) => ({ file, location, overwrite: modal.overwrite })),
+ );
}
- private uploadFile(file:UploadFile, locationId:string):void {
+ private uploadAndCreateFileLink(data:UploadData):void {
let isUploadError = false;
this.storageFilesResourceService
- .uploadLink(this.uploadResourceLink(file.name, locationId))
+ .uploadLink(this.uploadResourceLink(data.file.name, data.location))
.pipe(
- switchMap((link) => this.uploadAndNotify(link, file)),
+ switchMap((link) => this.uploadAndNotify(link, data.file, data.overwrite)),
catchError((error) => {
isUploadError = true;
return throwError(error);
}),
- switchMap((f) => this.fileLinkResourceService.addFileLinks(
+ switchMap((uploadResponse) => this.createFileLinkData(data.file, uploadResponse)),
+ filter(isNotNull),
+ switchMap((file) => this.fileLinkResourceService.addFileLinks(
this.collectionKey,
this.addFileLinksHref,
this.storage._links.self,
- [f],
+ [file],
)),
)
.subscribe(
@@ -321,9 +360,9 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnD
},
(error) => {
if (isUploadError) {
- this.handleUploadError(error as HttpErrorResponse, file.name);
+ this.handleUploadError(error as HttpErrorResponse, data.file.name);
} else {
- this.toastService.addError(this.text.toast.linkingAfterUploadFailed(file.name, this.resource.id as string));
+ this.toastService.addError(this.text.toast.linkingAfterUploadFailed(data.file.name, this.resource.id as string));
}
console.error(error);
@@ -347,23 +386,20 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnD
}
}
- private uploadAndNotify(link:IUploadLink, file:UploadFile):Observable<IFileLinkOriginData> {
+ private uploadAndNotify(link:IUploadLink, file:File, overwrite:boolean|null):Observable<FileUploadResponse> {
const { method, href } = link._links.destination;
- interface FileUploadResponse {
- file_name:string;
- file_id:string;
- }
-
const formData = new FormData();
formData.append('file', file, file.name);
- formData.append('overwrite', 'false');
+ if (overwrite !== null) {
+ formData.append('overwrite', String(overwrite));
+ }
const observable = this.http.request<FileUploadResponse>(
method,
href,
{
body: formData,
- headers: { 'X-External-Request': 'true' },
+ headers: { [EXTERNAL_REQUEST_HEADER]: 'true' },
observe: 'events',
reportProgress: true,
responseType: 'json',
@@ -387,10 +423,25 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnD
throw new Error('Upload data is null.');
}
+ return data;
+ }),
+ );
+ }
+
+ private createFileLinkData(file:File, response:FileUploadResponse):Observable<IFileLinkOriginData|null> {
+ return this.fileLinks$
+ .pipe(
+ take(1),
+ map((fileLinks) => {
+ const existingFileLink = fileLinks.find((l) => compareId(l.originData.id, response.file_id));
+ if (existingFileLink) {
+ return null;
+ }
+
const now = this.timezoneService.parseDate(new Date()).toISOString();
return ({
- id: data.file_id,
- name: data.file_name,
+ id: response.file_id,
+ name: response.file_name,
mimeType: file.type,
size: file.size,
createdAt: now,
@@ -516,7 +567,7 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnD
return;
}
- this.openSelectLocationDialog(files[0]);
+ this.storageFileUpload(files[0]);
}
public onDragOver(event:DragEvent):void {
diff --git a/frontend/src/app/shared/components/storages/upload-conflict-modal/upload-conflict-modal.component.html b/frontend/src/app/shared/components/storages/upload-conflict-modal/upload-conflict-modal.component.html
new file mode 100644
index 00000000000..277f3157edc
--- /dev/null
+++ b/frontend/src/app/shared/components/storages/upload-conflict-modal/upload-conflict-modal.component.html
@@ -0,0 +1,48 @@
+<div
+ class="spot-modal"
+>
+ <div
+ class="spot-modal--header"
+ >
+ <span
+ class="spot-modal--header-title"
+ [textContent]="text.header"
+ ></span>
+ </div>
+
+ <div
+ class="spot-modal--body spot-container"
+ >
+ <span
+ class="spot-body-small"
+ [textContent]="text.body()"
+ ></span>
+ </div>
+
+ <div
+ class="spot-action-bar"
+ >
+ <div
+ class="spot-action-bar--right"
+ >
+ <button
+ type="button"
+ class="button spot-action-bar--action"
+ [textContent]="text.buttons.cancel"
+ (click)="closeMe()"
+ ></button>
+ <button
+ type="button"
+ class="button spot-action-bar--action"
+ [textContent]="text.buttons.keepBoth"
+ (click)="close(false)"
+ ></button>
+ <button
+ type="button"
+ class="button spot-action-bar--action -highlight"
+ [textContent]="text.buttons.replace"
+ (click)="close(true)"
+ ></button>
+ </div>
+ </div>
+</div>
diff --git a/frontend/src/app/shared/components/storages/upload-conflict-modal/upload-conflict-modal.component.ts b/frontend/src/app/shared/components/storages/upload-conflict-modal/upload-conflict-modal.component.ts
new file mode 100644
index 00000000000..178b11d4561
--- /dev/null
+++ b/frontend/src/app/shared/components/storages/upload-conflict-modal/upload-conflict-modal.component.ts
@@ -0,0 +1,72 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2023 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,
+ ChangeDetectorRef,
+ Component,
+ ElementRef,
+ Inject,
+} from '@angular/core';
+
+import { I18nService } from 'core-app/core/i18n/i18n.service';
+import { OpModalLocalsMap } from 'core-app/shared/components/modal/modal.types';
+import { OpModalComponent } from 'core-app/shared/components/modal/modal.component';
+import { OpModalLocalsToken } from 'core-app/shared/components/modal/modal.service';
+
+@Component({
+ templateUrl: 'upload-conflict-modal.component.html',
+ changeDetection: ChangeDetectionStrategy.OnPush,
+})
+export class UploadConflictModalComponent extends OpModalComponent {
+ public overwrite:boolean|null = null;
+
+ public text = {
+ header: this.i18n.t('js.storages.files.already_existing_header'),
+ body: () => this.i18n.t('js.storages.files.already_existing_body', { fileName: this.locals.fileName as string }),
+ buttons: {
+ keepBoth: this.i18n.t('js.storages.files.upload_keep_both'),
+ replace: this.i18n.t('js.storages.files.upload_replace'),
+ cancel: this.i18n.t('js.button_cancel'),
+ },
+ };
+
+ public constructor(
+ @Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,
+ readonly cdRef:ChangeDetectorRef,
+ readonly elementRef:ElementRef,
+ private readonly i18n:I18nService,
+ ) {
+ super(locals, cdRef, elementRef);
+ }
+
+ public close(overwrite:boolean):void {
+ this.overwrite = overwrite;
+ this.service.close();
+ }
+}
diff --git a/modules/storages/config/locales/js-en.yml b/modules/storages/config/locales/js-en.yml
index 2b36d21162e..12f0c5b02a4 100644
--- a/modules/storages/config/locales/js-en.yml
+++ b/modules/storages/config/locales/js-en.yml
@@ -29,11 +29,17 @@ en:
To add a link, see or upload files related to this work package, please login to %{storageType}.
files:
+ already_existing_header: "This file already exists"
+ already_existing_body: >
+ A file with the name "%{fileName}" already exists in the location, where you are trying
+ to upload this file. What would you like to do?
directory_not_writeable: "You do not have to permission to add files to this folder."
dragging_many_files: "The upload to %{storageType} supports only one file at once."
empty_folder: "This folder is empty."
empty_folder_location_hint: "Click the button below to upload the file to this location."
file_not_selectable_location: "Selecting a file is not possible in the process of choosing a location."
+ upload_keep_both: "Keep both"
+ upload_replace: "Replace"
file_links:
empty: >
@@ -41,8 +47,8 @@ en:
within %{storageType}.
download: "Download %{fileName}"
no_permission: "You have no permission to see this file."
- open: 'Open file on storage'
- open_location: 'Open file in location'
+ open: "Open file on storage"
+ open_location: "Open file in location"
remove: "Remove file link"
remove_confirmation: >
Are you sure you want to unlink the file from this work package? Unlinking does not affect the original file