Project

General

Profile

« Previous | Next » 

Revision 58412

added Terms of Use functionality - follow 'ToU' comments to enable

View differences:

app.component.ts
1
import { Component, OnInit } from '@angular/core';
1
import {Component, OnInit, ViewChild} from '@angular/core';
2 2
import { NavigationEnd, Router, RoutesRecognized } from '@angular/router';
3 3
import { AuthenticationService } from './services/authentication.service';
4 4
import { environment } from '../environments/environment';
5 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';
6 12

  
7 13
@Component({
8 14
  selector: 'oa-repo-manager',
......
10 16
  styleUrls: ['./app.component.css'],
11 17
})
12 18
export class AppComponent implements OnInit {
19
  reposOfUser: RepositorySnippet[] = [];
20
  modalTitle = 'Terms of Use';
21
  isModalShown: boolean;
22
  modalButton = 'OK';
13 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

  
14 33
  open: boolean = true;
15 34

  
16 35
  constructor(private router: Router,
17 36
              private authService: AuthenticationService,
18 37
              private matomoInjector: MatomoInjector,
19
              private matomoTracker: MatomoTracker) {
38
              private matomoTracker: MatomoTracker,
39
              private repositoryService: RepositoryService,
40
              private fb: FormBuilder) {
20 41

  
21 42
    console.log('21-06-2019. Fixed matomo to log userIds?');
22 43

  
......
50 71
    this.authService.tryLogin();
51 72
  }
52 73

  
74
  getReposOfUser(): void {
75
    this.repositoryService.getRepositoriesOfUser()
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

  
53 107
  ngOnInit() {
54 108
    this.router.events.subscribe((evt) => {
55 109
      if (!(evt instanceof NavigationEnd)) {
......
60 114
      }
61 115
      window.scrollTo(0, 0);
62 116
    });
117

  
118
    // this.getReposOfUser();
119

  
63 120
  }
64 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

  
65 138
  isLandingRoute() {
66 139
    // console.log('Is home route? Route is: ' + this.router.url);
67 140
    return (this.router.url === '/') || (this.router.url === '/home') || (this.router.url === '/about');

Also available in: Unified diff