1
|
import { Component, Input, OnInit } from '@angular/core';
|
2
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
3
|
import { didntChooseBaseUrl, invalidCustomBaseUrl } from '../../../domain/shared-messages';
|
4
|
import { ValidatorService } from '../../../services/validator.service';
|
5
|
|
6
|
@Component({
|
7
|
selector: 'compatibility-validate-step1',
|
8
|
templateUrl: 'compatibility-validate-step1.component.html'
|
9
|
})
|
10
|
|
11
|
export class CompatibilityValidateStep1Component implements OnInit {
|
12
|
group: FormGroup;
|
13
|
errorMessage: string;
|
14
|
|
15
|
chosenUrl: string;
|
16
|
|
17
|
@Input() type: string;
|
18
|
@Input() baseUrlList: string[];
|
19
|
|
20
|
constructor(private fb: FormBuilder,
|
21
|
private valService: ValidatorService) {}
|
22
|
|
23
|
ngOnInit() {
|
24
|
this.group = this.fb.group({
|
25
|
selectBaseUrl : '',
|
26
|
customBaseUrl : ''
|
27
|
});
|
28
|
this.group.get('customBaseUrl').disable();
|
29
|
}
|
30
|
|
31
|
chooseUrl(choice: boolean){
|
32
|
if (choice) {
|
33
|
this.group.get('selectBaseUrl').enable();
|
34
|
this.group.get('customBaseUrl').disable();
|
35
|
} else {
|
36
|
this.group.get('selectBaseUrl').disable();
|
37
|
this.group.get('customBaseUrl').enable();
|
38
|
}
|
39
|
}
|
40
|
|
41
|
submitForm() {
|
42
|
if ( this.group.get('selectBaseUrl').value || this.group.get('customBaseUrl').value ) {
|
43
|
let response: boolean;
|
44
|
if (this.group.get('customBaseUrl').value ) {
|
45
|
this.valService.identifyRepository(this.group.get('customBaseUrl').value).subscribe(
|
46
|
res => response = res,
|
47
|
error => console.log(error)
|
48
|
);
|
49
|
if ( response ) {
|
50
|
this.chosenUrl = this.group.get('customBaseUrl').value;
|
51
|
console.log('added new baseUrl!');
|
52
|
return true;
|
53
|
} else {
|
54
|
if (this.group.get('selectBaseUrl').value) {
|
55
|
this.chosenUrl = this.group.get('selectBaseUrl').value;
|
56
|
return true;
|
57
|
} else {
|
58
|
this.errorMessage = invalidCustomBaseUrl;
|
59
|
}
|
60
|
}
|
61
|
} else {
|
62
|
this.chosenUrl = this.group.get('selectBaseUrl').value;
|
63
|
console.log('selected baseUrl!');
|
64
|
return true;
|
65
|
}
|
66
|
} else {
|
67
|
console.log('something went wrong');
|
68
|
this.errorMessage = didntChooseBaseUrl;
|
69
|
}
|
70
|
return false;
|
71
|
}
|
72
|
}
|