Skip to content

Commit 97fcf38

Browse files
committed
feat(preprint-details): Extracted static string to en.json. Refactored doi
1 parent 313e8e1 commit 97fcf38

19 files changed

Lines changed: 286 additions & 184 deletions

src/app/features/preprints/components/preprint-details/additional-info/additional-info.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h3>{{ 'preprints.preprintStepper.review.sections.metadata.publicationCitation'
1313

1414
@if (preprintValue.originalPublicationDate) {
1515
<section class="flex flex-column gap-2">
16-
<h3>{{ 'Original Publication Date' | translate }}</h3>
16+
<h3>{{ 'preprints.preprintStepper.review.sections.metadata.publicationDate' | translate }}</h3>
1717

1818
{{ preprintValue.originalPublicationDate | date: 'MMM d, y, h:mm a' }}
1919
</section>

src/app/features/preprints/components/preprint-details/citation-section/citation-section.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ export class CitationSectionComponent implements OnInit {
6464
? this.translateService.instant('project.overview.metadata.citationLoadingPlaceholder')
6565
: this.translateService.instant('project.overview.metadata.noCitationStylesFound');
6666
});
67+
private PreprintResourceType = 'preprints';
6768

6869
constructor() {
6970
this.setupFilterDebounce();
7071
this.setupCitationStylesEffect();
7172
}
7273

7374
ngOnInit() {
74-
this.actions.getDefaultCitations('preprints', this.preprintId());
75+
this.actions.getDefaultCitations(this.PreprintResourceType, this.preprintId());
7576
}
7677

7778
protected handleCitationStyleFilterSearch(event: SelectFilterEvent) {
@@ -80,7 +81,7 @@ export class CitationSectionComponent implements OnInit {
8081
}
8182

8283
protected handleGetStyledCitation(event: SelectChangeEvent) {
83-
this.actions.getStyledCitation('preprints', this.preprintId(), event.value.id);
84+
this.actions.getStyledCitation(this.PreprintResourceType, this.preprintId(), event.value.id);
8485
}
8586

8687
private setupFilterDebounce(): void {

src/app/features/preprints/components/preprint-details/general-information/general-information.component.html

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ <h3>{{ 'preprints.preprintStepper.review.sections.metadata.affiliatedInstitution
2020
}
2121

2222
<section class="flex flex-column gap-2">
23-
<h3>{{ 'Authors' | translate }}</h3>
23+
<h3>{{ 'preprints.preprintStepper.review.sections.metadata.authors' | translate }}</h3>
2424

2525
<div class="flex flex-column gap-1 line-height-2 md:flex-row">
2626
@for (contributor of bibliographicContributors(); track contributor.id) {
@@ -36,14 +36,15 @@ <h3>{{ 'Authors' | translate }}</h3>
3636
</div>
3737
</section>
3838

39+
<!-- [RNi] TODO: Extract to separate component -->
3940
@if (preprintProvider()?.assertionsEnabled) {
4041
<section class="flex flex-column gap-2">
4142
<h3>{{ 'preprints.preprintStepper.review.sections.authorAssertions.conflictOfInterest' | translate }}</h3>
4243

43-
@if (!preprintValue.hasCoi) {
44-
<p>{{ 'preprints.preprintStepper.review.sections.authorAssertions.noCoi' | translate }}</p>
45-
} @else {
44+
@if (preprintValue.hasCoi) {
4645
{{ preprintValue.coiStatement }}
46+
} @else {
47+
<p>{{ 'preprints.preprintStepper.review.sections.authorAssertions.noCoi' | translate }}</p>
4748
}
4849
</section>
4950

@@ -107,36 +108,7 @@ <h3>
107108
</section>
108109
}
109110

110-
<section class="flex flex-column gap-2">
111-
<h3>{{ preprintProvider()?.preprintWord | titlecase }} DOI</h3>
112-
113-
<p-select
114-
class="w-full"
115-
appendTo="body"
116-
optionLabel="label"
117-
optionValue="value"
118-
[ngModel]="preprintValue.id"
119-
[options]="versionsDropdownOptions()"
120-
[loading]="arePreprintVersionIdsLoading()"
121-
(onChange)="selectPreprintVersion($event.value)"
122-
/>
123-
@if (preprintValue.preprintDoiLink) {
124-
@if (preprintValue.preprintDoiCreated) {
125-
<a [href]="preprintValue.preprintDoiLink">{{ preprintValue.preprintDoiLink }}</a>
126-
} @else {
127-
<p>{{ preprintValue.preprintDoiLink }}</p>
128-
<p>DOIs are minted by a third party, and may take up to 24 hours to be registered.</p>
129-
}
130-
} @else {
131-
@if (!preprintValue.isPublic) {
132-
<p>DOI created after preprint is made public</p>
133-
} @else if (preprintProvider()?.reviewsWorkflow && !preprintValue.isPublished) {
134-
<p>DOI created after moderator approval</p>
135-
} @else {
136-
<p>No DOI</p>
137-
}
138-
}
139-
</section>
111+
<osf-preprint-doi-section [preprintProvider]="preprintProvider()" />
140112
</div>
141113
}
142114

src/app/features/preprints/components/preprint-details/general-information/general-information.component.ts

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ import { createDispatchMap, select } from '@ngxs/store';
33
import { TranslatePipe } from '@ngx-translate/core';
44

55
import { Card } from 'primeng/card';
6-
import { Select } from 'primeng/select';
76
import { Skeleton } from 'primeng/skeleton';
87

9-
import { Location, TitleCasePipe } from '@angular/common';
10-
import { ChangeDetectionStrategy, Component, computed, effect, inject, input, OnDestroy, signal } from '@angular/core';
8+
import { ChangeDetectionStrategy, Component, computed, effect, input, OnDestroy, signal } from '@angular/core';
119
import { FormsModule } from '@angular/forms';
12-
import { Router } from '@angular/router';
1310

11+
import { PreprintDoiSectionComponent } from '@osf/features/preprints/components/preprint-details/preprint-doi-section/preprint-doi-section.component';
1412
import { ApplicabilityStatus, PreregLinkInfo } from '@osf/features/preprints/enums';
1513
import { PreprintProviderDetails } from '@osf/features/preprints/models';
1614
import { FetchPreprintById, PreprintSelectors } from '@osf/features/preprints/store/preprint';
@@ -21,14 +19,12 @@ import { ContributorsSelectors, GetAllContributors, ResetContributorsState } fro
2119

2220
@Component({
2321
selector: 'osf-preprint-general-information',
24-
imports: [Card, TranslatePipe, TruncatedTextComponent, Skeleton, Select, FormsModule, TitleCasePipe],
22+
imports: [Card, TranslatePipe, TruncatedTextComponent, Skeleton, FormsModule, PreprintDoiSectionComponent],
2523
templateUrl: './general-information.component.html',
2624
styleUrl: './general-information.component.scss',
2725
changeDetection: ChangeDetectionStrategy.OnPush,
2826
})
2927
export class GeneralInformationComponent implements OnDestroy {
30-
private readonly router = inject(Router);
31-
private readonly location = inject(Location);
3228
readonly ApplicabilityStatus = ApplicabilityStatus;
3329
readonly PreregLinkInfo = PreregLinkInfo;
3430

@@ -51,19 +47,6 @@ export class GeneralInformationComponent implements OnDestroy {
5147
return this.contributors().filter((contributor) => contributor.isBibliographic);
5248
});
5349

54-
preprintVersionIds = select(PreprintSelectors.getPreprintVersionIds);
55-
arePreprintVersionIdsLoading = select(PreprintSelectors.arePreprintVersionIdsLoading);
56-
57-
versionsDropdownOptions = computed(() => {
58-
const preprintVersionIds = this.preprintVersionIds();
59-
if (!preprintVersionIds.length) return [];
60-
61-
return preprintVersionIds.map((versionId, index) => ({
62-
label: `Version ${preprintVersionIds.length - index}`,
63-
value: versionId,
64-
}));
65-
});
66-
6750
skeletonData = Array.from({ length: 5 }, () => null);
6851

6952
constructor() {
@@ -78,17 +61,4 @@ export class GeneralInformationComponent implements OnDestroy {
7861
ngOnDestroy(): void {
7962
this.actions.resetContributorsState();
8063
}
81-
82-
selectPreprintVersion(versionId: string) {
83-
if (this.preprint()!.id === versionId) return;
84-
85-
this.actions.fetchPreprintById(versionId).subscribe({
86-
complete: () => {
87-
const currentUrl = this.router.url;
88-
const newUrl = currentUrl.replace(/[^/]+$/, versionId);
89-
90-
this.location.replaceState(newUrl);
91-
},
92-
});
93-
}
9464
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@let preprintValue = preprint()!;
2+
@let preprintProviderValue = preprintProvider()!;
3+
<section class="flex flex-column gap-2">
4+
<h3>{{ 'preprints.details.doi.title' | translate: { documentType: preprintProviderValue.preprintWord } }}</h3>
5+
6+
<p-select
7+
class="w-full"
8+
appendTo="body"
9+
optionLabel="label"
10+
optionValue="value"
11+
[ngModel]="preprintValue.id"
12+
[options]="versionsDropdownOptions()"
13+
[loading]="arePreprintVersionIdsLoading()"
14+
(onChange)="selectPreprintVersion($event.value)"
15+
/>
16+
@if (preprintValue.preprintDoiLink) {
17+
@if (preprintValue.preprintDoiCreated) {
18+
<a [href]="preprintValue.preprintDoiLink">{{ preprintValue.preprintDoiLink }}</a>
19+
} @else {
20+
<p>{{ preprintValue.preprintDoiLink }}</p>
21+
<p>{{ 'preprints.details.doi.pendingDoiMinted' | translate }}</p>
22+
}
23+
} @else {
24+
@if (!preprintValue.isPublic) {
25+
<p>{{ 'preprints.details.doi.pendingDoi' | translate: { documentType: preprintProviderValue.preprintWord } }}</p>
26+
} @else if (preprintProvider()?.reviewsWorkflow && !preprintValue.isPublished) {
27+
<p>{{ 'preprints.details.doi.pendingDoiModeration' | translate }}</p>
28+
} @else {
29+
<p>{{ 'preprints.details.doi.noDoi' | translate }}</p>
30+
}
31+
}
32+
</section>

src/app/features/preprints/components/preprint-details/preprint-doi-section/preprint-doi-section.component.scss

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { PreprintDoiSectionComponent } from './preprint-doi-section.component';
4+
5+
describe.skip('PreprintDoiSectionComponent', () => {
6+
let component: PreprintDoiSectionComponent;
7+
let fixture: ComponentFixture<PreprintDoiSectionComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
imports: [PreprintDoiSectionComponent],
12+
}).compileComponents();
13+
14+
fixture = TestBed.createComponent(PreprintDoiSectionComponent);
15+
component = fixture.componentInstance;
16+
fixture.detectChanges();
17+
});
18+
19+
it('should create', () => {
20+
expect(component).toBeTruthy();
21+
});
22+
});
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { createDispatchMap, select } from '@ngxs/store';
2+
3+
import { TranslatePipe } from '@ngx-translate/core';
4+
5+
import { Select } from 'primeng/select';
6+
7+
import { Location } from '@angular/common';
8+
import { ChangeDetectionStrategy, Component, computed, inject, input } from '@angular/core';
9+
import { FormsModule } from '@angular/forms';
10+
import { Router } from '@angular/router';
11+
12+
import { PreprintProviderDetails } from '@osf/features/preprints/models';
13+
import { FetchPreprintById, PreprintSelectors } from '@osf/features/preprints/store/preprint';
14+
15+
@Component({
16+
selector: 'osf-preprint-doi-section',
17+
imports: [Select, FormsModule, TranslatePipe],
18+
templateUrl: './preprint-doi-section.component.html',
19+
styleUrl: './preprint-doi-section.component.scss',
20+
changeDetection: ChangeDetectionStrategy.OnPush,
21+
})
22+
export class PreprintDoiSectionComponent {
23+
private readonly router = inject(Router);
24+
private readonly location = inject(Location);
25+
26+
private actions = createDispatchMap({
27+
fetchPreprintById: FetchPreprintById,
28+
});
29+
30+
preprintProvider = input.required<PreprintProviderDetails | undefined>();
31+
preprint = select(PreprintSelectors.getPreprint);
32+
33+
preprintVersionIds = select(PreprintSelectors.getPreprintVersionIds);
34+
arePreprintVersionIdsLoading = select(PreprintSelectors.arePreprintVersionIdsLoading);
35+
36+
versionsDropdownOptions = computed(() => {
37+
const preprintVersionIds = this.preprintVersionIds();
38+
if (!preprintVersionIds.length) return [];
39+
40+
return preprintVersionIds.map((versionId, index) => ({
41+
label: `Version ${preprintVersionIds.length - index}`,
42+
value: versionId,
43+
}));
44+
});
45+
46+
selectPreprintVersion(versionId: string) {
47+
if (this.preprint()!.id === versionId) return;
48+
49+
this.actions.fetchPreprintById(versionId).subscribe({
50+
complete: () => {
51+
const currentUrl = this.router.url;
52+
const newUrl = currentUrl.replace(/[^/]+$/, versionId);
53+
54+
this.location.replaceState(newUrl);
55+
},
56+
});
57+
}
58+
}

src/app/features/preprints/components/preprint-details/preprint-file-section/preprint-file-section.component.html

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@
2525

2626
<div class="flex flex-row align-items-center">
2727
<p>{{ fileVersionsValue[0].name }}</p>
28-
<p class="m-auto">Version: {{ fileVersionsValue[0].id }}</p>
29-
<p-button severity="info" label="Download previous versions" (click)="versionsMenu.toggle($event)" />
28+
<p class="m-auto">{{ 'preprints.details.file.version' | translate: { version: fileVersionsValue[0].id } }}</p>
29+
<p-button
30+
severity="info"
31+
[label]="'preprints.details.file.downloadPreviousVersion' | translate"
32+
(click)="versionsMenu.toggle($event)"
33+
/>
3034

3135
<p-menu #versionsMenu [model]="versionMenuItems()" appendTo="body" popup />
3236
</div>
@@ -40,11 +44,13 @@
4044
@let fileValue = file()!;
4145

4246
<div class="flex flex-column gap-1 justify-content-start md:flex-row">
43-
<span>{{ dateLabel() }}: {{ fileValue.dateCreated | date: 'longDate' }}</span>
47+
<span>{{ dateLabel() | translate }}: {{ fileValue.dateCreated | date: 'longDate' }}</span>
4448
@if (isMedium() || isLarge()) {
4549
<span>|</span>
4650
}
47-
<span>Last edited: {{ fileValue.dateModified | date: 'longDate' }}</span>
51+
<span>
52+
{{ 'preprints.details.file.lastEdited' | translate }} : {{ fileValue.dateModified | date: 'longDate' }}
53+
</span>
4854
</div>
4955
}
5056

src/app/features/preprints/components/preprint-details/preprint-file-section/preprint-file-section.component.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { select } from '@ngxs/store';
22

3+
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
4+
35
import { Button } from 'primeng/button';
46
import { Menu } from 'primeng/menu';
57
import { Skeleton } from 'primeng/skeleton';
@@ -16,7 +18,7 @@ import { IS_LARGE, IS_MEDIUM } from '@shared/utils';
1618

1719
@Component({
1820
selector: 'osf-preprint-file-section',
19-
imports: [LoadingSpinnerComponent, DatePipe, Skeleton, Menu, Button],
21+
imports: [LoadingSpinnerComponent, DatePipe, Skeleton, Menu, Button, TranslatePipe],
2022
templateUrl: './preprint-file-section.component.html',
2123
styleUrl: './preprint-file-section.component.scss',
2224
providers: [DatePipe],
@@ -25,6 +27,7 @@ import { IS_LARGE, IS_MEDIUM } from '@shared/utils';
2527
export class PreprintFileSectionComponent {
2628
private readonly sanitizer = inject(DomSanitizer);
2729
private readonly datePipe = inject(DatePipe);
30+
private readonly translateService = inject(TranslateService);
2831

2932
providerReviewsWorkflow = input.required<ProviderReviewsWorkflow | null>();
3033

@@ -49,7 +52,10 @@ export class PreprintFileSectionComponent {
4952
if (!fileVersions.length) return [];
5053

5154
return fileVersions.map((version, index) => ({
52-
label: `Version ${++index}, ${this.datePipe.transform(version.dateCreated, 'mm/dd/yyyy hh:mm:ss')}`,
55+
label: this.translateService.instant('preprints.details.file.downloadVersion', {
56+
version: ++index,
57+
date: this.datePipe.transform(version.dateCreated, 'mm/dd/yyyy hh:mm:ss'),
58+
}),
5359
url: version.downloadLink,
5460
}));
5561
});
@@ -58,6 +64,8 @@ export class PreprintFileSectionComponent {
5864
const reviewsWorkflow = this.providerReviewsWorkflow();
5965
if (!reviewsWorkflow) return '';
6066

61-
return reviewsWorkflow === ProviderReviewsWorkflow.PreModeration ? 'Submitted' : 'Created';
67+
return reviewsWorkflow === ProviderReviewsWorkflow.PreModeration
68+
? 'preprints.details.file.submitted'
69+
: 'preprints.details.file.created';
6270
});
6371
}

0 commit comments

Comments
 (0)