Project

General

Profile

1
import { Component, Input, OnInit } from '@angular/core';
2
import { AuthenticationService } from '../../services/authentication.service';
3
import { BrokerService } from '../../services/broker.service';
4
import { ActivatedRoute, Router } from '@angular/router';
5
import { loadingRepoMessage, loadingUserRepoInfoEmpty, reposRetrievalError } from '../../domain/shared-messages';
6

    
7
@Component ({
8
  selector: 'app-content-events',
9
  templateUrl: 'content-events.component.html'
10
})
11

    
12
export class ContentEventsComponent implements OnInit {
13
  datasourcesOfUser = [];
14
  tilesView: boolean;
15
  errorMessage: string;
16
  noDatasourcesMessage: string;
17
  loadingMessage: string;
18

    
19
  @Input() parent = '';
20

    
21
  constructor(private authService: AuthenticationService,
22
              private brokerService: BrokerService,
23
              private router: Router,
24
              private route: ActivatedRoute) {}
25

    
26
  ngOnInit() {
27
    this.tilesView = true;
28
    this.getDatasourcesOfUser();
29
    let body = document.getElementsByTagName('body')[0];
30
    body.classList.add("top_bar_active");   //add the class
31
    body.classList.remove("page_heading_active");
32
    body.classList.remove("landing");
33
    body.classList.add("dashboard");
34
  }
35

    
36

    
37
  getDatasourcesOfUser() {
38
    this.loadingMessage = loadingRepoMessage;
39
    this.brokerService.getDatasourcesOfUser().subscribe(
40
      res => {
41
        this.datasourcesOfUser = res['datasourcesOfUser'];
42
      },
43
      error => {
44
        console.log(error);
45
        this.loadingMessage = '';
46
        this.errorMessage = reposRetrievalError;
47
      },
48
      () => {
49
        this.loadingMessage = '';
50
        if (!this.datasourcesOfUser || !this.datasourcesOfUser.length) {
51
          this.noDatasourcesMessage = loadingUserRepoInfoEmpty;
52
        } else {
53
          this.datasourcesOfUser.sort( function(a, b) {
54
            if ( a['first']['value'] < b['first']['value'] ) {
55
              return -1;
56
            } else if (a['first']['value'] > b['first']['value']) {
57
              return 1;
58
            } else {
59
              return 0;
60
            }
61
          });
62
        }
63
      }
64
    );
65
  }
66

    
67
  toggleTiles() {
68
    this.tilesView = !this.tilesView;
69
  }
70

    
71
  goToRepoEvents(repoName: string) {
72
    const newName = repoName.replace(/\//g, '|');
73
    this.router.navigate([newName], {relativeTo: this.route});
74
  }
75

    
76
  changeView(view: string) {
77
    this.tilesView = (view == 'tiles');
78
  }
79

    
80
}
(6-6/13)