1
|
import { Component, OnInit, Type, ViewChild } from '@angular/core';
|
2
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
3
|
import { DatasourceInterfaceFormComponent } from './sources-forms/datasource-interface-form.component';
|
4
|
import { Repository, RepositoryInterface } from '../../domain/typeScriptClasses';
|
5
|
import { RepositoryService } from '../../services/repository.service';
|
6
|
import { ActivatedRoute } from '@angular/router';
|
7
|
import {
|
8
|
Description,
|
9
|
interfaceFormDesc,
|
10
|
} from '../../domain/oa-description';
|
11
|
import { formInfoLoading, loadingRepoError } from '../../domain/shared-messages';
|
12
|
import { DatasourceUpdateFormComponent } from './sources-forms/datasource-update-form.component';
|
13
|
|
14
|
|
15
|
|
16
|
@Component ({
|
17
|
selector: 'sources-update-repo',
|
18
|
templateUrl: 'sources-update-repo.component.html'
|
19
|
})
|
20
|
|
21
|
export class SourcesUpdateRepoComponent implements OnInit {
|
22
|
loadingMessage: string;
|
23
|
errorMessage: string;
|
24
|
|
25
|
repoId: string;
|
26
|
logoURL: string;
|
27
|
repo: Repository;
|
28
|
repoInterfaces: RepositoryInterface[] = [];
|
29
|
|
30
|
@ViewChild('datasourceUpdateForm') datasourceUpdateForm: DatasourceUpdateFormComponent;
|
31
|
|
32
|
group: FormGroup;
|
33
|
interfaceFormDesc: Description = interfaceFormDesc;
|
34
|
updateDatasourceInterfaces: Type<any> = DatasourceInterfaceFormComponent;
|
35
|
|
36
|
constructor (
|
37
|
private fb: FormBuilder,
|
38
|
private repoService: RepositoryService,
|
39
|
private route: ActivatedRoute )
|
40
|
{}
|
41
|
|
42
|
|
43
|
ngOnInit() {
|
44
|
this.readRepoId();
|
45
|
}
|
46
|
|
47
|
readRepoId() {
|
48
|
this.repoId = this.route.snapshot.paramMap.get('id');
|
49
|
console.log(`repoId is ${this.repoId}`);
|
50
|
this.getRepo();
|
51
|
this.getRepoInterfaces();
|
52
|
}
|
53
|
|
54
|
getRepo() {
|
55
|
if (this.repoId) {
|
56
|
this.loadingMessage = formInfoLoading;
|
57
|
this.repoService.getRepositoryById(this.repoId).subscribe(
|
58
|
repo => {
|
59
|
this.repo = repo;
|
60
|
},
|
61
|
error => {
|
62
|
console.log(error);
|
63
|
this.loadingMessage = '';
|
64
|
this.errorMessage = loadingRepoError;
|
65
|
},
|
66
|
() => {
|
67
|
this.loadingMessage = '';
|
68
|
this.logoURL = this.repo.logoUrl;
|
69
|
}
|
70
|
);
|
71
|
}
|
72
|
}
|
73
|
|
74
|
getRepoInterfaces() {
|
75
|
this.group = this.fb.group({});
|
76
|
this.repoService.getRepositoryInterface(this.repoId).subscribe(
|
77
|
interfaces => {
|
78
|
this.repoInterfaces = interfaces.sort( function(a,b) {
|
79
|
if(a.id<b.id){
|
80
|
return -1;
|
81
|
} else if(a.id>b.id){
|
82
|
return 1;
|
83
|
} else {
|
84
|
return 0;
|
85
|
}
|
86
|
});
|
87
|
console.log(`the number of interfaces for ${this.repoId} is ${this.repoInterfaces.length}`);
|
88
|
},
|
89
|
error => {
|
90
|
console.log(error);
|
91
|
this.loadingMessage = '';
|
92
|
this.errorMessage = loadingRepoError;
|
93
|
}, () => this.loadingMessage = ''
|
94
|
);
|
95
|
}
|
96
|
|
97
|
getNewLogoUrl(newURL: string) {
|
98
|
this.logoURL = newURL;
|
99
|
}
|
100
|
|
101
|
}
|