1 |
58412
|
andreas.ma
|
import {Component, OnInit, ViewChild} from '@angular/core';
|
2 |
54722
|
myrto.kouk
|
import { NavigationEnd, Router, RoutesRecognized } from '@angular/router';
|
3 |
54479
|
myrto.kouk
|
import { AuthenticationService } from './services/authentication.service';
|
4 |
|
|
import { environment } from '../environments/environment';
|
5 |
61424
|
stefania.m
|
import { MatomoTracker } from 'ngx-matomo';
|
6 |
58412
|
andreas.ma
|
import { ConfirmationDialogComponent } from './shared/reusablecomponents/confirmation-dialog.component';
|
7 |
|
|
import { RepositoryService } from './services/repository.service';
|
8 |
62080
|
stefania.m
|
import {RepositorySnippet, TermsOfUse} from './domain/typeScriptClasses';
|
9 |
58412
|
andreas.ma
|
import {FormBuilder, FormGroup, FormControl, FormArray} from '@angular/forms';
|
10 |
|
|
import {element} from 'protractor';
|
11 |
62080
|
stefania.m
|
import {timeout, timestamp} from 'rxjs/operators';
|
12 |
54479
|
myrto.kouk
|
|
13 |
|
|
@Component({
|
14 |
|
|
selector: 'oa-repo-manager',
|
15 |
|
|
templateUrl: './app.component.html',
|
16 |
58065
|
stefania.m
|
styleUrls: ['./app.component.css'],
|
17 |
54479
|
myrto.kouk
|
})
|
18 |
|
|
export class AppComponent implements OnInit {
|
19 |
58412
|
andreas.ma
|
reposOfUser: RepositorySnippet[] = [];
|
20 |
|
|
modalTitle = 'Terms of Use';
|
21 |
|
|
isModalShown: boolean;
|
22 |
|
|
modalButton = 'OK';
|
23 |
58065
|
stefania.m
|
|
24 |
58412
|
andreas.ma
|
agreementForm = this.fb.group({
|
25 |
|
|
terms: this.fb.array([])
|
26 |
|
|
});
|
27 |
|
|
|
28 |
|
|
consentTermsOfUseDate: Date;
|
29 |
|
|
|
30 |
|
|
@ViewChild('subscribeToTermsModal')
|
31 |
|
|
public subscribeToTermsModal: ConfirmationDialogComponent;
|
32 |
|
|
|
33 |
58065
|
stefania.m
|
open: boolean = true;
|
34 |
|
|
|
35 |
54479
|
myrto.kouk
|
constructor(private router: Router,
|
36 |
54722
|
myrto.kouk
|
private authService: AuthenticationService,
|
37 |
58412
|
andreas.ma
|
private matomoTracker: MatomoTracker,
|
38 |
|
|
private repositoryService: RepositoryService,
|
39 |
|
|
private fb: FormBuilder) {
|
40 |
54722
|
myrto.kouk
|
|
41 |
62080
|
stefania.m
|
// console.log('21-06-2019. Fixed matomo to log userIds?');
|
42 |
54747
|
myrto.kouk
|
|
43 |
54479
|
myrto.kouk
|
/*disabling console.log in production*/
|
44 |
|
|
if ( environment.production === true ) {
|
45 |
|
|
console.log = function () {};
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
// URL of the SPA to redirect the user to after login
|
49 |
|
|
// this.authService.redirectUrl = "/dashboard";
|
50 |
|
|
|
51 |
|
|
if (window.location.pathname.includes('/compatibility/browseHistory/')) {
|
52 |
|
|
this.authService.redirectUrl = window.location.pathname;
|
53 |
|
|
console.log('redirectUrl', this.authService.redirectUrl);
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
this.authService.tryLogin();
|
57 |
|
|
}
|
58 |
|
|
|
59 |
58412
|
andreas.ma
|
getReposOfUser(): void {
|
60 |
62080
|
stefania.m
|
this.repositoryService.getRepositoriesSnippetsOfUser().subscribe(
|
61 |
|
|
repos => {
|
62 |
|
|
this.reposOfUser = repos;
|
63 |
|
|
},
|
64 |
|
|
error => {
|
65 |
|
|
console.log(error);
|
66 |
|
|
},
|
67 |
58412
|
andreas.ma
|
() => {
|
68 |
62092
|
j.balasis9
|
// console.log(this.reposOfUser);
|
69 |
62080
|
stefania.m
|
this.reposOfUser.forEach(repo => {
|
70 |
|
|
if (!repo.consentTermsOfUse || !repo.fullTextDownload) {
|
71 |
58412
|
andreas.ma
|
this.addTerm(repo.officialname, repo.id, repo.consentTermsOfUse);
|
72 |
|
|
this.isModalShown = true;
|
73 |
|
|
}
|
74 |
|
|
});
|
75 |
|
|
}
|
76 |
|
|
);
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
updateTerms() {
|
80 |
62080
|
stefania.m
|
this.repositoryService.updateRepositoriesTerms(this.agreementForm.value.terms).subscribe(
|
81 |
|
|
res => {},
|
82 |
|
|
err => {console.log(err)}
|
83 |
|
|
);
|
84 |
58412
|
andreas.ma
|
}
|
85 |
|
|
|
86 |
54479
|
myrto.kouk
|
ngOnInit() {
|
87 |
54722
|
myrto.kouk
|
this.router.events.subscribe((evt) => {
|
88 |
54479
|
myrto.kouk
|
if (!(evt instanceof NavigationEnd)) {
|
89 |
|
|
return;
|
90 |
|
|
}
|
91 |
62080
|
stefania.m
|
if (this.authService.isLoggedIn_) {
|
92 |
56149
|
myrto.kouk
|
this.matomoTracker.setUserId(this.authService.getUserEmail());
|
93 |
|
|
}
|
94 |
54479
|
myrto.kouk
|
window.scrollTo(0, 0);
|
95 |
|
|
});
|
96 |
58412
|
andreas.ma
|
|
97 |
62080
|
stefania.m
|
this.authService.isLoggedIn.subscribe(
|
98 |
|
|
logged => {if(logged){this.getReposOfUser()}},
|
99 |
|
|
error => {console.log(error)}
|
100 |
|
|
);
|
101 |
58412
|
andreas.ma
|
|
102 |
54479
|
myrto.kouk
|
}
|
103 |
|
|
|
104 |
62080
|
stefania.m
|
addTerm(name: string, id: string, consent: boolean) {
|
105 |
58412
|
andreas.ma
|
this.terms.push(this.newTerm(name, id, consent));
|
106 |
|
|
}
|
107 |
|
|
|
108 |
62080
|
stefania.m
|
newTerm(name: string, id: string, consent: boolean): FormGroup {
|
109 |
58412
|
andreas.ma
|
return this.fb.group({
|
110 |
|
|
id: [id],
|
111 |
|
|
name: [name],
|
112 |
62080
|
stefania.m
|
// accept: [(consent ? consent : true)]
|
113 |
|
|
consentTermsOfUse: false,
|
114 |
|
|
fullTextDownload: false
|
115 |
58412
|
andreas.ma
|
});
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
get terms() {
|
119 |
|
|
return this.agreementForm.get('terms') as FormArray;
|
120 |
|
|
}
|
121 |
|
|
|
122 |
58110
|
stefania.m
|
isLandingRoute() {
|
123 |
58108
|
stefania.m
|
// console.log('Is home route? Route is: ' + this.router.url);
|
124 |
58110
|
stefania.m
|
return (this.router.url === '/') || (this.router.url === '/home') || (this.router.url === '/about');
|
125 |
57088
|
stefania.m
|
}
|
126 |
|
|
|
127 |
58065
|
stefania.m
|
public toggleOpen(event: MouseEvent) {
|
128 |
|
|
event.preventDefault();
|
129 |
|
|
this.open = !this.open;
|
130 |
|
|
}
|
131 |
|
|
|
132 |
57088
|
stefania.m
|
// ngAfterContentInit() {
|
133 |
|
|
//
|
134 |
|
|
// // this.loadScript('assets/js/common.js');
|
135 |
|
|
// // this.loadScript('assets/js/uikit_custom.js');
|
136 |
|
|
// // this.loadScript('assets/js/altair_admin_common.js');
|
137 |
|
|
// this.loadScript('assets/js/altair_admin_common.min.js');
|
138 |
|
|
//
|
139 |
|
|
// // setTimeout( () => {
|
140 |
|
|
// // // this.loadScript('assets/js/common.js');
|
141 |
|
|
// // // this.loadScript('assets/js/uikit_custom.js');
|
142 |
|
|
// // this.loadScript('assets/js/altair_admin_common.min.js');
|
143 |
|
|
// // }, 2000);
|
144 |
|
|
//
|
145 |
|
|
// // $.getScript('assets/js/altair_admin_common.min.js');
|
146 |
|
|
//
|
147 |
|
|
//
|
148 |
|
|
//
|
149 |
|
|
// // // Load the script
|
150 |
|
|
// // // var self = this;
|
151 |
|
|
// //
|
152 |
|
|
// // var script = <HTMLScriptElement>document.createElement("SCRIPT");
|
153 |
|
|
// // script.src = 'assets/js/altair_admin_common.min.js';
|
154 |
|
|
// // script.type = 'text/javascript';
|
155 |
|
|
// // // self.script = <HTMLScriptElement>document.createElement("SCRIPT");
|
156 |
|
|
// // // self.script.src = '../Content/js/settings.js';
|
157 |
|
|
// // // self.script.type = 'text/javascript';
|
158 |
|
|
// // document.getElementsByTagName("head")[0].appendChild(script);
|
159 |
|
|
// }
|
160 |
|
|
//
|
161 |
|
|
// public loadScript(url) {
|
162 |
|
|
// console.log('preparing to load...')
|
163 |
|
|
// let node = document.createElement('script');
|
164 |
|
|
// node.src = url;
|
165 |
|
|
// node.type = 'text/javascript';
|
166 |
|
|
// document.getElementsByTagName('head')[0].appendChild(node);
|
167 |
|
|
// }
|
168 |
|
|
|
169 |
54479
|
myrto.kouk
|
}
|