Project

General

Profile

1
import { Component, OnInit } from '@angular/core';
2
import { BrowseEntry, Term } from '../../domain/typeScriptClasses';
3
import { ActivatedRoute, Router } from '@angular/router';
4
import { loadingTopics, loadingTopicsError, noTopicsFound } from '../../domain/shared-messages';
5
import { BrokerService } from '../../services/broker.service';
6

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

    
12
export class ContentEventsOfRepositoryComponent implements OnInit {
13
  errorMessage: string;
14
  loadingMessage: string;
15
  noTopics: string;
16

    
17
  repoName = '';
18
  correctName = '';
19
  topics: Map<string, Term> = new Map<string, Term>();
20
  repoTopics: BrowseEntry[] = [];
21
  moreList: BrowseEntry[] = [];
22
  missingList: BrowseEntry[] = [];
23
  totalMore = 0;
24
  totalMissing = 0;
25

    
26
  constructor(
27
    private route: ActivatedRoute,
28
    private router: Router,
29
    private brokerService: BrokerService
30
  ) {}
31

    
32
  ngOnInit() {
33
    this.repoName = this.route.snapshot.paramMap.get('name');
34
    this.getCorrectName();
35
    this.getTopics();
36
    let body = document.getElementsByTagName('body')[0];
37
    body.classList.remove("top_bar_active");   //remove the class
38
    body.classList.remove("page_heading_active");
39
    body.classList.remove("landing");
40
    body.classList.add("dashboard");
41
  }
42

    
43
  getRepoTopics(): void {
44
    this.loadingMessage = loadingTopics;
45
    this.brokerService.getTopicsForDataSource(this.correctName)
46
      .subscribe(
47
        topics => {
48
          this.repoTopics = topics;
49
        },
50
        error => {
51
          console.log(error);
52
          this.errorMessage = loadingTopicsError;
53
          this.loadingMessage = '';
54
        },
55
        () => {
56
          this.loadingMessage = '';
57
          if (this.repoTopics.length === 0) {
58
            this.noTopics = noTopicsFound;
59
          } else {
60
            for (const browseEntry of this.repoTopics) {
61
              if (browseEntry.value.startsWith('ENRICH/MORE')) {
62
                this.totalMore += browseEntry.size;
63
                this.moreList.push(browseEntry);
64
              } else if (browseEntry.value.startsWith('ENRICH/MISSING')) {
65
                this.totalMissing += browseEntry.size;
66
                this.missingList.push(browseEntry);
67
              }
68
            }
69
          }
70
        }
71
      );
72
  }
73

    
74

    
75
  getTopics () {
76
    this.loadingMessage = loadingTopics;
77
    this.brokerService.getDnetTopics().subscribe(
78
      topics => this.topics = topics,
79
      error => {
80
        console.log(error);
81
        this.errorMessage = loadingTopicsError;
82
        this.loadingMessage = '';
83
      },
84
      () => {
85
        this.loadingMessage = '';
86
        console.log(this.topics);
87
        this.getRepoTopics();
88
      }
89
    );
90
  }
91

    
92
  goToEventsList(topic: string) {
93
    const temp = topic.replace(/\//g, '|');
94
    let chosenTopic = temp[0];
95
    for (let i = 1; i < temp.length; i++) {
96
      chosenTopic += '|' + temp[i];
97
    }
98
    chosenTopic = encodeURIComponent(chosenTopic);
99
    /*this.router.navigate([`/content/events/${this.repoName}`, chosenTopic]);*/
100
    console.log(temp, this.route.url);
101
    this.router.navigate([temp], {relativeTo: this.route});
102

    
103
  }
104

    
105
  getCorrectName() {
106
    const temp = this.repoName.split('|');
107
    this.correctName = temp[0];
108
    this.repoName = temp[0];
109
    for (let i = 1; i < temp.length; i++) {
110
      this.correctName += `/${temp[i]}`;
111
      this.repoName += ` | ${temp[i]}`;
112
    }
113
  }
114

    
115
}
(4-4/13)