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
  }
37

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

    
69

    
70
  getTopics () {
71
    this.loadingMessage = loadingTopics;
72
    this.brokerService.getDnetTopics().subscribe(
73
      topics => this.topics = topics,
74
      error => {
75
        console.log(error);
76
        this.errorMessage = loadingTopicsError;
77
        this.loadingMessage = '';
78
      },
79
      () => {
80
        this.loadingMessage = '';
81
        console.log(this.topics);
82
        this.getRepoTopics();
83
      }
84
    );
85
  }
86

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

    
98
  }
99

    
100
  getCorrectName() {
101
    const temp = this.repoName.split('|');
102
    this.correctName = temp[0];
103
    this.repoName = temp[0];
104
    for (let i = 1; i < temp.length; i++) {
105
      this.correctName += `/${temp[i]}`;
106
      this.repoName += ` | ${temp[i]}`;
107
    }
108
  }
109

    
110
}
(4-4/13)