[MonitorDashboard]: Sidebar: add activeItem and subItem to check which element is active
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@57805 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
2feb26dc63
commit
bcdb3e4708
|
@ -1,9 +1,5 @@
|
|||
<aside id="sidebar_main">
|
||||
<div *ngIf= "showHeader" class="sidebar_main_header">
|
||||
<div *ngIf="name" class="uk-padding-small">
|
||||
<div class="uk-text-bold">{{name}}</div>
|
||||
<div>Monitor Dashboard</div>
|
||||
</div>
|
||||
<div *ngIf="header" class="uk-padding-small">
|
||||
<img *ngIf="header.logoUrl" [src]="header.logoUrl">
|
||||
<div class="uk-text-bold uk-margin-top">{{header.name}}</div>
|
||||
|
@ -13,11 +9,11 @@
|
|||
<div class="menu_section uk-margin-top">
|
||||
<ul>
|
||||
<ng-template ngFor [ngForOf]="items" let-item let-i="index">
|
||||
<li [class.current_section]="isTheActiveMenu(item.route)"
|
||||
<li [class.current_section]="isTheActiveMenuItem(item)"
|
||||
[class.act_section]="item.open"
|
||||
[title]="item.name"
|
||||
[class.submenu_trigger]="item.items.length > 1">
|
||||
<a *ngIf="item.items.length <= 1 && item.route" [routerLink]="item.route">
|
||||
<a *ngIf="item.items.length <= 1 && item.route" [routerLink]="!isTheActiveMenuItem(item)?item.route:null">
|
||||
<span *ngIf="item.icon" class="menu_icon"><i class="material-icons">{{item.icon}}</i></span>
|
||||
<span class="menu_title">{{item.name}}</span>
|
||||
</a>
|
||||
|
@ -28,8 +24,8 @@
|
|||
</a>
|
||||
<ul [style.display]="(item.open?'block':'none')">
|
||||
<ng-template ngFor [ngForOf]="item.items" let-subItem let-j="index">
|
||||
<li *ngIf="subItem.route" [class.act_item]="isTheActiveMenu(subItem.route)">
|
||||
<a [routerLink]="subItem.route">
|
||||
<li *ngIf="subItem.route" [class.act_item]="isTheActiveMenuItem(subItem, true)">
|
||||
<a [routerLink]="!isTheActiveMenuItem(subItem, true)?subItem.route:null">
|
||||
<span *ngIf="subItem.icon" class="menu_icon"><i class="material-icons">{{subItem.icon}}</i></span>
|
||||
<span class="menu_title">{{subItem.name}}</span>
|
||||
</a>
|
||||
|
|
|
@ -8,10 +8,10 @@ import {Header, Item} from "../../../utils/entities/sidebar";
|
|||
})
|
||||
export class SideBarComponent implements OnInit {
|
||||
@Input() items: Item[] = [];
|
||||
// TODO remove it
|
||||
@Input() name = null;
|
||||
@Input() header: Header = null;
|
||||
@Input() showHeader: boolean = true;
|
||||
@Input() activeItem: string = '';
|
||||
@Input() activeSubItem: string = '';
|
||||
|
||||
constructor(private router: Router) {
|
||||
}
|
||||
|
@ -19,11 +19,9 @@ export class SideBarComponent implements OnInit {
|
|||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
private getCurrentRoute(): string {
|
||||
return this.router.url.split('?')[0];
|
||||
}
|
||||
|
||||
isTheActiveMenu(route: string): boolean {
|
||||
return this.getCurrentRoute().indexOf(route) !== -1;
|
||||
isTheActiveMenuItem(item: Item, subItem = false): boolean {
|
||||
return (!subItem && this.activeItem === item.id) ||
|
||||
(subItem && this.activeSubItem === item.id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,8 +72,9 @@
|
|||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
<dashboard-sidebar *ngIf="sideBar && stakeholder" [items]="sideBar.items" [name]="stakeholder.index_name"
|
||||
[showHeader]=false
|
||||
<dashboard-sidebar *ngIf="sideBar && stakeholder" [items]="sideBar.items"
|
||||
[activeItem]="activeCategory?activeCategory.alias:null"
|
||||
[activeSubItem]="activeSubCategory?activeSubCategory.alias:null" [showHeader]=false
|
||||
></dashboard-sidebar>
|
||||
<div *ngIf="activeSubCategory"
|
||||
id="page_content" click-outside-or-esc targetId="page_content" [escClose]="false"
|
||||
|
|
|
@ -87,25 +87,21 @@ export class MonitorComponent implements OnInit, OnDestroy {
|
|||
if (params['stakeholder'] == "fwf") {
|
||||
stakeholder = new Stakeholder("fwf", "funder", "fwf_________::FWF", "Austrian Science Fund (FWF)", "FWF",
|
||||
false, "fwf", true, true, null);
|
||||
stakeholder = this.stakeholderUtils.
|
||||
createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
|
||||
stakeholder = this.stakeholderUtils.createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
|
||||
stakeholder.logoUrl = "./assets/fwf.png";
|
||||
} else if (params['stakeholder'] == "arc") {
|
||||
stakeholder = new Stakeholder("arc", "funder", "arc_________::ARC",
|
||||
"Australian Research Council (ARC)", "ARC",
|
||||
false, "arc", true, true, null);
|
||||
stakeholder = this.stakeholderUtils.
|
||||
createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
|
||||
stakeholder = this.stakeholderUtils.createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
|
||||
stakeholder.logoUrl = "./assets/arc1.gif";
|
||||
} else {
|
||||
stakeholder = new Stakeholder("ec", "funder", "ec__________::EC",
|
||||
"European Commission", "EC",
|
||||
false, "ec", true, true, null);
|
||||
stakeholder = this.stakeholderUtils.
|
||||
createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
|
||||
stakeholder = this.stakeholderUtils.createFunderFromDefaultProfile(stakeholder, StakeholderCreator.createFunderDefaultProfile().topics);
|
||||
stakeholder.logoUrl = "./assets/ec.png";
|
||||
}
|
||||
|
||||
if (stakeholder) {
|
||||
this.stakeholder = stakeholder;
|
||||
this.seoService.createLinkForCanonicalURL(url, false);
|
||||
|
@ -160,15 +156,24 @@ export class MonitorComponent implements OnInit, OnDestroy {
|
|||
|
||||
private setView(params: Params) {
|
||||
if (params && params['topic']) {
|
||||
this.activeTopic = this.stakeholder.topics.filter(topic => topic.alias === decodeURIComponent(params['topic']))[0];
|
||||
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.filter(category =>
|
||||
(category.alias === params['category']) && category.isPublic && category.isActive)[0];
|
||||
this.activeCategory = this.activeTopic.categories.find(category =>
|
||||
(category.alias === params['category']) && category.isPublic && category.isActive);
|
||||
} else {
|
||||
let category: Category = this.activeTopic.categories[0];
|
||||
if(category) {
|
||||
this.navigateTo(this.stakeholder.alias, this.activeTopic.alias, category.alias);
|
||||
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();
|
||||
}
|
||||
|
@ -176,30 +181,37 @@ export class MonitorComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
if (this.activeCategory) {
|
||||
if (params['subCategory']) {
|
||||
this.activeSubCategory = this.activeCategory.subCategories.filter(subCategory =>
|
||||
(subCategory.alias === params['subCategory'] && subCategory.isPublic && subCategory.isActive))[0];
|
||||
this.activeSubCategory = this.activeCategory.subCategories.find(subCategory =>
|
||||
(subCategory.alias === params['subCategory'] && subCategory.isPublic && subCategory.isActive));
|
||||
} else {
|
||||
this.activeSubCategory = this.activeCategory.subCategories.filter(subCategory =>
|
||||
!subCategory.alias && subCategory.isPublic && subCategory.isActive)[0];
|
||||
this.activeSubCategory = this.activeCategory.subCategories.find(subCategory =>
|
||||
subCategory.isPublic && subCategory.isActive);
|
||||
}
|
||||
if (this.activeSubCategory) {
|
||||
this.setSideBar();
|
||||
this.setIndicators();
|
||||
return;
|
||||
} else {
|
||||
let subCategory: SubCategory = this.activeCategory.subCategories.filter(subCategory =>
|
||||
subCategory.isPublic && subCategory.isActive)[0];
|
||||
this.navigateTo(this.stakeholder.alias, this.activeTopic.alias, this.activeCategory.alias, subCategory.alias);
|
||||
return;
|
||||
this.navigateToError();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.navigateToError();
|
||||
} else {
|
||||
let topic: Topic = this.stakeholder.topics[0];
|
||||
let category: Category = topic.categories.filter(category => category.isPublic && category.isActive)[0];
|
||||
if(topic && category) {
|
||||
this.navigateTo(this.stakeholder.alias, topic.alias, category.alias);
|
||||
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();
|
||||
} else {
|
||||
this.navigateToError();
|
||||
}
|
||||
} else {
|
||||
this.navigateToError();
|
||||
}
|
||||
} else {
|
||||
this.navigateToError();
|
||||
}
|
||||
|
@ -212,14 +224,14 @@ export class MonitorComponent implements OnInit, OnDestroy {
|
|||
if (category.isPublic && category.isActive) {
|
||||
let subItems: Item[] = [];
|
||||
category.subCategories.forEach(subCategory => {
|
||||
if (subCategory.alias != null && subCategory.isPublic && subCategory.isActive) {
|
||||
subItems.push(new Item(subCategory.name, (
|
||||
if (subCategory.isPublic && subCategory.isActive) {
|
||||
subItems.push(new Item(subCategory.alias, subCategory.name, (
|
||||
'/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias + '/' + subCategory.alias),
|
||||
null, null, false));
|
||||
}
|
||||
});
|
||||
const open = this.activeCategory.alias === category.alias;
|
||||
items.push(new Item(category.name, (
|
||||
items.push(new Item(category.alias, category.name, (
|
||||
'/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias),
|
||||
subItems, null, open));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import {ElementRef, TemplateRef} from "@angular/core";
|
||||
|
||||
export class Header {
|
||||
name: string;
|
||||
dashboard: string;
|
||||
|
@ -13,20 +11,20 @@ export class Header {
|
|||
}
|
||||
|
||||
export class Item {
|
||||
id: string;
|
||||
name: string;
|
||||
route: string;
|
||||
items: Item[];
|
||||
icon: string;
|
||||
open: boolean;
|
||||
action: TemplateRef<ElementRef>;
|
||||
|
||||
constructor(name: string, route: string, items: Item[], icon, open: boolean, action: TemplateRef<ElementRef> = null) {
|
||||
constructor(id: string, name: string, route: string, items: Item[], icon, open: boolean) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.route = route;
|
||||
this.items = items;
|
||||
this.icon = icon;
|
||||
this.open = open;
|
||||
this.action = action;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue