Skip to content

Commit

Permalink
add bread crump
Browse files Browse the repository at this point in the history
  • Loading branch information
Arminmow committed Aug 24, 2024
1 parent 8188d1e commit 833d8a6
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Routes } from '@angular/router';
// import { AuthComponent } from './page/auth/auth.component';
import { DashboardComponent } from './page/dashboard/dashboard.component';
import { GraphComponent } from './page/graph/graph/graph.component';
import { ProfileComponent } from './components/profile/profile.component';
Expand Down
8 changes: 8 additions & 0 deletions src/app/components/bread-crump/bread-crump.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<nz-breadcrumb>
<nz-breadcrumb-item>
<a routerLink="/">Home</a>
</nz-breadcrumb-item>
<nz-breadcrumb-item *ngFor="let breadcrumb of breadcrumbs">
<a [routerLink]="breadcrumb.url">{{ breadcrumb.label }}</a>
</nz-breadcrumb-item>
</nz-breadcrumb>
Empty file.
23 changes: 23 additions & 0 deletions src/app/components/bread-crump/bread-crump.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { BreadCrumpComponent } from './bread-crump.component';

describe('BreadCrumpComponent', () => {
let component: BreadCrumpComponent;
let fixture: ComponentFixture<BreadCrumpComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [BreadCrumpComponent]
})
.compileComponents();

fixture = TestBed.createComponent(BreadCrumpComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
42 changes: 42 additions & 0 deletions src/app/components/bread-crump/bread-crump.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { NgFor, NgIf } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, NavigationEnd, Router, RouterLink } from '@angular/router';
import { NzBreadCrumbComponent, NzBreadCrumbItemComponent } from 'ng-zorro-antd/breadcrumb';
import { filter } from 'rxjs';

@Component({
selector: 'app-bread-crump',
standalone: true,
imports: [NzBreadCrumbComponent, NzBreadCrumbItemComponent, NgIf, NgFor, RouterLink],
templateUrl: './bread-crump.component.html',
styleUrl: './bread-crump.component.scss',
})
export class BreadCrumpComponent implements OnInit {
breadcrumbs: Array<{label: string, url: string}> = [];

constructor(private router: Router) {}

ngOnInit() {
this.router.events.pipe(
filter(event => event instanceof NavigationEnd)
).subscribe(() => {
this.generateBreadcrumbs();
});

this.generateBreadcrumbs();
}

private generateBreadcrumbs() {
const urlParts = this.router.url.split('/').filter(part => part);
this.breadcrumbs = urlParts.map((part, index) => {
const url = '/' + urlParts.slice(0, index + 1).join('/');
const label = this.formatLabel(part);
return { label, url };
});
}

private formatLabel(part: string): string {
part = part.split('?')[0];
return part.charAt(0).toUpperCase() + part.slice(1).replace(/-/g, ' ');
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div class="edit-user-container" >
<app-bread-crump></app-bread-crump>
<ng-container *ngIf="userData">
<app-edit-profile [userData]="userData"></app-edit-profile>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { PermisionsService } from '../../../services/permisisons/permisions.serv
import { EditRoleComponent } from '../edit-role/edit-role.component';
import { ActivatedRoute } from '@angular/router';
import { NgIf } from '@angular/common';
import { BreadCrumpComponent } from "../../bread-crump/bread-crump.component";

@Component({
selector: 'app-edit-user',
standalone: true,
imports: [EditProfileComponent, EditPasswordComponent, EditRoleComponent, NgIf],
imports: [EditProfileComponent, EditPasswordComponent, EditRoleComponent, NgIf, BreadCrumpComponent],
templateUrl: './edit-user.component.html',
styleUrl: './edit-user.component.scss',
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

<div class="container">
<app-bread-crump></app-bread-crump>
<div class="container__description">
<h1 class="container__description__title">Manage Users</h1>
<p class="container__description__text">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { UserService } from '../../../services/user/user.service';
import { NotificationService } from '../../../services/notification/notification.service';
import { Router } from '@angular/router';
import { NzTagComponent } from 'ng-zorro-antd/tag';
import { BreadCrumpComponent } from "../../bread-crump/bread-crump.component";

@Component({
selector: 'app-users-table',
Expand All @@ -24,7 +25,8 @@ import { NzTagComponent } from 'ng-zorro-antd/tag';
AddUserComponent,
NzPaginationComponent,
NzTagComponent,
],
BreadCrumpComponent
],
templateUrl: './users-table.component.html',
styleUrl: './users-table.component.scss',
})
Expand Down

0 comments on commit 833d8a6

Please sign in to comment.