diff --git a/src/app/app.module.ts b/src/app/app.module.ts index e4b6d45e2..07332a1ef 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -35,8 +35,8 @@ import { AppRoutingModule } from './app-routing.module'; NgxChartsModule, CoreModule, SharedModule, - NavigationModule, HomeModule, + NavigationModule, AboutModule, LoginModule, ClientsModule, diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index 0467ce164..796674551 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -53,6 +53,7 @@ import { ShellComponent } from './shell/shell.component'; import { SidenavComponent } from './shell/sidenav/sidenav.component'; import { ToolbarComponent } from './shell/toolbar/toolbar.component'; import { ContentComponent } from './shell/content/content.component'; +import { BreadcrumbComponent } from './shell/breadcrumb/breadcrumb.component'; @NgModule({ imports: [ @@ -100,7 +101,8 @@ import { ContentComponent } from './shell/content/content.component'; ShellComponent, SidenavComponent, ToolbarComponent, - ContentComponent + ContentComponent, + BreadcrumbComponent ], exports: [ LayoutModule, diff --git a/src/app/core/shell/breadcrumb/breadcrumb.component.html b/src/app/core/shell/breadcrumb/breadcrumb.component.html new file mode 100644 index 000000000..7d09da8c1 --- /dev/null +++ b/src/app/core/shell/breadcrumb/breadcrumb.component.html @@ -0,0 +1,12 @@ + diff --git a/src/app/core/shell/breadcrumb/breadcrumb.component.scss b/src/app/core/shell/breadcrumb/breadcrumb.component.scss new file mode 100644 index 000000000..41060f241 --- /dev/null +++ b/src/app/core/shell/breadcrumb/breadcrumb.component.scss @@ -0,0 +1,4 @@ +li { + display: inline; + list-style-type: none; +} diff --git a/src/app/core/shell/breadcrumb/breadcrumb.component.spec.ts b/src/app/core/shell/breadcrumb/breadcrumb.component.spec.ts new file mode 100644 index 000000000..1fddbf835 --- /dev/null +++ b/src/app/core/shell/breadcrumb/breadcrumb.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { BreadcrumbComponent } from './breadcrumb.component'; + +describe('BreadcrumbComponent', () => { + let component: BreadcrumbComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ BreadcrumbComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(BreadcrumbComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/core/shell/breadcrumb/breadcrumb.component.ts b/src/app/core/shell/breadcrumb/breadcrumb.component.ts new file mode 100644 index 000000000..eb1b86d61 --- /dev/null +++ b/src/app/core/shell/breadcrumb/breadcrumb.component.ts @@ -0,0 +1,69 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Router, NavigationEnd } from '@angular/router'; + +import { filter } from 'rxjs/operators'; + +import { Breadcrumb } from './breadcrumb.model'; + +@Component({ + selector: 'mifosx-breadcrumb', + templateUrl: './breadcrumb.component.html', + styleUrls: ['./breadcrumb.component.scss'] +}) +export class BreadcrumbComponent implements OnInit { + + breadcrumbs: Breadcrumb[]; + + constructor(private activatedRoute: ActivatedRoute, + private router: Router) { + this.generateBreadcrumbs(); + } + + generateBreadcrumbs() { + const routeDataBreadcrumb = 'breadcrumb'; + const routeParamBreadcrumb = 'routeParamBreadcrumb'; + const onNavigationEnd = this.router.events.pipe(filter(event => event instanceof NavigationEnd)); + + onNavigationEnd.subscribe(() => { + this.breadcrumbs = []; + let currentRoute = this.activatedRoute.root; + let url = ''; + + while (currentRoute.children.length > 0) { + const childrenRoutes = currentRoute.children; + let breadcrumbLabel = 'Home'; + + childrenRoutes.forEach(route => { + currentRoute = route; + if (route.outlet !== 'primary') { + return; + } + const hasData = (route.routeConfig && route.routeConfig.data); + if (hasData) { + if (route.snapshot.data.hasOwnProperty(routeParamBreadcrumb)) { + breadcrumbLabel = route.snapshot.params[route.snapshot.data[routeParamBreadcrumb]]; + } else if (route.snapshot.data.hasOwnProperty(routeDataBreadcrumb)) { + breadcrumbLabel = route.snapshot.data[routeDataBreadcrumb]; + } + } + + const routeURL = route.snapshot.url.map(segment => segment.path).join('/'); + url += `/${routeURL}`; + + const breadcrumb: Breadcrumb = { + label: breadcrumbLabel, + url: url + }; + + if (breadcrumb.url !== '//home') { + this.breadcrumbs.push(breadcrumb); + } + }); + } + }); + } + + ngOnInit() { + } + +} diff --git a/src/app/core/shell/breadcrumb/breadcrumb.model.ts b/src/app/core/shell/breadcrumb/breadcrumb.model.ts new file mode 100644 index 000000000..e88fdb43e --- /dev/null +++ b/src/app/core/shell/breadcrumb/breadcrumb.model.ts @@ -0,0 +1,4 @@ +export interface Breadcrumb { + label: string; + url: string; +} diff --git a/src/app/core/shell/content/content.component.html b/src/app/core/shell/content/content.component.html index 45a39fd1f..0680b43f9 100644 --- a/src/app/core/shell/content/content.component.html +++ b/src/app/core/shell/content/content.component.html @@ -1,2 +1 @@ - diff --git a/src/app/core/shell/shell.component.html b/src/app/core/shell/shell.component.html index e8569d35d..8d750a5de 100644 --- a/src/app/core/shell/shell.component.html +++ b/src/app/core/shell/shell.component.html @@ -19,6 +19,7 @@ + diff --git a/src/app/core/shell/toolbar/toolbar.component.html b/src/app/core/shell/toolbar/toolbar.component.html index a51361109..1654a7b7e 100644 --- a/src/app/core/shell/toolbar/toolbar.component.html +++ b/src/app/core/shell/toolbar/toolbar.component.html @@ -108,7 +108,7 @@ - + diff --git a/src/app/self-service/self-service-routing.module.ts b/src/app/self-service/self-service-routing.module.ts index 1cb5aa78c..118cbbcc2 100644 --- a/src/app/self-service/self-service-routing.module.ts +++ b/src/app/self-service/self-service-routing.module.ts @@ -11,17 +11,17 @@ const routes: Routes = [ { path: 'self-service/users', component: UserManagementComponent, - data: { title: extract('Self Service Users') } + data: { title: extract('Self Service Users'), breadcrumb: 'Self Service Users' } }, { path: 'self-service/users/create', component: CreateUserComponent, - data: { title: extract('Create Self Service User') } + data: { title: extract('Create Self Service User'), breadcrumb: 'Create' } }, { path: 'self-service/users/view', component: ViewUserComponent, - data: { title: extract('View Self Service User') } + data: { title: extract('View Self Service User'), breadcrumb: 'View' }, } ]) ]; diff --git a/src/app/self-service/user-management/user-management.component.html b/src/app/self-service/user-management/user-management.component.html index c97e1d986..0406736aa 100644 --- a/src/app/self-service/user-management/user-management.component.html +++ b/src/app/self-service/user-management/user-management.component.html @@ -1,3 +1,4 @@ +SELF SERVICE USER MANAGEMENT