From b2253b7d5a53a5ac7edf54d737518eb9ec886451 Mon Sep 17 00:00:00 2001 From: Konstantinos Triantafyllou Date: Wed, 13 May 2020 08:46:22 +0000 Subject: [PATCH] [Monitor Dashboard | Trunk]: Fix a bug when a new empty topic has been created git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@58689 d315682c-612b-4755-9ff5-7f18f6832af3 --- src/app/app.component.ts | 8 ++--- src/app/stakeholder/stakeholder.component.ts | 1 + src/app/topic/indicators.component.ts | 38 ++++++++++++-------- src/app/topic/topic.component.html | 2 +- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index f6f6646..cf98d00 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -123,7 +123,7 @@ export class AppComponent implements OnInit, OnDestroy { if (this.adminMenuItems.length == 0) { //nstructor(id: string, name: string, route: string, items: Item[], icon, open: boolean) { this.adminMenuItems.push(new MenuItem("stakeholders", "Manage Stakeholders", "", "/admin", false, [], [], {})); - let adminOptions = new MenuItem("adminOptions", "Admin Options", "", "", false, [], [], {}) + /*let adminOptions = new MenuItem("adminOptions", "Admin Options", "", "", false, [], [], {}) adminOptions.items.push(new MenuItem("pages", "Pages", "", "/pages", false, [], [], {})); adminOptions.items.push(new MenuItem("portals", "Portals", "", "/portals", false, [], [], {})); adminOptions.items.push(new MenuItem("entities", "Entities", "", "/entities", false, [], [], {})); @@ -134,11 +134,7 @@ export class AppComponent implements OnInit, OnDestroy { monitorOptions.items.push(new MenuItem("entities", "Entities", "", "/entities", false, [], [], {communityId: 'openaire'})); monitorOptions.items.push(new MenuItem("classes", "Class help texts", "", "/classContents", false, [], [], {communityId: 'openaire'})); monitorOptions.items.push(new MenuItem("helptexts", "Help texts", "", "/helptexts", false, [], [], {communityId: 'openaire'})); - this.adminMenuItems.push(monitorOptions); - // this.adminMenuItems.push(new Item("pages", "Pages", "/pages", [], null, false)); - // this.adminMenuItems.push(new Item("monitor", "Monitor", "/portals", [], null, false)); - // this.adminMenuItems.push(new Item("entities", "Entities", "/entities", [], null, false)); - // this.adminMenuItems.push(new Item("helptexts", "Help texts", "/helptexts?communityId=openaire", [], null, false)); + this.adminMenuItems.push(monitorOptions);*/ } } } diff --git a/src/app/stakeholder/stakeholder.component.ts b/src/app/stakeholder/stakeholder.component.ts index b78a101..e39154e 100644 --- a/src/app/stakeholder/stakeholder.component.ts +++ b/src/app/stakeholder/stakeholder.component.ts @@ -184,6 +184,7 @@ export class StakeholderComponent implements OnInit, OnDestroy, IDeactivateCompo ]; this.stakeholderService.deleteElement(this.properties.monitorServiceAPIURL, path).subscribe(() => { this.stakeholder.topics.splice(this.index, 1); + this.index = -1; UIkit.notification('Topic has been successfully deleted', { status: 'success', timeout: 3000, diff --git a/src/app/topic/indicators.component.ts b/src/app/topic/indicators.component.ts index eccab99..6f732b0 100644 --- a/src/app/topic/indicators.component.ts +++ b/src/app/topic/indicators.component.ts @@ -111,9 +111,11 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV this.filterCharts(); this.filterNumbers(); } - this.preview = '/' + this.stakeholder.alias + '/' + this.stakeholder.topics[this.topicIndex].alias + - '/' + this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].alias + - '/' + this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].alias; + if (this.topicIndex && this.categoryIndex && this.subcategoryIndex) { + this.preview = '/' + this.stakeholder.alias + '/' + this.stakeholder.topics[this.topicIndex].alias + + '/' + this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].alias + + '/' + this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].alias; + } } initReorder() { @@ -291,7 +293,11 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV } get charts(): Section[] { - return this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].charts; + if (this.topicIndex && this.categoryIndex && this.subcategoryIndex) { + return this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].charts; + } else { + return []; + } } set charts(sections: Section[]) { @@ -299,7 +305,11 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV } get numbers(): Section[] { - return this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].numbers; + if (this.topicIndex && this.categoryIndex && this.subcategoryIndex) { + return this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].numbers; + } else { + return []; + } } set numbers(sections: Section[]) { @@ -506,7 +516,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV deleteIndicatorOpen(section: Section, indicatorId: string, type: string = 'chart') { this.section = section; - if(type === 'chart') { + if (type === 'chart') { this.index = this.charts.find(value => value._id == section._id).indicators.findIndex(value => value._id == indicatorId); } else { this.index = this.numbers.find(value => value._id == section._id).indicators.findIndex(value => value._id == indicatorId); @@ -566,7 +576,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV }); } - saveSection(section : Section, index: number, type: IndicatorType = "chart") { + saveSection(section: Section, index: number, type: IndicatorType = "chart") { let path = [ this.stakeholder._id, this.stakeholder.topics[this.topicIndex]._id, @@ -574,7 +584,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]._id ]; this.stakeholderService.saveSection(this.properties.monitorServiceAPIURL, section, path, index).subscribe(section => { - if(type === 'chart') { + if (type === 'chart') { this.charts[index] = section; this.filterCharts(); } else { @@ -605,15 +615,15 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]._id ]; this.stakeholderService.saveSection(this.properties.monitorServiceAPIURL, this.section, path, index).subscribe(section => { - if(type === 'chart') { - if(index !== -1) { + if (type === 'chart') { + if (index !== -1) { this.charts.splice(index, 0, section); } else { this.charts.push(section); } this.filterCharts(); } else { - if(index !== -1) { + if (index !== -1) { this.numbers.splice(index, 0, section); } else { this.numbers.push(section); @@ -644,7 +654,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV this.deleteChartSectionModal.open(); } - deleteSection(type: IndicatorType = 'chart') { + deleteSection(type: IndicatorType = 'chart') { let path = [ this.stakeholder._id, this.stakeholder.topics[this.topicIndex]._id, @@ -652,8 +662,8 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]._id, this.section._id ]; - this.stakeholderService.deleteElement(this.properties.monitorServiceAPIURL, path).subscribe(()=> { - if(type === "chart") { + this.stakeholderService.deleteElement(this.properties.monitorServiceAPIURL, path).subscribe(() => { + if (type === "chart") { this.charts.splice(this.index, 1); this.filterCharts(); } else { diff --git a/src/app/topic/topic.component.html b/src/app/topic/topic.component.html index 1bd3655..2cd991a 100644 --- a/src/app/topic/topic.component.html +++ b/src/app/topic/topic.component.html @@ -5,7 +5,7 @@ alt="BETA"> -