Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
[isLoading]="isFilesLoading()"
[actions]="filesTreeActions"
[viewOnly]="filesViewOnly()"
[viewOnlyDownloadable]="false"
[viewOnlyDownloadable]="true"
[resourceId]="projectId()"
[provider]="provider()"
(folderIsOpening)="folderIsOpening($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h2 class="mb-2">{{ 'common.labels.title' | translate }}</h2>
</label>
<p class="mb-1">{{ 'shared.title.description' | translate }}</p>
<osf-text-input
id="registration-title-id"
[inputId]="'registration-title-id'"
[control]="metadataForm.controls['title']"
[maxLength]="inputLimits.fullName.maxLength"
>
Expand All @@ -33,6 +33,7 @@ <h2>{{ 'common.labels.description' | translate }}</h2>
rows="5"
cols="30"
pTextarea
[ariaLabel]="'common.labels.description' | translate"
></textarea>
@if (
metadataForm.controls['description'].errors?.['required'] &&
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/components/stepper/stepper.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[class.invalid]="step.invalid"
[class.current]="i === currentStep().index"
(click)="onStepClick(step)"
[attr.aria-label]="step.label | translate"
>
@if (step.invalid && i !== currentStep().index) {
<osf-icon iconClass="fas fa-exclamation" />
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/components/subjects/subjects.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ <h2 class="mb-2">{{ 'shared.subjects.title' | translate }}</h2>
(onNodeSelect)="selectSubject($event.node.data)"
(onNodeUnselect)="removeSubject($event.node.data)"
[ariaLabel]="'shared.subjects.subjectTree' | translate"
[togglerAriaLabel]="'common.accessibility.toggleTreeNode' | translate"
>
</p-tree>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@if (label()) {
<label [for]="inputId">{{ label() | translate }}</label>
<label [for]="inputId()">{{ label() | translate }}</label>
}
<input
[id]="inputId"
[id]="inputId()"
pInputText
[type]="type()"
[formControl]="control()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class TextInputComponent {
minLength = input<number>();
maxLength = input<number>();

inputId = `input-${Math.random().toString(36).substring(2, 15)}`;
inputId = input<string>(`input-${Math.random().toString(36).substring(2, 15)}`);
helpId = `help-${Math.random().toString(36).substring(2, 15)}`;

getErrorMessage(): ValidationParams {
Expand Down
2 changes: 2 additions & 0 deletions src/app/shared/constants/files-limits.const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const FILE_SIZE_LIMIT = 5 * 1024 * 1024 * 1024;
export const FILE_COUNT_ATTACHMENTS_LIMIT = 1;
1 change: 1 addition & 0 deletions src/app/shared/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './addons-tab-options.const';
export * from './contributors.constants';
export * from './default-citation-titles.const';
export * from './default-table-params.constants';
export * from './files-limits.const';
export * from './filter-placeholders';
export * from './input-limits.const';
export * from './input-validation-messages.const';
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/services/toast.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class ToastService {
}

showWarn(summary: string, params?: unknown) {
this.messageService.add({ severity: 'warn', summary, data: { translationParams: params }, key: 'osf' });
this.messageService.add({ severity: 'warn', summary, life: 5000, data: { translationParams: params }, key: 'osf' });
}

showError(summary: string, params?: unknown) {
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"customizeOptions": "Customize options",
"toggleProjectVisibility": "Toggle project visibility",
"tagInput": "Tag input",
"toggleTreeNode": "Toggle tree node",
"copyButtonInfo": "Copy to clipboard button"
},
"dialogs": {
Expand Down
Loading