[MonitorDashboard]: Fix a bug with header and sidebar. Save sidebar open status per topic

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@57814 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
Konstantinos Triantafyllou 2019-12-04 18:25:36 +00:00
parent c3838e06b8
commit aac3e3d55f
4 changed files with 63 additions and 45 deletions

View File

@ -32,6 +32,14 @@ export class AppComponent implements OnInit, OnDestroy {
} }
ngOnInit() { 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() this.propertiesService.loadEnvironment()
.then(properties => { .then(properties => {
this.properties = properties; this.properties = properties;
@ -64,14 +72,6 @@ export class AppComponent implements OnInit, OnDestroy {
console.log(error); 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() { public ngOnDestroy() {

View File

@ -3,6 +3,7 @@ import {RouterModule} from '@angular/router';
import {FreeGuard} from '../openaireLibrary/login/freeGuard.guard'; import {FreeGuard} from '../openaireLibrary/login/freeGuard.guard';
import {PreviousRouteRecorder} from '../openaireLibrary/utils/piwik/previousRouteRecorder.guard'; import {PreviousRouteRecorder} from '../openaireLibrary/utils/piwik/previousRouteRecorder.guard';
import {MonitorComponent} from "./monitor.component"; import {MonitorComponent} from "./monitor.component";
import {CanExitGuard} from "../openaireLibrary/utils/can-exit.guard";
@NgModule({ @NgModule({
imports: [ imports: [
@ -12,28 +13,28 @@ import {MonitorComponent} from "./monitor.component";
path: ':stakeholder', path: ':stakeholder',
component: MonitorComponent, component: MonitorComponent,
canActivate: [FreeGuard], canActivate: [FreeGuard],
canDeactivate: [PreviousRouteRecorder], canDeactivate: [PreviousRouteRecorder, CanExitGuard],
data: {hasHeader: false} data: {hasHeader: false}
}, },
{ {
path: ':stakeholder/:topic', path: ':stakeholder/:topic',
component: MonitorComponent, component: MonitorComponent,
canActivate: [FreeGuard], canActivate: [FreeGuard],
canDeactivate: [PreviousRouteRecorder], canDeactivate: [PreviousRouteRecorder, CanExitGuard],
data: {hasHeader: false} data: {hasHeader: false}
}, },
{ {
path: ':stakeholder/:topic/:category', path: ':stakeholder/:topic/:category',
component: MonitorComponent, component: MonitorComponent,
canActivate: [FreeGuard], canActivate: [FreeGuard],
canDeactivate: [PreviousRouteRecorder], canDeactivate: [PreviousRouteRecorder, CanExitGuard],
data: {hasHeader: false} data: {hasHeader: false}
}, },
{ {
path: ':stakeholder/:topic/:category/:subCategory', path: ':stakeholder/:topic/:category/:subCategory',
component: MonitorComponent, component: MonitorComponent,
canActivate: [FreeGuard], canActivate: [FreeGuard],
canDeactivate: [PreviousRouteRecorder], canDeactivate: [PreviousRouteRecorder, CanExitGuard],
data: {hasHeader: false} data: {hasHeader: false}
} }
]) ])

View File

@ -18,12 +18,17 @@ import {IndicatorUtils, StakeholderUtils} from "../utils/indicator-utils";
import {StakeholderCreator} from "../utils/entities/stakeholderCreator"; import {StakeholderCreator} from "../utils/entities/stakeholderCreator";
import {LayoutService} from "../library/sharedComponents/sidebar/layout.service"; import {LayoutService} from "../library/sharedComponents/sidebar/layout.service";
import {FormBuilder, FormControl} from "@angular/forms"; import {FormBuilder, FormControl} from "@angular/forms";
import {IDeactivateComponent} from "../openaireLibrary/utils/can-exit.guard";
@Component({ @Component({
selector: 'monitor', selector: 'monitor',
templateUrl: 'monitor.component.html', 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 piwiksub: any;
public pageContents = null; public pageContents = null;
public divContents = null; public divContents = null;
@ -68,11 +73,9 @@ export class MonitorComponent implements OnInit, OnDestroy {
public ngOnInit() { public ngOnInit() {
this.keyword = this._fb.control(''); this.keyword = this._fb.control('');
this.keyword.valueChanges.subscribe(value => { this.keyword.valueChanges.subscribe(value => {
console.log("KEyword Changed!"); console.log("Keyword Changed!");
//TODO do a real action //TODO do a real action
}); });
this.layoutService.setHasSidebar(false);
this.layoutService.setHasHeader(false);
this.route.data this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => { .subscribe((data: { envSpecific: EnvProperties }) => {
this.route.params.subscribe(params => { 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() { public get open() {
return this.layoutService.open; return this.layoutService.open;
} }
@ -156,15 +173,13 @@ export class MonitorComponent implements OnInit, OnDestroy {
private setView(params: Params) { private setView(params: Params) {
if (params && params['topic']) { if (params && params['topic']) {
this.activeTopic = this.stakeholder.topics. this.activeTopic = this.stakeholder.topics.find(topic => topic.alias === decodeURIComponent(params['topic']) && topic.isPublic && topic.isActive);
find(topic => topic.alias === decodeURIComponent(params['topic']) && topic.isPublic && topic.isActive);
if (this.activeTopic) { if (this.activeTopic) {
if (params['category']) { if (params['category']) {
this.activeCategory = this.activeTopic.categories.find(category => this.activeCategory = this.activeTopic.categories.find(category =>
(category.alias === params['category']) && category.isPublic && category.isActive); (category.alias === params['category']) && category.isPublic && category.isActive);
} else { } else {
this.activeCategory = this.activeTopic.categories. this.activeCategory = this.activeTopic.categories.find(category => category.isPublic && category.isActive);
find(category => category.isPublic && category.isActive);
if (this.activeCategory) { if (this.activeCategory) {
this.activeSubCategory = this.activeCategory.subCategories.find(subCategory => this.activeSubCategory = this.activeCategory.subCategories.find(subCategory =>
subCategory.isPublic && subCategory.isActive); subCategory.isPublic && subCategory.isActive);
@ -220,7 +235,7 @@ export class MonitorComponent implements OnInit, OnDestroy {
private setSideBar() { private setSideBar() {
let items: Item[] = []; let items: Item[] = [];
this.activeTopic.categories.forEach(category => { this.activeTopic.categories.forEach((category, index) => {
if (category.isPublic && category.isActive) { if (category.isPublic && category.isActive) {
let subItems: Item[] = []; let subItems: Item[] = [];
category.subCategories.forEach(subCategory => { category.subCategories.forEach(subCategory => {
@ -230,7 +245,10 @@ export class MonitorComponent implements OnInit, OnDestroy {
null, null, false)); 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, ( items.push(new Item(category.alias, category.name, (
'/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias), '/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias),
subItems, null, open)); subItems, null, open));

View File

@ -77,7 +77,6 @@ export class StakeholderUtils {
category.subCategories = subTokeep; category.subCategories = subTokeep;
} }
} }
console.log(funder);
return funder; return funder;
} }
} }