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 { MatomoTracker } from 'ngx-matomo';
|
6
|
import { ConfirmationDialogComponent } from './shared/reusablecomponents/confirmation-dialog.component';
|
7
|
import { RepositoryService } from './services/repository.service';
|
8
|
import {RepositorySnippet, TermsOfUse} from './domain/typeScriptClasses';
|
9
|
import {FormBuilder, FormGroup, FormControl, FormArray} from '@angular/forms';
|
10
|
import {element} from 'protractor';
|
11
|
import {timeout, 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')
|
31
|
public subscribeToTermsModal: ConfirmationDialogComponent;
|
32
|
|
33
|
open: boolean = true;
|
34
|
|
35
|
constructor(private router: Router,
|
36
|
private authService: AuthenticationService,
|
37
|
private matomoTracker: MatomoTracker,
|
38
|
private repositoryService: RepositoryService,
|
39
|
private fb: FormBuilder) {
|
40
|
|
41
|
// console.log('21-06-2019. Fixed matomo to log userIds?');
|
42
|
|
43
|
/*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
|
getReposOfUser(): void {
|
60
|
this.repositoryService.getRepositoriesSnippetsOfUser().subscribe(
|
61
|
repos => {
|
62
|
this.reposOfUser = repos;
|
63
|
},
|
64
|
error => {
|
65
|
console.log(error);
|
66
|
},
|
67
|
() => {
|
68
|
// console.log(this.reposOfUser);
|
69
|
this.reposOfUser.forEach(repo => {
|
70
|
if (repo.consentTermsOfUse === null || repo.fullTextDownload === null) {
|
71
|
this.addTerm(repo.officialname, repo.id, repo.consentTermsOfUse);
|
72
|
this.isModalShown = true;
|
73
|
}
|
74
|
});
|
75
|
}
|
76
|
);
|
77
|
}
|
78
|
|
79
|
updateTerms() {
|
80
|
this.repositoryService.updateRepositoriesTerms(this.agreementForm.value.terms).subscribe(
|
81
|
res => {},
|
82
|
err => {console.log(err)}
|
83
|
);
|
84
|
}
|
85
|
|
86
|
ngOnInit() {
|
87
|
this.router.events.subscribe((evt) => {
|
88
|
if (!(evt instanceof NavigationEnd)) {
|
89
|
return;
|
90
|
}
|
91
|
if (this.authService.isLoggedIn_) {
|
92
|
this.matomoTracker.setUserId(this.authService.getUserEmail());
|
93
|
}
|
94
|
window.scrollTo(0, 0);
|
95
|
});
|
96
|
|
97
|
this.authService.isLoggedIn.subscribe(
|
98
|
logged => {if(logged){this.getReposOfUser()}},
|
99
|
error => {console.log(error)}
|
100
|
);
|
101
|
|
102
|
}
|
103
|
|
104
|
addTerm(name: string, id: string, consent: boolean) {
|
105
|
this.terms.push(this.newTerm(name, id, consent));
|
106
|
}
|
107
|
|
108
|
newTerm(name: string, id: string, consent: boolean): FormGroup {
|
109
|
return this.fb.group({
|
110
|
id: [id],
|
111
|
name: [name],
|
112
|
// accept: [(consent ? consent : true)]
|
113
|
consentTermsOfUse: false,
|
114
|
fullTextDownload: false
|
115
|
});
|
116
|
}
|
117
|
|
118
|
get terms() {
|
119
|
return this.agreementForm.get('terms') as FormArray;
|
120
|
}
|
121
|
|
122
|
isLandingRoute() {
|
123
|
// console.log('Is home route? Route is: ' + this.router.url);
|
124
|
return (this.router.url === '/') || (this.router.url === '/home') || (this.router.url === '/about');
|
125
|
}
|
126
|
|
127
|
public toggleOpen(event: MouseEvent) {
|
128
|
event.preventDefault();
|
129
|
this.open = !this.open;
|
130
|
}
|
131
|
|
132
|
// 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
|
}
|