Skip to content

Commit

Permalink
fix loading artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
larscom committed Dec 22, 2024
1 parent 2713920 commit b47da23
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@for (job of jobs(); track job.id) {
<li nz-menu-item>
<button
[nzLoading]="loading()"
[nzLoading]="isLoading(job.id)"
(click)="download($event, job)"
[style.color]="job.status | statusColor"
nz-button
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Job } from '$groups/model/job'
import { Job, JobId } from '$groups/model/job'
import { PipelineId } from '$groups/model/pipeline'
import { ProjectId } from '$groups/model/project'
import { CommonModule } from '@angular/common'
Expand All @@ -25,12 +25,11 @@ export class DownloadArtifactsIconComponent {
private http = inject(HttpClient)
private injector = inject(Injector)
private notification = inject(NzNotificationService)
private loadingJobIds = signal<number[]>([])

projectId = input.required<ProjectId>()
pipelineId = input.required<PipelineId>()

loading = signal(false)

jobs = toSignal(
combineLatest([
toObservable(this.projectId, { injector: this.injector }),
Expand All @@ -49,19 +48,23 @@ export class DownloadArtifactsIconComponent {
{ initialValue: [] }
)

isLoading(jobId: JobId): boolean {
return this.loadingJobIds().includes(jobId)
}

download(e: MouseEvent, { id, name }: Job) {
e.stopPropagation()

this.loadingJobIds.set([...this.loadingJobIds(), id])

const params = {
project_id: this.projectId(),
job_id: id
}

this.loading.set(true)

this.http
.get('/api/artifacts', { params, responseType: 'blob' })
.pipe(finalize(() => this.loading.set(false)))
.pipe(finalize(() => this.loadingJobIds.set(this.loadingJobIds().filter((jobId) => jobId !== id))))
.subscribe({
next: (blob) => FileSaver.saveAs(blob, `${name}_${id}.zip`),
error: ({ status, error }: HttpErrorResponse) => {
Expand Down

0 comments on commit b47da23

Please sign in to comment.