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