Skip to content

Commit 08298b1

Browse files
authored
Feat - My Preprints (#184)
* feat(my-preprints): Implemented My Preprints page * fix(conflicts): Fixes after merge conflicts * fix(preprint-service): Using dynamic query params for getMyPreprints method * fix(my-preprints): Preventing second api call while initializing page * feat(my-preprints): Extracted string to en.json * fix(comments): Fixed PR comments
1 parent 405f6a4 commit 08298b1

28 files changed

+608
-26
lines changed

src/app/core/constants/nav-items.constant.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const MENU_ITEMS: MenuItem[] = [
5656
routerLinkActiveOptions: { exact: false },
5757
},
5858
{
59-
routerLink: '/my-preprints',
59+
routerLink: 'preprints/my-preprints',
6060
label: 'navigation.preprintsSubRoutes.myPreprints',
6161
routerLinkActiveOptions: { exact: false },
6262
},

src/app/features/preprints/components/stepper/metadata-step/metadata-step.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ <h2 class="m-b-24">{{ 'preprints.preprintStepper.metadata.publicationCitationTit
9696
class="w-6 md:w-9rem"
9797
styleClass="w-full"
9898
[label]="'common.buttons.next' | translate"
99-
[pTooltip]="metadataForm.invalid ? ('preprintStepper.common.validation.fillRequiredFields' | translate) : ''"
99+
[pTooltip]="
100+
metadataForm.invalid ? ('preprints.preprintStepper.common.validation.fillRequiredFields' | translate) : ''
101+
"
100102
tooltipPosition="top"
101103
[disabled]="metadataForm.invalid || !createdPreprint()?.licenseId"
102104
[loading]="isUpdatingPreprint()"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './create-new-version-steps.const';
22
export * from './form-input-limits.const';
3+
export * from './preprints-fields.const';
34
export * from './prereg-link-options.const';
45
export * from './submit-preprint-steps.const';
56
export * from './update-preprint-steps.const';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const preprintSortFieldMap: Record<string, string> = {
2+
title: 'title',
3+
dateModified: 'date_modified',
4+
};

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
import { ApiData } from '@core/models';
2-
import { Preprint, PreprintJsonApi, PreprintsRelationshipsJsonApi } from '@osf/features/preprints/models';
1+
import { ApiData, JsonApiResponseWithPaging } from '@core/models';
2+
import {
3+
Preprint,
4+
PreprintAttributesJsonApi,
5+
PreprintEmbedsJsonApi,
6+
PreprintRelationshipsJsonApi,
7+
PreprintShortInfoWithTotalCount,
8+
} from '@osf/features/preprints/models';
39

410
export class PreprintsMapper {
511
static toCreatePayload(title: string, abstract: string, providerId: string) {
@@ -22,7 +28,9 @@ export class PreprintsMapper {
2228
};
2329
}
2430

25-
static fromPreprintJsonApi(response: ApiData<PreprintJsonApi, null, PreprintsRelationshipsJsonApi, null>): Preprint {
31+
static fromPreprintJsonApi(
32+
response: ApiData<PreprintAttributesJsonApi, null, PreprintRelationshipsJsonApi, null>
33+
): Preprint {
2634
return {
2735
id: response.id,
2836
dateCreated: response.attributes.date_created,
@@ -76,4 +84,25 @@ export class PreprintsMapper {
7684
},
7785
};
7886
}
87+
88+
static fromMyPreprintJsonApi(
89+
response: JsonApiResponseWithPaging<ApiData<PreprintAttributesJsonApi, PreprintEmbedsJsonApi, null, null>[], null>
90+
): PreprintShortInfoWithTotalCount {
91+
return {
92+
data: response.data.map((preprintData) => {
93+
return {
94+
id: preprintData.id,
95+
title: preprintData.attributes.title,
96+
dateModified: preprintData.attributes.date_modified,
97+
contributors: preprintData.embeds.bibliographic_contributors.data.map((contrData) => {
98+
return {
99+
id: contrData.id,
100+
name: contrData.embeds.users.data.attributes.full_name,
101+
};
102+
}),
103+
};
104+
}),
105+
totalCount: response.links.meta.total,
106+
};
107+
}
79108
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { BooleanOrNull, StringOrNull } from '@core/helpers';
22
import { ApplicabilityStatus, PreregLinkInfo } from '@osf/features/preprints/enums';
3-
import { LicenseRecordJsonApi } from '@shared/models';
3+
import { ContributorResponse, LicenseRecordJsonApi } from '@shared/models';
44

5-
export interface PreprintJsonApi {
5+
export interface PreprintAttributesJsonApi {
66
date_created: string;
77
date_modified: string;
88
date_published: Date | null;
@@ -34,7 +34,7 @@ export interface PreprintJsonApi {
3434
prereg_link_info: PreregLinkInfo | null;
3535
}
3636

37-
export interface PreprintsRelationshipsJsonApi {
37+
export interface PreprintRelationshipsJsonApi {
3838
primary_file: {
3939
data: {
4040
id: string;
@@ -54,3 +54,9 @@ export interface PreprintsRelationshipsJsonApi {
5454
};
5555
};
5656
}
57+
58+
export interface PreprintEmbedsJsonApi {
59+
bibliographic_contributors: {
60+
data: ContributorResponse[];
61+
};
62+
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BooleanOrNull, StringOrNull } from '@core/helpers';
22
import { ApplicabilityStatus, PreregLinkInfo } from '@osf/features/preprints/enums';
3-
import { LicenseOptions } from '@shared/models';
3+
import { IdName, LicenseOptions } from '@shared/models';
44

55
export interface Preprint {
66
id: string;
@@ -35,3 +35,15 @@ export interface PreprintFilesLinks {
3535
filesLink: string;
3636
uploadFileLink: string;
3737
}
38+
39+
export interface PreprintShortInfo {
40+
id: string;
41+
title: string;
42+
dateModified: string;
43+
contributors: IdName[];
44+
}
45+
46+
export interface PreprintShortInfoWithTotalCount {
47+
data: PreprintShortInfo[];
48+
totalCount: number;
49+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<osf-sub-header
2+
[title]="'preprints.myPreprints.title' | translate"
3+
[icon]="'preprints'"
4+
[showButton]="true"
5+
[buttonLabel]="'preprints.addPreprint' | translate: { preprintWord: 'preprint' | titlecase }"
6+
(buttonClick)="addPreprintBtnClicked()"
7+
/>
8+
9+
<section class="flex-1 flex flex-column bg-white p-3 md:p-4">
10+
<osf-search-input
11+
class="w-full"
12+
[control]="searchControl"
13+
[placeholder]="'preprints.myPreprints.searchPlaceholder' | translate"
14+
/>
15+
16+
<p-table
17+
class="mt-4"
18+
[value]="areMyPreprintsLoading() ? skeletonData : preprints()"
19+
[rows]="tableParams().rows"
20+
[first]="tableParams().firstRowIndex"
21+
[rowsPerPageOptions]="tableParams().rowsPerPageOptions"
22+
[paginator]="true"
23+
[totalRecords]="tableParams().totalRecords"
24+
paginatorDropdownAppendTo="body"
25+
[resizableColumns]="true"
26+
[autoLayout]="true"
27+
[scrollable]="true"
28+
[sortMode]="'single'"
29+
[lazy]="true"
30+
[lazyLoadOnInit]="true"
31+
(onPage)="onPageChange($event)"
32+
(onSort)="onSort($event)"
33+
[sortField]="sortColumn()"
34+
[sortOrder]="sortOrder() === 0 ? 1 : -1"
35+
[customSort]="true"
36+
[resetPageOnSort]="false"
37+
>
38+
<ng-template #header>
39+
<tr>
40+
<th pSortableColumn="title">
41+
{{ 'preprints.myPreprints.table.titleLabel' | translate }}
42+
<p-sortIcon field="title" />
43+
</th>
44+
<th>{{ 'preprints.myPreprints.table.contributorsLabel' | translate }}</th>
45+
<th pSortableColumn="dateModified">
46+
{{ 'preprints.myPreprints.table.modifiedLabel' | translate }}
47+
<p-sortIcon field="dateModified" />
48+
</th>
49+
</tr>
50+
</ng-template>
51+
<ng-template #body let-item>
52+
@if (item?.id) {
53+
<tr class="cursor-pointer" (click)="navigateToPreprintDetails(item)">
54+
<td>{{ item.title }}</td>
55+
<td>
56+
<osf-list-info-shortener [data]="item.contributors" />
57+
</td>
58+
<td>{{ item.dateModified | date: 'MMM d, y, h:mm a' }}</td>
59+
</tr>
60+
} @else {
61+
<tr class="loading-row">
62+
<td colspan="4">
63+
<p-skeleton width="100%" height="3.3rem" borderRadius="0" />
64+
</td>
65+
</tr>
66+
}
67+
</ng-template>
68+
<ng-template pTemplate="emptymessage">
69+
<tr>
70+
<td colspan="4" class="text-center">{{ 'common.search.noResultsFound' | translate }}</td>
71+
</tr>
72+
</ng-template>
73+
</p-table>
74+
</section>

src/app/features/preprints/pages/my-preprints/my-preprints.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 { MyPreprintsComponent } from './my-preprints.component';
4+
5+
describe('MyPreprintsComponent', () => {
6+
let component: MyPreprintsComponent;
7+
let fixture: ComponentFixture<MyPreprintsComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
imports: [MyPreprintsComponent],
12+
}).compileComponents();
13+
14+
fixture = TestBed.createComponent(MyPreprintsComponent);
15+
component = fixture.componentInstance;
16+
fixture.detectChanges();
17+
});
18+
19+
it('should create', () => {
20+
expect(component).toBeTruthy();
21+
});
22+
});

0 commit comments

Comments
 (0)