1
|
import {Component, OnInit, ViewChild} from '@angular/core';
|
2
|
import { NavigationEnd, Router, RoutesRecognized } from '@angular/router';
|
3
|
import { AuthenticationService } from './services/authentication.service';
|
4
|
import { environment } from '../environments/environment';
|
5
|
import { MatomoInjector, MatomoTracker } from 'ngx-matomo';
|
6
|
import { ConfirmationDialogComponent } from './shared/reusablecomponents/confirmation-dialog.component';
|
7
|
import { RepositoryService } from './services/repository.service';
|
8
|
import { RepositorySnippet } from './domain/typeScriptClasses';
|
9
|
import {FormBuilder, FormGroup, FormControl, FormArray} from '@angular/forms';
|
10
|
import {element} from 'protractor';
|
11
|
import {timestamp} from 'rxjs/operators';
|
12
|
|
13
|
@Component({
|
14
|
selector: 'oa-repo-manager',
|
15
|
templateUrl: './app.component.html',
|
16
|
styleUrls: ['./app.component.css'],
|
17
|
})
|
18
|
export class AppComponent implements OnInit {
|
19
|
reposOfUser: RepositorySnippet[] = [];
|
20
|
modalTitle = 'Terms of Use';
|
21
|
isModalShown: boolean;
|
22
|
modalButton = 'OK';
|
23
|
|
24
|
agreementForm = this.fb.group({
|
25
|
terms: this.fb.array([])
|
26
|
});
|
27
|
|
28
|
consentTermsOfUseDate: Date;
|
29
|
|
30
|
@ViewChild('subscribeToTermsModal', { static: false })
|
31
|
public subscribeToTermsModal: ConfirmationDialogComponent;
|
32
|
|
33
|
open: boolean = true;
|
34
|
|
35
|
constructor(private router: Router,
|
36
|
private authService: AuthenticationService,
|
37
|
private matomoInjector: MatomoInjector,
|
38
|
private matomoTracker: MatomoTracker,
|
39
|
private repositoryService: RepositoryService,
|
40
|
private fb: FormBuilder) {
|
41
|
|
42
|
console.log('21-06-2019. Fixed matomo to log userIds?');
|
43
|
|
44
|
let piwikUrl;
|
45
|
if (window.location.origin.includes('beta')) {
|
46
|
// piwikUrl = 'https://analytics.openaire.eu/piwik.php?idsite=92&rec=1';
|
47
|
piwikUrl = '92';
|
48
|
} else if (window.location.origin.includes('localhost:4200') ||
|
49
|
window.location.origin.includes('athenarc')) {
|
50
|
// piwikUrl = 'https://analytics.openaire.eu/piwik.php?idsite=92&rec=1';
|
51
|
piwikUrl = '9222222';
|
52
|
} else {
|
53
|
// piwikUrl = 'https://analytics.openaire.eu/piwik.php?idsite=111&rec=1';
|
54
|
piwikUrl = '111';
|
55
|
}
|
56
|
this.matomoInjector.init('https://analytics.openaire.eu/', piwikUrl);
|
57
|
|
58
|
/*disabling console.log in production*/
|
59
|
if ( environment.production === true ) {
|
60
|
console.log = function () {};
|
61
|
}
|
62
|
|
63
|
// URL of the SPA to redirect the user to after login
|
64
|
// this.authService.redirectUrl = "/dashboard";
|
65
|
|
66
|
if (window.location.pathname.includes('/compatibility/browseHistory/')) {
|
67
|
this.authService.redirectUrl = window.location.pathname;
|
68
|
console.log('redirectUrl', this.authService.redirectUrl);
|
69
|
}
|
70
|
|
71
|
this.authService.tryLogin();
|
72
|
}
|
73
|
|
74
|
getReposOfUser(): void {
|
75
|
this.repositoryService.getRepositoriesSnippetsOfUser()
|
76
|
.subscribe(
|
77
|
repos => { this.reposOfUser = repos; },
|
78
|
error => { console.log(error); },
|
79
|
() => {
|
80
|
console.log(this.reposOfUser);
|
81
|
this.reposOfUser.forEach( repo => {
|
82
|
// TODO: change !repo.consentTermsOfUse check when it gets a non-null value
|
83
|
if (this.authService.isLoggedIn && !repo.consentTermsOfUse) {
|
84
|
this.addTerm(repo.officialname, repo.id, repo.consentTermsOfUse);
|
85
|
this.isModalShown = true;
|
86
|
}
|
87
|
});
|
88
|
}
|
89
|
);
|
90
|
}
|
91
|
|
92
|
updateTerms() {
|
93
|
/* update consentTermsOfUse, consentTermsOfUseDate(?)
|
94
|
depending on what value will consentTermsOfUse hold
|
95
|
Also what type of consentTermsOfUse will be? boolean or string */
|
96
|
for (let i = 0; i < this.terms.length; i++) {
|
97
|
const id = this.terms.controls[i].get('id').value;
|
98
|
if (this.terms.controls[i].get('accept').value === true) {
|
99
|
console.log(`Agreed to the Terms of Use for: `, id);
|
100
|
}
|
101
|
}
|
102
|
this.consentTermsOfUseDate = new Date(Date.now());
|
103
|
console.log(this.consentTermsOfUseDate);
|
104
|
console.log('will POST when backend is ready');
|
105
|
}
|
106
|
|
107
|
ngOnInit() {
|
108
|
this.router.events.subscribe((evt) => {
|
109
|
if (!(evt instanceof NavigationEnd)) {
|
110
|
return;
|
111
|
}
|
112
|
if (this.authService.isLoggedIn) {
|
113
|
this.matomoTracker.setUserId(this.authService.getUserEmail());
|
114
|
}
|
115
|
window.scrollTo(0, 0);
|
116
|
});
|
117
|
|
118
|
// this.getReposOfUser();
|
119
|
|
120
|
}
|
121
|
|
122
|
addTerm(name: string, id: string, consent: string) {
|
123
|
this.terms.push(this.newTerm(name, id, consent));
|
124
|
}
|
125
|
|
126
|
newTerm(name: string, id: string, consent: string): FormGroup {
|
127
|
return this.fb.group({
|
128
|
id: [id],
|
129
|
name: [name],
|
130
|
accept: [(consent ? consent : true)]
|
131
|
});
|
132
|
}
|
133
|
|
134
|
get terms() {
|
135
|
return this.agreementForm.get('terms') as FormArray;
|
136
|
}
|
137
|
|
138
|
isLandingRoute() {
|
139
|
// console.log('Is home route? Route is: ' + this.router.url);
|
140
|
return (this.router.url === '/') || (this.router.url === '/home') || (this.router.url === '/about');
|
141
|
}
|
142
|
|
143
|
public toggleOpen(event: MouseEvent) {
|
144
|
event.preventDefault();
|
145
|
this.open = !this.open;
|
146
|
}
|
147
|
|
148
|
// ngAfterContentInit() {
|
149
|
//
|
150
|
// // this.loadScript('assets/js/common.js');
|
151
|
// // this.loadScript('assets/js/uikit_custom.js');
|
152
|
// // this.loadScript('assets/js/altair_admin_common.js');
|
153
|
// this.loadScript('assets/js/altair_admin_common.min.js');
|
154
|
//
|
155
|
// // setTimeout( () => {
|
156
|
// // // this.loadScript('assets/js/common.js');
|
157
|
// // // this.loadScript('assets/js/uikit_custom.js');
|
158
|
// // this.loadScript('assets/js/altair_admin_common.min.js');
|
159
|
// // }, 2000);
|
160
|
//
|
161
|
// // $.getScript('assets/js/altair_admin_common.min.js');
|
162
|
//
|
163
|
//
|
164
|
//
|
165
|
// // // Load the script
|
166
|
// // // var self = this;
|
167
|
// //
|
168
|
// // var script = <HTMLScriptElement>document.createElement("SCRIPT");
|
169
|
// // script.src = 'assets/js/altair_admin_common.min.js';
|
170
|
// // script.type = 'text/javascript';
|
171
|
// // // self.script = <HTMLScriptElement>document.createElement("SCRIPT");
|
172
|
// // // self.script.src = '../Content/js/settings.js';
|
173
|
// // // self.script.type = 'text/javascript';
|
174
|
// // document.getElementsByTagName("head")[0].appendChild(script);
|
175
|
// }
|
176
|
//
|
177
|
// public loadScript(url) {
|
178
|
// console.log('preparing to load...')
|
179
|
// let node = document.createElement('script');
|
180
|
// node.src = url;
|
181
|
// node.type = 'text/javascript';
|
182
|
// document.getElementsByTagName('head')[0].appendChild(node);
|
183
|
// }
|
184
|
|
185
|
}
|