[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:
parent
c3838e06b8
commit
aac3e3d55f
|
@ -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() {
|
||||
|
|
|
@ -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}
|
||||
}
|
||||
])
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -77,7 +77,6 @@ export class StakeholderUtils {
|
|||
category.subCategories = subTokeep;
|
||||
}
|
||||
}
|
||||
console.log(funder);
|
||||
return funder;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue