monitor-dashboard/src/app/topic/topic.component.ts

98 lines
2.9 KiB
TypeScript
Raw Normal View History

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";
declare var UIkit;
@Component({
selector: 'topic',
templateUrl: './topic.component.html',
})
export class TopicComponent 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;
public 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.route.params.subscribe( params => {
this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
if (stakeholder) {
this.sideBarService.setHasSidebar(true);
this.stakeholder = stakeholder;
this.topic = this.stakeholder.topics.filter(topic => topic.alias === params['topic'])[0];
this.title.setTitle(stakeholder.index_name);
if(!this.topic) {
this.navigateToError();
}
}
});
});
});
}
public ngOnDestroy() {
}
public newTopicOpen() {
this.topic = new Topic(null, null, null,true, true);
this.valid = true;
}
public close(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.close(element);
} else {
this.valid = false;
}
}
private navigateToError() {
this.router.navigate(['/error'], {queryParams: {'page': this.router.url}});
}
}