1
|
import {Component, OnDestroy, OnInit} from '@angular/core';
|
2
|
import {ActivatedRoute, Router} from '@angular/router';
|
3
|
import {Title} from '@angular/platform-browser';
|
4
|
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
5
|
|
6
|
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
|
7
|
import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component';
|
8
|
import {Stakeholder, Topic} from "../utils/entities/stakeholder";
|
9
|
import {SideBarService} from "../library/sharedComponents/sidebar/sideBar.service";
|
10
|
import {StakeholderService} from "../services/stakeholder.service";
|
11
|
|
12
|
declare var UIkit;
|
13
|
|
14
|
@Component({
|
15
|
selector: 'topic',
|
16
|
templateUrl: './topic.component.html',
|
17
|
})
|
18
|
export class TopicComponent implements OnInit, OnDestroy {
|
19
|
public status: number;
|
20
|
public loading: boolean = true;
|
21
|
public errorCodes: ErrorCodes;
|
22
|
public stakeholder: Stakeholder;
|
23
|
public analysisOpen: boolean = true;
|
24
|
private errorMessages: ErrorMessagesComponent;
|
25
|
public topic: Topic;
|
26
|
public valid = true;
|
27
|
public properties: EnvProperties;
|
28
|
|
29
|
constructor(
|
30
|
private route: ActivatedRoute,
|
31
|
private router: Router,
|
32
|
private title: Title,
|
33
|
private sideBarService: SideBarService,
|
34
|
private stakeholderService: StakeholderService) {
|
35
|
this.errorCodes = new ErrorCodes();
|
36
|
this.errorMessages = new ErrorMessagesComponent();
|
37
|
this.status = this.errorCodes.LOADING;
|
38
|
}
|
39
|
|
40
|
public ngOnInit() {
|
41
|
this.route.data
|
42
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
43
|
this.properties = data.envSpecific;
|
44
|
this.route.params.subscribe( params => {
|
45
|
this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
|
46
|
if (stakeholder) {
|
47
|
this.sideBarService.setHasSidebar(true);
|
48
|
this.stakeholder = stakeholder;
|
49
|
this.topic = this.stakeholder.topics.filter(topic => topic.alias === params['topic'])[0];
|
50
|
this.title.setTitle(stakeholder.index_name);
|
51
|
if(!this.topic) {
|
52
|
this.navigateToError();
|
53
|
}
|
54
|
}
|
55
|
});
|
56
|
});
|
57
|
});
|
58
|
}
|
59
|
|
60
|
public ngOnDestroy() {
|
61
|
}
|
62
|
|
63
|
public newTopicOpen() {
|
64
|
this.topic = new Topic(null, null, null,true, true);
|
65
|
this.valid = true;
|
66
|
}
|
67
|
|
68
|
public close(element) {
|
69
|
UIkit.drop(element).hide();
|
70
|
}
|
71
|
|
72
|
get open(): boolean {
|
73
|
return this.sideBarService.open;
|
74
|
}
|
75
|
|
76
|
public toggleOpen(event = null) {
|
77
|
if (!event) {
|
78
|
this.sideBarService.setOpen(!this.open);
|
79
|
} else if (event && event['value'] === true) {
|
80
|
this.sideBarService.setOpen(false);
|
81
|
}
|
82
|
}
|
83
|
|
84
|
public createTopic(element) {
|
85
|
if(this.topic.name && this.topic.name !== '') {
|
86
|
this.topic.alias = this.topic.name.toLowerCase();
|
87
|
this.stakeholder.topics.push(this.topic);
|
88
|
this.close(element);
|
89
|
} else {
|
90
|
this.valid = false;
|
91
|
}
|
92
|
}
|
93
|
|
94
|
private navigateToError() {
|
95
|
this.router.navigate(['/error'], {queryParams: {'page': this.router.url}});
|
96
|
}
|
97
|
}
|