Skip to content

Commit 4bf70b8

Browse files
authored
Merge pull request #720 from mkovalua/fix/ENG-9542
[ENG-9542] specify needed columns to extract for registation/preprint/project csv tsv downloading for /institutions/cos/dashboard/
2 parents 25ae015 + d08f9dd commit 4bf70b8

File tree

4 files changed

+101
-11
lines changed

4 files changed

+101
-11
lines changed

src/app/features/admin-institutions/helpers/download-url.helper.ts

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,78 @@
1+
import { CurrentResourceType } from '@shared/enums';
2+
13
import { DOWNLOAD_FORMATS } from '../constants';
24
import { DownloadType } from '../enums';
35

4-
export function downloadResults(downloadUrl: string | null, type: DownloadType) {
6+
interface ResourceNameText {
7+
singular_upper: string;
8+
plural_lower: string;
9+
}
10+
11+
export const INSTITUTIONS_CSV_TSV_FIELDS = {
12+
[CurrentResourceType.Preprints]: [
13+
'title',
14+
'dateCreated',
15+
'dateModified',
16+
'sameAs',
17+
'rights.name',
18+
'creator.@id',
19+
'creator.name',
20+
'usage.viewCount',
21+
'usage.downloadCount',
22+
],
23+
[CurrentResourceType.Projects]: [
24+
'title',
25+
'dateCreated',
26+
'dateModified',
27+
'sameAs',
28+
'storageRegion.prefLabel',
29+
'storageByteCount',
30+
'creator.@id',
31+
'creator.name',
32+
'usage.viewCount',
33+
'resourceNature.displayLabel',
34+
'rights.name',
35+
'hasOsfAddon.prefLabel',
36+
'funder.name',
37+
],
38+
[CurrentResourceType.Registrations]: [
39+
'title',
40+
'dateCreated',
41+
'dateModified',
42+
'sameAs',
43+
'storageRegion.prefLabel',
44+
'storageByteCount',
45+
'creator.@id',
46+
'creator.name',
47+
'usage.viewCount',
48+
'resourceNature.displayLabel',
49+
'rights.name',
50+
'funder.name',
51+
'conformsTo.title',
52+
],
53+
};
54+
55+
export const INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE = {
56+
[CurrentResourceType.Projects]: {
57+
singular_upper: 'Project',
58+
plural_lower: 'projects',
59+
},
60+
[CurrentResourceType.Registrations]: {
61+
singular_upper: 'Registration',
62+
plural_lower: 'registrations',
63+
},
64+
[CurrentResourceType.Preprints]: {
65+
singular_upper: 'Preprint',
66+
plural_lower: 'preprints',
67+
},
68+
};
69+
70+
export function downloadResults(
71+
downloadUrl: string | null,
72+
type: DownloadType,
73+
fields: string[],
74+
resourceNameText: ResourceNameText
75+
) {
576
if (!downloadUrl) {
677
return;
778
}
@@ -12,7 +83,11 @@ export function downloadResults(downloadUrl: string | null, type: DownloadType)
1283
cardSearchUrl.searchParams.set('page[size]', '10000');
1384
cardSearchUrl.searchParams.set('page[cursor]', '');
1485
cardSearchUrl.searchParams.set('acceptMediatype', format);
15-
cardSearchUrl.searchParams.set('withFileName', `projects-search-results`);
86+
cardSearchUrl.searchParams.set('withFileName', `${resourceNameText.plural_lower}-search-results`);
87+
88+
if (type === DownloadType.CSV || type === DownloadType.TSV) {
89+
cardSearchUrl.searchParams.set(`fields[${resourceNameText.singular_upper}]`, fields.join(','));
90+
}
1691

1792
const downloadLink = cardSearchUrl.toString();
1893
window.open(downloadLink, '_blank');

src/app/features/admin-institutions/pages/institutions-preprints/institutions-preprints.component.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Button } from 'primeng/button';
77
import { CommonModule } from '@angular/common';
88
import { ChangeDetectionStrategy, Component, computed, OnDestroy, OnInit, signal } from '@angular/core';
99

10-
import { ResourceType, SortOrder } from '@osf/shared/enums';
10+
import { CurrentResourceType, ResourceType, SortOrder } from '@osf/shared/enums';
1111
import { PaginationLinksModel, ResourceModel, SearchFilters } from '@osf/shared/models';
1212
import {
1313
FetchResources,
@@ -23,7 +23,7 @@ import { AdminTableComponent } from '../../components';
2323
import { FiltersSectionComponent } from '../../components/filters-section/filters-section.component';
2424
import { preprintsTableColumns } from '../../constants';
2525
import { DownloadType } from '../../enums';
26-
import { downloadResults } from '../../helpers';
26+
import { downloadResults, INSTITUTIONS_CSV_TSV_FIELDS, INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE } from '../../helpers';
2727
import { mapPreprintResourceToTableData } from '../../mappers/institution-preprint-to-table-data.mapper';
2828
import { TableCellData } from '../../models';
2929
import { InstitutionsAdminSelectors } from '../../store';
@@ -105,6 +105,11 @@ export class InstitutionsPreprintsComponent implements OnInit, OnDestroy {
105105
}
106106

107107
download(type: DownloadType) {
108-
downloadResults(this.selfLink(), type);
108+
downloadResults(
109+
this.selfLink(),
110+
type,
111+
INSTITUTIONS_CSV_TSV_FIELDS[CurrentResourceType.Preprints],
112+
INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE[CurrentResourceType.Preprints]
113+
);
109114
}
110115
}

src/app/features/admin-institutions/pages/institutions-projects/institutions-projects.component.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
2121

2222
import { UserSelectors } from '@core/store/user';
2323
import { RequestAccessErrorDialogComponent } from '@osf/features/admin-institutions/components/request-access-error-dialog/request-access-error-dialog.component';
24-
import { ResourceType, SortOrder } from '@osf/shared/enums';
24+
import { CurrentResourceType, ResourceType, SortOrder } from '@osf/shared/enums';
2525
import { PaginationLinksModel, ResourceModel, SearchFilters } from '@osf/shared/models';
2626
import { CustomDialogService, ToastService } from '@osf/shared/services';
2727
import {
@@ -39,7 +39,7 @@ import { FiltersSectionComponent } from '../../components/filters-section/filter
3939
import { projectTableColumns } from '../../constants';
4040
import { ContactDialogComponent } from '../../dialogs';
4141
import { ContactOption, DownloadType } from '../../enums';
42-
import { downloadResults } from '../../helpers';
42+
import { downloadResults, INSTITUTIONS_CSV_TSV_FIELDS, INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE } from '../../helpers';
4343
import { mapProjectResourceToTableCellData } from '../../mappers/institution-project-to-table-data.mapper';
4444
import { ContactDialogData, TableCellData, TableCellLink, TableIconClickEvent } from '../../models';
4545
import { InstitutionsAdminSelectors, RequestProjectAccess, SendUserMessage } from '../../store';
@@ -128,7 +128,12 @@ export class InstitutionsProjectsComponent implements OnInit, OnDestroy {
128128
}
129129

130130
download(type: DownloadType) {
131-
downloadResults(this.selfLink(), type);
131+
downloadResults(
132+
this.selfLink(),
133+
type,
134+
INSTITUTIONS_CSV_TSV_FIELDS[CurrentResourceType.Projects],
135+
INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE[CurrentResourceType.Projects]
136+
);
132137
}
133138

134139
onIconClick(event: TableIconClickEvent): void {

src/app/features/admin-institutions/pages/institutions-registrations/institutions-registrations.component.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { CommonModule } from '@angular/common';
88
import { ChangeDetectionStrategy, Component, computed, OnDestroy, OnInit, signal } from '@angular/core';
99

1010
import { TableCellData } from '@osf/features/admin-institutions/models';
11-
import { ResourceType, SortOrder } from '@osf/shared/enums';
11+
import { CurrentResourceType, ResourceType, SortOrder } from '@osf/shared/enums';
1212
import { PaginationLinksModel, ResourceModel, SearchFilters } from '@osf/shared/models';
1313
import {
1414
ClearFilterSearchResults,
@@ -25,7 +25,7 @@ import { AdminTableComponent } from '../../components';
2525
import { FiltersSectionComponent } from '../../components/filters-section/filters-section.component';
2626
import { registrationTableColumns } from '../../constants';
2727
import { DownloadType } from '../../enums';
28-
import { downloadResults } from '../../helpers';
28+
import { downloadResults, INSTITUTIONS_CSV_TSV_FIELDS, INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE } from '../../helpers';
2929
import { mapRegistrationResourceToTableData } from '../../mappers/institution-registration-to-table-data.mapper';
3030
import { InstitutionsAdminSelectors } from '../../store';
3131

@@ -106,6 +106,11 @@ export class InstitutionsRegistrationsComponent implements OnInit, OnDestroy {
106106
}
107107

108108
download(type: DownloadType) {
109-
downloadResults(this.selfLink(), type);
109+
downloadResults(
110+
this.selfLink(),
111+
type,
112+
INSTITUTIONS_CSV_TSV_FIELDS[CurrentResourceType.Registrations],
113+
INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE[CurrentResourceType.Registrations]
114+
);
110115
}
111116
}

0 commit comments

Comments
 (0)