diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 99de85a..21bde89 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -32,6 +32,14 @@ export class AppComponent implements OnInit, OnDestroy { } ngOnInit() { + this.subscriptions.push(this.layoutService.hasSidebar.subscribe(hasSidebar => { + this.hasSidebar = hasSidebar; + this.cdr.detectChanges(); + })); + this.subscriptions.push(this.layoutService.hasHeader.subscribe(hasHeader => { + this.hasHeader = hasHeader; + this.cdr.detectChanges(); + })); this.propertiesService.loadEnvironment() .then(properties => { this.properties = properties; @@ -64,14 +72,6 @@ export class AppComponent implements OnInit, OnDestroy { console.log(error); }); }); - this.subscriptions.push(this.layoutService.hasSidebar.subscribe(hasSidebar => { - this.hasSidebar = hasSidebar; - this.cdr.detectChanges(); - })); - this.subscriptions.push(this.layoutService.hasHeader.subscribe(hasHeader => { - this.hasHeader = hasHeader; - this.cdr.detectChanges(); - })); } public ngOnDestroy() { diff --git a/src/app/monitor/monitor-routing.module.ts b/src/app/monitor/monitor-routing.module.ts index d5a8a2f..91677fb 100644 --- a/src/app/monitor/monitor-routing.module.ts +++ b/src/app/monitor/monitor-routing.module.ts @@ -3,6 +3,7 @@ import {RouterModule} from '@angular/router'; import {FreeGuard} from '../openaireLibrary/login/freeGuard.guard'; import {PreviousRouteRecorder} from '../openaireLibrary/utils/piwik/previousRouteRecorder.guard'; import {MonitorComponent} from "./monitor.component"; +import {CanExitGuard} from "../openaireLibrary/utils/can-exit.guard"; @NgModule({ imports: [ @@ -12,28 +13,28 @@ import {MonitorComponent} from "./monitor.component"; path: ':stakeholder', component: MonitorComponent, canActivate: [FreeGuard], - canDeactivate: [PreviousRouteRecorder], + canDeactivate: [PreviousRouteRecorder, CanExitGuard], data: {hasHeader: false} }, { path: ':stakeholder/:topic', component: MonitorComponent, canActivate: [FreeGuard], - canDeactivate: [PreviousRouteRecorder], + canDeactivate: [PreviousRouteRecorder, CanExitGuard], data: {hasHeader: false} }, { path: ':stakeholder/:topic/:category', component: MonitorComponent, canActivate: [FreeGuard], - canDeactivate: [PreviousRouteRecorder], + canDeactivate: [PreviousRouteRecorder, CanExitGuard], data: {hasHeader: false} }, { path: ':stakeholder/:topic/:category/:subCategory', component: MonitorComponent, canActivate: [FreeGuard], - canDeactivate: [PreviousRouteRecorder], + canDeactivate: [PreviousRouteRecorder, CanExitGuard], data: {hasHeader: false} } ]) diff --git a/src/app/monitor/monitor.component.ts b/src/app/monitor/monitor.component.ts index afb75e4..a7f08eb 100644 --- a/src/app/monitor/monitor.component.ts +++ b/src/app/monitor/monitor.component.ts @@ -18,12 +18,17 @@ import {IndicatorUtils, StakeholderUtils} from "../utils/indicator-utils"; import {StakeholderCreator} from "../utils/entities/stakeholderCreator"; import {LayoutService} from "../library/sharedComponents/sidebar/layout.service"; import {FormBuilder, FormControl} from "@angular/forms"; +import {IDeactivateComponent} from "../openaireLibrary/utils/can-exit.guard"; @Component({ selector: 'monitor', templateUrl: 'monitor.component.html', }) -export class MonitorComponent implements OnInit, OnDestroy { +export class MonitorComponent implements OnInit, OnDestroy, IDeactivateComponent { + private static sidebarStatus: { + id; + status; + }; public piwiksub: any; public pageContents = null; public divContents = null; @@ -68,11 +73,9 @@ export class MonitorComponent implements OnInit, OnDestroy { public ngOnInit() { this.keyword = this._fb.control(''); this.keyword.valueChanges.subscribe(value => { - console.log("KEyword Changed!"); + console.log("Keyword Changed!"); //TODO do a real action }); - this.layoutService.setHasSidebar(false); - this.layoutService.setHasHeader(false); this.route.data .subscribe((data: { envSpecific: EnvProperties }) => { this.route.params.subscribe(params => { @@ -130,6 +133,20 @@ export class MonitorComponent implements OnInit, OnDestroy { }); } + canExit() { + if (this.sideBar) { + let status = []; + this.sideBar.items.forEach(item => { + status.push(item.open); + }); + MonitorComponent.sidebarStatus = { + id: this.activeTopic.alias, + status: status + }; + } + return true; + } + public get open() { return this.layoutService.open; } @@ -156,24 +173,22 @@ export class MonitorComponent implements OnInit, OnDestroy { private setView(params: Params) { if (params && params['topic']) { - this.activeTopic = this.stakeholder.topics. - find(topic => topic.alias === decodeURIComponent(params['topic']) && topic.isPublic && topic.isActive); + this.activeTopic = this.stakeholder.topics.find(topic => topic.alias === decodeURIComponent(params['topic']) && topic.isPublic && topic.isActive); if (this.activeTopic) { if (params['category']) { this.activeCategory = this.activeTopic.categories.find(category => (category.alias === params['category']) && category.isPublic && category.isActive); } else { - this.activeCategory = this.activeTopic.categories. - find(category => category.isPublic && category.isActive); + this.activeCategory = this.activeTopic.categories.find(category => category.isPublic && category.isActive); if (this.activeCategory) { - this.activeSubCategory = this.activeCategory.subCategories.find(subCategory => - subCategory.isPublic && subCategory.isActive); - if (this.activeSubCategory) { - this.setSideBar(); - this.setIndicators(); - } else { - this.navigateToError(); - } + this.activeSubCategory = this.activeCategory.subCategories.find(subCategory => + subCategory.isPublic && subCategory.isActive); + if (this.activeSubCategory) { + this.setSideBar(); + this.setIndicators(); + } else { + this.navigateToError(); + } } else { this.navigateToError(); } @@ -191,36 +206,36 @@ export class MonitorComponent implements OnInit, OnDestroy { this.setSideBar(); this.setIndicators(); } else { - this.navigateToError(); + this.navigateToError(); } - return; + return; } } this.navigateToError(); } else { this.activeTopic = this.stakeholder.topics.find(topic => topic.isPublic && topic.isActive); - if(this.activeTopic) { - this.activeCategory = this.activeTopic.categories.find(category => category.isPublic && category.isActive); - if (this.activeCategory) { - this.activeSubCategory = this.activeCategory.subCategories.find(subCategory => subCategory.isPublic && subCategory.isActive); - if (this.activeSubCategory) { - this.setSideBar(); - this.setIndicators(); + if (this.activeTopic) { + this.activeCategory = this.activeTopic.categories.find(category => category.isPublic && category.isActive); + if (this.activeCategory) { + this.activeSubCategory = this.activeCategory.subCategories.find(subCategory => subCategory.isPublic && subCategory.isActive); + if (this.activeSubCategory) { + this.setSideBar(); + this.setIndicators(); + } else { + this.navigateToError(); + } } else { - this.navigateToError(); + this.navigateToError(); } - } else { - this.navigateToError(); - } } else { - this.navigateToError(); + this.navigateToError(); } } } private setSideBar() { let items: Item[] = []; - this.activeTopic.categories.forEach(category => { + this.activeTopic.categories.forEach((category, index) => { if (category.isPublic && category.isActive) { let subItems: Item[] = []; category.subCategories.forEach(subCategory => { @@ -230,7 +245,10 @@ export class MonitorComponent implements OnInit, OnDestroy { null, null, false)); } }); - const open = this.activeCategory.alias === category.alias; + let open = this.activeCategory.alias === category.alias; + if (MonitorComponent.sidebarStatus && MonitorComponent.sidebarStatus.id === this.activeTopic.alias) { + open = MonitorComponent.sidebarStatus.status[index]; + } items.push(new Item(category.alias, category.name, ( '/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias), subItems, null, open)); diff --git a/src/app/utils/indicator-utils.ts b/src/app/utils/indicator-utils.ts index 642ffff..583b881 100644 --- a/src/app/utils/indicator-utils.ts +++ b/src/app/utils/indicator-utils.ts @@ -77,7 +77,6 @@ export class StakeholderUtils { category.subCategories = subTokeep; } } - console.log(funder); return funder; } }