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
3 changes: 2 additions & 1 deletion src/app/features/files/pages/files/files.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export class FilesComponent {
readonly currentFolder = select(FilesSelectors.getCurrentFolder);
readonly provider = select(FilesSelectors.getProvider);
readonly resourceDetails = select(CurrentResourceSelectors.getResourceDetails);
readonly resourceMetadata = select(CurrentResourceSelectors.getCurrentResource);
readonly rootFolders = select(FilesSelectors.getRootFolders);
readonly isRootFoldersLoading = select(FilesSelectors.isRootFoldersLoading);
readonly configuredStorageAddons = select(FilesSelectors.getConfiguredStorageAddons);
Expand Down Expand Up @@ -436,7 +437,7 @@ export class FilesComponent {
const folderId = this.currentFolder()?.id ?? '';
const isRootFolder = !this.currentFolder()?.relationships?.parentFolderLink;
const storageLink = this.currentRootFolder()?.folder?.links?.download ?? '';
const resourcePath = this.urlMap.get(this.resourceType()) ?? 'nodes';
const resourcePath = this.resourceMetadata()?.type ?? 'nodes';

if (resourceId && folderId) {
this.dataciteService.logFileDownload(resourceId, resourcePath).subscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';

import { MetaTagsService, ToastService } from '@osf/shared/services';
import { DataciteService } from '@shared/services/datacite/datacite.service';
import { GetActivityLogs } from '@shared/stores/activity-logs';

import { ProjectOverviewComponent } from './project-overview.component';

import { DataciteMockFactory } from '@testing/mocks/datacite.service.mock';

describe('ProjectOverviewComponent', () => {
let fixture: ComponentFixture<ProjectOverviewComponent>;
let component: ProjectOverviewComponent;
let store: Store;
let dataciteService: jest.Mocked<DataciteService>;

beforeEach(async () => {
TestBed.overrideComponent(ProjectOverviewComponent, { set: { template: '' } });

dataciteService = DataciteMockFactory();
await TestBed.configureTestingModule({
imports: [ProjectOverviewComponent],
providers: [
Expand All @@ -33,6 +37,7 @@ describe('ProjectOverviewComponent', () => {

provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting(),
{ provide: DataciteService, useValue: dataciteService },

{ provide: DialogService, useValue: { open: () => ({ onClose: of(null) }) } },
{ provide: TranslateService, useValue: { instant: (k: string) => k } },
Expand All @@ -46,8 +51,8 @@ describe('ProjectOverviewComponent', () => {
component = fixture.componentInstance;
});

it('should create', () => {
expect(component).toBeTruthy();
it('should log to datacite', () => {
expect(dataciteService.logIdentifiableView).toHaveBeenCalledWith(component.currentProject$);
});

it('dispatches GetActivityLogs with numeric page and pageSize on init', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
inject,
OnInit,
} from '@angular/core';
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
import { takeUntilDestroyed, toObservable, toSignal } from '@angular/core/rxjs-interop';
import { FormsModule } from '@angular/forms';
import { ActivatedRoute, NavigationEnd, Router, RouterLink } from '@angular/router';

Expand Down Expand Up @@ -200,6 +200,8 @@ export class ProjectOverviewComponent implements OnInit {
this.areSubjectsLoading()
);

currentProject$ = toObservable(this.currentProject);

currentResource = computed(() => {
const project = this.currentProject();
if (project) {
Expand Down Expand Up @@ -288,6 +290,8 @@ export class ProjectOverviewComponent implements OnInit {
this.actions.getLinkedProjects(projectId);
this.actions.getActivityLogs(projectId, this.activityDefaultPage, this.activityPageSize);
}

this.dataciteService.logIdentifiableView(this.currentProject$).subscribe();
}

handleOpenMakeDecisionDialog() {
Expand Down
11 changes: 7 additions & 4 deletions src/app/shared/components/files-tree/files-tree.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { select } from '@ngxs/store';

import { TranslatePipe, TranslateService } from '@ngx-translate/core';

import { PrimeTemplate } from 'primeng/api';
Expand Down Expand Up @@ -37,6 +39,7 @@ import { FileLabelModel, FileMenuAction, FilesTreeActions, OsfFile } from '@osf/
import { FileSizePipe } from '@osf/shared/pipes';
import { CustomConfirmationService, FilesService, ToastService } from '@osf/shared/services';
import { DataciteService } from '@osf/shared/services/datacite/datacite.service';
import { CurrentResourceSelectors } from '@shared/stores';

import { CustomPaginatorComponent } from '../custom-paginator/custom-paginator.component';
import { FileMenuComponent } from '../file-menu/file-menu.component';
Expand Down Expand Up @@ -86,6 +89,8 @@ export class FilesTreeComponent implements OnDestroy, AfterViewInit {
isDragOver = signal(false);
hasViewOnly = computed(() => hasViewOnlyParam(this.router) || this.viewOnly());

readonly resourceMetadata = select(CurrentResourceSelectors.getCurrentResource);

entryFileClicked = output<OsfFile>();
folderIsOpening = output<boolean>();
uploadFilesConfirmed = output<File[] | File>();
Expand Down Expand Up @@ -249,10 +254,8 @@ export class FilesTreeComponent implements OnDestroy, AfterViewInit {
}

downloadFileOrFolder(file: OsfFile) {
if (file.target.id && file.target.type) {
this.dataciteService.logFileDownload(file.target.id, file.target.type).subscribe();
}

const resourceType = this.resourceMetadata()?.type ?? 'nodes';
this.dataciteService.logFileDownload(this.resourceId(), resourceType).subscribe();
if (file.kind === 'file') {
this.downloadFile(file.links.download);
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/app/shared/services/datacite/datacite.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class DataciteService {
private readonly http: HttpClient = inject(HttpClient);
private readonly environment = inject(ENVIRONMENT);

get webUrl() {
return this.environment.webUrl;
get apiDomainUrl() {
return this.environment.apiDomainUrl;
}

get dataciteTrackerAddress() {
Expand Down Expand Up @@ -56,7 +56,7 @@ export class DataciteService {
}

private logFile(targetId: string, targetType: string, event: DataciteEvent): Observable<void> {
const url = `${this.webUrl}/${targetType}/${targetId}/identifiers`;
const url = `${this.apiDomainUrl}/v2/${targetType}/${targetId}/identifiers`;
return this.http.get<IdentifiersJsonApiResponse>(url).pipe(
map((item) => ({
identifiers: item.data.map<Identifier>((identifierData) => ({
Expand Down
Loading