All files / src/app/features/jobs/job-detail job-detail.component.ts

72.72% Statements 48/66
0% Branches 0/4
53.57% Functions 15/28
97.82% Lines 45/46

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 1041x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x               2x   8x       8x     8x 8x 8x 8x 8x 8x 8x 8x       3x       2x     1x 1x 1x   2x       1x       1x       2x     2x         1x               2x 2x       1x     1x           1x      
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
import { JobService } from '@core/services/job.service';
import { catchError, Subject, take, takeUntil, tap } from 'rxjs';
import { Job } from '@core/model/job.interface';
import { Title } from '@angular/platform-browser';
import { ActivityType } from '@core/model/activity-type';
import { MatButton, MatIconButton } from '@angular/material/button';
import { ConfirmDialogService } from '@core/services/confirm-dialog.service';
import { MatCardModule } from '@angular/material/card';
import { ModalService } from '@core/services/modal.service';
import { NotificationService } from '@core/services/notification.service';
import { ApiError } from '@core/errors/api-error';
import { JobAttachmentsComponent } from '@features/jobs/job-attachments/job-attachments.component';
import { JobActivitiesComponent } from "@features/jobs/job-activities/job-activities.component";
import { JobSummaryComponent } from '@features/jobs/job-summary/job-summary.component';
import { MatIcon } from '@angular/material/icon';
import { MatTooltip } from '@angular/material/tooltip';
import { ErrorProcessorService } from '@core/services/error-processor.service';
import { JobEditableFieldComponent } from '../job-editable-field/job-editable-field.component';
 
@Component({
  selector: 'app-job-detail',
  imports: [JobSummaryComponent, MatCardModule, MatButton, JobAttachmentsComponent, JobActivitiesComponent, MatButton, MatIconButton, MatIcon, MatTooltip, RouterLink, JobEditableFieldComponent],
  templateUrl: './job-detail.component.html',
  styleUrl: './job-detail.component.scss'
})
export class JobDetailComponent implements OnInit, OnDestroy {
 
  private destroy$: Subject<boolean> = new Subject<boolean>();
 
  public job!: Job;
 
  public ActivityType = ActivityType;
 
  constructor(
    private router: Router,
    private activatedRoute: ActivatedRoute, 
    private jobService: JobService,
    private confirmDialogService: ConfirmDialogService,
    private modalService: ModalService,
    private notificationService: NotificationService,
    private title: Title,
    private errorProcessorService: ErrorProcessorService
  ) {}
 
  private loadJob(jobId: string): void {
    this.jobService.getJobById(jobId).pipe(
      take(1),
      // set page title once the job  is available
      tap((job: Job) =>{
        this.title.setTitle(`Job - ${job.title}`);
      }),
      catchError((error: ApiError) => {
        console.log(error);
        this.router.navigate(["/jobs"]);
        return this.errorProcessorService.processError(error);
      })
    ).subscribe((job) => this.job = job);
  }
 
  reloadJob(job: Job) {
    this.loadJob(job.id);
  }
 
  ngOnDestroy(): void {
    this.destroy$.next(true);
  }
 
  ngOnInit(): void {
    this.activatedRoute.params
      .pipe(takeUntil(this.destroy$))
      .subscribe(params => {
        this.loadJob(params['id']);
    });
  }
 
  editJob(job: Job) :void {
    this.modalService.openJobModal('job', job, () => this.loadJob(job.id))
  }
 
  onJobChanged(job: Job): void {
    this.job = job;
  }
 
  onDelete(job: Job) :void {
    this.notificationService.confirmation($localize`:@@job.deleted:Job successfully deleted.`);
    this.router.navigate(["/jobs"]);
  }
 
  confirmDeleteJob(job: Job) :void {
    this.jobService.deleteJob(job.id).pipe(
      take(1),
      tap(() => {
        this.onDelete(job);
      })
    ).subscribe();
  }
 
  deleteJob(job: Job) :void {
    this.confirmDialogService.openConfirmDialog($localize `:@@warning.job.delete:Delete job "${job.title}" ? All data will be lost.`, () => this.confirmDeleteJob(job));
  }
}