[Monitor Dashboard | Trunk]: 1. Fix bug with topics. 2. Change number edit to be same as charts

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@59891 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
Konstantinos Triantafyllou 2020-11-16 16:48:07 +00:00
parent d0687323bd
commit f54486f752
3 changed files with 105 additions and 86 deletions

View File

@ -55,7 +55,7 @@
<i uk-icon="more-vertical" (click)="$event.stopPropagation();$event.preventDefault()"></i>
<div #element uk-dropdown="mode: click; pos: bottom-right; delay-hide: 0; flip: false">
<ul class="uk-nav uk-dropdown-nav">
<li *ngIf="isAdministrator && !indicator.defaultId && !editing"><a
<li *ngIf="!editing"><a
(click)="editNumberIndicatorOpen(number, indicator._id)">Edit</a></li>
<ng-template ngFor [ngForOf]="stakeholderUtils.visibility" let-v>
<li *ngIf="indicator.visibility != v.value"><a (click)="changeIndicatorStatus(number._id,
@ -92,7 +92,7 @@
</div>
</div>
</ng-template>
<div *ngIf="isAdministrator" class="disable-sortable uk-sortable-nodrag uk-width-1-1">
<div class="disable-sortable uk-sortable-nodrag uk-width-1-1">
<div class="uk-width-1-3@l uk-width-1-2@m uk-width-1-1 uk-card uk-card-default uk-card-body clickable"
(click)="editNumberIndicatorOpen(number)">
<div>
@ -301,7 +301,7 @@
</div>
</div>
</div>
<div class="uk-flex uk-flex-middle">
<div *ngIf="indicator.defaultId === null" class="uk-flex uk-flex-middle">
<button class="uk-icon-button uk-button-secondary uk-margin-medium-top"
(click)="addJsonPath(i)">
<icon name="add"></icon>

View File

@ -262,6 +262,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.numberSections.push(this.fb.group({
_id: this.fb.control(section._id),
title: this.fb.control(section.title),
creationDate: this.fb.control(section.creationDate),
stakeholderAlias: this.fb.control(section.stakeholderAlias),
defaultId: this.fb.control(section.defaultId),
type: this.fb.control(section.type),
@ -273,6 +274,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.chartSections.push(this.fb.group({
_id: this.fb.control(section._id),
title: this.fb.control(section.title),
creationDate: this.fb.control(section.creationDate),
stakeholderAlias: this.fb.control(section.stakeholderAlias),
defaultId: this.fb.control(section.defaultId),
type: this.fb.control(section.type),
@ -430,7 +432,9 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
public validateJsonPath(index: number) {
let indicatorPath: FormGroup = <FormGroup>this.numberIndicatorPaths.at(index);
this.getJsonPath(index).disable();
if(this.indicator.defaultId === null) {
this.getJsonPath(index).disable();
}
indicatorPath.get('result').setErrors({validating: true});
this.subscriptions.push(this.statisticsService.getNumbers(null, indicatorPath.get('url').value).subscribe(response => {
let result = JSON.parse(JSON.stringify(response));
@ -440,8 +444,11 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}
});
setTimeout(() => {
this.getJsonPath(index).enable();
if(this.indicator.defaultId === null) {
this.getJsonPath(index).enable();
}
indicatorPath.get('result').setErrors(null);
console.debug(result);
if(typeof result === 'string' || typeof result === 'number') {
result = Number(result);
if (result !== Number.NaN) {
@ -497,48 +504,54 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
if(this.numberIndicatorPaths.at(index).get('url').valid) {
this.validateJsonPath(index);
}
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('url').valueChanges.subscribe(value => {
this.numberIndicatorPaths.at(index).get('result').setValue(null);
if (this.numberIndicatorPaths.at(index).get('url').valid) {
let indicatorPath: IndicatorPath = this.indicatorUtils.generateIndicatorByNumberUrl(this.statisticsService.getNumberSource(value), value, this.stakeholder, this.numberIndicatorPaths.at(index).get('jsonPath').value);
if ((indicatorPath.chartObject && Object.keys(indicatorPath.parameters).indexOf("index_id") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_name") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_shortName") == -1)
|| (!indicatorPath.chartObject && indicatorPath.url.indexOf("index_id") == -1 && indicatorPath.url.indexOf("index_name") == -1 && (indicatorPath.url).indexOf("index_shortName") == -1)) {
// default profile
if (this.stakeholder.defaultId == null) {
this.urlParameterizedMessage = "This indicator couldn't be generated properly. Stakeholders based on this profile may not inherit the data correctly."
if(this.indicator.defaultId === null) {
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('url').valueChanges.subscribe(value => {
this.numberIndicatorPaths.at(index).get('result').setValue(null);
if (this.numberIndicatorPaths.at(index).get('url').valid) {
let indicatorPath: IndicatorPath = this.indicatorUtils.generateIndicatorByNumberUrl(this.statisticsService.getNumberSource(value), value, this.stakeholder, this.numberIndicatorPaths.at(index).get('jsonPath').value);
if ((indicatorPath.chartObject && Object.keys(indicatorPath.parameters).indexOf("index_id") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_name") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_shortName") == -1)
|| (!indicatorPath.chartObject && indicatorPath.url.indexOf("index_id") == -1 && indicatorPath.url.indexOf("index_name") == -1 && (indicatorPath.url).indexOf("index_shortName") == -1)) {
// default profile
if (this.stakeholder.defaultId == null) {
this.urlParameterizedMessage = "This indicator couldn't be generated properly. Stakeholders based on this profile may not inherit the data correctly."
} else {
this.urlParameterizedMessage = "This indicator couldn't be generated properly. Please make sure chart data is for the current stakeholder."
}
} else {
this.urlParameterizedMessage = "This indicator couldn't be generated properly. Please make sure chart data is for the current stakeholder."
this.urlParameterizedMessage = null;
}
if (this.indicator.indicatorPaths[index]) {
this.indicator.indicatorPaths[index] = indicatorPath;
} else {
this.indicator.indicatorPaths.push(indicatorPath);
}
if (indicatorPath.source) {
this.numberIndicatorPaths.at(index).get('source').setValue(indicatorPath.source);
}
} else {
this.urlParameterizedMessage = null;
}
})
);
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('jsonPath').valueChanges.subscribe(value => {
if (this.indicator.indicatorPaths[index]) {
this.indicator.indicatorPaths[index] = indicatorPath;
} else {
this.indicator.indicatorPaths.push(indicatorPath);
this.indicator.indicatorPaths[index].jsonPath = value;
}
if(indicatorPath.source) {
this.numberIndicatorPaths.at(index).get('source').setValue(indicatorPath.source);
this.numberIndicatorPaths.at(index).get('result').setValue(null);
})
);
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('source').valueChanges.subscribe(value => {
if (this.indicator.indicatorPaths[index]) {
this.indicator.indicatorPaths[index].source = value;
}
} else {
this.urlParameterizedMessage = null;
}
})
);
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('jsonPath').valueChanges.subscribe(value => {
if (this.indicator.indicatorPaths[index]) {
this.indicator.indicatorPaths[index].jsonPath = value;
}
this.numberIndicatorPaths.at(index).get('result').setValue(null);
})
);
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('source').valueChanges.subscribe(value => {
if (this.indicator.indicatorPaths[index]) {
this.indicator.indicatorPaths[index].source = value;
}
})
);
})
);
} else {
this.numberIndicatorPaths.at(index).get('url').disable();
this.numberIndicatorPaths.at(index).get('jsonPath').disable();
this.numberIndicatorPaths.at(index).get('source').disable();
}
}
}
@ -632,6 +645,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
_id: this.fb.control(this.indicator._id),
name: this.fb.control(this.indicator.name, Validators.required),
description: this.fb.control(this.indicator.description),
creationDate: this.fb.control(this.indicator.creationDate),
additionalDescription: this.fb.control(this.indicator.additionalDescription),
visibility: this.fb.control(this.indicator.visibility),
indicatorPaths: this.fb.array([], Validators.required),
@ -689,6 +703,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.chartIndicatorFb = this.fb.group({
_id: this.fb.control(this.indicator._id),
name: this.fb.control(this.indicator.name),
creationDate: this.fb.control(this.indicator.creationDate),
description: this.fb.control(this.indicator.description),
additionalDescription: this.fb.control(this.indicator.additionalDescription),
visibility: this.fb.control(this.indicator.visibility),

View File

@ -28,7 +28,8 @@ declare var UIkit;
templateUrl: './topic.component.html',
})
export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
public subscriptions: any[] = [];
private subscriptions: any[] = [];
private paramsSub: any;
public properties: EnvProperties;
public stakeholderUtils: StakeholderUtils = new StakeholderUtils();
public loading: boolean = true;
@ -79,7 +80,7 @@ export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
public ngOnInit() {
this.properties = properties;
let subscription: Subscription;
this.subscriptions.push(this.route.params.subscribe(params => {
this.paramsSub = this.route.params.subscribe(params => {
if (subscription) {
subscription.unsubscribe();
}
@ -107,8 +108,7 @@ export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
}
});
this.subscriptions.push(subscription);
}));
});
}
public ngOnDestroy() {
@ -117,9 +117,12 @@ export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
value.unsubscribe();
}
});
if(this.paramsSub instanceof Subscriber) {
this.paramsSub.unsubscribe();
}
}
canExit():boolean {
canExit(): boolean {
this.subscriptions.forEach(value => {
if (value instanceof Subscriber) {
value.unsubscribe();
@ -142,7 +145,7 @@ export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
this.saveSubCategory();
}
}
// public closeDeleteModal() {
// this.deleteModal.cancel();
// }
@ -163,6 +166,7 @@ export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
_id: this.fb.control(topic._id),
name: this.fb.control(topic.name, Validators.required),
description: this.fb.control(topic.description),
creationDate: this.fb.control(topic.creationDate),
alias: this.fb.control(topic.alias, [
Validators.required,
this.stakeholderUtils.aliasValidator(topics)
@ -184,7 +188,7 @@ export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
}));
}
public editTopicOpen(index= -1) {
public editTopicOpen(index = -1) {
this.index = index;
this.type = 'topic';
if (index === -1) {
@ -213,7 +217,7 @@ export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
}
}
public changeTopicStatus(index: number, visibility:Visibility) {
public changeTopicStatus(index: number, visibility: Visibility) {
this.type = 'topic';
let path = [
this.stakeholder._id,
@ -221,16 +225,16 @@ export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
];
this.changeStatus(this.stakeholder.topics[index], path, visibility);
}
public deleteTopicOpen( index=this.topicIndex, childrenAction: string = null) {
public deleteTopicOpen(index = this.topicIndex, childrenAction: string = null) {
this.type = 'topic';
this.index = index;
this.element = this.stakeholder.topics[this.index];
this.deleteOpen(childrenAction);
}
public deleteTopic(index=this.topicIndex) {
public deleteTopic(index = this.topicIndex) {
let path: string[] = [
this.stakeholder._id,
this.stakeholder.topics[index]._id
@ -256,6 +260,7 @@ export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
_id: this.fb.control(category._id),
name: this.fb.control(category.name, Validators.required),
description: this.fb.control(category.description),
creationDate: this.fb.control(category.creationDate),
alias: this.fb.control(category.alias, [
Validators.required,
this.stakeholderUtils.aliasValidator(categories)
@ -305,7 +310,7 @@ export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
}
}
public changeCategoryStatus(index: number, visibility:Visibility) {
public changeCategoryStatus(index: number, visibility: Visibility) {
this.index = index;
this.type = 'category';
let path = [
@ -315,7 +320,7 @@ export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
];
this.changeStatus(this.stakeholder.topics[this.topicIndex].categories[this.index], path, visibility);
}
public deleteCategoryOpen(index: number, childrenAction: string = null) {
this.type = 'category';
@ -342,6 +347,7 @@ export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
_id: this.fb.control(subCategory._id),
name: this.fb.control(subCategory.name, Validators.required),
description: this.fb.control(subCategory.description),
creationDate: this.fb.control(subCategory.creationDate),
alias: this.fb.control(subCategory.alias, [
Validators.required,
this.stakeholderUtils.aliasValidator(subCategories)
@ -395,20 +401,19 @@ export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
}
}
}
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);
}
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);
}
public deleteSubcategoryOpen(index, childrenAction: string = null) {
this.type = 'subcategory';
@ -450,12 +455,12 @@ export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
private deleteOpen(childrenAction: string = null) {
this.elementChildrenActionOnDelete = null;
if(childrenAction == "delete") {
if (childrenAction == "delete") {
this.elementChildrenActionOnDelete = childrenAction;
} else if(childrenAction == "disconnect") {
} else if (childrenAction == "disconnect") {
this.elementChildrenActionOnDelete = childrenAction;
}
this.deleteModal.alertTitle = 'Delete ' + this.type;
this.deleteModal.cancelButtonText = 'No';
this.deleteModal.okButtonText = 'Yes';
@ -467,7 +472,6 @@ export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
private save(message: string, path: string[], saveElement: any, callback: Function, redirect = false) {
this.subscriptions.push(this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, saveElement, path).subscribe(saveElement => {
callback(saveElement);
this.stakeholderService.setStakeholder(this.stakeholder);
UIkit.notification(message, {
status: 'success',
timeout: 3000,
@ -507,19 +511,18 @@ export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
});
}));
}
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);
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);
}
}
private changeStatus(element: Topic | Category | SubCategory, path: string[], visibility:Visibility) {
private changeStatus(element: Topic | Category | SubCategory, path: string[], visibility: Visibility) {
this.subscriptions.push(this.stakeholderService.changeVisibility(this.properties.monitorServiceAPIURL, path, visibility).subscribe(visibility => {
element.visibility = visibility;
this.stakeholderService.setStakeholder(this.stakeholder);
@ -547,26 +550,27 @@ export class TopicComponent implements OnInit, OnDestroy, IDeactivateComponent {
this.categoryIndex = categoryIndex;
this.subCategoryIndex = subcategoryIndex;
}
public getPluralTypeName(): string {
if(this.type == "topic") {
if (this.type == "topic") {
return "Topics";
} else if(this.type == "category") {
} else if (this.type == "category") {
return "Categories";
} else if(this.type == "subcategory") {
} else if (this.type == "subcategory") {
return "Subcategories";
} else {
return this.type;
}
}
public get isSmallScreen() {
return this.layoutService.isSmallScreen;
}
public get open() {
return this.layoutService.open;
}
public toggleOpen(event: MouseEvent) {
event.preventDefault();
this.layoutService.setOpen(!this.open);