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
|
import {Tools} from "../utils/Tools";
|
12
|
|
13
|
declare var UIkit;
|
14
|
|
15
|
@Component({
|
16
|
selector: 'home',
|
17
|
templateUrl: './home.component.html',
|
18
|
})
|
19
|
export class HomeComponent implements OnInit, OnDestroy {
|
20
|
public status: number;
|
21
|
public loading: boolean = true;
|
22
|
public errorCodes: ErrorCodes;
|
23
|
public stakeholder: Stakeholder;
|
24
|
public analysisOpen: boolean = true;
|
25
|
private errorMessages: ErrorMessagesComponent;
|
26
|
public topic: Topic;
|
27
|
public valid = true;
|
28
|
properties: EnvProperties;
|
29
|
|
30
|
constructor(
|
31
|
private route: ActivatedRoute,
|
32
|
private router: Router,
|
33
|
private title: Title,
|
34
|
private sideBarService: SideBarService,
|
35
|
private stakeholderService: StakeholderService) {
|
36
|
this.errorCodes = new ErrorCodes();
|
37
|
this.errorMessages = new ErrorMessagesComponent();
|
38
|
this.status = this.errorCodes.LOADING;
|
39
|
}
|
40
|
|
41
|
public ngOnInit() {
|
42
|
this.route.data
|
43
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
44
|
this.properties = data.envSpecific;
|
45
|
this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
|
46
|
if (stakeholder) {
|
47
|
this.sideBarService.setHasSidebar(true);
|
48
|
this.stakeholder = Tools.copy(stakeholder);
|
49
|
this.topic = null;
|
50
|
this.title.setTitle(stakeholder.index_name);
|
51
|
}
|
52
|
});
|
53
|
});
|
54
|
}
|
55
|
|
56
|
public ngOnDestroy() {
|
57
|
}
|
58
|
|
59
|
public newTopicOpen() {
|
60
|
this.topic = new Topic(null, null, null,true, true);
|
61
|
this.valid = true;
|
62
|
}
|
63
|
|
64
|
public hide(element) {
|
65
|
UIkit.drop(element).hide();
|
66
|
}
|
67
|
|
68
|
get open(): boolean {
|
69
|
return this.sideBarService.open;
|
70
|
}
|
71
|
|
72
|
public toggleOpen(event = null) {
|
73
|
if (!event) {
|
74
|
this.sideBarService.setOpen(!this.open);
|
75
|
} else if (event && event['value'] === true) {
|
76
|
this.sideBarService.setOpen(false);
|
77
|
}
|
78
|
}
|
79
|
|
80
|
public createTopic(element) {
|
81
|
if(this.topic.name && this.topic.name !== '') {
|
82
|
this.topic.alias = this.topic.name.toLowerCase();
|
83
|
this.stakeholder.topics.push(this.topic);
|
84
|
this.hide(element);
|
85
|
} else {
|
86
|
this.valid = false;
|
87
|
}
|
88
|
}
|
89
|
}
|