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
import { SharedService } from "../../../services/shared.service";
7

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

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

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

    
27
  constructor(
28
    private route: ActivatedRoute,
29
    private router: Router,
30
    private brokerService: BrokerService,
31
    private sharedService: SharedService
32
  ) {}
33

    
34
  ngOnInit() {
35

    
36
    if(this.sharedService.getRepository()) {
37
      this.repoName = this.sharedService.getRepository().officialName;
38
      this.getCorrectName();
39
      this.getTopics();
40
    }
41

    
42
    this.sharedService.repository$.subscribe(
43
      r => {
44
        if (r) {
45
          this.repoName = r.officialName;
46
          this.getCorrectName();
47
          this.getTopics();
48
        }
49
      }
50
    );
51

    
52
    // this.repoName = this.route.snapshot.paramMap.get('name');
53
    // this.getCorrectName();
54
    // this.getTopics();
55
    let body = document.getElementsByTagName('body')[0];
56
    body.classList.remove("top_bar_active");   //remove the class
57
    body.classList.remove("page_heading_active");
58
    body.classList.remove("landing");
59
    body.classList.add("dashboard");
60
  }
61

    
62
  getRepoTopics(): void {
63
    this.loadingMessage = loadingTopics;
64
    this.brokerService.getTopicsForDataSource(this.correctName)
65
      .subscribe(
66
        topics => {
67
          this.repoTopics = topics;
68
        },
69
        error => {
70
          console.log(error);
71
          this.errorMessage = loadingTopicsError;
72
          this.loadingMessage = '';
73
        },
74
        () => {
75
          this.loadingMessage = '';
76
          if (this.repoTopics.length === 0) {
77
            this.noTopics = noTopicsFound;
78
          } else {
79
            for (const browseEntry of this.repoTopics) {
80
              if (browseEntry.value.startsWith('ENRICH/MORE')) {
81
                this.totalMore += browseEntry.size;
82
                this.moreList.push(browseEntry);
83
              } else if (browseEntry.value.startsWith('ENRICH/MISSING')) {
84
                this.totalMissing += browseEntry.size;
85
                this.missingList.push(browseEntry);
86
              }
87
            }
88
          }
89
        }
90
      );
91
  }
92

    
93

    
94
  getTopics () {
95
    this.loadingMessage = loadingTopics;
96
    this.brokerService.getDnetTopics().subscribe(
97
      topics => this.topics = topics,
98
      error => {
99
        console.log(error);
100
        this.errorMessage = loadingTopicsError;
101
        this.loadingMessage = '';
102
      },
103
      () => {
104
        this.loadingMessage = '';
105
        console.log(this.topics);
106
        this.getRepoTopics();
107
      }
108
    );
109
  }
110

    
111
  goToEventsList(topic: string) {
112
    const temp = topic.replace(/\//g, '|');
113
    let chosenTopic = temp[0];
114
    for (let i = 1; i < temp.length; i++) {
115
      chosenTopic += '|' + temp[i];
116
    }
117
    chosenTopic = encodeURIComponent(chosenTopic);
118
    /*this.router.navigate([`/content/events/${this.repoName}`, chosenTopic]);*/
119
    console.log(temp, this.route.url);
120
    this.router.navigate([temp], {relativeTo: this.route});
121

    
122
  }
123

    
124
  getCorrectName() {
125
    const temp = this.repoName.split('|');
126
    this.correctName = temp[0];
127
    this.repoName = temp[0];
128
    for (let i = 1; i < temp.length; i++) {
129
      this.correctName += `/${temp[i]}`;
130
      this.repoName += ` | ${temp[i]}`;
131
    }
132
  }
133

    
134
}
(4-4/6)