All files / src/app/features/jobs/forms/create-job-with-url-form create-job-with-url-form.component.ts

77.41% Statements 24/31
0% Branches 0/4
60% Functions 6/10
100% Lines 19/19

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 539x 9x 9x 9x 9x   9x 9x 9x 9x               9x   2x     2x   2x 2x       2x                       2x         1x 1x 1x        
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { FormBuilder, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { MatFormField, MatHint, MatLabel } from '@angular/material/form-field';
import { StatusIconComponent } from '@layout/shared/status-icon/status-icon.component';
import { JobService } from '@core/services/job.service';
import { JobMetadata } from '@core/model/job-metadata.interface';
import { BaseChildComponent } from '@core/component/base-child.component';
import { ModalService } from '@core/services/modal.service';
import { MatInput } from '@angular/material/input';
import { MatButton } from '@angular/material/button';
 
@Component({
  selector: 'app-create-job-with-url-form',
  imports: [ReactiveFormsModule, MatFormField, MatInput, MatHint, MatLabel, StatusIconComponent, MatButton],
  templateUrl: './create-job-with-url-form.component.html',
  styleUrl: './create-job-with-url-form.component.scss'
})
export class CreateJobWithUrlFormComponent extends BaseChildComponent implements OnInit {
 
  @Output() onJobCreation = new EventEmitter<JobMetadata>;
 
  public urlForm: FormGroup | undefined;
  public urlFormLoading = false;
 
  constructor(private readonly fb: FormBuilder, private readonly jobService: JobService, private readonly modalService: ModalService) {
    super();
  }
 
  ngOnInit(): void {
    this.urlForm = this.fb.group({
      url: [
        '',
        [
          Validators.required,
          Validators.pattern('(https?://)?([\\da-z.-]+)\\.([a-z.]{2,6})\\b([-a-zA-Z0-9@:%._\\+~#?&//=]*)')
        ]
      ],
    });
  }
 
  get url() {
    return this.urlForm?.get('url');
  }
 
 
  getMetadataFromUrl(): void {
    this.jobService.getJobMetadata(this.url?.value).subscribe((metadata: JobMetadata) => {
      this.data.metadata = { jobMetadata: metadata };
      this.success();
    });
  }
}