Commit 802f81a1 by Tuukka Kivilahti

now menu works

1 parent 16d94af2
Pipeline #55 failed
in 0 seconds
...@@ -10,10 +10,8 @@ const APP_ROUTES: Routes = [ ...@@ -10,10 +10,8 @@ const APP_ROUTES: Routes = [
/*{ path: 'viplist', loadChildren: 'app/modules/viplist/viplist.module#ViplistModule' },*/ /*{ path: 'viplist', loadChildren: 'app/modules/viplist/viplist.module#ViplistModule' },*/
{ path: 'viplist', component: InfoViplistPageComponent }, { path: 'viplist', component: InfoViplistPageComponent },
{ path: 'old', loadChildren: 'app/modules/old-moya/old-moya.module#OldMoyaModule' }, { path: 'old', loadChildren: 'app/modules/old-moya/old-moya.module#OldMoyaModule' },
{ path: 'user', pathMatch: 'full', component: FrontpageComponent }, { path: 'index', component: FrontpageComponent },
{ path: 'info', pathMatch: 'full', component: FrontpageComponent }, { path: '', pathMatch: 'full' , redirectTo: '/index', }
{ path: 'admin', pathMatch: 'full', component: FrontpageComponent },
{ path: '', pathMatch: 'full', component: FrontpageComponent }
]; ];
@NgModule({ @NgModule({
......
...@@ -27,6 +27,11 @@ export class MENU { ...@@ -27,6 +27,11 @@ export class MENU {
static USER: MenuGroup[] = [ static USER: MenuGroup[] = [
{ {
'name': '',
'items': [
{ 'path': '/index', 'name': 'Frontpage' },
]},
{
'name': 'Event', 'name': 'Event',
'items': [ 'items': [
{ 'path': '/old/user', 'name': 'Poll', 'params': {p: 'poll/index.jsf'} }, { 'path': '/old/user', 'name': 'Poll', 'params': {p: 'poll/index.jsf'} },
......
import {Component, OnInit} from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {MenuGroup} from '../models/menu-group.model'; import {MenuGroup} from '../models/menu-group.model';
import {MENU} from "../defines/menu"; import {MENU} from "../defines/menu";
import {ActivatedRoute, UrlSegment} from "@angular/router"; import {ActivatedRoute, Router, RouterEvent, UrlSegment} from "@angular/router";
@Component({ @Component({
selector: 'left-menu', selector: 'left-menu',
...@@ -16,13 +16,14 @@ export class LeftMenuComponent implements OnInit { ...@@ -16,13 +16,14 @@ export class LeftMenuComponent implements OnInit {
searchPath(path : string, menu : MenuGroup[]): boolean { searchPath(path : string, menu : MenuGroup[]): boolean {
menu.forEach(group => { for(let i in menu) {
group.items.forEach(item => { for(let n in menu[i].items) {
let item = menu[i].items[n];
if(path.startsWith(item.path)) { if(path.startsWith(item.path)) {
return true; return true;
} }
}); }
}); }
return false; return false;
} }
...@@ -30,29 +31,29 @@ export class LeftMenuComponent implements OnInit { ...@@ -30,29 +31,29 @@ export class LeftMenuComponent implements OnInit {
constructor(private route: ActivatedRoute) { constructor(private route: Router) {
this.route.url.subscribe(segments => { route.events.filter(e => e instanceof RouterEvent).subscribe(event => {
let path : string = segments.map(segment => segment.path).join("/");
console.log(path); const revent = event as RouterEvent;
if(this.searchPath(path, MENU.USER)) { if(this.searchPath(revent.url, MENU.USER)) {
this.activateUser(); this.activateUser();
return; return;
} }
if(this.searchPath(path, MENU.INFO)) { if(this.searchPath(revent.url, MENU.INFO)) {
this.activateInfo(); this.activateInfo();
return; return;
} }
if(this.searchPath(path, MENU.ADMIN)) { if(this.searchPath(revent.url, MENU.ADMIN)) {
this.activateAdmin(); this.activateAdmin();
return; return;
} }
}); });
} }
...@@ -63,22 +64,17 @@ export class LeftMenuComponent implements OnInit { ...@@ -63,22 +64,17 @@ export class LeftMenuComponent implements OnInit {
activateInfo() { activateInfo() {
console.log("activating info");
this.menu = MENU.INFO; this.menu = MENU.INFO;
this.styleClass = "infoMenu"; this.styleClass = "infoMenu";
} }
activateUser() { activateUser() {
console.log("activating user");
this.menu = MENU.USER; this.menu = MENU.USER;
this.styleClass = "userMenu"; this.styleClass = "userMenu";
} }
activateAdmin() { activateAdmin() {
console.log("activating admin");
this.menu = MENU.ADMIN; this.menu = MENU.ADMIN;
this.styleClass = "adminMenu"; this.styleClass = "adminMenu";
} }
......
<nav id="topNav"> <nav id="topNav">
<a class="topNavItem" id="userTopNav" routerLink="/user" routerLinkActive="active" i18n>Kävijänäkymä</a> <a class="topNavItem" id="userTopNav" routerLink="/index" routerLinkActive="active" i18n>Kävijänäkymä</a>
<a class="topNavItem" id="infoTopNav" routerLink="/info" routerLinkActive="active" [queryParams]="{p: 'useradmin/list.jsf'}" i18n>Infonäkymä</a> <a class="topNavItem" id="infoTopNav" routerLink="/old/info" routerLinkActive="active" [queryParams]="{p: 'useradmin/list.jsf'}" i18n>Infonäkymä</a>
<a class="topNavItem" id="adminTopNav" routerLink="/admin" routerLinkActive="active" i18n>Ylläpitonäkymä</a> <a class="topNavItem" id="adminTopNav" routerLink="/old/admin" routerLinkActive="active" [queryParams]="{p: 'product/list.jsf'}" i18n>Ylläpitonäkymä</a>
</nav> </nav>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!