2019-11-12 16:55:37 +01:00
|
|
|
import {Component, OnDestroy, OnInit, ViewChild} from '@angular/core';
|
2019-11-04 12:50:25 +01:00
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
2020-11-13 17:42:12 +01:00
|
|
|
import {Title} from '@angular/platform-browser';
|
2019-11-04 12:50:25 +01:00
|
|
|
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
2020-10-23 15:58:16 +02:00
|
|
|
import {
|
|
|
|
Category,
|
|
|
|
Stakeholder,
|
|
|
|
SubCategory,
|
|
|
|
Topic,
|
|
|
|
Visibility
|
|
|
|
} from "../openaireLibrary/monitor/entities/stakeholder";
|
2020-06-03 15:44:03 +02:00
|
|
|
import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service";
|
2019-11-11 14:28:36 +01:00
|
|
|
import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class";
|
2019-11-12 16:55:37 +01:00
|
|
|
import {AlertModal} from "../openaireLibrary/utils/modal/alert";
|
2019-12-06 14:52:26 +01:00
|
|
|
import {Subscriber, Subscription} from "rxjs";
|
2019-11-26 20:11:24 +01:00
|
|
|
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
|
2020-11-02 15:46:19 +01:00
|
|
|
import {IndicatorUtils, StakeholderUtils} from "../utils/indicator-utils";
|
2019-12-20 12:13:34 +01:00
|
|
|
import {StringUtils} from "../openaireLibrary/utils/string-utils.class";
|
2020-01-08 12:00:50 +01:00
|
|
|
import {IDeactivateComponent} from "../openaireLibrary/utils/can-exit.guard";
|
2020-10-12 14:54:57 +02:00
|
|
|
import {LayoutService} from "../openaireLibrary/dashboard/sharedComponents/sidebar/layout.service";
|
2020-11-12 18:57:57 +01:00
|
|
|
import {Option} from "../openaireLibrary/sharedComponents/input/input.component";
|
2020-11-13 17:42:12 +01:00
|
|
|
import {properties} from "../../environments/environment";
|
2019-11-04 12:50:25 +01:00
|
|
|
|
|
|
|
declare var UIkit;
|
|
|
|
|
|
|
|
@Component({
|
2019-12-20 12:13:34 +01:00
|
|
|
selector: 'topic',
|
|
|
|
templateUrl: './topic.component.html',
|
2019-11-04 12:50:25 +01:00
|
|
|
})
|
2020-01-08 12:00:50 +01:00
|
|
|
export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
|
2020-11-16 17:48:07 +01:00
|
|
|
private subscriptions: any[] = [];
|
|
|
|
private paramsSub: any;
|
2019-12-20 12:13:34 +01:00
|
|
|
public properties: EnvProperties;
|
|
|
|
public stakeholderUtils: StakeholderUtils = new StakeholderUtils();
|
|
|
|
public loading: boolean = true;
|
|
|
|
public stakeholder: Stakeholder;
|
|
|
|
/**
|
|
|
|
* Current topic
|
|
|
|
**/
|
|
|
|
public topicIndex: number = 0;
|
|
|
|
/**
|
|
|
|
* categoryIndex: Current category to be edited, selectedCategoryIndex: selected on menu(opened)
|
|
|
|
*/
|
|
|
|
public categoryIndex: number = 0;
|
|
|
|
public selectedCategoryIndex: number = 0;
|
|
|
|
/**
|
|
|
|
* Current Subcategory to be edited
|
|
|
|
*/
|
|
|
|
public subCategoryIndex: number = 0;
|
|
|
|
/**
|
|
|
|
* Current element and index of topic, category or subcategory to be deleted.
|
|
|
|
*/
|
|
|
|
public form: FormGroup;
|
|
|
|
public element: Topic | Category | SubCategory;
|
|
|
|
public type: 'topic' | 'category' | 'subcategory' = "topic";
|
|
|
|
public index: number = -1;
|
|
|
|
/**
|
|
|
|
* Check form validity
|
|
|
|
*/
|
|
|
|
public toggle: boolean = false;
|
|
|
|
|
2021-07-14 18:02:04 +02:00
|
|
|
@ViewChild('deleteModal', { static: true }) deleteModal: AlertModal;
|
|
|
|
@ViewChild('editModal', { static: true }) editModal: AlertModal;
|
2020-06-23 10:33:13 +02:00
|
|
|
public elementChildrenActionOnDelete: string;
|
2020-11-02 15:46:19 +01:00
|
|
|
public filters: FormGroup;
|
|
|
|
public all: Option = {
|
|
|
|
value: 'all',
|
|
|
|
label: 'All'
|
|
|
|
};
|
|
|
|
|
2019-12-20 12:13:34 +01:00
|
|
|
constructor(
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
private title: Title,
|
|
|
|
private fb: FormBuilder,
|
2020-10-12 14:54:57 +02:00
|
|
|
private stakeholderService: StakeholderService,
|
|
|
|
private layoutService: LayoutService) {
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnInit() {
|
2020-11-13 17:42:12 +01:00
|
|
|
this.properties = properties;
|
2019-12-20 12:13:34 +01:00
|
|
|
let subscription: Subscription;
|
2020-11-16 17:48:07 +01:00
|
|
|
this.paramsSub = this.route.params.subscribe(params => {
|
2019-12-20 12:13:34 +01:00
|
|
|
if (subscription) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
subscription = this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
|
|
|
|
if (stakeholder) {
|
2020-01-08 12:00:50 +01:00
|
|
|
this.stakeholder = stakeholder;
|
2020-10-12 14:54:57 +02:00
|
|
|
if(params['topic']) {
|
|
|
|
this.topicIndex = this.stakeholder.topics.findIndex(topic => topic.alias === params['topic']);
|
|
|
|
}else{
|
|
|
|
this.topicIndex = 0;
|
|
|
|
}
|
|
|
|
this.categoryIndex = 0;
|
|
|
|
this.subCategoryIndex = 0;
|
2020-11-02 15:46:19 +01:00
|
|
|
this.filters = this.fb.group({
|
|
|
|
chartType: this.fb.control('all'),
|
|
|
|
status: this.fb.control('all'),
|
|
|
|
keyword: this.fb.control('')
|
|
|
|
});
|
2019-12-20 12:13:34 +01:00
|
|
|
if (this.topicIndex === -1) {
|
|
|
|
this.navigateToError();
|
|
|
|
} else {
|
2020-11-19 18:14:12 +01:00
|
|
|
this.title.setTitle(stakeholder.name + " | Indicators");
|
2019-12-20 12:13:34 +01:00
|
|
|
this.toggle = true;
|
|
|
|
}
|
2019-11-04 12:50:25 +01:00
|
|
|
}
|
2019-12-20 12:13:34 +01:00
|
|
|
});
|
|
|
|
this.subscriptions.push(subscription);
|
2020-11-16 17:48:07 +01:00
|
|
|
});
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
2020-11-13 17:42:12 +01:00
|
|
|
this.subscriptions.forEach(value => {
|
|
|
|
if (value instanceof Subscriber) {
|
|
|
|
value.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
2020-11-16 17:48:07 +01:00
|
|
|
if(this.paramsSub instanceof Subscriber) {
|
|
|
|
this.paramsSub.unsubscribe();
|
|
|
|
}
|
2020-01-08 12:00:50 +01:00
|
|
|
}
|
|
|
|
|
2020-11-16 17:48:07 +01:00
|
|
|
canExit(): boolean {
|
2019-12-20 12:13:34 +01:00
|
|
|
this.subscriptions.forEach(value => {
|
|
|
|
if (value instanceof Subscriber) {
|
|
|
|
value.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
2020-01-08 12:00:50 +01:00
|
|
|
this.stakeholderService.setStakeholder(this.stakeholder);
|
|
|
|
return true;
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
|
|
|
|
2020-01-10 15:20:42 +01:00
|
|
|
hide(element: any) {
|
|
|
|
UIkit.dropdown(element).hide();
|
|
|
|
}
|
|
|
|
|
2019-12-20 12:13:34 +01:00
|
|
|
public saveElement() {
|
|
|
|
if (this.type === "topic") {
|
|
|
|
this.saveTopic();
|
|
|
|
} else if (this.type === "category") {
|
|
|
|
this.saveCategory();
|
|
|
|
} else {
|
|
|
|
this.saveSubCategory();
|
2019-12-06 14:52:26 +01:00
|
|
|
}
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
2020-11-16 17:48:07 +01:00
|
|
|
|
2020-06-23 10:33:13 +02:00
|
|
|
// public closeDeleteModal() {
|
|
|
|
// this.deleteModal.cancel();
|
|
|
|
// }
|
2019-12-20 12:13:34 +01:00
|
|
|
|
|
|
|
public deleteElement() {
|
|
|
|
if (this.type === "topic") {
|
|
|
|
this.deleteTopic();
|
|
|
|
} else if (this.type === "category") {
|
|
|
|
this.deleteCategory();
|
|
|
|
} else {
|
|
|
|
this.deleteSubcategory();
|
2019-12-06 14:52:26 +01:00
|
|
|
}
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private buildTopic(topic: Topic) {
|
|
|
|
let topics = this.stakeholder.topics.filter(element => element._id !== topic._id);
|
|
|
|
this.form = this.fb.group({
|
|
|
|
_id: this.fb.control(topic._id),
|
|
|
|
name: this.fb.control(topic.name, Validators.required),
|
|
|
|
description: this.fb.control(topic.description),
|
2020-11-16 17:48:07 +01:00
|
|
|
creationDate: this.fb.control(topic.creationDate),
|
2019-12-20 12:13:34 +01:00
|
|
|
alias: this.fb.control(topic.alias, [
|
|
|
|
Validators.required,
|
|
|
|
this.stakeholderUtils.aliasValidator(topics)
|
|
|
|
]
|
|
|
|
),
|
2020-10-23 15:58:16 +02:00
|
|
|
visibility: this.fb.control(topic.visibility),
|
2020-01-08 12:00:50 +01:00
|
|
|
defaultId: this.fb.control(topic.defaultId),
|
2020-06-11 12:12:30 +02:00
|
|
|
categories: this.fb.control(topic.categories),
|
2020-06-12 12:46:11 +02:00
|
|
|
icon: this.fb.control(topic.icon)
|
2019-12-20 12:13:34 +01:00
|
|
|
});
|
|
|
|
this.subscriptions.push(this.form.get('name').valueChanges.subscribe(value => {
|
|
|
|
let i = 1;
|
|
|
|
value = this.stakeholderUtils.generateAlias(value);
|
|
|
|
this.form.controls['alias'].setValue(value);
|
|
|
|
while (this.form.get('alias').invalid) {
|
|
|
|
this.form.controls['alias'].setValue(value + i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2020-11-16 17:48:07 +01:00
|
|
|
public editTopicOpen(index = -1) {
|
2020-10-12 14:54:57 +02:00
|
|
|
this.index = index;
|
2019-12-20 12:13:34 +01:00
|
|
|
this.type = 'topic';
|
2020-10-12 14:54:57 +02:00
|
|
|
if (index === -1) {
|
2020-10-23 15:58:16 +02:00
|
|
|
this.buildTopic(new Topic(null, null, null, "PUBLIC"));
|
2020-10-12 14:54:57 +02:00
|
|
|
} else {
|
|
|
|
this.buildTopic(this.stakeholder.topics[index]);
|
|
|
|
}
|
2019-12-20 12:13:34 +01:00
|
|
|
this.editOpen();
|
|
|
|
}
|
|
|
|
|
2020-11-02 15:46:19 +01:00
|
|
|
public saveTopic() {
|
2019-12-20 12:13:34 +01:00
|
|
|
if (!this.form.invalid) {
|
|
|
|
let path = [this.stakeholder._id];
|
|
|
|
let callback = (topic: Topic): void => {
|
2020-11-02 15:46:19 +01:00
|
|
|
if (this.index === -1) {
|
|
|
|
this.stakeholder.topics.push(topic);
|
|
|
|
} else {
|
|
|
|
this.stakeholder.topics[this.index] = HelperFunctions.copy(topic);
|
|
|
|
}
|
2019-12-20 12:13:34 +01:00
|
|
|
};
|
2020-11-02 15:46:19 +01:00
|
|
|
if (this.index === -1) {
|
|
|
|
this.save('Topic has been successfully created', path, this.form.value, callback);
|
|
|
|
} else {
|
|
|
|
this.save('Topic has been successfully saved', path, this.form.value, callback);
|
|
|
|
}
|
2019-11-13 11:26:50 +01:00
|
|
|
}
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
|
|
|
|
2020-11-16 17:48:07 +01:00
|
|
|
public changeTopicStatus(index: number, visibility: Visibility) {
|
2019-12-20 12:13:34 +01:00
|
|
|
this.type = 'topic';
|
|
|
|
let path = [
|
|
|
|
this.stakeholder._id,
|
2020-10-12 14:54:57 +02:00
|
|
|
this.stakeholder.topics[index]._id
|
2019-12-20 12:13:34 +01:00
|
|
|
];
|
2020-11-03 11:04:45 +01:00
|
|
|
this.changeStatus(this.stakeholder.topics[index], path, visibility);
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
|
|
|
|
2020-11-16 17:48:07 +01:00
|
|
|
|
|
|
|
public deleteTopicOpen(index = this.topicIndex, childrenAction: string = null) {
|
2019-12-20 12:13:34 +01:00
|
|
|
this.type = 'topic';
|
2020-10-12 14:54:57 +02:00
|
|
|
this.index = index;
|
2019-12-20 12:13:34 +01:00
|
|
|
this.element = this.stakeholder.topics[this.index];
|
2020-06-23 10:33:13 +02:00
|
|
|
this.deleteOpen(childrenAction);
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
|
|
|
|
2020-12-08 11:09:15 +01:00
|
|
|
public deleteTopic() {
|
2019-12-20 12:13:34 +01:00
|
|
|
let path: string[] = [
|
|
|
|
this.stakeholder._id,
|
2020-12-08 11:09:15 +01:00
|
|
|
this.stakeholder.topics[this.index]._id
|
2019-12-20 12:13:34 +01:00
|
|
|
];
|
|
|
|
let callback = (): void => {
|
2020-12-08 11:09:15 +01:00
|
|
|
this.stakeholder.topics.splice(this.index, 1);
|
2019-12-20 12:13:34 +01:00
|
|
|
};
|
2020-12-08 11:09:15 +01:00
|
|
|
this.delete('Topic has been successfully be deleted', path, callback, (this.topicIndex === this.index));
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public toggleCategory(index: number) {
|
2020-10-12 14:54:57 +02:00
|
|
|
if (this.categoryIndex !== index) {
|
|
|
|
this.categoryIndex = index;
|
2019-12-20 12:13:34 +01:00
|
|
|
this.toggle = true;
|
|
|
|
} else {
|
|
|
|
this.toggle = !this.toggle;
|
2019-11-13 11:26:50 +01:00
|
|
|
}
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private buildCategory(category: Category) {
|
|
|
|
let categories = this.stakeholder.topics[this.topicIndex].categories.filter(element => element._id !== category._id);
|
|
|
|
this.form = this.fb.group({
|
|
|
|
_id: this.fb.control(category._id),
|
|
|
|
name: this.fb.control(category.name, Validators.required),
|
|
|
|
description: this.fb.control(category.description),
|
2020-11-16 17:48:07 +01:00
|
|
|
creationDate: this.fb.control(category.creationDate),
|
2019-12-20 12:13:34 +01:00
|
|
|
alias: this.fb.control(category.alias, [
|
|
|
|
Validators.required,
|
|
|
|
this.stakeholderUtils.aliasValidator(categories)
|
|
|
|
]
|
|
|
|
),
|
2020-10-23 15:58:16 +02:00
|
|
|
visibility: this.fb.control(category.visibility),
|
2020-01-08 12:00:50 +01:00
|
|
|
defaultId: this.fb.control(category.defaultId),
|
2019-12-20 12:13:34 +01:00
|
|
|
subCategories: this.fb.control(category.subCategories)
|
|
|
|
});
|
|
|
|
this.subscriptions.push(this.form.get('name').valueChanges.subscribe(value => {
|
|
|
|
let i = 1;
|
|
|
|
value = this.stakeholderUtils.generateAlias(value);
|
|
|
|
this.form.controls['alias'].setValue(value);
|
|
|
|
while (this.form.get('alias').invalid) {
|
|
|
|
this.form.controls['alias'].setValue(value + i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
public editCategoryOpen(index: number = -1) {
|
|
|
|
this.index = index;
|
|
|
|
this.type = 'category';
|
|
|
|
if (index === -1) {
|
2020-10-23 15:58:16 +02:00
|
|
|
this.buildCategory(new Category(null, null, null, "PUBLIC"));
|
2019-12-20 12:13:34 +01:00
|
|
|
} else {
|
|
|
|
this.buildCategory(this.stakeholder.topics[this.topicIndex].categories[index]);
|
2019-12-06 14:52:26 +01:00
|
|
|
}
|
2019-12-20 12:13:34 +01:00
|
|
|
this.editOpen();
|
|
|
|
}
|
|
|
|
|
|
|
|
public saveCategory() {
|
|
|
|
if (!this.form.invalid) {
|
|
|
|
let path = [this.stakeholder._id, this.stakeholder.topics[this.topicIndex]._id];
|
|
|
|
let callback = (category: Category): void => {
|
|
|
|
if (this.index === -1) {
|
|
|
|
this.stakeholder.topics[this.topicIndex].categories.push(category);
|
2019-12-06 14:52:26 +01:00
|
|
|
} else {
|
2019-12-20 12:13:34 +01:00
|
|
|
this.stakeholder.topics[this.topicIndex].categories[this.index] = HelperFunctions.copy(category);
|
2019-12-06 14:52:26 +01:00
|
|
|
}
|
2019-12-20 12:13:34 +01:00
|
|
|
};
|
|
|
|
if (this.index === -1) {
|
|
|
|
this.save('Category has been successfully created', path, this.form.value, callback);
|
|
|
|
} else {
|
|
|
|
this.save('Category has been successfully saved', path, this.form.value, callback);
|
|
|
|
}
|
2019-12-06 14:52:26 +01:00
|
|
|
}
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
|
|
|
|
2020-11-16 17:48:07 +01:00
|
|
|
public changeCategoryStatus(index: number, visibility: Visibility) {
|
2019-12-20 12:13:34 +01:00
|
|
|
this.index = index;
|
|
|
|
this.type = 'category';
|
|
|
|
let path = [
|
|
|
|
this.stakeholder._id,
|
|
|
|
this.stakeholder.topics[this.topicIndex]._id,
|
|
|
|
this.stakeholder.topics[this.topicIndex].categories[this.index]._id
|
|
|
|
];
|
2020-11-03 11:04:45 +01:00
|
|
|
this.changeStatus(this.stakeholder.topics[this.topicIndex].categories[this.index], path, visibility);
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
2020-11-16 17:48:07 +01:00
|
|
|
|
2019-12-20 12:13:34 +01:00
|
|
|
|
2020-06-23 10:33:13 +02:00
|
|
|
public deleteCategoryOpen(index: number, childrenAction: string = null) {
|
2019-12-20 12:13:34 +01:00
|
|
|
this.type = 'category';
|
|
|
|
this.index = index;
|
|
|
|
this.element = this.stakeholder.topics[this.topicIndex].categories[this.index];
|
2020-06-23 10:33:13 +02:00
|
|
|
this.deleteOpen(childrenAction);
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public deleteCategory() {
|
|
|
|
let path: string[] = [
|
|
|
|
this.stakeholder._id,
|
|
|
|
this.stakeholder.topics[this.topicIndex]._id,
|
|
|
|
this.stakeholder.topics[this.topicIndex].categories[this.index]._id
|
|
|
|
];
|
|
|
|
let callback = (): void => {
|
|
|
|
this.stakeholder.topics[this.topicIndex].categories.splice(this.index, 1);
|
|
|
|
};
|
|
|
|
this.delete('Category has been successfully be deleted', path, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
private buildSubcategory(subCategory: SubCategory) {
|
|
|
|
let subCategories = this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories.filter(element => element._id !== subCategory._id);
|
|
|
|
this.form = this.fb.group({
|
|
|
|
_id: this.fb.control(subCategory._id),
|
|
|
|
name: this.fb.control(subCategory.name, Validators.required),
|
|
|
|
description: this.fb.control(subCategory.description),
|
2020-11-16 17:48:07 +01:00
|
|
|
creationDate: this.fb.control(subCategory.creationDate),
|
2019-12-20 12:13:34 +01:00
|
|
|
alias: this.fb.control(subCategory.alias, [
|
|
|
|
Validators.required,
|
|
|
|
this.stakeholderUtils.aliasValidator(subCategories)
|
|
|
|
]
|
|
|
|
),
|
2020-10-23 15:58:16 +02:00
|
|
|
visibility: this.fb.control(subCategory.visibility),
|
2020-01-08 12:00:50 +01:00
|
|
|
defaultId: this.fb.control(subCategory.defaultId),
|
2019-12-20 12:13:34 +01:00
|
|
|
charts: this.fb.control(subCategory.charts),
|
|
|
|
numbers: this.fb.control(subCategory.numbers)
|
|
|
|
});
|
|
|
|
this.subscriptions.push(this.form.get('name').valueChanges.subscribe(value => {
|
|
|
|
let i = 1;
|
|
|
|
value = this.stakeholderUtils.generateAlias(value);
|
|
|
|
this.form.controls['alias'].setValue(value);
|
|
|
|
while (this.form.get('alias').invalid) {
|
|
|
|
this.form.controls['alias'].setValue(value + i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
public editSubCategoryOpen(index: number = -1) {
|
|
|
|
this.index = index;
|
|
|
|
this.type = 'subcategory';
|
|
|
|
if (index === -1) {
|
2020-10-23 15:58:16 +02:00
|
|
|
this.buildSubcategory(new SubCategory(null, null, null, "PUBLIC"));
|
2019-12-20 12:13:34 +01:00
|
|
|
} else {
|
|
|
|
this.buildSubcategory(this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories[index]);
|
2019-11-05 15:59:06 +01:00
|
|
|
}
|
2019-12-20 12:13:34 +01:00
|
|
|
this.editOpen();
|
|
|
|
}
|
|
|
|
|
|
|
|
public saveSubCategory() {
|
|
|
|
if (!this.form.invalid) {
|
|
|
|
let path: string[] = [
|
|
|
|
this.stakeholder._id,
|
|
|
|
this.stakeholder.topics[this.topicIndex]._id,
|
2020-05-12 17:30:49 +02:00
|
|
|
this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex]._id
|
2019-12-20 12:13:34 +01:00
|
|
|
];
|
|
|
|
let callback = (subCategory: SubCategory): void => {
|
|
|
|
if (this.index === -1) {
|
|
|
|
this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories.push(subCategory);
|
2019-11-24 17:30:04 +01:00
|
|
|
} else {
|
2020-12-11 19:34:50 +01:00
|
|
|
this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories[this.index] = HelperFunctions.copy(subCategory);
|
2019-12-06 14:52:26 +01:00
|
|
|
}
|
2019-12-20 12:13:34 +01:00
|
|
|
};
|
|
|
|
if (this.index === -1) {
|
|
|
|
this.save('Subcategory has been successfully created', path, this.form.value, callback);
|
|
|
|
} else {
|
|
|
|
this.save('Subcategory has been successfully saved', path, this.form.value, callback);
|
|
|
|
}
|
2019-12-06 14:52:26 +01:00
|
|
|
}
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
2020-11-16 17:48:07 +01:00
|
|
|
|
|
|
|
public changeSubcategoryStatus(index: number, visibility: Visibility) {
|
|
|
|
this.index = index;
|
|
|
|
this.type = 'subcategory';
|
|
|
|
let path = [
|
|
|
|
this.stakeholder._id,
|
|
|
|
this.stakeholder.topics[this.topicIndex]._id,
|
|
|
|
this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex]._id,
|
|
|
|
this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories[this.index]._id
|
|
|
|
];
|
|
|
|
this.changeStatus(this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories[this.index], path, visibility);
|
|
|
|
}
|
|
|
|
|
2019-12-20 12:13:34 +01:00
|
|
|
|
2020-06-23 10:33:13 +02:00
|
|
|
public deleteSubcategoryOpen(index, childrenAction: string = null) {
|
2019-12-20 12:13:34 +01:00
|
|
|
this.type = 'subcategory';
|
|
|
|
this.index = index;
|
|
|
|
this.element = this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories[this.index];
|
2020-06-23 10:33:13 +02:00
|
|
|
this.deleteOpen(childrenAction);
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public deleteSubcategory() {
|
|
|
|
let path: string[] = [
|
|
|
|
this.stakeholder._id,
|
|
|
|
this.stakeholder.topics[this.topicIndex]._id,
|
|
|
|
this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex]._id,
|
|
|
|
this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories[this.index]._id
|
|
|
|
];
|
|
|
|
let callback = (): void => {
|
|
|
|
this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex].subCategories.splice(this.index, 1);
|
|
|
|
};
|
|
|
|
this.delete('Subcategory has been successfully be deleted', path, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
private navigateToError() {
|
|
|
|
this.router.navigate(['/error'], {queryParams: {'page': this.router.url}});
|
|
|
|
}
|
|
|
|
|
|
|
|
private editOpen() {
|
|
|
|
this.editModal.cancelButtonText = 'Cancel';
|
|
|
|
this.editModal.okButtonLeft = false;
|
|
|
|
this.editModal.alertMessage = false;
|
|
|
|
if (this.index === -1) {
|
|
|
|
this.editModal.alertTitle = 'Create a new ' + this.type;
|
|
|
|
this.editModal.okButtonText = 'Create';
|
|
|
|
} else {
|
|
|
|
this.editModal.alertTitle = 'Edit ' + this.type + '\'s information ';
|
|
|
|
this.editModal.okButtonText = 'Save';
|
2019-12-06 14:52:26 +01:00
|
|
|
}
|
2019-12-20 12:13:34 +01:00
|
|
|
this.editModal.open();
|
|
|
|
}
|
|
|
|
|
2020-06-23 10:33:13 +02:00
|
|
|
private deleteOpen(childrenAction: string = null) {
|
|
|
|
this.elementChildrenActionOnDelete = null;
|
2020-11-16 17:48:07 +01:00
|
|
|
if (childrenAction == "delete") {
|
2020-06-23 10:33:13 +02:00
|
|
|
this.elementChildrenActionOnDelete = childrenAction;
|
2020-11-16 17:48:07 +01:00
|
|
|
} else if (childrenAction == "disconnect") {
|
2020-06-23 10:33:13 +02:00
|
|
|
this.elementChildrenActionOnDelete = childrenAction;
|
|
|
|
}
|
2020-11-16 17:48:07 +01:00
|
|
|
|
2019-12-20 12:13:34 +01:00
|
|
|
this.deleteModal.alertTitle = 'Delete ' + this.type;
|
|
|
|
this.deleteModal.cancelButtonText = 'No';
|
|
|
|
this.deleteModal.okButtonText = 'Yes';
|
2020-06-23 10:33:13 +02:00
|
|
|
// this.deleteModal.cancelButton = false;
|
|
|
|
// this.deleteModal.okButton = false;
|
2019-12-20 12:13:34 +01:00
|
|
|
this.deleteModal.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
private save(message: string, path: string[], saveElement: any, callback: Function, redirect = false) {
|
2020-11-13 17:42:12 +01:00
|
|
|
this.subscriptions.push(this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, saveElement, path).subscribe(saveElement => {
|
2019-12-20 12:13:34 +01:00
|
|
|
callback(saveElement);
|
|
|
|
UIkit.notification(message, {
|
|
|
|
status: 'success',
|
2020-12-01 16:43:43 +01:00
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
2019-12-20 12:13:34 +01:00
|
|
|
});
|
|
|
|
if (redirect) {
|
|
|
|
this.router.navigate(['../' + saveElement.alias], {
|
|
|
|
relativeTo: this.route
|
2019-12-06 14:52:26 +01:00
|
|
|
});
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
|
|
|
}, error => {
|
|
|
|
UIkit.notification(error.error.message, {
|
|
|
|
status: 'danger',
|
2020-12-01 16:43:43 +01:00
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
2019-12-20 12:13:34 +01:00
|
|
|
});
|
2020-11-13 17:42:12 +01:00
|
|
|
}));
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private delete(message: string, path: string[], callback: Function, redirect = false) {
|
2020-11-13 17:42:12 +01:00
|
|
|
this.subscriptions.push(this.stakeholderService.deleteElement(this.properties.monitorServiceAPIURL, path, this.elementChildrenActionOnDelete).subscribe(() => {
|
2019-12-20 12:13:34 +01:00
|
|
|
callback();
|
|
|
|
UIkit.notification(message, {
|
|
|
|
status: 'success',
|
2020-12-01 16:43:43 +01:00
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
2019-12-20 12:13:34 +01:00
|
|
|
});
|
|
|
|
if (redirect) {
|
|
|
|
this.back();
|
|
|
|
}
|
|
|
|
}, error => {
|
|
|
|
UIkit.notification(error.error.message, {
|
|
|
|
status: 'danger',
|
2020-12-01 16:43:43 +01:00
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
2019-12-20 12:13:34 +01:00
|
|
|
});
|
2020-11-13 17:42:12 +01:00
|
|
|
}));
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
2020-11-16 17:48:07 +01:00
|
|
|
|
|
|
|
public toggleStatusByIndex(index: number, visibility: Visibility, type) {
|
|
|
|
if (type == "sub") {
|
|
|
|
this.changeSubcategoryStatus(index, visibility);
|
|
|
|
} else if (type == "cat") {
|
|
|
|
this.changeCategoryStatus(index, visibility);
|
|
|
|
} else if (type == "topic") {
|
|
|
|
this.changeTopicStatus(index, visibility);
|
2020-10-23 15:58:16 +02:00
|
|
|
}
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
2020-11-03 11:04:45 +01:00
|
|
|
|
2020-11-16 17:48:07 +01:00
|
|
|
private changeStatus(element: Topic | Category | SubCategory, path: string[], visibility: Visibility) {
|
2020-11-13 17:42:12 +01:00
|
|
|
this.subscriptions.push(this.stakeholderService.changeVisibility(this.properties.monitorServiceAPIURL, path, visibility).subscribe(visibility => {
|
2020-10-23 15:58:16 +02:00
|
|
|
element.visibility = visibility;
|
2020-12-01 16:43:43 +01:00
|
|
|
UIkit.notification(StringUtils.capitalize(this.type) + ' has been <b>successfully changed</b> to ' + element.visibility.toLowerCase(), {
|
2019-12-20 12:13:34 +01:00
|
|
|
status: 'success',
|
2020-12-01 16:43:43 +01:00
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
2019-12-20 12:13:34 +01:00
|
|
|
});
|
|
|
|
}, error => {
|
|
|
|
UIkit.notification(error.error.message, {
|
|
|
|
status: 'danger',
|
2020-12-01 16:43:43 +01:00
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
2019-12-20 12:13:34 +01:00
|
|
|
});
|
2020-11-13 17:42:12 +01:00
|
|
|
}));
|
2019-12-20 12:13:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
back() {
|
|
|
|
this.router.navigate(['../'], {
|
|
|
|
relativeTo: this.route
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
chooseSubcategory(categoryIndex: number, subcategoryIndex: number) {
|
|
|
|
this.categoryIndex = categoryIndex;
|
|
|
|
this.subCategoryIndex = subcategoryIndex;
|
|
|
|
}
|
2020-11-16 17:48:07 +01:00
|
|
|
|
2020-06-23 10:33:13 +02:00
|
|
|
public getPluralTypeName(): string {
|
2020-11-16 17:48:07 +01:00
|
|
|
if (this.type == "topic") {
|
2020-06-23 10:33:13 +02:00
|
|
|
return "Topics";
|
2020-11-16 17:48:07 +01:00
|
|
|
} else if (this.type == "category") {
|
2020-06-23 10:33:13 +02:00
|
|
|
return "Categories";
|
2020-11-16 17:48:07 +01:00
|
|
|
} else if (this.type == "subcategory") {
|
2020-06-23 10:33:13 +02:00
|
|
|
return "Subcategories";
|
|
|
|
} else {
|
|
|
|
return this.type;
|
|
|
|
}
|
|
|
|
}
|
2020-11-16 17:48:07 +01:00
|
|
|
|
2020-10-12 14:54:57 +02:00
|
|
|
public get isSmallScreen() {
|
|
|
|
return this.layoutService.isSmallScreen;
|
|
|
|
}
|
2020-11-16 17:48:07 +01:00
|
|
|
|
2020-10-12 14:54:57 +02:00
|
|
|
public get open() {
|
|
|
|
return this.layoutService.open;
|
|
|
|
}
|
2020-11-16 17:48:07 +01:00
|
|
|
|
2020-10-12 14:54:57 +02:00
|
|
|
public toggleOpen(event: MouseEvent) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.layoutService.setOpen(!this.open);
|
|
|
|
}
|
2019-11-04 12:50:25 +01:00
|
|
|
}
|