90 lines
2.6 KiB
TypeScript
90 lines
2.6 KiB
TypeScript
import {Component, OnDestroy, OnInit} from '@angular/core';
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
import {Title} from '@angular/platform-browser';
|
|
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
|
|
|
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
|
|
import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component';
|
|
import {Stakeholder, Topic} from "../utils/entities/stakeholder";
|
|
import {SideBarService} from "../library/sharedComponents/sidebar/sideBar.service";
|
|
import {StakeholderService} from "../services/stakeholder.service";
|
|
import {Tools} from "../utils/Tools";
|
|
|
|
declare var UIkit;
|
|
|
|
@Component({
|
|
selector: 'home',
|
|
templateUrl: './home.component.html',
|
|
})
|
|
export class HomeComponent implements OnInit, OnDestroy {
|
|
public status: number;
|
|
public loading: boolean = true;
|
|
public errorCodes: ErrorCodes;
|
|
public stakeholder: Stakeholder;
|
|
public analysisOpen: boolean = true;
|
|
private errorMessages: ErrorMessagesComponent;
|
|
public topic: Topic;
|
|
public valid = true;
|
|
properties: EnvProperties;
|
|
|
|
constructor(
|
|
private route: ActivatedRoute,
|
|
private router: Router,
|
|
private title: Title,
|
|
private sideBarService: SideBarService,
|
|
private stakeholderService: StakeholderService) {
|
|
this.errorCodes = new ErrorCodes();
|
|
this.errorMessages = new ErrorMessagesComponent();
|
|
this.status = this.errorCodes.LOADING;
|
|
}
|
|
|
|
public ngOnInit() {
|
|
this.route.data
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
this.properties = data.envSpecific;
|
|
this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
|
|
if (stakeholder) {
|
|
this.sideBarService.setHasSidebar(true);
|
|
this.stakeholder = Tools.copy(stakeholder);
|
|
this.topic = null;
|
|
this.title.setTitle(stakeholder.index_name);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
public ngOnDestroy() {
|
|
}
|
|
|
|
public newTopicOpen() {
|
|
this.topic = new Topic(null, null, null,true, true);
|
|
this.valid = true;
|
|
}
|
|
|
|
public hide(element) {
|
|
UIkit.drop(element).hide();
|
|
}
|
|
|
|
get open(): boolean {
|
|
return this.sideBarService.open;
|
|
}
|
|
|
|
public toggleOpen(event = null) {
|
|
if (!event) {
|
|
this.sideBarService.setOpen(!this.open);
|
|
} else if (event && event['value'] === true) {
|
|
this.sideBarService.setOpen(false);
|
|
}
|
|
}
|
|
|
|
public createTopic(element) {
|
|
if(this.topic.name && this.topic.name !== '') {
|
|
this.topic.alias = this.topic.name.toLowerCase();
|
|
this.stakeholder.topics.push(this.topic);
|
|
this.hide(element);
|
|
} else {
|
|
this.valid = false;
|
|
}
|
|
}
|
|
}
|