From 4c41f74841f3d1951b42b0d11b0612a1a3c79fac Mon Sep 17 00:00:00 2001 From: John Pinto Date: Wed, 4 Dec 2024 11:59:14 +0000 Subject: [PATCH] Initial work to create download link. --- .../datashare/download-link.service.spec.ts | 16 ++++++ src/app/datashare/download-link.service.ts | 52 +++++++++++++++++++ .../file-section/file-section.component.html | 7 +-- .../file-section/file-section.component.scss | 15 ++++++ .../file-section/file-section.component.ts | 17 +++++- 5 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 src/app/datashare/download-link.service.spec.ts create mode 100644 src/app/datashare/download-link.service.ts create mode 100644 src/themes/datashare/app/item-page/simple/field-components/file-section/file-section.component.scss diff --git a/src/app/datashare/download-link.service.spec.ts b/src/app/datashare/download-link.service.spec.ts new file mode 100644 index 00000000000..dc59c122797 --- /dev/null +++ b/src/app/datashare/download-link.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { DownloadLinkService } from './download-link.service'; + +describe('DownloadLinkService', () => { + let service: DownloadLinkService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(DownloadLinkService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/datashare/download-link.service.ts b/src/app/datashare/download-link.service.ts new file mode 100644 index 00000000000..559f64eef9f --- /dev/null +++ b/src/app/datashare/download-link.service.ts @@ -0,0 +1,52 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; +import { Item } from '../core/shared/item.model'; +import { BaseDataService } from '../core/data/base/base-data.service'; +import { RequestService } from '../core/data/request.service'; +import { RemoteDataBuildService } from '../core/cache/builders/remote-data-build.service'; +import { ObjectCacheService } from '../core/cache/object-cache.service'; +import { HALEndpointService } from '../core/shared/hal-endpoint.service'; +import { HttpClient } from '@angular/common/http'; + +import { environment } from '../../environments/environment'; + +@Injectable({ + providedIn: 'root' +}) +export class DownloadLinkService { + + + constructor( + protected httpClient: HttpClient, + ) { + } + + getDownloadLink(itemId: string): Observable { + console.log("itemId:", itemId); + console.log(`${environment.rest.baseUrl}/api/datashare/items/${itemId}/zip-file-link`); + const options = { + responseType: 'text' as const, + }; + return this.httpClient.get(`${environment.rest.baseUrl}/api/datashare/items/${itemId}/zip-file-link`, options).pipe( + map((response: string) => { + console.log('response:', response); + return response; + }) + ); + + } + isDownloadLinkAvailable(itemId: string): Observable { + console.log("itemId:", itemId); + console.log(`${environment.rest.baseUrl}/api/datashare/items/${itemId}/zip-file-link`); + const options = { + responseType: 'text' as const, + }; + return this.httpClient.get(`${environment.rest.baseUrl}/api/datashare/items/${itemId}/zip-file-downloadable`, options).pipe( + map((response: string) => { + console.log('response:', response); + return Boolean(response); + }) + ); + } +} diff --git a/src/themes/datashare/app/item-page/simple/field-components/file-section/file-section.component.html b/src/themes/datashare/app/item-page/simple/field-components/file-section/file-section.component.html index 1d73e13be35..b7d39977e7b 100644 --- a/src/themes/datashare/app/item-page/simple/field-components/file-section/file-section.component.html +++ b/src/themes/datashare/app/item-page/simple/field-components/file-section/file-section.component.html @@ -1,9 +1,10 @@
- - +
diff --git a/src/themes/datashare/app/item-page/simple/field-components/file-section/file-section.component.scss b/src/themes/datashare/app/item-page/simple/field-components/file-section/file-section.component.scss new file mode 100644 index 00000000000..6ed8af340a1 --- /dev/null +++ b/src/themes/datashare/app/item-page/simple/field-components/file-section/file-section.component.scss @@ -0,0 +1,15 @@ +a.download-zip, +a.download-zip:hover, +a.download-zip:focus, +a.download-zip:active, +a.download-zip:visited { + text-decoration: none; + border-bottom: none; + -webkit-tap-highlight-color: white; + + +} + +img.download-all { + width: 15rem; +} \ No newline at end of file diff --git a/src/themes/datashare/app/item-page/simple/field-components/file-section/file-section.component.ts b/src/themes/datashare/app/item-page/simple/field-components/file-section/file-section.component.ts index 4a600b31108..2510266db27 100644 --- a/src/themes/datashare/app/item-page/simple/field-components/file-section/file-section.component.ts +++ b/src/themes/datashare/app/item-page/simple/field-components/file-section/file-section.component.ts @@ -10,7 +10,7 @@ import { MetadataFieldWrapperComponent } from '../../../../../../../app/shared/m import { FileSizePipe } from '../../../../../../../app/shared/utils/file-size-pipe'; import { VarDirective } from '../../../../../../../app/shared/utils/var.directive'; import { getFirstCompletedRemoteData } from '../../../../../../../app/core/shared/operators'; -import { map, Observable, switchMap, tap } from 'rxjs'; +import { filter, map, Observable, switchMap, tap } from 'rxjs'; import { RemoteData } from '../../../../../../../app/core/data/remote-data'; import { PaginatedList } from '../../../../../../../app/core/data/paginated-list.model'; import { Bitstream } from '../../../../../../../app/core/shared/bitstream.model'; @@ -23,11 +23,14 @@ import { DSONameService } from '../../../../../../../app/core/breadcrumbs/dso-na import { APP_CONFIG, AppConfig } from '../../../../../../../config/app-config.interface'; import { PaginationService } from '../../../../../../../app/core/pagination/pagination.service'; import { PaginationComponent } from '../../../../../../../app/shared/pagination/pagination.component'; +import { DownloadLinkService } from '../../../../../../../app/datashare/download-link.service'; +import { response } from 'express'; @Component({ selector: 'ds-themed-item-page-file-section', templateUrl: './file-section.component.html', // templateUrl: '../../../../../../../app/item-page/simple/field-components/file-section/file-section.component.html', + styleUrls: ['./file-section.component.scss'], animations: [slideSidebarPadding], standalone: true, imports: [ @@ -45,6 +48,8 @@ export class FileSectionComponent extends BaseComponent { cclicenses$: Observable>>; licenses$: Observable>>; + downloadLink$: Observable; + downloadLinkAvailable$: Observable; cclicenseOptions = Object.assign(new PaginationComponentOptions(), { id: 'cclbo', @@ -66,6 +71,7 @@ export class FileSectionComponent extends BaseComponent { protected paginationService: PaginationService, public dsoNameService: DSONameService, @Inject(APP_CONFIG) protected appConfig: AppConfig, + protected downloadLinkService: DownloadLinkService, ) { super(bitstreamDataService, notificationsService, translateService, dsoNameService, appConfig); @@ -109,6 +115,15 @@ export class FileSectionComponent extends BaseComponent { ), ); + this.downloadLink$ = this.downloadLinkService.getDownloadLink(this.item.id).pipe( + filter(response => !!response && response.length > 0), + map(response => response) + ); + this.downloadLinkAvailable$ = this.downloadLinkService.isDownloadLinkAvailable(this.item.id).pipe( + filter((response: boolean) => !!response && response), + map(response => response) + ); + } hasValuesInBundle(bundle: PaginatedList) {