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
79 changes: 77 additions & 2 deletions src/app/features/admin-institutions/helpers/download-url.helper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,78 @@
import { CurrentResourceType } from '@shared/enums';

import { DOWNLOAD_FORMATS } from '../constants';
import { DownloadType } from '../enums';

export function downloadResults(downloadUrl: string | null, type: DownloadType) {
interface ResourceNameText {
singular_upper: string;
plural_lower: string;
}

export const INSTITUTIONS_CSV_TSV_FIELDS = {
[CurrentResourceType.Preprints]: [
'title',
'dateCreated',
'dateModified',
'sameAs',
'rights.name',
'creator.@id',
'creator.name',
'usage.viewCount',
'usage.downloadCount',
],
[CurrentResourceType.Projects]: [
'title',
'dateCreated',
'dateModified',
'sameAs',
'storageRegion.prefLabel',
'storageByteCount',
'creator.@id',
'creator.name',
'usage.viewCount',
'resourceNature.displayLabel',
'rights.name',
'hasOsfAddon.prefLabel',
'funder.name',
],
[CurrentResourceType.Registrations]: [
'title',
'dateCreated',
'dateModified',
'sameAs',
'storageRegion.prefLabel',
'storageByteCount',
'creator.@id',
'creator.name',
'usage.viewCount',
'resourceNature.displayLabel',
'rights.name',
'funder.name',
'conformsTo.title',
],
};

export const INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE = {
[CurrentResourceType.Projects]: {
singular_upper: 'Project',
plural_lower: 'projects',
},
[CurrentResourceType.Registrations]: {
singular_upper: 'Registration',
plural_lower: 'registrations',
},
[CurrentResourceType.Preprints]: {
singular_upper: 'Preprint',
plural_lower: 'preprints',
},
};

export function downloadResults(
downloadUrl: string | null,
type: DownloadType,
fields: string[],
resourceNameText: ResourceNameText
) {
if (!downloadUrl) {
return;
}
Expand All @@ -12,7 +83,11 @@ export function downloadResults(downloadUrl: string | null, type: DownloadType)
cardSearchUrl.searchParams.set('page[size]', '10000');
cardSearchUrl.searchParams.set('page[cursor]', '');
cardSearchUrl.searchParams.set('acceptMediatype', format);
cardSearchUrl.searchParams.set('withFileName', `projects-search-results`);
cardSearchUrl.searchParams.set('withFileName', `${resourceNameText.plural_lower}-search-results`);

if (type === DownloadType.CSV || type === DownloadType.TSV) {
cardSearchUrl.searchParams.set(`fields[${resourceNameText.singular_upper}]`, fields.join(','));
}

const downloadLink = cardSearchUrl.toString();
window.open(downloadLink, '_blank');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Button } from 'primeng/button';
import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, Component, computed, OnDestroy, OnInit, signal } from '@angular/core';

import { ResourceType, SortOrder } from '@osf/shared/enums';
import { CurrentResourceType, ResourceType, SortOrder } from '@osf/shared/enums';
import { PaginationLinksModel, ResourceModel, SearchFilters } from '@osf/shared/models';
import {
FetchResources,
Expand All @@ -23,7 +23,7 @@ import { AdminTableComponent } from '../../components';
import { FiltersSectionComponent } from '../../components/filters-section/filters-section.component';
import { preprintsTableColumns } from '../../constants';
import { DownloadType } from '../../enums';
import { downloadResults } from '../../helpers';
import { downloadResults, INSTITUTIONS_CSV_TSV_FIELDS, INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE } from '../../helpers';
import { mapPreprintResourceToTableData } from '../../mappers/institution-preprint-to-table-data.mapper';
import { TableCellData } from '../../models';
import { InstitutionsAdminSelectors } from '../../store';
Expand Down Expand Up @@ -105,6 +105,11 @@ export class InstitutionsPreprintsComponent implements OnInit, OnDestroy {
}

download(type: DownloadType) {
downloadResults(this.selfLink(), type);
downloadResults(
this.selfLink(),
type,
INSTITUTIONS_CSV_TSV_FIELDS[CurrentResourceType.Preprints],
INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE[CurrentResourceType.Preprints]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

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

download(type: DownloadType) {
downloadResults(this.selfLink(), type);
downloadResults(
this.selfLink(),
type,
INSTITUTIONS_CSV_TSV_FIELDS[CurrentResourceType.Projects],
INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE[CurrentResourceType.Projects]
);
}

onIconClick(event: TableIconClickEvent): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, Component, computed, OnDestroy, OnInit, signal } from '@angular/core';

import { TableCellData } from '@osf/features/admin-institutions/models';
import { ResourceType, SortOrder } from '@osf/shared/enums';
import { CurrentResourceType, ResourceType, SortOrder } from '@osf/shared/enums';
import { PaginationLinksModel, ResourceModel, SearchFilters } from '@osf/shared/models';
import {
ClearFilterSearchResults,
Expand All @@ -25,7 +25,7 @@ import { AdminTableComponent } from '../../components';
import { FiltersSectionComponent } from '../../components/filters-section/filters-section.component';
import { registrationTableColumns } from '../../constants';
import { DownloadType } from '../../enums';
import { downloadResults } from '../../helpers';
import { downloadResults, INSTITUTIONS_CSV_TSV_FIELDS, INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE } from '../../helpers';
import { mapRegistrationResourceToTableData } from '../../mappers/institution-registration-to-table-data.mapper';
import { InstitutionsAdminSelectors } from '../../store';

Expand Down Expand Up @@ -106,6 +106,11 @@ export class InstitutionsRegistrationsComponent implements OnInit, OnDestroy {
}

download(type: DownloadType) {
downloadResults(this.selfLink(), type);
downloadResults(
this.selfLink(),
type,
INSTITUTIONS_CSV_TSV_FIELDS[CurrentResourceType.Registrations],
INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE[CurrentResourceType.Registrations]
);
}
}
Loading