-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refact: modifie le sidemenu pour qu'il puisse inclure des collapsibles
- Loading branch information
1 parent
e239b79
commit 6475a28
Showing
4 changed files
with
103 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 53 additions & 9 deletions
62
frontend-implicaction/src/app/shared/components/sidemenu/sidemenu.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,62 @@ | ||
<ul class="list-group list-group-flush py-2"> | ||
<ng-container *ngFor="let menuItem of menuItems"> | ||
<li class="list-group-item"> | ||
<a | ||
[routerLinkActive]="'active'" | ||
[routerLink]="menuItem.routerLink" | ||
[queryParams]="menuItem.queryParams" | ||
[routerLinkActiveOptions]="menuItem.routerLinkActiveOptions" | ||
> | ||
<li class="list-group-item nav-item"> | ||
<ng-container *ngIf="!menuItem.items; else templateCollapsable"> | ||
<a | ||
role="button" | ||
class="nav-link" | ||
[routerLinkActive]="'active'" | ||
[routerLink]="menuItem.routerLink" | ||
[queryParams]="menuItem.queryParams" | ||
[routerLinkActiveOptions]="menuItem.routerLinkActiveOptions" | ||
> | ||
<span> | ||
<i *ngIf="menuItem.icon" [class]="menuItem.icon"></i> {{menuItem.label}} | ||
</span> | ||
|
||
<span *ngIf="menuItem.badge" class="badge bg-primary rounded-pill me-3">{{menuItem.badge}}</span> | ||
</a> | ||
<span *ngIf="menuItem.badge" class="badge bg-primary rounded-pill me-3">{{menuItem.badge}}</span> | ||
</a> | ||
</ng-container> | ||
|
||
<ng-template #templateCollapsable> | ||
<a | ||
class="nav-link cursor-pointer" | ||
data-bs-target="#collapsed-nav" | ||
data-bs-toggle="collapse" | ||
aria-expanded="false" | ||
(click)="menuItem.expanded = !menuItem.expanded" | ||
[ngClass]="{'collapsed': !menuItem.expanded, 'expanded active': menuItem.expanded}" | ||
> | ||
<span> | ||
<i *ngIf="menuItem.icon" [class]="menuItem.icon"></i> {{menuItem.label}} | ||
</span> | ||
</a> | ||
|
||
<ul | ||
id="collapsed-nav" | ||
class="nav-content" | ||
data-bs-parent="#sidebar-nav" | ||
[ngClass]="{'collapse': !menuItem.expanded}" | ||
> | ||
<ng-container *ngFor="let item of menuItem.items"> | ||
<li routerLinkActive="active"> | ||
<a | ||
role="button" | ||
class="nav-link" | ||
[routerLink]="item.routerLink" | ||
[queryParams]="item.queryParams" | ||
> | ||
<span> | ||
<i *ngIf="item.icon" [class]="item.icon"></i> {{item.label}} | ||
</span> | ||
|
||
<span *ngIf="item.badge" class="badge bg-primary rounded-pill me-3">{{item.badge}}</span> | ||
</a> | ||
</li> | ||
</ng-container> | ||
</ul> | ||
</ng-template> | ||
|
||
</li> | ||
</ng-container> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 18 additions & 2 deletions
20
frontend-implicaction/src/app/shared/components/sidemenu/sidemenu.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
import {Component, Input} from '@angular/core'; | ||
import {Component, Input, OnInit} from '@angular/core'; | ||
import {MenuItem} from "primeng/api"; | ||
import {NavigationEnd, Router} from "@angular/router"; | ||
|
||
@Component({ | ||
selector: 'app-sidemenu', | ||
templateUrl: './sidemenu.component.html', | ||
styleUrls: ['./sidemenu.component.scss'] | ||
}) | ||
export class SidemenuComponent { | ||
export class SidemenuComponent implements OnInit { | ||
|
||
@Input() menuItems: MenuItem[]; | ||
|
||
constructor(private router: Router) { | ||
} | ||
|
||
ngOnInit(): void { | ||
this.router.events.subscribe(routerEvent => { | ||
if (routerEvent instanceof NavigationEnd) { | ||
// Get your url | ||
console.log(routerEvent.url); | ||
console.log(this.menuItems.find(item => !!item.items && item.items.find(i => i.url && this.router.isActive(i.url, false)))); | ||
} | ||
}); | ||
|
||
|
||
} | ||
|
||
} |