Revision 58098
Added by Stefania Martziou about 4 years ago
metrics-enable.component.ts | ||
---|---|---|
1 | 1 |
import { Component, OnInit, ViewChild } from '@angular/core'; |
2 | 2 |
import { ActivatedRoute, Router } from '@angular/router'; |
3 |
import { ConfirmationDialogComponent } from '../../shared/reusablecomponents/confirmation-dialog.component'; |
|
4 |
import { PiwikService } from '../../services/piwik.service'; |
|
5 |
import { RepositoryService } from '../../services/repository.service'; |
|
6 |
import { PiwikInfo, Repository } from '../../domain/typeScriptClasses'; |
|
3 |
import { ConfirmationDialogComponent } from '../../../shared/reusablecomponents/confirmation-dialog.component';
|
|
4 |
import { PiwikService } from '../../../services/piwik.service';
|
|
5 |
import { RepositoryService } from '../../../services/repository.service';
|
|
6 |
import { PiwikInfo, Repository } from '../../../domain/typeScriptClasses';
|
|
7 | 7 |
import { enabledMetricsError, enabledMetricsSuccess, enablingMetrics, |
8 |
loadingRepoError, loadingRepoMessage } from '../../domain/shared-messages'; |
|
9 |
import { AuthenticationService } from '../../services/authentication.service'; |
|
8 |
loadingRepoError, loadingRepoMessage } from '../../../domain/shared-messages'; |
|
9 |
import { AuthenticationService } from '../../../services/authentication.service'; |
|
10 |
import { SharedService } from "../../../services/shared.service"; |
|
10 | 11 |
|
11 | 12 |
@Component ({ |
12 | 13 |
selector: 'metrics-enable', |
... | ... | |
20 | 21 |
|
21 | 22 |
readonly analyticsUrl = 'https://analytics.openaire.eu/addsite.php?'; |
22 | 23 |
readonly authenticationToken = '32846584f571be9b57488bf4088f30ea'; /* THE ACTUAL TOKEN WILL BE NEEDED EVENTUALLY!! */ |
24 |
|
|
23 | 25 |
repo: Repository; |
24 | 26 |
oaId: string; |
25 | 27 |
|
... | ... | |
36 | 38 |
private router: Router, |
37 | 39 |
private authService: AuthenticationService, |
38 | 40 |
private piwikService: PiwikService, |
39 |
private repoService: RepositoryService |
|
41 |
private repoService: RepositoryService, |
|
42 |
private sharedService: SharedService |
|
40 | 43 |
) {} |
41 | 44 |
|
42 | 45 |
ngOnInit() { |
43 |
this.getRepo(); |
|
46 |
|
|
47 |
if(this.sharedService.getRepository()) { |
|
48 |
this.repo = this.sharedService.getRepository(); |
|
49 |
this.getOAid(); |
|
50 |
} |
|
51 |
|
|
52 |
this.sharedService.repository$.subscribe( |
|
53 |
r => { |
|
54 |
this.repo = r; |
|
55 |
if (this.repo) { |
|
56 |
this.getOAid(); |
|
57 |
} |
|
58 |
} |
|
59 |
); |
|
60 |
|
|
61 |
// this.getRepo(); |
|
44 | 62 |
this.isModalShown = false; |
45 | 63 |
let body = document.getElementsByTagName('body')[0]; |
46 | 64 |
body.classList.remove("top_bar_active"); //remove the class |
... | ... | |
49 | 67 |
body.classList.add("dashboard"); |
50 | 68 |
} |
51 | 69 |
|
52 |
getRepo(): void { |
|
53 |
const id = this.route.snapshot.paramMap.get('id'); |
|
54 |
this.loadingMessage = loadingRepoMessage; |
|
55 |
this.repoService.getRepositoryById(id).subscribe( |
|
56 |
repo => { |
|
57 |
this.repo = repo; |
|
58 |
}, |
|
59 |
error => { |
|
60 |
console.log(error); |
|
61 |
this.errorMessage = loadingRepoError; |
|
62 |
this.loadingMessage = ''; |
|
63 |
}, () => { |
|
64 |
if (this.repo) { |
|
65 |
this.getOAid(); |
|
66 |
} |
|
67 |
this.loadingMessage = ''; |
|
68 |
} |
|
69 |
); |
|
70 |
} |
|
70 |
// getRepo(): void {
|
|
71 |
// const id = this.route.snapshot.paramMap.get('id');
|
|
72 |
// this.loadingMessage = loadingRepoMessage;
|
|
73 |
// this.repoService.getRepositoryById(id).subscribe(
|
|
74 |
// repo => {
|
|
75 |
// this.repo = repo;
|
|
76 |
// },
|
|
77 |
// error => {
|
|
78 |
// console.log(error);
|
|
79 |
// this.errorMessage = loadingRepoError;
|
|
80 |
// this.loadingMessage = '';
|
|
81 |
// }, () => {
|
|
82 |
// if (this.repo) {
|
|
83 |
// this.getOAid();
|
|
84 |
// }
|
|
85 |
// this.loadingMessage = '';
|
|
86 |
// }
|
|
87 |
// );
|
|
88 |
// }
|
|
71 | 89 |
|
72 | 90 |
getOAid () { |
73 | 91 |
this.piwikService.getOpenaireId(this.repo.id).subscribe( |
... | ... | |
108 | 126 |
console.log(`enableMetrics answered: ${response}`); |
109 | 127 |
this.successMessage = enabledMetricsSuccess; |
110 | 128 |
this.loadingMessage = ''; |
129 |
|
|
130 |
//save piwik and update shareRepo |
|
131 |
this.repo.piwikInfo = piwik; |
|
132 |
this.sharedService.setRepository(this.repo); |
|
111 | 133 |
}, |
112 | 134 |
error => { |
113 | 135 |
console.log(error); |
... | ... | |
115 | 137 |
this.loadingMessage = ''; |
116 | 138 |
}, |
117 | 139 |
() => { |
118 |
this.router.navigate([`/getImpact/instructions/${this.repo.id}`]); |
|
140 |
this.router.navigate([`/repository/${this.repo.id}/getImpact/instructions/`]); |
|
141 |
// this.router.navigate([`/getImpact/instructions/${this.repo.id}`]); |
|
119 | 142 |
} |
120 | 143 |
); |
121 | 144 |
} |
Also available in: Unified diff
Second commit for the new layout provided by the UX team