2019-11-04 12:50:25 +01:00
|
|
|
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';
|
2019-11-05 15:59:06 +01:00
|
|
|
import {Category, Stakeholder, SubCategory, Topic} from "../utils/entities/stakeholder";
|
2019-11-04 12:50:25 +01:00
|
|
|
import {SideBarService} from "../library/sharedComponents/sidebar/sideBar.service";
|
|
|
|
import {StakeholderService} from "../services/stakeholder.service";
|
2019-11-05 15:59:06 +01:00
|
|
|
import {Tools} from "../utils/Tools";
|
2019-11-04 12:50:25 +01:00
|
|
|
|
|
|
|
declare var UIkit;
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'topic',
|
|
|
|
templateUrl: './topic.component.html',
|
|
|
|
})
|
|
|
|
export class TopicComponent implements OnInit, OnDestroy {
|
2019-11-08 16:47:47 +01:00
|
|
|
public properties: EnvProperties;
|
2019-11-04 12:50:25 +01:00
|
|
|
public loading: boolean = true;
|
|
|
|
public stakeholder: Stakeholder;
|
2019-11-05 15:59:06 +01:00
|
|
|
public topicIndex: number = -1;
|
|
|
|
public topic: Topic = null;
|
|
|
|
public categoryIndex: number = -1;
|
2019-11-08 16:47:47 +01:00
|
|
|
public selectedCategoryIndex: number = -1;
|
2019-11-05 15:59:06 +01:00
|
|
|
public copyCategory: Category = null;
|
|
|
|
public subCategoryIndex: number = -1;
|
|
|
|
public copySubCategory: SubCategory = null;
|
2019-11-04 12:50:25 +01:00
|
|
|
public valid = true;
|
2019-11-05 15:59:06 +01:00
|
|
|
public edit: boolean = false;
|
|
|
|
public toggle: boolean = false;
|
2019-11-04 12:50:25 +01:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
private title: Title,
|
|
|
|
private sideBarService: SideBarService,
|
|
|
|
private stakeholderService: StakeholderService) {
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2019-11-05 15:59:06 +01:00
|
|
|
this.stakeholder = Tools.copy(stakeholder);
|
|
|
|
this.topicIndex = this.stakeholder.topics.findIndex(topic => topic.alias === params['topic']);
|
|
|
|
if(this.topicIndex === -1) {
|
2019-11-04 12:50:25 +01:00
|
|
|
this.navigateToError();
|
2019-11-05 15:59:06 +01:00
|
|
|
} else {
|
|
|
|
this.title.setTitle(stakeholder.index_name);
|
2019-11-08 16:47:47 +01:00
|
|
|
this.categoryIndex = 0;
|
|
|
|
this.selectedCategoryIndex = 0;
|
|
|
|
this.subCategoryIndex = 0;
|
|
|
|
this.toggle = true;
|
2019-11-04 12:50:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
}
|
|
|
|
|
2019-11-05 15:59:06 +01:00
|
|
|
public hide(element) {
|
|
|
|
this.edit = false;
|
|
|
|
UIkit.drop(element).hide();
|
2019-11-04 12:50:25 +01:00
|
|
|
}
|
|
|
|
|
2019-11-05 15:59:06 +01:00
|
|
|
public show(element) {
|
|
|
|
this.edit = true;
|
|
|
|
UIkit.drop(element).show();
|
2019-11-04 12:50:25 +01:00
|
|
|
}
|
|
|
|
|
2019-11-05 15:59:06 +01:00
|
|
|
public toggleCategory(index: number) {
|
2019-11-08 16:47:47 +01:00
|
|
|
if(this.selectedCategoryIndex !== index) {
|
|
|
|
this.selectedCategoryIndex = index;
|
2019-11-05 15:59:06 +01:00
|
|
|
this.toggle = true;
|
|
|
|
} else {
|
|
|
|
this.toggle = !this.toggle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public editCategoryOpen(index:number = -1, element = null) {
|
|
|
|
if(index === -1) {
|
|
|
|
this.copyCategory = new Category(null, null, null, true, true);
|
|
|
|
} else {
|
|
|
|
if(element.className.indexOf('uk-open') !== -1) {
|
|
|
|
this.hide(element);
|
|
|
|
} else {
|
|
|
|
this.copyCategory = Tools.copy(this.stakeholder.topics[this.topicIndex].categories[index]);
|
|
|
|
this.show(element);
|
|
|
|
this.valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public saveCategory(element, index = -1) {
|
|
|
|
if(this.copyCategory.name && this.copyCategory.name !== '') {
|
|
|
|
this.copyCategory.alias = this.copyCategory.name.toLowerCase();
|
|
|
|
if(index === -1) {
|
|
|
|
this.stakeholder.topics[this.topicIndex].categories.push(this.copyCategory);
|
|
|
|
} else {
|
|
|
|
this.stakeholder.topics[this.topicIndex].categories[index] = Tools.copy(this.copyCategory);
|
|
|
|
}
|
|
|
|
this.hide(element);
|
|
|
|
} else {
|
|
|
|
this.valid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public editSubCategoryOpen(index:number = -1, element = null) {
|
|
|
|
if(index === -1) {
|
|
|
|
this.copySubCategory = new SubCategory(null, null, null, true, true);
|
|
|
|
} else {
|
|
|
|
if(element.className.indexOf('uk-open') !== -1) {
|
|
|
|
this.hide(element);
|
|
|
|
} else {
|
|
|
|
this.copySubCategory = Tools.copy(this.stakeholder.topics[this.topicIndex].
|
|
|
|
categories[this.categoryIndex].subCategories[index]);
|
|
|
|
this.show(element);
|
|
|
|
this.valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public saveSubCategory(element, index = -1) {
|
|
|
|
if(this.copySubCategory.name && this.copySubCategory.name !== '') {
|
|
|
|
this.copySubCategory.alias = this.copySubCategory.name.toLowerCase();
|
|
|
|
if(index === -1) {
|
2019-11-08 16:47:47 +01:00
|
|
|
this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].
|
2019-11-05 15:59:06 +01:00
|
|
|
subCategories.push(this.copySubCategory);
|
|
|
|
} else {
|
2019-11-08 16:47:47 +01:00
|
|
|
this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].
|
2019-11-05 15:59:06 +01:00
|
|
|
subCategories[index] = Tools.copy(this.copySubCategory);
|
|
|
|
}
|
|
|
|
this.hide(element);
|
|
|
|
} else {
|
|
|
|
this.valid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 16:47:47 +01:00
|
|
|
public editTopicOpen(element) {
|
|
|
|
if(element.className.indexOf('uk-open') !== -1) {
|
|
|
|
this.hide(element);
|
|
|
|
} else {
|
|
|
|
this.topic = Tools.copy(this.stakeholder.topics[this.topicIndex]);
|
|
|
|
this.valid = true;
|
|
|
|
this.show(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-05 15:59:06 +01:00
|
|
|
public saveTopic(element) {
|
2019-11-04 12:50:25 +01:00
|
|
|
if(this.topic.name && this.topic.name !== '') {
|
|
|
|
this.topic.alias = this.topic.name.toLowerCase();
|
2019-11-05 15:59:06 +01:00
|
|
|
this.stakeholder.topics[this.topicIndex] = Tools.copy(this.topic);
|
|
|
|
this.hide(element);
|
2019-11-04 12:50:25 +01:00
|
|
|
} else {
|
|
|
|
this.valid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-05 15:59:06 +01:00
|
|
|
public deleteTopic(element) {
|
|
|
|
/*this.stakeholder.topics.splice(this.topicIndex, 1);
|
|
|
|
this.hide(element);
|
|
|
|
this.back();*/
|
|
|
|
}
|
|
|
|
|
2019-11-04 12:50:25 +01:00
|
|
|
private navigateToError() {
|
|
|
|
this.router.navigate(['/error'], {queryParams: {'page': this.router.url}});
|
|
|
|
}
|
2019-11-05 15:59:06 +01:00
|
|
|
|
2019-11-08 16:47:47 +01:00
|
|
|
public getDefaultSubcategoryIndex(categoryIndex: number) {
|
|
|
|
return this.stakeholder.topics[this.topicIndex].categories[categoryIndex].
|
|
|
|
subCategories.findIndex(subcategory => subcategory.alias === null);
|
|
|
|
}
|
|
|
|
|
2019-11-05 15:59:06 +01:00
|
|
|
back() {
|
|
|
|
this.router.navigate(['../'], {
|
|
|
|
relativeTo: this.route
|
|
|
|
});
|
|
|
|
}
|
2019-11-08 16:47:47 +01:00
|
|
|
|
|
|
|
chooseSubcategory(categoryIndex: number, subcategoryIndex: number) {
|
|
|
|
/*let topic: Topic = this.stakeholder.topics[this.topicIndex];
|
|
|
|
let category: Category = topic.categories[this.categoryIndex];
|
|
|
|
let subCatetegory: SubCategory = category.subCategories[index];*/
|
|
|
|
this.categoryIndex = categoryIndex;
|
|
|
|
this.subCategoryIndex = subcategoryIndex;
|
|
|
|
}
|
2019-11-04 12:50:25 +01:00
|
|
|
}
|