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
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,7 @@
</ng-icon>
</a>
<div *ngIf="isOpen" class="p-4 border-t bg-white">
<div class="flex justify-end mb-3">
<button
class="flex items-center gap-2 px-4 py-2 bg-primary-opacity-50 text-white rounded-md shadow hover:bg-primary' transition"
(click)="downloadMultipleFiles()"
>
<ng-icon name="matCloudDownloadOutline"></ng-icon>
{{ 'record.metadata.api.form.downloadAll' | translate }}
</button>
</div>
<div class="flex justify-end mb-3"></div>
<div class="space-y-2">
<div
*ngFor="let entry of liste$ | async"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { HttpClient } from '@angular/common/http'
import { Component, Input, OnInit, inject } from '@angular/core'
import { NgIcon, provideIcons, provideNgIconsConfig } from '@ng-icons/core'
import { TranslateDirective, TranslatePipe } from '@ngx-translate/core'
import { map, take, Observable } from 'rxjs'
import { EMPTY, Observable, from, of } from 'rxjs'
import { concatMap, delay, map, switchMap, take, tap } from 'rxjs/operators'
import { matCloudDownloadOutline } from '@ng-icons/material-icons/outline'
import { CdkAccordionModule } from '@angular/cdk/accordion'

Expand All @@ -12,7 +13,6 @@ import { CdkAccordionModule } from '@angular/cdk/accordion'
templateUrl: './gpf-api-dl-list-item.component.html',
styleUrls: ['./gpf-api-dl-list-item.component.css'],
standalone: true,

imports: [
CommonModule,
TranslateDirective,
Expand All @@ -21,12 +21,8 @@ import { CdkAccordionModule } from '@angular/cdk/accordion'
CdkAccordionModule,
],
providers: [
provideIcons({
matCloudDownloadOutline,
}),
provideNgIconsConfig({
size: '1.5em',
}),
provideIcons({ matCloudDownloadOutline }),
provideNgIconsConfig({ size: '1.5em' }),
],
})
export class GpfApiDlListItemComponent implements OnInit {
Expand All @@ -37,43 +33,12 @@ export class GpfApiDlListItemComponent implements OnInit {
@Input() format: string
@Input() isFromWfs: boolean

liste$: Observable<any>
liste$: Observable<{ id: string }[]>
isOpen = false

ngOnInit(): void {
this.liste$ = this.http
.get(`${this.link['id']}?limit=50`)
.pipe(map((response) => response['entry']))
}

async downloadMultipleFiles() {
this.liste$.pipe(take(1)).subscribe(async (fileUrls: { id: string }[]) => {
if (!fileUrls || fileUrls.length === 0) {
console.warn('Aucun fichier à télécharger.')
return
}

for (const fileUrl of fileUrls) {
if (fileUrl?.id) {
await this.downloadFile(fileUrl.id)
} else {
console.warn('Fichier invalide :', fileUrl)
}
}
})
}

private downloadFile(url: string): Promise<void> {
return new Promise((resolve) => {
setTimeout(() => {
const link = document.createElement('a')
link.href = url
link.setAttribute('download', '')
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
resolve()
}, 1000) // Attendre 1s entre chaque téléchargement
})
}
}
Loading