diff --git a/src/app/features/registries/components/custom-step/custom-step.component.ts b/src/app/features/registries/components/custom-step/custom-step.component.ts index 59721646c..e32768270 100644 --- a/src/app/features/registries/components/custom-step/custom-step.component.ts +++ b/src/app/features/registries/components/custom-step/custom-step.component.ts @@ -29,10 +29,11 @@ import { FormBuilder, FormControl, FormGroup, FormsModule, ReactiveFormsModule, import { ActivatedRoute, Router } from '@angular/router'; import { InfoIconComponent } from '@osf/shared/components'; -import { INPUT_VALIDATION_MESSAGES } from '@osf/shared/constants'; +import { FILE_COUNT_ATTACHMENTS_LIMIT, INPUT_VALIDATION_MESSAGES } from '@osf/shared/constants'; import { FieldType } from '@osf/shared/enums'; import { CustomValidators, findChangedFields } from '@osf/shared/helpers'; import { FilePayloadJsonApi, OsfFile, PageSchema } from '@osf/shared/models'; +import { ToastService } from '@osf/shared/services'; import { FilesMapper } from '../../mappers/files.mapper'; import { RegistriesSelectors, SetUpdatedFields, UpdateStepValidation } from '../../store'; @@ -77,6 +78,7 @@ export class CustomStepComponent implements OnDestroy { private readonly route = inject(ActivatedRoute); private readonly router = inject(Router); private readonly fb = inject(FormBuilder); + private toastService = inject(ToastService); readonly pages = select(RegistriesSelectors.getPagesSchema); readonly FieldType = FieldType; @@ -180,7 +182,12 @@ export class CustomStepComponent implements OnDestroy { onAttachFile(file: OsfFile, questionKey: string): void { this.attachedFiles[questionKey] = this.attachedFiles[questionKey] || []; + if (!this.attachedFiles[questionKey].some((f) => f.file_id === file.id)) { + if (this.attachedFiles[questionKey].length >= FILE_COUNT_ATTACHMENTS_LIMIT) { + this.toastService.showWarn('shared.files.limitText'); + return; + } this.attachedFiles[questionKey].push(file); this.stepForm.patchValue({ [questionKey]: [...(this.attachedFiles[questionKey] || []), file], diff --git a/src/app/features/registries/components/files-control/files-control.component.html b/src/app/features/registries/components/files-control/files-control.component.html index ea73def20..884f72428 100644 --- a/src/app/features/registries/components/files-control/files-control.component.html +++ b/src/app/features/registries/components/files-control/files-control.component.html @@ -58,7 +58,7 @@ [isLoading]="isFilesLoading()" [actions]="filesTreeActions" [viewOnly]="filesViewOnly()" - [viewOnlyDownloadable]="false" + [viewOnlyDownloadable]="true" [resourceId]="projectId()" [provider]="provider()" (folderIsOpening)="folderIsOpening($event)" diff --git a/src/app/features/registries/components/files-control/files-control.component.ts b/src/app/features/registries/components/files-control/files-control.component.ts index 980a2763e..6bff47341 100644 --- a/src/app/features/registries/components/files-control/files-control.component.ts +++ b/src/app/features/registries/components/files-control/files-control.component.ts @@ -16,8 +16,9 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { CreateFolderDialogComponent } from '@osf/features/files/components'; import { FilesTreeComponent, LoadingSpinnerComponent } from '@osf/shared/components'; +import { FILE_SIZE_LIMIT } from '@osf/shared/constants'; import { FilesTreeActions, OsfFile } from '@osf/shared/models'; -import { FilesService } from '@osf/shared/services'; +import { FilesService, ToastService } from '@osf/shared/services'; import { CreateFolder, @@ -57,6 +58,7 @@ export class FilesControlComponent { private readonly dialogService = inject(DialogService); private readonly translateService = inject(TranslateService); private readonly destroyRef = inject(DestroyRef); + private toastService = inject(ToastService); readonly files = select(RegistriesSelectors.getFiles); readonly filesTotalCount = select(RegistriesSelectors.getFilesTotalCount); @@ -103,6 +105,10 @@ export class FilesControlComponent { onFileSelected(event: Event): void { const input = event.target as HTMLInputElement; const file = input.files?.[0]; + if (file && file.size > FILE_SIZE_LIMIT) { + this.toastService.showWarn('shared.files.limitText'); + return; + } if (!file) return; this.uploadFile(file); diff --git a/src/app/features/registries/components/metadata/metadata.component.html b/src/app/features/registries/components/metadata/metadata.component.html index 620c66986..75d6a4897 100644 --- a/src/app/features/registries/components/metadata/metadata.component.html +++ b/src/app/features/registries/components/metadata/metadata.component.html @@ -11,7 +11,7 @@
{{ 'shared.title.description' | translate }}