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
|
setTimeout(() => {
|
36
|
this.getTopics();
|
37
|
}, 500);
|
38
|
}
|
39
|
|
40
|
getRepoTopics(): void {
|
41
|
this.loadingMessage = loadingTopics;
|
42
|
this.brokerService.getTopicsForDataSource(this.correctName)
|
43
|
.subscribe(
|
44
|
topics => {
|
45
|
this.repoTopics = topics;
|
46
|
},
|
47
|
error => {
|
48
|
console.log(error);
|
49
|
this.errorMessage = loadingTopicsError;
|
50
|
this.loadingMessage = '';
|
51
|
},
|
52
|
() => {
|
53
|
this.loadingMessage = '';
|
54
|
if (this.repoTopics.length === 0) {
|
55
|
this.noTopics = noTopicsFound;
|
56
|
} else {
|
57
|
for (const browseEntry of this.repoTopics) {
|
58
|
if (browseEntry.value.startsWith('ENRICH/MORE')) {
|
59
|
this.totalMore += browseEntry.size;
|
60
|
this.moreList.push(browseEntry);
|
61
|
} else if (browseEntry.value.startsWith('ENRICH/MISSING')) {
|
62
|
this.totalMissing += browseEntry.size;
|
63
|
this.missingList.push(browseEntry);
|
64
|
}
|
65
|
}
|
66
|
}
|
67
|
}
|
68
|
);
|
69
|
}
|
70
|
|
71
|
|
72
|
getTopics () {
|
73
|
this.loadingMessage = loadingTopics;
|
74
|
this.brokerService.getDnetTopics().subscribe(
|
75
|
topics => this.topics = topics,
|
76
|
error => {
|
77
|
console.log(error);
|
78
|
this.errorMessage = loadingTopicsError;
|
79
|
this.loadingMessage = '';
|
80
|
},
|
81
|
() => {
|
82
|
this.loadingMessage = '';
|
83
|
console.log(this.topics);
|
84
|
this.getRepoTopics();
|
85
|
}
|
86
|
);
|
87
|
}
|
88
|
|
89
|
goToEventsList(topic: string) {
|
90
|
const temp = topic.replace(/\//g, '|');
|
91
|
let chosenTopic = temp[0];
|
92
|
for (let i = 1; i < temp.length; i++) {
|
93
|
chosenTopic += '|' + temp[i];
|
94
|
}
|
95
|
chosenTopic = encodeURIComponent(chosenTopic);
|
96
|
/*this.router.navigate([`/content/events/${this.repoName}`, chosenTopic]);*/
|
97
|
console.log(temp, this.route.url);
|
98
|
this.router.navigate([temp], {relativeTo: this.route});
|
99
|
|
100
|
}
|
101
|
|
102
|
getCorrectName() {
|
103
|
const temp = this.repoName.split('|');
|
104
|
this.correctName = temp[0];
|
105
|
this.repoName = temp[0];
|
106
|
for (let i = 1; i < temp.length; i++) {
|
107
|
this.correctName += `/${temp[i]}`;
|
108
|
this.repoName += ` | ${temp[i]}`;
|
109
|
}
|
110
|
}
|
111
|
|
112
|
}
|