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 {loadingRepoMessage, loadingUserRepoInfoEmpty, reposRetrievalError} from "../../domain/shared-messages";
5

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

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

    
18
  @Input() parent: string = '';
19

    
20
  constructor(private authService: AuthenticationService,
21
              private brokerService: BrokerService) {}
22

    
23
  ngOnInit() {
24
    this.tilesView = true;
25
    this.getDatasourcesOfUser();
26
  }
27

    
28

    
29
  getDatasourcesOfUser() {
30
    this.loadingMessage = loadingRepoMessage;
31
    this.brokerService.getDatasourcesOfUser(this.authService.getUserEmail()).subscribe(
32
      res => {
33
        this.datasourcesOfUser = res['datasourcesOfUser'];
34
      },
35
      error => {
36
        console.log(error);
37
        this.loadingMessage = '';
38
        this.errorMessage = reposRetrievalError;
39
      },
40
      () => {
41
        this.loadingMessage = '';
42
        if (!this.datasourcesOfUser.length) {
43
          this.noDatasourcesMessage = loadingUserRepoInfoEmpty;
44
        /*} else {
45
          this.datasourcesOfUser.forEach(
46
            d => {
47
              console.log( d['first']['value'],' -> ',d['first']['size'] );
48
            }
49
          );*/
50
        }
51
      }
52
    );
53
  }
54

    
55
  toggleTiles(){
56
    this.tilesView = !this.tilesView;
57
  }
58

    
59
}
(6-6/13)