1
|
import { Component, OnInit, QueryList, ViewChild, ViewChildren } from '@angular/core';
|
2
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
3
|
import { Repository, RepositoryInterface } from '../../domain/typeScriptClasses';
|
4
|
import { RepositoryService } from '../../services/repository.service';
|
5
|
import { ActivatedRoute, Router } from '@angular/router';
|
6
|
import { formInfoLoading, loadingRepoError } from '../../domain/shared-messages';
|
7
|
import { DatasourceUpdateFormComponent } from './sources-forms/datasource-update-form.component';
|
8
|
import { ConfirmationDialogComponent } from '../../shared/reusablecomponents/confirmation-dialog.component';
|
9
|
import { AuthenticationService } from '../../services/authentication.service';
|
10
|
import { DatasourceNewInterfaceFormComponent } from './sources-forms/datasource-new-interface-form.component';
|
11
|
|
12
|
@Component ({
|
13
|
selector: 'sources-update-repo',
|
14
|
templateUrl: 'sources-update-repo.component.html'
|
15
|
})
|
16
|
|
17
|
export class SourcesUpdateRepoComponent implements OnInit {
|
18
|
loadingMessage: string;
|
19
|
errorMessage: string;
|
20
|
|
21
|
repoId: string;
|
22
|
logoURL: string;
|
23
|
repo: Repository;
|
24
|
repoInterfaces: RepositoryInterface[] = [];
|
25
|
|
26
|
@ViewChild('datasourceUpdateForm') datasourceUpdateForm: DatasourceUpdateFormComponent;
|
27
|
|
28
|
group: FormGroup;
|
29
|
|
30
|
@ViewChildren('interfacesArray') interfacesArray: QueryList<DatasourceNewInterfaceFormComponent>;
|
31
|
dataForInterfaceComp: any[] = [];
|
32
|
|
33
|
isModalShown: boolean;
|
34
|
@ViewChild('updateLogoUrlModal')
|
35
|
public updateLogoUrlModal: ConfirmationDialogComponent;
|
36
|
|
37
|
constructor ( private fb: FormBuilder,
|
38
|
private repoService: RepositoryService,
|
39
|
private authService: AuthenticationService,
|
40
|
private route: ActivatedRoute,
|
41
|
private router: Router) { }
|
42
|
|
43
|
|
44
|
ngOnInit() {
|
45
|
this.readRepoId();
|
46
|
let body = document.getElementsByTagName('body')[0];
|
47
|
body.classList.remove("top_bar_active"); //remove the class
|
48
|
}
|
49
|
|
50
|
readRepoId() {
|
51
|
this.repoId = this.route.snapshot.paramMap.get('id');
|
52
|
console.log(`repoId is ${this.repoId}`);
|
53
|
this.getRepo();
|
54
|
}
|
55
|
|
56
|
getRepo() {
|
57
|
if (this.repoId) {
|
58
|
this.loadingMessage = formInfoLoading;
|
59
|
this.repoService.getRepositoryById(this.repoId).subscribe(
|
60
|
repo => {
|
61
|
this.repo = repo;
|
62
|
},
|
63
|
error => {
|
64
|
console.log(error);
|
65
|
this.loadingMessage = '';
|
66
|
this.errorMessage = loadingRepoError;
|
67
|
},
|
68
|
() => {
|
69
|
if ( this.authService.activateFrontAuthorization && (this.authService.getUserEmail() !== this.repo.registeredBy.trim()) ) {
|
70
|
this.router.navigateByUrl('/403-forbidden', { skipLocationChange: true });
|
71
|
} else {
|
72
|
this.logoURL = this.repo.logoUrl;
|
73
|
this.getRepoInterfaces();
|
74
|
}
|
75
|
}
|
76
|
);
|
77
|
}
|
78
|
}
|
79
|
|
80
|
getRepoInterfaces() {
|
81
|
this.group = this.fb.group({});
|
82
|
this.repoService.getRepositoryInterface(this.repoId).subscribe(
|
83
|
interfaces => {
|
84
|
this.repoInterfaces = interfaces.sort( function(a, b) {
|
85
|
if (a.id < b.id) {
|
86
|
return -1;
|
87
|
} else if (a.id > b.id) {
|
88
|
return 1;
|
89
|
} else {
|
90
|
return 0;
|
91
|
}
|
92
|
});
|
93
|
console.log(`the number of interfaces for ${this.repoId} is ${this.repoInterfaces.length}`);
|
94
|
},
|
95
|
error => {
|
96
|
console.log(error);
|
97
|
this.loadingMessage = '';
|
98
|
this.errorMessage = loadingRepoError;
|
99
|
},
|
100
|
() => {
|
101
|
this.loadingMessage = '';
|
102
|
this.fillInterfacesForms();
|
103
|
}
|
104
|
);
|
105
|
}
|
106
|
|
107
|
|
108
|
fillInterfacesForms() {
|
109
|
this.dataForInterfaceComp = [];
|
110
|
if (this.repoInterfaces && (this.repoInterfaces.length > 0)) {
|
111
|
for (let i = 0; i < this.repoInterfaces.length; i++) {
|
112
|
this.dataForInterfaceComp.push([
|
113
|
false, i,
|
114
|
{ id: this.repo.id,
|
115
|
datasourceType: this.repo.datasourceType,
|
116
|
datasourceClass: this.repo.datasourceClass,
|
117
|
registeredBy: this.repo.registeredBy
|
118
|
},
|
119
|
this.repoInterfaces[i]
|
120
|
]);
|
121
|
}
|
122
|
} else {
|
123
|
this.dataForInterfaceComp.push([
|
124
|
false, 0,
|
125
|
{ id: this.repo.id,
|
126
|
datasourceType: this.repo.datasourceType,
|
127
|
datasourceClass: this.repo.datasourceClass,
|
128
|
registeredBy: this.repo.registeredBy
|
129
|
}
|
130
|
]);
|
131
|
}
|
132
|
}
|
133
|
|
134
|
addInterfaceToList(intrf?: RepositoryInterface) {
|
135
|
const curIndex = this.dataForInterfaceComp.length;
|
136
|
const curRepoInfo = { id: this.repo.id, datasourceType: this.repo.datasourceType,
|
137
|
datasourceClass: this.repo.datasourceClass, registeredBy: this.repo.registeredBy };
|
138
|
if (intrf) {
|
139
|
this.dataForInterfaceComp.push([false, curIndex, curRepoInfo, intrf]);
|
140
|
} else {
|
141
|
this.dataForInterfaceComp.push([false, curIndex, curRepoInfo]);
|
142
|
}
|
143
|
}
|
144
|
|
145
|
removeInterfaceFromList(i: number) {
|
146
|
const tempArray = this.dataForInterfaceComp;
|
147
|
this.dataForInterfaceComp = [];
|
148
|
tempArray.splice(i, 1);
|
149
|
this.dataForInterfaceComp = tempArray;
|
150
|
console.log(JSON.stringify(this.dataForInterfaceComp));
|
151
|
}
|
152
|
|
153
|
getInterfaces() {
|
154
|
this.repoInterfaces = [];
|
155
|
for (const el of this.interfacesArray.toArray()) {
|
156
|
const intrf = el.getInterface();
|
157
|
if (intrf) {
|
158
|
this.repoInterfaces.push(intrf);
|
159
|
console.log(JSON.stringify(intrf));
|
160
|
}
|
161
|
}
|
162
|
console.log('new interfaces is ', this.repoInterfaces);
|
163
|
}
|
164
|
|
165
|
updateLogoUrl(logoUrl: string) {
|
166
|
this.updateLogoUrlModal.ids = [logoUrl];
|
167
|
this.updateLogoUrlModal.showModal();
|
168
|
}
|
169
|
|
170
|
updatedLogoUrl(event: any) {
|
171
|
this.repo.logoUrl = this.logoURL;
|
172
|
this.datasourceUpdateForm.updateGroup.get('logoUrl').setValue(this.logoURL);
|
173
|
this.datasourceUpdateForm.updateRepo();
|
174
|
|
175
|
}
|
176
|
|
177
|
getNewLogoUrl( event: any ) {
|
178
|
this.logoURL = event.target.value;
|
179
|
|
180
|
}
|
181
|
|
182
|
}
|