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
5 changes: 4 additions & 1 deletion src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { provideStates } from '@ngxs/store';

import { Routes } from '@angular/router';

import { ProjectFilesState } from '@osf/features/project/files/store/project-files.state';

import { MyProfileResourceFiltersOptionsState } from './features/my-profile/components/filters/store';
import { MyProfileResourceFiltersState } from './features/my-profile/components/my-profile-resource-filters/store';
import { MyProfileState } from './features/my-profile/store';
Expand Down Expand Up @@ -117,9 +119,10 @@ export const routes: Routes = [
path: 'files',
loadComponent: () =>
import('@osf/features/project/files/project-files.component').then((mod) => mod.ProjectFilesComponent),
providers: [provideStates([ProjectFilesState])],
},
{
path: 'files/:fileId',
path: 'files/:fileGuid',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need file's guid on this page, not id, it's different file properties

loadComponent: () =>
import('@osf/features/project/files/components/file-detail/file-detail.component').then(
(mod) => mod.FileDetailComponent
Expand Down
3 changes: 2 additions & 1 deletion src/app/core/models/json-api.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ export interface JsonApiResponseWithPaging<Data, Included> extends JsonApiRespon
};
}

export interface ApiData<Attributes, Embeds, Relationships> {
export interface ApiData<Attributes, Embeds, Relationships, Links> {
id: string;
attributes: Attributes;
embeds: Embeds;
type: string;
relationships: Relationships;
links: Links;
}
21 changes: 18 additions & 3 deletions src/app/core/services/json-api.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { map, Observable } from 'rxjs';

import { HttpClient, HttpParams } from '@angular/common/http';
import { HttpClient, HttpEvent, HttpParams } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';

import { JsonApiResponse } from '@osf/core/models';
Expand Down Expand Up @@ -49,8 +49,23 @@ export class JsonApiService {
return this.http.patch<JsonApiResponse<T, null>>(url, body).pipe(map((response) => response.data));
}

put<T>(url: string, body: unknown): Observable<T> {
return this.http.put<JsonApiResponse<T, null>>(url, body).pipe(map((response) => response.data));
put<T>(url: string, body: unknown, params?: Record<string, unknown>): Observable<T> {
return this.http
.put<JsonApiResponse<T, null>>(url, body, { params: this.buildHttpParams(params) })
.pipe(map((response) => response.data));
}

putFile<T>(
url: string,
file: File,
params?: Record<string, string>
): Observable<HttpEvent<JsonApiResponse<T, null>>> {
return this.http.put<JsonApiResponse<T, null>>(url, file, {
params: params,
reportProgress: true,
observe: 'events',
responseType: 'json' as const,
});
}

delete(url: string, body?: unknown): Observable<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiData } from '@osf/core/models';
import { Education, Employment } from '@osf/shared/models';

export type ContributorResponse = ApiData<ContributorAttributes, ContributorEmbeds, ContributorRelationships>;
export type ContributorResponse = ApiData<ContributorAttributes, ContributorEmbeds, ContributorRelationships, null>;

export interface ContributorAttributes {
index: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<div class="metadata p-4 flex flex-column gap-3">
<div class="flex justify-content-between">
<h2>{{ 'project.files.detail.fileMetadata.title' | translate }}</h2>

<div class="flex gap-2">
<p-button severity="secondary"><i class="osf-icon-download p-1"></i></p-button>
<p-button severity="secondary" (click)="editFileMetadataVisible = true">{{
'project.files.detail.fileMetadata.edit' | translate
}}</p-button>
</div>
</div>

<div class="flex flex-column gap-2">
<h3>{{ 'project.files.detail.fileMetadata.fields.title' | translate }}</h3>

@if (fileMetadata().isLoading) {
<p-skeleton width="3rem" height="19px"></p-skeleton>
} @else {
<span>{{ fileMetadata().data?.title }}</span>
}
</div>

@if (fileMetadata().data?.description) {
<div class="flex flex-column gap-2">
<h3>{{ 'project.files.detail.fileMetadata.fields.description' | translate }}</h3>

@if (fileMetadata().isLoading) {
<p-skeleton width="6rem" height="19px"></p-skeleton>
} @else {
<div>
{{ fileMetadata().data?.description }}
</div>
}
</div>
}

@if (fileMetadata().data?.resourceTypeGeneral) {
<div class="flex flex-column gap-2">
<h3>{{ 'project.files.detail.fileMetadata.fields.resourceType' | translate }}</h3>

@if (fileMetadata().isLoading) {
<p-skeleton width="7.5rem" height="19px"></p-skeleton>
} @else {
<div>
<span>{{ fileMetadata().data?.resourceTypeGeneral }}</span>
</div>
}
</div>
}

@if (fileMetadata().data?.language) {
<div class="flex flex-column gap-2">
<h3>{{ 'project.files.detail.fileMetadata.fields.resourceLanguage' | translate }}</h3>

@if (fileMetadata().isLoading) {
<p-skeleton width="10rem" height="19px"></p-skeleton>
} @else {
<div>
<span>{{ fileMetadata().data?.language }}</span>
</div>
}
</div>
}
</div>

<p-dialog
[header]="'project.files.detail.fileMetadata.edit' | translate"
[modal]="true"
[(visible)]="editFileMetadataVisible"
[style]="{ width: '25rem' }"
>
<form [formGroup]="fileMetadataForm" (ngSubmit)="setFileMetadata()" class="flex flex-column gap-3">
<div class="flex flex-column gap-1">
<p>{{ 'project.files.detail.fileMetadata.fields.title' | translate }}</p>
<input pInputText id="title" [formControl]="titleControl" />
</div>
<div class="flex flex-column gap-1">
<p>{{ 'project.files.detail.fileMetadata.fields.description' | translate }}</p>
<input pInputText id="description" [formControl]="descriptionControl" />
</div>
<div class="flex flex-column gap-1">
<p>{{ 'project.files.detail.fileMetadata.fields.resourceType' | translate }}</p>
<p-select
class="w-full"
[options]="resourceTypes"
optionValue="value"
optionLabel="value"
appendTo="body"
[formControl]="resourceTypeControl"
[showClear]="true"
></p-select>
</div>
<div class="flex flex-column gap-1">
<p>{{ 'project.files.detail.fileMetadata.fields.resourceLanguage' | translate }}</p>
<p-select
class="w-full"
[options]="languages"
optionValue="value"
optionLabel="label"
appendTo="body"
[formControl]="resourceLanguageControl"
[showClear]="true"
></p-select>
</div>

<div class="flex btn-full-width gap-2">
<p-button
[label]="'common.buttons.cancel' | translate"
severity="info"
class="w-full"
(click)="editFileMetadataVisible = false"
type="button"
/>
<p-button
[label]="'common.buttons.save' | translate"
class="w-full"
type="submit"
[disabled]="!fileMetadataForm.valid"
/>
</div>
</form>
</p-dialog>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@use "../../file-detail.component.scss";
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { select, Store } from '@ngxs/store';

import { TranslateModule } from '@ngx-translate/core';

import { Button } from 'primeng/button';
import { Dialog } from 'primeng/dialog';
import { InputText } from 'primeng/inputtext';
import { Select } from 'primeng/select';
import { Skeleton } from 'primeng/skeleton';

import { ChangeDetectionStrategy, Component, DestroyRef, inject } from '@angular/core';
import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
import { FormBuilder, FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';

import { ProjectFilesSelectors, SetFileMetadata } from '@osf/features/project/files/store';

import { LANGUAGES, RESOURCE_TYPES } from '../../constants/files-details.constants';

@Component({
selector: 'osf-file-metadata',
standalone: true,
imports: [Button, Dialog, InputText, Select, FormsModule, ReactiveFormsModule, Skeleton, TranslateModule],
templateUrl: './file-metadata.component.html',
styleUrl: './file-metadata.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FileMetadataComponent {
readonly store = inject(Store);
readonly destroyRef = inject(DestroyRef);
readonly fb = inject(FormBuilder);

fileMetadata = select(ProjectFilesSelectors.getFileCustomMetadata);
isIframeLoading = true;
editFileMetadataVisible = false;

fileMetadataForm = new FormGroup({
title: new FormControl<string | null>(null),
description: new FormControl<string | null>(null),
resourceType: new FormControl<string | null>(null),
resourceLanguage: new FormControl<string | null>(null),
});

protected readonly resourceTypes = RESOURCE_TYPES;
protected readonly languages = LANGUAGES;

get titleControl(): FormControl<string | null> {
return this.fileMetadataForm.get('title') as FormControl<string | null>;
}

get descriptionControl(): FormControl<string | null> {
return this.fileMetadataForm.get('description') as FormControl<string | null>;
}

get resourceTypeControl(): FormControl<string | null> {
return this.fileMetadataForm.get('resourceType') as FormControl<string | null>;
}

get resourceLanguageControl(): FormControl<string | null> {
return this.fileMetadataForm.get('resourceLanguage') as FormControl<string | null>;
}

constructor() {
toObservable(this.fileMetadata)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((metadata) => {
if (metadata.data) {
this.fileMetadataForm.patchValue({
title: metadata.data.title,
description: metadata.data.description,
resourceType: metadata.data.resourceTypeGeneral,
resourceLanguage: metadata.data.language,
});
}
});
}

setFileMetadata() {
if (this.fileMetadataForm.valid) {
const formValues = {
title: this.fileMetadataForm.get('title')?.value ?? null,
description: this.fileMetadataForm.get('description')?.value ?? null,
resource_type_general: this.fileMetadataForm.get('resourceType')?.value ?? null,
language: this.fileMetadataForm.get('resourceLanguage')?.value ?? null,
};

const fileId = this.fileMetadata().data?.id;
if (fileId) {
this.store.dispatch(new SetFileMetadata(formValues, fileId));
}

this.editFileMetadataVisible = false;
}
}
}
Loading