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
  topics: Map<string,Term> = new Map<string,Term>();
19
  repoTopics: BrowseEntry[] = [];
20
  moreList: BrowseEntry[] = [];
21
  missingList: BrowseEntry[] = [];
22
  totalMore = 0;
23
  totalMissing = 0;
24

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

    
31
  ngOnInit() {
32
    this.repoName = this.route.snapshot.paramMap.get('name');
33
    setTimeout(() => {
34
      this.getTopics();
35
    },500);
36
  }
37

    
38
  getRepoTopics(): void {
39
    this.loadingMessage = loadingTopics;
40
    this.brokerService.getTopicsForDataSource(this.repoName)
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(let browseEntry of this.repoTopics) {
56
              if(browseEntry.value.startsWith("ENRICH/MORE")) {
57
                this.totalMore += browseEntry.size;
58
                this.moreList.push(browseEntry);
59
              }
60
              else if(browseEntry.value.startsWith("ENRICH/MISSING")) {
61
                this.totalMissing += browseEntry.size;
62
                this.missingList.push(browseEntry);
63
              }
64
            }
65
          }
66
        }
67
      );
68
  }
69

    
70

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

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

    
99
  }
100

    
101

    
102
}
(4-4/13)