Skip to content

Commit 11e5c0b

Browse files
committed
feat(datacite-tracker): implemented datacite view tracking for registries and preprints
1 parent 944d851 commit 11e5c0b

19 files changed

Lines changed: 107 additions & 51 deletions

src/app/features/preprints/mappers/preprint-providers.mapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class PreprintProvidersMapper {
3131
backgroundColor: brandRaw.attributes.background_color,
3232
},
3333
iri: response.links.iri,
34-
faviconUrl: response.attributes.assets.favicon,
34+
faviconUrl: response.attributes.assets?.favicon,
3535
squareColorNoTransparentImageUrl: response.attributes.assets?.square_color_no_transparent,
3636
reviewsWorkflow: response.attributes.reviews_workflow,
3737
facebookAppId: response.attributes.facebook_app_id,

src/app/features/preprints/mappers/preprints.mapper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { LicensesMapper } from '@osf/shared/mappers';
22
import { ApiData, JsonApiResponseWithMeta, ResponseJsonApi } from '@osf/shared/models';
33
import { StringOrNull } from '@shared/helpers';
4+
import { IdentifiersMapper } from '@shared/mappers/identifiers.mapper';
45

56
import {
67
Preprint,
@@ -136,6 +137,7 @@ export class PreprintsMapper {
136137
views: meta.metrics.views,
137138
},
138139
embeddedLicense: LicensesMapper.fromLicenseDataJsonApi(data.embeds.license.data),
140+
identifiers: IdentifiersMapper.fromEmbeds(data.embeds.identifiers),
139141
preprintDoiLink: links.preprint_doi,
140142
articleDoiLink: links.doi,
141143
};

src/app/features/preprints/models/preprint-json-api.models.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { UserPermissions } from '@osf/shared/enums';
22
import { BooleanOrNull, StringOrNull } from '@osf/shared/helpers';
33
import { ContributorResponse, LicenseRecordJsonApi, LicenseResponseJsonApi } from '@osf/shared/models';
4+
import { IdentifiersEmbedJsonApiResponse } from '@shared/models/identifiers/identifier-json-api';
45

56
import { ApplicabilityStatus, PreregLinkInfo, ReviewsState } from '../enums';
67

@@ -69,6 +70,7 @@ export interface PreprintEmbedsJsonApi {
6970
data: ContributorResponse[];
7071
};
7172
license: LicenseResponseJsonApi;
73+
identifiers: IdentifiersEmbedJsonApiResponse;
7274
}
7375

7476
export interface PreprintMetaJsonApi {

src/app/features/preprints/models/preprint.models.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { UserPermissions } from '@osf/shared/enums';
22
import { BooleanOrNull, StringOrNull } from '@osf/shared/helpers';
33
import { IdName, License, LicenseOptions } from '@osf/shared/models';
4+
import { Identifier } from '@shared/models/identifiers/indentifier.model';
45

56
import { ApplicabilityStatus, PreregLinkInfo, ReviewsState } from '../enums';
67

@@ -43,6 +44,7 @@ export interface Preprint {
4344
embeddedLicense?: License;
4445
preprintDoiLink?: string;
4546
articleDoiLink?: string;
47+
identifiers?: Identifier[];
4648
}
4749

4850
export interface PreprintFilesLinks {

src/app/features/preprints/pages/preprint-details/preprint-details.component.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Button } from 'primeng/button';
66
import { DialogService } from 'primeng/dynamicdialog';
77
import { Skeleton } from 'primeng/skeleton';
88

9-
import { filter, map, of } from 'rxjs';
9+
import { filter, map, Observable, of } from 'rxjs';
1010

1111
import { DatePipe, Location } from '@angular/common';
1212
import {
@@ -19,7 +19,7 @@ import {
1919
OnDestroy,
2020
OnInit,
2121
} from '@angular/core';
22-
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
22+
import { takeUntilDestroyed, toObservable, toSignal } from '@angular/core/rxjs-interop';
2323
import { ActivatedRoute, Router } from '@angular/router';
2424

2525
import { UserSelectors } from '@core/store/user';
@@ -46,6 +46,7 @@ import {
4646
import { GetPreprintProviderById, PreprintProvidersSelectors } from '@osf/features/preprints/store/preprint-providers';
4747
import { CreateNewVersion, PreprintStepperSelectors } from '@osf/features/preprints/store/preprint-stepper';
4848
import { IS_MEDIUM, pathJoin } from '@osf/shared/helpers';
49+
import { DataciteTrackerComponent } from '@shared/components/datacite-tracker/datacite-tracker.component';
4950
import { ReviewPermissions, UserPermissions } from '@shared/enums';
5051
import { MetaTagsService } from '@shared/services';
5152
import { ContributorsSelectors } from '@shared/stores';
@@ -75,7 +76,7 @@ import { environment } from 'src/environments/environment';
7576
providers: [DialogService, DatePipe],
7677
changeDetection: ChangeDetectionStrategy.OnPush,
7778
})
78-
export class PreprintDetailsComponent implements OnInit, OnDestroy {
79+
export class PreprintDetailsComponent extends DataciteTrackerComponent implements OnInit, OnDestroy {
7980
@HostBinding('class') classes = 'flex-1 flex flex-column w-full';
8081

8182
private readonly router = inject(Router);
@@ -105,6 +106,7 @@ export class PreprintDetailsComponent implements OnInit, OnDestroy {
105106
preprintProvider = select(PreprintProvidersSelectors.getPreprintProviderDetails(this.providerId()));
106107
isPreprintProviderLoading = select(PreprintProvidersSelectors.isPreprintProviderDetailsLoading);
107108
preprint = select(PreprintSelectors.getPreprint);
109+
preprint$ = toObservable(select(PreprintSelectors.getPreprint));
108110
isPreprintLoading = select(PreprintSelectors.isPreprintLoading);
109111
contributors = select(ContributorsSelectors.getContributors);
110112
areContributorsLoading = select(ContributorsSelectors.isContributorsLoading);
@@ -281,12 +283,19 @@ export class PreprintDetailsComponent implements OnInit, OnDestroy {
281283
this.fetchPreprint(this.preprintId());
282284
},
283285
});
286+
this.setupDataciteViewTrackerEffect().subscribe();
284287
}
285288

286289
ngOnDestroy() {
287290
this.actions.resetState();
288291
}
289292

293+
protected getDoi(): Observable<string | null> {
294+
return this.preprint$.pipe(
295+
filter((project) => project != null),
296+
map((project) => project?.identifiers?.find((item) => item.category == 'doi')?.value ?? null)
297+
);
298+
}
290299
fetchPreprintVersion(preprintVersionId: string) {
291300
const currentUrl = this.router.url;
292301
const newUrl = currentUrl.replace(/[^/]+$/, preprintVersionId);

src/app/features/preprints/services/preprints.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class PreprintsService {
7777
const params = {
7878
'metrics[views]': 'total',
7979
'metrics[downloads]': 'total',
80-
'embed[]': 'license',
80+
'embed[]': ['license', 'identifiers'],
8181
};
8282
return this.jsonApiService
8383
.get<

src/app/features/project/overview/mappers/project-overview.mapper.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { InstitutionsMapper } from '@shared/mappers';
2+
import { IdentifiersMapper } from '@shared/mappers/identifiers.mapper';
23
import { License } from '@shared/models';
34

45
import { ProjectOverview, ProjectOverviewGetResponseJsoApi } from '../models';
@@ -46,12 +47,7 @@ export class ProjectOverviewMapper {
4647
type: contributor.embeds.users.data.type,
4748
})),
4849
affiliatedInstitutions: InstitutionsMapper.fromInstitutionsResponse(response.embeds.affiliated_institutions),
49-
identifiers: response.embeds.identifiers?.data.map((identifier) => ({
50-
id: identifier.id,
51-
type: identifier.type,
52-
value: identifier.attributes.value,
53-
category: identifier.attributes.category,
54-
})),
50+
identifiers: IdentifiersMapper.fromEmbeds(response.embeds.identifiers),
5551
...(response.embeds.storage?.data &&
5652
!response.embeds.storage?.errors && {
5753
storage: {

src/app/features/project/overview/models/project-overview.models.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { UserPermissions } from '@osf/shared/enums';
2-
import { Institution, InstitutionsJsonApiResponse, JsonApiResponse, License } from '@osf/shared/models';
2+
import { Identifier, Institution, InstitutionsJsonApiResponse, JsonApiResponse, License } from '@osf/shared/models';
3+
import { IdentifiersEmbedJsonApiResponse } from '@shared/models/identifiers/identifier-json-api';
34

45
export interface ProjectOverviewContributor {
56
familyName: string;
@@ -38,7 +39,7 @@ export interface ProjectOverview {
3839
storageLimitStatus: string;
3940
storageUsage: string;
4041
};
41-
identifiers?: ProjectIdentifiers[];
42+
identifiers?: Identifier[];
4243
supplements?: ProjectSupplements[];
4344
analyticsKey: string;
4445
currentUserCanComment: boolean;
@@ -100,16 +101,7 @@ export interface ProjectOverviewGetResponseJsoApi {
100101
};
101102
embeds: {
102103
affiliated_institutions: InstitutionsJsonApiResponse;
103-
identifiers: {
104-
data: {
105-
id: string;
106-
type: string;
107-
attributes: {
108-
category: string;
109-
value: string;
110-
};
111-
}[];
112-
};
104+
identifiers: IdentifiersEmbedJsonApiResponse;
113105
bibliographic_contributors: {
114106
data: {
115107
embeds: {
@@ -208,13 +200,6 @@ export interface ProjectOverviewResponseJsonApi extends JsonApiResponse<ProjectO
208200
data: ProjectOverviewGetResponseJsoApi;
209201
}
210202

211-
export interface ProjectIdentifiers {
212-
id: string;
213-
type: string;
214-
category: string;
215-
value: string;
216-
}
217-
218203
export interface ProjectSupplements {
219204
id: string;
220205
type: string;

src/app/features/registry/mappers/registry-overview.mapper.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { RegistryOverview, RegistryOverviewJsonApiData } from '@osf/features/registry/models';
22
import { ReviewPermissionsMapper } from '@osf/shared/mappers';
33
import { RegistrationMapper } from '@osf/shared/mappers/registration';
4+
import { IdentifiersMapper } from '@shared/mappers/identifiers.mapper';
45
import { MapRegistryStatus } from '@shared/mappers/registry/map-registry-status.mapper';
56

67
export function MapRegistryOverview(data: RegistryOverviewJsonApiData): RegistryOverview | null {
@@ -36,12 +37,7 @@ export function MapRegistryOverview(data: RegistryOverviewJsonApiData): Registry
3637
middleName: contributor?.embeds?.users?.data?.attributes?.middle_names,
3738
type: contributor?.embeds?.users?.data?.type,
3839
})),
39-
identifiers: data.embeds.identifiers?.data.map((identifier) => ({
40-
id: identifier.id,
41-
type: identifier.type,
42-
value: identifier.attributes.value,
43-
category: identifier.attributes.category,
44-
})),
40+
identifiers: IdentifiersMapper.fromEmbeds(data.embeds.identifiers),
4541
analyticsKey: data.attributes?.analyticsKey,
4642
currentUserCanComment: data.attributes.current_user_can_comment,
4743
currentUserPermissions: data.attributes.current_user_permissions,

src/app/features/registry/models/get-registry-overview-json-api.model.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { RegistrationReviewStates, RevisionReviewStates } from '@osf/shared/enums';
22
import { ApiData, JsonApiResponse, ProviderDataJsonApi, SchemaResponseDataJsonApi } from '@osf/shared/models';
3+
import { IdentifiersEmbedJsonApiResponse } from '@shared/models/identifiers/identifier-json-api';
34

45
export type GetRegistryOverviewJsonApi = JsonApiResponse<RegistryOverviewJsonApiData, null>;
56

@@ -87,16 +88,7 @@ export interface RegistryOverviewJsonApiEmbed {
8788
};
8889
};
8990
};
90-
identifiers: {
91-
data: {
92-
id: string;
93-
type: string;
94-
attributes: {
95-
category: string;
96-
value: string;
97-
};
98-
}[];
99-
};
91+
identifiers: IdentifiersEmbedJsonApiResponse;
10092
schema_responses: {
10193
data: SchemaResponseDataJsonApi[];
10294
};

0 commit comments

Comments
 (0)